lime
Class LimeServer

java.lang.Object
  extended bylime.LimeServer
All Implemented Interfaces:
java.util.EventListener, GroupChangedListener, PropertyKeys, java.lang.Runnable

public class LimeServer
extends java.lang.Object
implements java.lang.Runnable, PropertyKeys, GroupChangedListener

The runtime support needed to run Lime on a given host.

There can be multiple Lime servers running on a single host, as long as they are started on separate ports at least 3 apart. This is because (port+1) is used for loading agents, and (port+2) is used for the group manager's SinglePhaseDisseminator. Note that other (future) detectors/disseminators could use more ports.

The server must be explicitly activated by calling the boot method.

The server also provides methods that allow an agent in it to engage the corresponding host in the Lime community. Engagement takes place as a distributed transaction that reconciles the state of the system by shuffling misplaced tuples and installing weak reaction operations among the engaging host and those already in the system. Similarly, disengagement removes a host from the community.

The server can be accessed from within a program, or started from command line using the Launcher.

Version:
7/10/2003
Author:
Amy L. Murphy, Gian Pietro Picco, Christine Julien, Chien-Liang Fok, Tom Elgin
See Also:
Launcher

Field Summary
private  java.lang.Object changingHostLock
          This is used to ensure that the changingHost variable is set before retrieving it.
private  LimeServerID[] changingHosts
           
(package private)  ConnectionMgr cmgr
          This is the connection manager.
private  boolean connect
           
private static boolean debugON
           
protected static java.util.Properties defaultProperties
          The default server properties.
(package private)  boolean disengaging
           
private  boolean engage
          Determines whether the LimeServer should engage immediately.
private  boolean engaged
           
private  java.lang.String engMode
           
private static boolean errorsON
           
private  GroupManager gm
           
(package private)  java.lang.String gmDetector
          A key that specifies the Detector that GroupManager should use.
(package private)  java.lang.String gmDisseminator
          A key that specifies the Disseminator that GroupManager should use.
(package private)  double gmMaxSpeed
          A key that specifies the maximum speed at which the host can be moving.
(package private)  double gmNetworkLatency
          A key that specifies to GroupManager the latency of the network.
(package private)  int gmPeriod
          A key that specified the period at which GroupManager broadcasts beacons.
(package private)  double gmRange
          A key that specifies the broadcast range in meters of the wireless card.
private  int gpsBaud
           
private  java.lang.String gpsPort
           
private  java.util.Vector groupMembers
           
private  LocationGenerator lg
           
private  java.net.ServerSocket loadSS
           
private  LimeServerID localServerID
           
private static java.util.Hashtable maxTIDServer
          Records the highest tuple ID for each tuple space.
private  java.lang.String mcastaddr
           
private  int mcastport
           
private  LimeServerID mcastServerID
          An ID prepresenting the multicast group this LIMEServer is part of.
private static boolean messagesON
           
private  int port
           
static java.util.Properties properties
          The server properties.
private static LimeServer server
           
private  boolean shutdown
           
private static java.lang.Boolean shutdownLock
           
private  java.lang.String tsfactory
           
 
Fields inherited from interface lime.PropertyKeys
CONNECTkey, DEBUGkey, ENGAGEkey, ENGAGEMENT_MODEkey, ERRORSkey, GM_DETECTORkey, GM_DISSEMINATORkey, GM_MAX_SPEEDkey, GM_MCASTADDRkey, GM_MCASTPORTkey, GM_NETWORK_LATENCYkey, GM_PERIODkey, GM_RANGEkey, GPS_BAUDkey, GPS_PORTkey, LOADkey, MESSAGESkey, PORTkey, QUITkey, TSFACTORYkey
 
Constructor Summary
private LimeServer()
          The constructor of the LimeServer.
 
Method Summary
 void boot()
          Activate the runtime support.
private  boolean createGroupManager()
          Creates a GroupManager for this LimeServer if there is currently no group manager for this server.
(package private) static void debug(java.lang.String msg)
           
(package private) static void debug(java.lang.String msg, java.lang.Object obj)
           
 void disengage()
          Start the disengagement protocol needed to allow a host to depart from a community of mobile hosts.
 void engage()
          Start the engagement protocol necessary to make this host part of a community of mobile hosts.
(package private) static void error(java.lang.String msg, java.lang.Throwable e, boolean exit)
          If errors are enabled, prints it to the screen.
(package private)  LimeServerID[] getChangingHosts()
          Returns the hosts that are changing in this engagement or disengagement.
private  LimeServerID[] getLeavingHosts(java.util.Vector newGroupMembers)
          This method returns the hosts that are leaving the group.
 int getLoadPort()
          Returns the port used to load agents onto this LimeServer.
 LimeServerID getmcastServerID()
          Returns the ID of the multicast server.
private  LimeServerID[] getNewHosts(java.util.Vector newGroupMembers)
          This method returns the hosts that are new to the group.
