org.locomotive.server
Class ServiceRoutingTable.ServiceEntry

java.lang.Object
  |
  +--org.locomotive.server.ServiceRoutingTable.ServiceEntry
Direct Known Subclasses:
HandlerRoutingTable.HandlerEntry, ServletRoutingTable.ServletEntry
Enclosing class:
ServiceRoutingTable

public abstract class ServiceRoutingTable.ServiceEntry
extends java.lang.Object

This little class is the companion to the ServiceRoutingTable. The ServiceRoutingTable creates these, and keeps a bunch of these around. To use this class, you'll want to override two methods: initialize(), and shutdown(), which will do whatever's appropriate to do at the beginning of and at the end of your service's life. If your service requires a persistent object, then create it in the intialize() method and store it in the service field.


Field Summary
protected  int availability
          This ServiceEntry's service may not be available to serve requests at certain times.
protected  boolean cached
           
protected  java.lang.String classname
           
protected  java.lang.String config_path
           
protected  long last_availability_event_timestamp
          The date/timestamp of when the last availability reporting event occurred.
 java.lang.String pattern
           
protected  java.util.Properties props
           
protected  java.lang.Object service
           
protected  java.lang.Class theclass
           
protected  java.lang.String unavailability_reason
          If the service is either temporarily or permanently unavailable, we should have a reason for the unavailability that we can show to the client.
protected  int unavailable_seconds
          We'll keep track of any waiting periods so that we can tell users what to expect.
 
Constructor Summary
protected ServiceRoutingTable.ServiceEntry(java.lang.String pat, java.lang.String cname, java.lang.String c_path)
          Creates a new ServiceEntry.
 
Method Summary
 int getAvailability()
          Returns the availability status of this ServiceEntry's service.
 long getLastAvailabilityEventTimestamp()
          Gets the timestamp of the last availability event.
 java.lang.Object getService()
          Regardless of what the service Object is, use this method to get a reference to it.
 java.lang.String getUnavailabilityReason()
          Returns the reason for the unavailability.
 int getUnavailableSeconds()
          Gets the number of seconds that this ServiceEntry's service is unavailable for.
protected abstract  void initialize()
          This needs to be overridden to instantiate and create the service.
protected  void load(Log server_log)
          This will load the config path and create the class object.
 void setAvailability(int availability)
          Sets the availability code for this ServiceEntry's service.
 void setLastAvailabilityEventTimestamp(long last_availability_event_timestamp)
          Sets the timestamp of the last availability event.
 void setUnavailabilityReason(java.lang.String reason)
          Sets the reason for the unavailability.
 void setUnavailableSeconds(int unavailable_seconds)
          Sets the number of seconds that this ServiceEntry's service is unavailable for.
abstract  boolean shutdown(Log server_log)
          This should also be overridden to call whatever cleanup/shutdown methods you need.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cached

protected boolean cached

pattern

public java.lang.String pattern

classname

protected java.lang.String classname

theclass

protected java.lang.Class theclass

config_path

protected java.lang.String config_path

props

protected java.util.Properties props

service

protected java.lang.Object service

availability

protected int availability
This ServiceEntry's service may not be available to serve requests at certain times. It starts off being available, and it may later be marked as either temporarily or permanently unavailable.
See Also:
ServletFactory

unavailable_seconds

protected int unavailable_seconds
We'll keep track of any waiting periods so that we can tell users what to expect. This unavailability timeout is only valid when availability is set to UNAVAILABLE_AND_WAITING.

unavailability_reason

protected java.lang.String unavailability_reason
If the service is either temporarily or permanently unavailable, we should have a reason for the unavailability that we can show to the client.

last_availability_event_timestamp

protected long last_availability_event_timestamp
The date/timestamp of when the last availability reporting event occurred. It is stored as the number of milliseconds elapsed between Jan 1, 1970 00:00:00 GMT and the actual time this event occurred.
Constructor Detail

ServiceRoutingTable.ServiceEntry

protected ServiceRoutingTable.ServiceEntry(java.lang.String pat,
                                           java.lang.String cname,
                                           java.lang.String c_path)
Creates a new ServiceEntry.
Parameters:
pat - the pattern to map the service to
cname - the service's class name
c_path - the path to the service's properties file
Method Detail

load

protected void load(Log server_log)
             throws InitializationException
This will load the config path and create the class object. The initialize() method below will still need to be called to acually initialize the object.
Throws:
InitializationException - if the class couldn't be found or loaded, or if the properties couldn't be loaded.

initialize

protected abstract void initialize()
                            throws InitializationException
This needs to be overridden to instantiate and create the service. You should catch all exceptions and rethrow them as InitializationExceptions. You Should never need to call this- load(), above, will call it, after the properties file has been loaded.

shutdown

public abstract boolean shutdown(Log server_log)
This should also be overridden to call whatever cleanup/shutdown methods you need. Again, exceptions should be caught and logged.

getUnavailableSeconds

public int getUnavailableSeconds()
Gets the number of seconds that this ServiceEntry's service is unavailable for.

setUnavailableSeconds

public void setUnavailableSeconds(int unavailable_seconds)
Sets the number of seconds that this ServiceEntry's service is unavailable for.

Parameters:
unavailable_seconds - the amount of time during which this ServiceEntry's servlets are unavailable.

getAvailability

public int getAvailability()
Returns the availability status of this ServiceEntry's service.

setAvailability

public void setAvailability(int availability)
Sets the availability code for this ServiceEntry's service.

Parameters:
availability - The new availability state, should be one of the following: ServiceEntry.AVAILABLE, ServiceEntry.UNAVAILABLE_AND_WAITING, ServiceEntry.PERMANENTLY_UNAVAILABLE.

getUnavailabilityReason

public java.lang.String getUnavailabilityReason()
Returns the reason for the unavailability.

setUnavailabilityReason

public void setUnavailabilityReason(java.lang.String reason)
Sets the reason for the unavailability.

Parameters:
reason - the text reason to use.

getLastAvailabilityEventTimestamp

public long getLastAvailabilityEventTimestamp()
Gets the timestamp of the last availability event. It is stored as the number of milliseconds elapsed between Jan 1, 1970 00:00:00 GMT and the actual time this event occurred.

setLastAvailabilityEventTimestamp

public void setLastAvailabilityEventTimestamp(long last_availability_event_timestamp)
Sets the timestamp of the last availability event. It is stored as the number of milliseconds elapsed between Jan 1, 1970 00:00:00 GMT and the actual time this event occurred.

Parameters:
last_availability_event_timestamp - the date/timestamp when the ServiceRoutingTable last received a report about service availability.

getService

public java.lang.Object getService()
Regardless of what the service Object is, use this method to get a reference to it.