things.thinger.kernel
Class ThingsProcess

java.lang.Object
  extended by java.lang.Thread
      extended by things.thinger.kernel.ThingsProcess
All Implemented Interfaces:
java.lang.Runnable, Verbose, ControlInterface, ProcessInterface, ResourceListener
Direct Known Subclasses:
HttpToolServiceThread, KernalBasic_THINGProcessWrapper, KernelBasicBase, Service

public abstract class ThingsProcess
extends java.lang.Thread
implements ProcessInterface, ControlInterface, ResourceListener, Verbose

The abstract base class for all manageable processes. All processes are interruptible, so be sure they catch it.

You will need to implement ProcessInterface and Verbose interfaces.

You should fix() the process first. Then init() it (this will start the thread). Then release() it. At that point, normal state management will work.

Version:
1.0

Version History

 EPG - Adapted - 6 SEP 04
 EPG - Added control interface - 26 JUN 05
 
Author:
Erich P. Gatejen

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static java.lang.String DEFAULT_NAME
          Constants
protected  RESULT internalResult
          The internal result.
protected  StringPoster myPostLogger
          Verbose poster for just Process internal action logging.
 SystemSuperInterface ssi
          System Super Interface
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ThingsProcess()
          Default Constructor.
 
Method Summary
 void acceptHalt()
          This will accept the halt if a halt is pending.
 void acceptPause()
          This thread will accept a pause request.
abstract  void constructThingsProcess()
          Complete construction.
abstract  void destructThingsProcess()
          Destroy.
abstract  void executeThingsProcess()
          This is the entry point for the actual processing.
protected  void finalize()
          finalizer.
 void fix(WhoAmI you)
          Fix the process to an ID.
 void forceFinalize()
          Force finalization.
 void forceHalt()
          Force halt.
 ThingsState getCurrentState()
          Get the state.
 int getCurrentStateNumeric()
          Get the state as a numeric.
 WhoAmI getProcessId()
           
abstract  java.lang.String getProcessName()
          Get process name.
 RESULT getResult()
          Get the latest result.
 long getStartTime()
          Get start time from epoch.
 ThingsState getThingsState()
          Get the process state.
 void init(SystemSuperInterface theSSI)
          Complete initialization.
 boolean isVerbose()
          Is it set to verbose?
 void release()
          Release the process for execution.
 void releasePause()
          Allow it to resume.
 void requestHalt()
          Request halt.
 boolean requestPause()
          Request that the process is paused.
 void run()
          RUN implementation.
 void screech(java.lang.String message)
          Post a verbose message if verbose mode is on.
 void verboseOff()
          Turn off the verbose mode.
 void verboseOn(StringPoster poster)
          Turn on the verbose mode.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface things.thinger.kernel.ResourceListener
getListenerId, resourceRevocation, resourceRevoked
 

Field Detail

DEFAULT_NAME

public static final java.lang.String DEFAULT_NAME
Constants

See Also:
Constant Field Values

ssi

public SystemSuperInterface ssi
System Super Interface

See Also:
SystemSuperInterface

myPostLogger

protected StringPoster myPostLogger
Verbose poster for just Process internal action logging.


internalResult

protected RESULT internalResult
The internal result. Subclasses can choose to change this, but otherwise it'll be INCONCLUSIVE.

Constructor Detail

ThingsProcess

public ThingsProcess()
Default Constructor.

Method Detail

executeThingsProcess

public abstract void executeThingsProcess()
                                   throws SystemException,
                                          java.lang.InterruptedException
This is the entry point for the actual processing. It's ok to let interrupted exceptions leave. It'll be the kernel or process that did it.

Throws:
SystemException
java.lang.InterruptedException

constructThingsProcess

public abstract void constructThingsProcess()
                                     throws SystemException
Complete construction. This will be called when the process is initialized.

Throws:
SystemException

destructThingsProcess

public abstract void destructThingsProcess()
                                    throws SystemException
Destroy. This will be called when the Process is finalizing.

Throws:
SystemException

getProcessName

public abstract java.lang.String getProcessName()
Get process name. It does not have to be a unique ID.

Specified by:
getProcessName in interface ProcessInterface
Returns:
the name as a String

fix

public final void fix(WhoAmI you)
               throws SystemException