(package private) static long getNextTupleID(java.lang.String name)
          Return the next tuple id for a given tuple space name.
 int getPort()
          Returns the port being used by this LIMEServer.
static LimeServer getServer()
          Return a handle to the Lime server.
 LimeServerID getServerID()
          Returns the ID of the local server.
 java.lang.String getTupleSpaceFactory()
          Returns the tuple space factory
 void groupChanged(GroupChangedEvent gce)
          The makeup of the group has changed.
 boolean isDebugOn()
          Returns true if debug messages should be printed.
 boolean isEngaged()
          Return true if the host is engaged, false otherwise
 boolean isErrorsOn()
          Returns true if error messages should be printed.
 boolean isMessagesOn()
          Returns true if messages should be printed.
 boolean isPermanentConnections()
          Returns true if TCP connections are maintained.
 boolean isShuttingDown()
          Returns whether shutdown has been called on this LimeServer.
 ILimeAgent loadAgent(java.lang.String classname, java.io.Serializable[] parameters)
          Load an agent into the Lime server.
private  void loadPropertyVars()
          Initializes the property variables based on the values within properties.
(package private) static void message(java.lang.String msg)
           
(package private) static void print(java.lang.String msg)
          Prints string text to the screen.
(package private)  void releaseShutdownLock()
          Releases the shutdown lock, allows thread that called shutdown to exit.
(package private)  void restartGM()
          Restarts the GroupManager.
 void run()
          Listens on the load port, when a client connects, it passes in the name of the agent that should be loaded into the LimeServer.
 void setProperty(java.lang.String key, java.lang.String value)
           
 void shutdown(boolean exit)
          Shuts down the LimeServer.
(package private)  void shutdownGM()
          Shuts down the GroupManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultProperties

protected static java.util.Properties defaultProperties
The default server properties.


properties

public static java.util.Properties properties
The server properties.


mcastaddr

private java.lang.String mcastaddr

mcastport

private int mcastport

port

private int port

connect

private boolean connect

tsfactory

private java.lang.String tsfactory

server

private static final LimeServer server

errorsON

private static boolean errorsON

debugON

private static boolean debugON

messagesON

private static boolean messagesON

shutdownLock

private static java.lang.Boolean shutdownLock

localServerID

private LimeServerID localServerID

engaged

private boolean engaged

gm

private GroupManager gm

groupMembers

private java.util.Vector groupMembers

changingHosts

private LimeServerID[] changingHosts

engMode

private java.lang.String engMode

gpsPort

private java.lang.String gpsPort

gpsBaud

private int gpsBaud

shutdown

private boolean shutdown

loadSS

private java.net.ServerSocket loadSS

gmPeriod

int gmPeriod
A key that specified the period at which GroupManager broadcasts beacons.


gmRange

double gmRange
A key that specifies the broadcast range in meters of the wireless card.


gmMaxSpeed

double gmMaxSpeed
A key that specifies the maximum speed at which the host can be moving.


gmNetworkLatency

double gmNetworkLatency
A key that specifies to GroupManager the latency of the network.


gmDetector

java.lang.String gmDetector
A key that specifies the Detector that GroupManager should use.


gmDisseminator

java.lang.String gmDisseminator
A key that specifies the Disseminator that GroupManager should use.


lg

private LocationGenerator lg

mcastServerID

private LimeServerID mcastServerID
An ID prepresenting the multicast group this LIMEServer is part of.


cmgr

ConnectionMgr cmgr
This is the connection manager. It managers the "Connections" to other hosts. There is only one ConnectionMgr per LimeServer, and this is it. Since LimeServer is a singleton, there is only one ConnectionMgr per JVM.


engage

private boolean engage
Determines whether the LimeServer should engage immediately. If this is not true, the LimeServer will not start GroupManager till engage() is called on it.


maxTIDServer

private static java.util.Hashtable maxTIDServer
Records the highest tuple ID for each tuple space.


changingHostLock

private java.lang.Object changingHostLock
This is used to ensure that the changingHost variable is set before retrieving it. It ensures that changingHost has the correct value prior to using it.


disengaging

boolean disengaging
Constructor Detail

LimeServer

private LimeServer()
The constructor of the LimeServer. It is private since LimeServer is a singleton.

Method Detail

groupChanged

public void groupChanged(GroupChangedEvent gce)
The makeup of the group has changed. This is the required method for completely implementing the GroupChangedListener. When the Group Manager has a new set of group members, it generates an event and passes it to this registered listener. This method then takes that event and processes it, calling the engage method if the new group is larger than the previous, and disengage if the new group is smaller.

Specified by:
groupChanged in interface GroupChangedListener
Parameters:
gce - the GroupChangedEvent

releaseShutdownLock

void releaseShutdownLock()
Releases the shutdown lock, allows thread that called shutdown to exit.


getNewHosts

private LimeServerID[] getNewHosts(java.util.Vector newGroupMembers)
This method returns the hosts that are new to the group. It is only used if this is an engagement (rather than a disengagement).

