pluginCore
Class PluginCore

java.lang.Object
  extended by pluginCore.PluginCore

public class PluginCore
extends Object

The PluginCore is the main object in the plug-in architecture. It handles the plug-ins, starting, stopping, and message passing among them. To run: myComputer$ java PluginCore pluginName


Nested Class Summary
private  class PluginCore.PluginListElement
          This is a single element that conains a plugin and a stable/unstable lock to controll acess to the plugin.
private  class PluginCore.PluginLoader
          The implementation of ClassLoader that is used by the PluginCore.
 
Field Summary
private static boolean DEBUG
          Turns on or off debugging output.
private static boolean ERROR
          Turns on or off error output.
private static int LIST_GROWTH_SIZE
          This is the number of elements that the list grows by each time it runs out of space.
private static int LIST_STARTING_SIZE
          This is the size of the PluginListElement list when the program starts.
private  int listSize
          Expand defines the number of slots the pluginList starts with and by how many it grows when it is full
private  PluginCore.PluginListElement[] pluginList
          This array contains the plug-ins that are currently loaded and running as their own threads
private static String pluginPrefix
           
 
Constructor Summary
PluginCore()
          Initializes the PluginCore.
 
Method Summary
private  void growList()
          Increase the size of pluginList by the ammount LIST_GROWTH_SIZE.
private  int insertPlugin(Plugin newPlug)
          Adds a plug-in into the list of active plug-ins.
 boolean isLocked(int id)
          Checks if a plugin has a unstable lock held on it.
private  boolean isValidId(int plugId)
          Checks to see if the plugin Id given is a valid address in the plugin list.
 String[] listLoadedPlugins()
          Lists the plug-ins that are currently loaded in the system.
private  void loadAdmin()
           
 int loadPlugin(String pluginName)
          Loads a new plug-in into the system and starts its thread running.
 int loadPlugin(String pluginName, Object[] stateIn)
          Loads a new plug-in into the system and initalizes it with the data from a previous plugin, that is contained in the stateIn array.
static void main(String[] args)
          The main function.
 int pluginIDRequest(String plugin)
          Gets the Id of a plug-in, this Id can then be used to send messages to that plug-in.
 int postMessage(Message messIn)
          Requests that the core send the message 'messIn' to the plug-in with the same Id as the destID field in the Message object.
protected  void printDebug(String debugMsg)
          This will print out an debug mesage identifying it as coming from the PluginCore.
protected  void printError(String errorMsg)
          This will print out an error message identifying it as coming from the PluginCore.
private static void printUseage()
          Prints the useage command to the command line when poor input is given.
 Object[] savePlugin(int pluginId)
          This will lock a plugin, stop it, reduce the state to a byte aray and return that array.
 void shutdown()
          Stops the system running, first calls the 'shutdown()' call for all loaded plug-ins then calls a join() on them before finally 'exiting itself.
private  boolean shutdownAndJoinPlugin(int plugId)
          This will shut down a plugin and join the thread.
 boolean unloadPlugin(int plugId)
          Removes a plugin from the running PluginCore.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pluginPrefix

private static final String pluginPrefix
See Also:
Constant Field Values

LIST_STARTING_SIZE

private static final int LIST_STARTING_SIZE
This is the size of the PluginListElement list when the program starts.

See Also:
Constant Field Values

LIST_GROWTH_SIZE

private static final int LIST_GROWTH_SIZE
This is the number of elements that the list grows by each time it runs out of space.

See Also:
Constant Field Values

DEBUG

private static final boolean DEBUG
Turns on or off debugging output.

See Also:
Constant Field Values

ERROR

private static final boolean ERROR
Turns on or off error output.

See Also:
Constant Field Values

pluginList

private PluginCore.PluginListElement[] pluginList
This array contains the plug-ins that are currently loaded and running as their own threads


listSize

private int listSize
Expand defines the number of slots the pluginList starts with and by how many it grows when it is full

Constructor Detail

PluginCore

public PluginCore()
Initializes the PluginCore.

Method Detail

growList

private void growList()
Increase the size of pluginList by the ammount LIST_GROWTH_SIZE.


loadPlugin

public int loadPlugin(String pluginName)
Loads a new plug-in into the system and starts its thread running.

Parameters:
pluginName - The full name of the object that you wish to load into the system.
Returns:
The plugin's Id is returned if successful and -1 is returned on failure.

loadPlugin

public int loadPlugin(String pluginName,
                      Object[] stateIn)
Loads a new plug-in into the system and initalizes it with the data from a previous plugin, that is contained in the stateIn array.

Parameters:
pluginName - The full name of the object that you wish to load into the system.
stateIn - The saved object array from the previous plugin.
Returns:
The plugin's Id is returned if successful and -1 is returned on failure.

insertPlugin

private int insertPlugin(Plugin newPlug)
Adds a plug-in into the list of active plug-ins.

Parameters:
newPlug - The plug-in to be added.
Returns:
The id of the plug-in on success or -1 on failure.

postMessage

public int postMessage(Message messIn)
Requests that the core send the message 'messIn' to the plug-in with the same Id as the destID field in the Message object. ToDo: This should really return true...

Parameters:
messIn - The message to be sent.
Returns:
Returns 1 on success and -1 on failure.

pluginIDRequest

public int pluginIDRequest(String plugin)
Gets the Id of a plug-in, this Id can then be used to send messages to that plug-in. If the plug-in is not already loaded then the system will attempt to load it, then return the ID.

Parameters:
plugin - The name of the plugin you are looking for, the PluginCore checks the field Plugin.pluginName.
Returns:
The Id of the plug-in, or a -1 on failure.

unloadPlugin

public boolean unloadPlugin(int plugId)
Removes a plugin from the running PluginCore. NOTE: This will not unload the plugin that called this that is kind of bad, but it will hang...

Parameters:
plugId - The Id of the plugin to remove.
Returns:
True on sucess, else false.

shutdownAndJoinPlugin

private boolean shutdownAndJoinPlugin(int plugId)
This will shut down a plugin and join the thread.

Parameters:
plugId - This is the id of the plugin to shutdown.
Returns:
True on sucess, else false.

isLocked

public boolean isLocked(int id)
Checks if a plugin has a unstable lock held on it.

Parameters:
id - The id of the plugin to ckeck.
Returns:
True if the plugin is locked, false if it is unlocked.

savePlugin

public Object[] savePlugin(int pluginId)
This will lock a plugin, stop it, reduce the state to a byte aray and return that array.

Parameters:
pluginId - The plugin to save.
Returns:
The state of the plugin in a byte array.

isValidId

private boolean isValidId(int plugId)
Checks to see if the plugin Id given is a valid address in the plugin list.

Parameters:
plugId - The id to check.
Returns:
True if the id is a valid address, else false.

shutdown

public void shutdown()
Stops the system running, first calls the 'shutdown()' call for all loaded plug-ins then calls a join() on them before finally 'exiting itself.


listLoadedPlugins

public String[] listLoadedPlugins()
Lists the plug-ins that are currently loaded in the system.

Returns:
A list of loaded plug-ins with newlines separating them.

loadAdmin

private void loadAdmin()

main

public static void main(String[] args)
The main function. This is where the magic happens.

Parameters:
args - Handed to the program on load.

printUseage

private static void printUseage()
Prints the useage command to the command line when poor input is given.


printDebug

protected void printDebug(String debugMsg)
This will print out an debug mesage identifying it as coming from the PluginCore.

Parameters:
debugMsg - This is the debug message.

printError

protected void printError(String errorMsg)
This will print out an error message identifying it as coming from the PluginCore.

Parameters:
debugMsg - This is the error message.