pluginCore
Class Plugin

java.lang.Object
  extended by java.lang.Thread
      extended by pluginCore.Plugin
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
AdminPlugin

public abstract class Plugin
extends Thread

The base class for all plug-ins that are to be loaded in the PluginCore. Plugin saveing and loading. The plugin must have a number of abstract methods written that will allow it to operate with other plugins and the plugin core. int send( Message messIn) This method receves the messages sent from other plugins, if your plugin does not intend to receve messages it can safely return error (-1) on this. boolean init( CoreHandler coreIn ) void run() void shutdown() Object[] savePluginState( ) boolean setPluginState( Object[] stateVec )


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected  boolean DEBUG
          Enable or disables debugging.
protected  CoreHandler frameworkCore
          The stub used to make calls back to the PluginCore.
protected  int pluginID
          The Id of this plug-in.
protected  String pluginName
          The name of this plug-in.
protected  boolean TRACE
          Enable or disable the traceing.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Plugin()
          Nice empty constructor.
 
Method Summary
 boolean debugStatus()
          Identifies if Debugging is enabled for this plug-in.
 int getID()
          Gets the plugin's Id.
 String getPluginName()
          Gets the name of the plug-in.
 boolean loadNewState(Object[] stateIn, CoreHandler coreIn)
          Sets the plugin's state with a object array from a previous plugin.
protected  void printDebug(String debugMsg)
          This will place debugging output in your program, turn on or off by setting DEBUG true/false.
protected  void printError(String errorMsg)
          This will allways print out the errorMsg to System.err
protected  void printTrace(String traceString)
          This can be turned off by setting TRACE to false, but will print the class name, plus the included method name.
abstract  int receive(Message msgIn)
          Hands a message to the plug-in from another plug-in via the PluginCore.
abstract  void run()
          The main loop of the plug-in.
 boolean safeJoin()
          Calls join and returns true if it was successful, false otherwise.
 boolean safeJoin(int timer)
          Calls join and returns true if it was successful, false otherwise.
 boolean safeSleep(int timeToSleep)
          Sleeps the thread for timeToSleep milliseconds.
abstract  Object[] savePluginState()
          Saves the current state of the object in a Vector.
 void setCoreHandeler(CoreHandler coreIn)
          Saves the core handler to the frameworkCore variable.
 void setID(int id)
          Sets the plug-in id for this plug-in.
abstract  boolean setPluginState(Object[] stateVec)
          Sets the current state of the object using a vector of objects.
abstract  void shutdown()
          Called by the PluginCore, allows plug-ins to exit in a tidy and controlled manner.
 String toString()
          Gets the String value of the plug-in.
 
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, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

frameworkCore

protected transient CoreHandler frameworkCore
The stub used to make calls back to the PluginCore.


pluginID

protected int pluginID
The Id of this plug-in.


DEBUG

protected boolean DEBUG
Enable or disables debugging.


TRACE

protected boolean TRACE
Enable or disable the traceing.


pluginName

protected String pluginName
The name of this plug-in.

Constructor Detail

Plugin

public Plugin()
Nice empty constructor.

Method Detail

run

public abstract void run()
The main loop of the plug-in.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

shutdown

public abstract void shutdown()
Called by the PluginCore, allows plug-ins to exit in a tidy and controlled manner. This call is followed by a safeJoin() call.


receive

public abstract int receive(Message msgIn)
Hands a message to the plug-in from another plug-in via the PluginCore.

Parameters:
msgIn - The message that is being delivered.
Returns:
1 on success, -1 on failure.

savePluginState

public abstract Object[] savePluginState()
Saves the current state of the object in a Vector. The order that objects are stored is very important to this and it is expected that the programer puts the fully qualified name of the originateing object as the frist field in the Vector so that other plugins can quickly identify the source of the data.

Returns:
The data from inside of the plugin held in a vector.

setPluginState

public abstract boolean setPluginState(Object[] stateVec)
Sets the current state of the object using a vector of objects. It is the job of the programer to properly interpert and use the data that is handed in from the vector. According to protocol it is proper to put the object name as the first field in the vector so that a later object can quickly idnetify how to deal with the data in the vector.

Parameters:
stateVec - This Vector object will hold the objects to load from.
Returns:
True on sucess, false otherwise.

setID

public void setID(int id)
Sets the plug-in id for this plug-in.

Parameters:
id - The new Id.

setCoreHandeler

public void setCoreHandeler(CoreHandler coreIn)
Saves the core handler to the frameworkCore variable.

Parameters:
coreIn - The core that is to be saved.

getID

public int getID()
Gets the plugin's Id.

Returns:
The plugin's Id.

loadNewState

public boolean loadNewState(Object[] stateIn,
                            CoreHandler coreIn)
                     throws IOException
Sets the plugin's state with a object array from a previous plugin.

Parameters:
stateIn - The object array with the saved state.
coreIn - The CoreHandler from the running core.
Returns:
True on sucess, else false.
Throws:
IOException

safeJoin

public boolean safeJoin()
Calls join and returns true if it was successful, false otherwise.

Returns:
True if successful, else false.

safeSleep

public boolean safeSleep(int timeToSleep)
Sleeps the thread for timeToSleep milliseconds.

Returns:
True if successful, else false.

debugStatus

public boolean debugStatus()
Identifies if Debugging is enabled for this plug-in.

Returns:
True if debugging is enabled, else false.

safeJoin

public boolean safeJoin(int timer)
Calls join and returns true if it was successful, false otherwise.

Parameters:
timer - The number of milliseconds to wait before forceing shutdown.
Returns:
True if successful, else false.

getPluginName

public String getPluginName()
Gets the name of the plug-in.

Returns:
The String name of the plug-in.

printTrace

protected void printTrace(String traceString)
This can be turned off by setting TRACE to false, but will print the class name, plus the included method name.

Parameters:
traceString - This is also printed with the trace call.

printDebug

protected void printDebug(String debugMsg)
This will place debugging output in your program, turn on or off by setting DEBUG true/false.

Parameters:
debugMsg - This is the message to be printed with the debug.

printError

protected void printError(String errorMsg)
This will allways print out the errorMsg to System.err

Parameters:
errorMsg - The error to print.

toString

public String toString()
Gets the String value of the plug-in.

Overrides:
toString in class Thread
Returns:
The String value of the plug-in.