com.webhydra.slug.process
Class AbstractProcessRunner

java.lang.Object
  extended by com.webhydra.slug.process.AbstractSlugService
      extended by com.webhydra.slug.process.AbstractProcessRunner
All Implemented Interfaces:
ISlugRunner, ISlugService
Direct Known Subclasses:
UnlimitedProcessRunner

public abstract class AbstractProcessRunner
extends AbstractSlugService
implements ISlugRunner

Abstract Scheduler of the SluggishProcesses.

Author:
rossen

Field Summary
protected  java.util.Map apl
          Active Process List (APL)
Holds map of sessions and a map of their running processes.
 
Fields inherited from class com.webhydra.slug.process.AbstractSlugService
setup
 
Constructor Summary
protected AbstractProcessRunner()
          Creates a new instance of AbstractProcessRunner
 
Method Summary
 SluggishProcess cancelProcess(java.lang.String session, java.lang.String pid)
          Cancel process Proces is signalled using SluggishProcess.cancel() and is removed from Active Process List (APL).
 ProcessStatus checkProcess(java.lang.String session, java.lang.String pid)
          Checks process status
 void cleanSession(java.lang.String session)
          Remove all processes for specified session.
 void clear()
          Cancels all running processes and removes them from this instance.
 SluggishProcess consumeProcess(java.lang.String session, java.lang.String pid)
          Remove specified process from the Active Process List (APL).
 long count()
          Returns estimated total number of sluggish processes in this runner instance.
 void prepare()
          Initialize the APL map
 void release()
          Default implementation.
protected  java.lang.String save(SluggishProcess proc, java.lang.String session)
          Save a new SluggishProcess in to the Active Process List (APL).
 
Methods inherited from class com.webhydra.slug.process.AbstractSlugService
getParams, init
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.webhydra.slug.process.ISlugRunner
activeCount, add
 
Methods inherited from interface com.webhydra.slug.process.ISlugService
init
 

Field Detail

apl

protected java.util.Map apl
Active Process List (APL)
Holds map of sessions and a map of their running processes. The user's session is used as a key to the a map of PIDs and the corresponding SluggishProces.

Constructor Detail

AbstractProcessRunner

protected AbstractProcessRunner()
Creates a new instance of AbstractProcessRunner

Method Detail

checkProcess

public ProcessStatus checkProcess(java.lang.String session,
                                  java.lang.String pid)
Checks process status

Specified by:
checkProcess in interface ISlugRunner
Parameters:
session - current user session ID.
pid - running Process ID (PID)
Returns:
current porcess status if process with provided PID exist in current session. If no process can be found then null is returned.

consumeProcess

public SluggishProcess consumeProcess(java.lang.String session,
                                      java.lang.String pid)
Remove specified process from the Active Process List (APL). If this is the last process for provided session then this session is removed from APL too.

Specified by:
consumeProcess in interface ISlugRunner
Parameters:
session - current user session ID.
pid - Process ID (PID) to be removed.
Returns:
removed process or null if PID is not found.

cancelProcess

public SluggishProcess cancelProcess(java.lang.String session,
                                     java.lang.String pid)
Cancel process Proces is signalled using SluggishProcess.cancel() and is removed from Active Process List (APL).

Specified by:
cancelProcess in interface ISlugRunner
Parameters:
session - current user session ID.
pid - Process ID (PID) to be canceled.
Returns:
process or null if PID is not found.

cleanSession

public void cleanSession(java.lang.String session)
Remove all processes for specified session.

Specified by:
cleanSession in interface ISlugRunner
Parameters:
session - user's session ID to cleanup.

save

protected java.lang.String save(SluggishProcess proc,
                                java.lang.String session)
                         throws java.security.InvalidParameterException
Save a new SluggishProcess in to the Active Process List (APL).

Parameters:
proc - process to be executed.
session - current user session ID.
Returns:
Proccess ID (PID) assigned to provided process/session pair.
Throws:
java.security.InvalidParameterException - if any of the provided parameters is null.

count

public long count()
Returns estimated total number of sluggish processes in this runner instance. Since the execution of this method may take considerable time it is not synchronized and as a result the returned count is an estimate and may vary from the real process count at the moment. Another factor is the underlaying Map implementation which size() method returns Integer.MAX_VALUE when it has more than Integer.MAX_VALUE elements.

Specified by:
count in interface ISlugRunner
Returns:
the estimated count of all running and completed processes accomodated in this instance.
See Also:
Map.size()

clear

public void clear()
Cancels all running processes and removes them from this instance.

Specified by:
clear in interface ISlugRunner

release

public void release()
Default implementation. Si,pyt invoces clean().

Specified by:
release in interface ISlugService
Overrides:
release in class AbstractSlugService
See Also:
clear()

prepare

public void prepare()
             throws SlugInitializationException
Initialize the APL map

Specified by:
prepare in interface ISlugService
Overrides:
prepare in class AbstractSlugService
Throws:
SlugInitializationException - not really thrown