Parameters:
newGroupMembers - The complete new group (groupmgmt.Members).
Returns:
the LimeServerIDs of only the new hosts.

getLeavingHosts

private LimeServerID[] getLeavingHosts(java.util.Vector newGroupMembers)
This method returns the hosts that are leaving the group. It is only used during a disengagement (rather than an engagement).

Parameters:
newGroupMembers - the complete new group (groupmgmt.Members)
Returns:
the LimeServerIDs of the hosts that were in the old group but are not in the new group.

getChangingHosts

LimeServerID[] getChangingHosts()
Returns the hosts that are changing in this engagement or disengagement. For engagement, the changing hosts are the new hosts. For disengagement, the changing hosts are the hosts that are leaving.

Returns:
the LimeServerIDs of the changing hosts.

restartGM

void restartGM()
Restarts the GroupManager. It is called by the TransactionMgr in the endOfTransaction Method.


shutdownGM

void shutdownGM()
Shuts down the GroupManager. It is called by the TransactionMgr in endOfTransaction when it wants to shutdown the system.


setProperty

public void setProperty(java.lang.String key,
                        java.lang.String value)

loadPropertyVars

private void loadPropertyVars()
Initializes the property variables based on the values within properties.


getServer

public static LimeServer getServer()
Return a handle to the Lime server.


getTupleSpaceFactory

public java.lang.String getTupleSpaceFactory()
Returns the tuple space factory


getServerID

public LimeServerID getServerID()
Returns the ID of the local server.

Returns:
the ID of the local server.

getmcastServerID

public LimeServerID getmcastServerID()
Returns the ID of the multicast server.

Returns:
the ID of the multicast server.

getPort

public int getPort()
Returns the port being used by this LIMEServer.


getLoadPort

public int getLoadPort()
Returns the port used to load agents onto this LimeServer.


isPermanentConnections

public boolean isPermanentConnections()
Returns true if TCP connections are maintained.


isDebugOn

public boolean isDebugOn()
Returns true if debug messages should be printed.


isErrorsOn

public boolean isErrorsOn()
Returns true if error messages should be printed.


isMessagesOn

public boolean isMessagesOn()
Returns true if messages should be printed.


engage

public void engage()
Start the engagement protocol necessary to make this host part of a community of mobile hosts. If there are no other host to engage with, this method will block all the processing on the host until another host to engage with (a leader) is found. Host engagement is allowed only if there is at least one agent with a shared tuple space is present at that host. Engagement has no effect if the host is already engaged, i.e., no engagement protocol is run in this case.


disengage

public void disengage()
Start the disengagement protocol needed to allow a host to depart from a community of mobile hosts. If the host is already disengaged, this method has no effect, i.e., the disengagement protocol is not run.


isEngaged

public boolean isEngaged()
Return true if the host is engaged, false otherwise


loadAgent

public ILimeAgent loadAgent(java.lang.String classname,
                            java.io.Serializable[] parameters)
                     throws AgentCreationException
Load an agent into the Lime server. The agent's class is described by a fully specified class name. The bytecode (.class files) for this class and all the other classes needed by the agent must be in a directory in the same CLASSPATH available to the Lime server (and to the tuple space engine, if the latter employs user-defined classes). If the Agent subclass has a constructor with parameters, it is possible to create the agent by supplying parameters in the method call. The correct constructor is automatically retrieved by the system based on the signature.

Parameters:
classname - the fully specified name of the agent's class.
parameters - the parameters for instantiating the agent. Their type must match the type of a constructor of classname.
Returns:
a reference to the newly created ILimeAgent.
Throws:
AgentCreationException - if it is impossible to create the agent, e.g., because classname is not a subclass of ILimeAgent, or the corresponding classes cannot be found.

createGroupManager

private boolean createGroupManager()
Creates a GroupManager for this LimeServer if there is currently no group manager for this server.

Returns:
true if the groupManager was created, false if the groupManager was already created.

boot

public void boot()
Activate the runtime support.


shutdown

public void shutdown(boolean exit)
Shuts down the LimeServer.

Parameters:
exit - true if the method should system.exit

isShuttingDown

public boolean isShuttingDown()
Returns whether shutdown has been called on this LimeServer. This is used by the TransactionMgr after it has finished processing a host disengagement transaction.


run

public void run()
Listens on the load port, when a client connects, it passes in the name of the agent that should be loaded into the LimeServer. It continuously loads agents.

Specified by:
run in interface java.lang.Runnable

print

static void print(java.lang.String msg)
Prints string text to the screen.


message

static void message(java.lang.String msg)

debug

static void debug(java.lang.String msg)

debug

static void debug(java.lang.String msg,
                  java.lang.Object obj)

error

static void error(java.lang.String msg,
                  java.lang.Throwable e,
                  boolean exit)
If errors are enabled, prints it to the screen.

Parameters:
msg - the message to print.

getNextTupleID

static long getNextTupleID(java.lang.String name)
Return the next tuple id for a given tuple space name. If the name does not exist in the hashtable maxTIDServer, insert the entry.