|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.locomotive.server.ServiceRoutingTable
An abstract way to route services to pattern Strings. This presently loads a file which maps a token or an extension to a class, as well as a path to a properties file. It will take care of loading and parsing the file, and loading the properties. Moreover, it'll even reload the file, or an individual service, for you. Here's the file format:
<url_pattern> <classname> [<path to properties file>] // comments after the double slashTo get this to work for you, you'll have to override the following:
Inner Class Summary | |
class |
ServiceRoutingTable.ServiceEntry
This little class is the companion to the ServiceRoutingTable. |
Field Summary | |
static int |
AVAILABLE
If the instance member availability is set to
AVAILABLE , that means that this ServiceEntry's
service is available to serve requests. |
static int |
PERMANENTLY_UNAVAILABLE
If the instance member availability is set to
PERMANENTLY_UNAVAILABLE , that means that
this ServiceEntry's service is unavailable, and probably won't
be available again until the system administrator(s) restart
the Locomotive. |
protected Log |
server_log
|
protected java.util.Hashtable |
service_configs
The Hashtable that stores service-to-propsfile mappings |
protected java.util.Hashtable |
service_extensions_hash
The Hashtable that stores extension-to-service mappings |
protected java.util.Hashtable |
service_tokens_hash
The Hashtable that stores token-to-service mappings |
static int |
SHUTDOWN
If the instance member availability is set to
SHUTDOWN , that means that the Object factory
for this service has been shut down. |
static int |
UNAVAILABLE_AND_WAITING
If the instance member availability is set to
UNAVAILABLE_AND_WAITING , that means that
this ServiceEntry's service is currently unavailable, but may
become available again after unavailable_seconds
have elapsed. |
Constructor Summary | |
ServiceRoutingTable(java.lang.String path,
Log log,
java.util.Vector classpath,
boolean auto_reload)
creates a new (but uninitialized) HanderRouting Table |
Method Summary | |
void |
addService(java.lang.String pattern,
java.lang.String classname,
java.lang.String config_path)
Creates and adds a new service to the ServiceRoutingTable. |
boolean |
containsService(java.lang.String pattern)
Returns true if there is a service associated with this pattern |
protected abstract ServiceRoutingTable.ServiceEntry |
createServiceEntry(java.lang.String pattern,
java.lang.String classname,
java.lang.String config_path)
Override this to return the ServiceEntry class you need. |
java.util.Properties |
getProperties(java.lang.Class theclass)
return the properties object for a given Class. |
ServiceRoutingTable.ServiceEntry |
getService(LocoConfig config,
java.lang.String pattern)
returns the Service Entry object appropriate for the given config and pattern string. |
void |
initialize()
initializes or re-initializes this object's routing structures based on the defaults and the contents of the file at the location specified in 'path' in the Constructor. |
protected void |
log(int log_level,
java.lang.String message)
Log with the correct class name |
void |
markServiceForReloading(java.lang.String pattern)
Marks a service for reloading, which means it will be reloaded on the next request for it, as opposed to right now, which is what the reloadService() method does. |
protected abstract void |
putInDefaults()
Override this to put in service defaults. |
void |
reloadService(java.lang.String pattern)
reloads a single service - that is, creates a new Service routing table entry, attempts to reload the properties, and if all goes well, replaces the old service with the new one. |
abstract void |
routeRequest(int request_id,
java.net.Socket sock,
java.io.InputStream is,
java.io.OutputStream os,
java.util.Hashtable cgi_envars,
java.util.Hashtable form_hash,
java.util.Hashtable steam_vars,
java.lang.String[] url_tokens,
java.lang.String request_uri,
long bstamp_id,
Response resp,
java.sql.Connection conn,
Session session,
java.util.Hashtable attributes)
This is the method which actually routes a request to a particular service. |
java.lang.Class |
routeToClass(LocoConfig config,
java.lang.String pattern)
returns the service class for the specified pattern NOTE: I think this is only used for Handlers! --JB |
java.lang.Object |
routeToService(LocoConfig config,
java.lang.String request_uri,
java.lang.String first_token)
Finds and returns the service Object associated with the specified request uri. |
ServiceRoutingTable.ServiceEntry |
routeToServiceEntry(LocoConfig config,
java.lang.String request_uri,
java.lang.String first_token)
Returns the ServiceEntry Object appropriate for the given config, URI, and first token. |
boolean |
shutdown()
Attempts to shut down each of the services |
protected void |
throwException(java.lang.String message)
throw an initializationException with the correct classname |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final int AVAILABLE
availability
is set to
AVAILABLE
, that means that this ServiceEntry's
service is available to serve requests.public static final int UNAVAILABLE_AND_WAITING
availability
is set to
UNAVAILABLE_AND_WAITING
, that means that
this ServiceEntry's service is currently unavailable, but may
become available again after unavailable_seconds
have elapsed.public static final int PERMANENTLY_UNAVAILABLE
availability
is set to
PERMANENTLY_UNAVAILABLE
, that means that
this ServiceEntry's service is unavailable, and probably won't
be available again until the system administrator(s) restart
the Locomotive.public static final int SHUTDOWN
availability
is set to
SHUTDOWN
, that means that the Object factory
for this service has been shut down.protected Log server_log
protected java.util.Hashtable service_tokens_hash
protected java.util.Hashtable service_extensions_hash
protected java.util.Hashtable service_configs
Constructor Detail |
public ServiceRoutingTable(java.lang.String path, Log log, java.util.Vector classpath, boolean auto_reload)
path
- the path to the table filelog
- a server logclasspath
- a Vector of paths to search for service classes inMethod Detail |
public void initialize() throws InitializationException
public boolean shutdown()
protected abstract ServiceRoutingTable.ServiceEntry createServiceEntry(java.lang.String pattern, java.lang.String classname, java.lang.String config_path)
public void addService(java.lang.String pattern, java.lang.String classname, java.lang.String config_path) throws InitializationException
pattern
- the pattern that the service is mapped to.classname
- the service class's name.config_path
- the path to the objects' properties file. Leave
this null if the service doesn't have a properties file.public boolean containsService(java.lang.String pattern)
public abstract void routeRequest(int request_id, java.net.Socket sock, java.io.InputStream is, java.io.OutputStream os, java.util.Hashtable cgi_envars, java.util.Hashtable form_hash, java.util.Hashtable steam_vars, java.lang.String[] url_tokens, java.lang.String request_uri, long bstamp_id, Response resp, java.sql.Connection conn, Session session, java.util.Hashtable attributes)
request_id
- the unique id for this requestsock
- the socket this request connected onis
- the inputstream from that socketos
- the outputstream from that socketreply_protocol
- the protocol type we received the request fromcgi_envars
- the CGI variables passed in with the requestform_hash
- the form data, if there was anyurl_tokens
- a tokenized form of the urlrequest_uri
- the unparsed url tokensbstamp_id
- the browser stamp id that came in from the
bstamp cookie for this requestconn
- the Database connection for this requestsession
- the Session object for this requestuser
- the user for this requestpublic java.lang.Class routeToClass(LocoConfig config, java.lang.String pattern)
public java.lang.Object routeToService(LocoConfig config, java.lang.String request_uri, java.lang.String first_token)
public ServiceRoutingTable.ServiceEntry routeToServiceEntry(LocoConfig config, java.lang.String request_uri, java.lang.String first_token)
config
- the LocoConfig Object.request_uri
- the URI of the request.first_token
- the first token of the request.public ServiceRoutingTable.ServiceEntry getService(LocoConfig config, java.lang.String pattern)
That it is synchronized should mean that we don't have to worry about synchonizing the methods inside, like initialize. We may want to rethink this...
public void markServiceForReloading(java.lang.String pattern)
public void reloadService(java.lang.String pattern) throws InitializationException
public java.util.Properties getProperties(java.lang.Class theclass)
protected abstract void putInDefaults() throws InitializationException
protected void log(int log_level, java.lang.String message)
protected void throwException(java.lang.String message) throws InitializationException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |