com.javageeks.gjas
Class LocalServerManager

java.lang.Object
  |
  +--com.javageeks.gjas.LocalServerManager
All Implemented Interfaces:
IServerManager

public class LocalServerManager
extends java.lang.Object
implements IServerManager

This class presents a local-to-this-JVM-only ServerManager. It is useful for localized testing, and for loading/running Services within their own JVM. Note that use of this ServerManager does not inherently prevent object-sharing or prevent inter-JVM communication of Services, since it does nothing to block sockets or any other IPC communication. For example, nothing prevents us from running a LocalServerManager with a SocketControlService that allows us to remotely (through the SocketControlService) start, stop and otherwise control the Services listed within this JVM.

Note that LocalServerManager, by default, uses the local (default) ClassLoader scheme to load and find its classes, so any classes loaded will need to be found on the CLASSPATH and/or as an extension.


Constructor Summary
LocalServerManager()
           
 
Method Summary
 IServer addService(Service svc, ConfigProperties args)
          Add the loaded Service to the list of Servers and start it
 IServer addService(java.lang.String svcName, ConfigProperties args)
          Add a Service by name; this presumes that the Service has already been deployed to this ServerManager via the deployService method.
 void deployService(java.lang.String serviceName, ClassLoaderStrategy strategy)
          Place a ClassLoaderStrategy into the service-loaders map, so subsequent addService() calls can use the loader to retrieve the necessary code.
 void error(java.lang.Exception ex)
           
 void error(java.lang.String msg)
           
 java.io.OutputStream getErrStream()
          Return the OutputStream used for writing errors.
 java.io.OutputStream getLogStream()
          Return the OutputStream used for writing to the log.
 IServer getService(java.lang.String instanceID)
          Obtain a reference to a Server instance by ID.
 java.lang.String[] getServices()
          Obtain a list of every Server instance running in the system.
 void killService(java.lang.String instanceID)
          Try to kill the Service--don't try to stop() it
 IServer loadService(Service svc)
           
 IServer loadService(java.lang.String svcName)
           
 void log(java.lang.Exception ex)
           
 void log(java.lang.String msg)
           
static void main(java.lang.String[] args)
          This is the entry point of the LocalServerManager system; it creates an instance of LocalServerManager (which in turn registers itself as the one-and-only ServerManager instance), then parses the command line for arguments indicating which Services to load and start.
 void removeService(java.lang.String instanceID)
          Attempt to stop (if necessary) and remove an instance of a Server.
 void setErrStream(java.io.OutputStream os)
          Set the OutputStream used for writing errors.
 void setLogStream(java.io.OutputStream os)
          Set the OutputStream used for writing to the log.
 void shutdown()
          Shut the entire system down, usually in preparation for terminating this VM (or perhaps for doing a complete shutdown/restart cycling).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalServerManager

public LocalServerManager()
Method Detail

shutdown

public void shutdown()
Shut the entire system down, usually in preparation for terminating this VM (or perhaps for doing a complete shutdown/restart cycling). Effectively, this is the same as calling getServices to get all Servers' instanceIDs, then calling removeService on each one.
Specified by:
shutdown in interface IServerManager

deployService

public void deployService(java.lang.String serviceName,
                          ClassLoaderStrategy strategy)
Place a ClassLoaderStrategy into the service-loaders map, so subsequent addService() calls can use the loader to retrieve the necessary code.
Specified by:
deployService in interface IServerManager

loadService

public IServer loadService(Service svc)
Specified by:
loadService in interface IServerManager

loadService

public IServer loadService(java.lang.String svcName)
Specified by:
loadService in interface IServerManager

addService

public IServer addService(Service svc,
                          ConfigProperties args)
Add the loaded Service to the list of Servers and start it
Specified by:
addService in interface IServerManager

addService

public IServer addService(java.lang.String svcName,
                          ConfigProperties args)
Add a Service by name; this presumes that the Service has already been deployed to this ServerManager via the deployService method.
Specified by:
addService in interface IServerManager

removeService

public void removeService(java.lang.String instanceID)
Attempt to stop (if necessary) and remove an instance of a Server. Because it's possible that multiple Servers of a given type can be running simultaneously (for example, sockets-based Services listening on multiple ports), we need to have the user identify which Server they wish shut down by using the Server instance's instanceID.
Specified by:
removeService in interface IServerManager

killService

public void killService(java.lang.String instanceID)
Try to kill the Service--don't try to stop() it
Specified by:
killService in interface IServerManager

getServices

public java.lang.String[] getServices()
Obtain a list of every Server instance running in the system.
Specified by:
getServices in interface IServerManager

getService

public IServer getService(java.lang.String instanceID)
Obtain a reference to a Server instance by ID. If it can't be found (perhaps it's shut down since the user obtained the ID?), then return a null instance.
Specified by:
getService in interface IServerManager

log

public void log(java.lang.String msg)
Specified by:
log in interface IServerManager

log

public void log(java.lang.Exception ex)
Specified by:
log in interface IServerManager

error

public void error(java.lang.String msg)
Specified by:
error in interface IServerManager

error

public void error(java.lang.Exception ex)
Specified by:
error in interface IServerManager

getLogStream

public java.io.OutputStream getLogStream()
Return the OutputStream used for writing to the log.

setLogStream

public void setLogStream(java.io.OutputStream os)
Set the OutputStream used for writing to the log.

getErrStream

public java.io.OutputStream getErrStream()
Return the OutputStream used for writing errors.

setErrStream

public void setErrStream(java.io.OutputStream os)
Set the OutputStream used for writing errors. On your head be the consequences if you set this to null!

main

public static void main(java.lang.String[] args)
This is the entry point of the LocalServerManager system; it creates an instance of LocalServerManager (which in turn registers itself as the one-and-only ServerManager instance), then parses the command line for arguments indicating which Services to load and start.