Fix the process to an ID. This is the FIRST thing you should do. The init() will fail without it.

Parameters:
you - the kernel imposed ID. The underlying thread will be named by a String representation of this id.
Throws:
SystemException

init

public final void init(SystemSuperInterface theSSI)
                throws java.lang.Throwable
Complete initialization. It will chain the initialization to the constructThingsProcess() method. You must fix() the process first.

Parameters:
theSSI - a supersystem interface
Throws:
throwable
java.lang.Throwable

release

public final void release()
                   throws SystemException
Release the process for execution. It will blow up only if it hasn't been init()'d.

Throws:
SystemException

getStartTime

public final long getStartTime()
Get start time from epoch.

Returns:
Returns the start time.

getProcessId

public final WhoAmI getProcessId()
Specified by:
getProcessId in interface ProcessInterface
Returns:
Returns the ID.

getThingsState

public ThingsState getThingsState()
                           throws SystemException
Get the process state.

Specified by:
getThingsState in interface ProcessInterface
Returns:
the state
Throws:
SystemException

requestPause

public boolean requestPause()
                     throws SystemException
Request that the process is paused. It will return true if it is already paused (but not if a request is just pending). The request will be ignored if the current state cannot be paused. Only a RUNNING process will respond to a pause. There is no count on this.

Specified by:
requestPause in interface ProcessInterface
Returns:
true if the process is already paused, else false
Throws:
SystemException

releasePause

public void releasePause()
                  throws SystemException
Allow it to resume. If the process is not in a state that can be run, it will ignore this release. It will not override a halt request.

Specified by:
releasePause in interface ProcessInterface
Throws:
SystemException

requestHalt

public void requestHalt()
                 throws SystemException
Request halt. It will interrupt a pause. It will ultimately cause a PANIC to propagate through the process user. If the process isn't running or paused, it will be ignored.

Specified by:
requestHalt in interface ProcessInterface
Throws:
SystemException

forceHalt

public void forceHalt()
               throws SystemException
Force halt.

Specified by:
forceHalt in interface ProcessInterface
Throws:
SystemException

getResult

public RESULT getResult()
                 throws ThingsException
Get the latest result. Overrides the basic implementation in the ThingsProcess.

Specified by:
getResult in interface ProcessInterface
Returns:
the latest or the last result for the thread. It is completely up to the implementation how to implement this.
Throws:
ThingsException - for whatever reason. It may come from the THING itself.

acceptPause

public void acceptPause()
                 throws SystemException
This thread will accept a pause request.

Specified by:
acceptPause in interface ControlInterface
Throws:
SystemException

acceptHalt

public void acceptHalt()
                throws SystemException
This will accept the halt if a halt is pending. THIS WILL THROW A SystemException.PANIC_PROCESS_RESPONDING_TO_HALT_OK if the halt is accepted!

Specified by:
acceptHalt in interface ControlInterface
Throws:
SystemException

getCurrentState

public ThingsState getCurrentState()
Get the state.

Returns:
Returns the state.

getCurrentStateNumeric

public int getCurrentStateNumeric()
Get the state as a numeric.

Returns:
Returns the state numeric.

run

public void run()
RUN implementation. Do not call directly. There are two phases--init and run.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

verboseOn

public void verboseOn(StringPoster poster)
               throws ThingsException
Turn on the verbose mode. It will test the poster and will throw a ThingsException if it has a problem.

Specified by:
verboseOn in interface Verbose
Parameters:
poster - StringPoster where to put the debug info
Throws:
ThingsException

verboseOff

public void verboseOff()
Turn off the verbose mode.

Specified by:
verboseOff in interface Verbose

screech

public void screech(java.lang.String message)
Post a verbose message if verbose mode is on. It will never throw an exception. The implementation may find a way to report exceptions.

Specified by:
screech in interface Verbose
Parameters:
message - The message.

isVerbose

public boolean isVerbose()
Is it set to verbose?

Specified by:
isVerbose in interface Verbose
Returns:
true if it is verbose, otherwise false.

forceFinalize

public void forceFinalize()
                   throws SystemException
Force finalization. This should be done by

Throws:
SystemException

finalize

protected void finalize()
                 throws java.lang.Throwable
finalizer.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable


Things.