org.elkoserver.foundation.server
Class Server

java.lang.Object
  extended by org.elkoserver.foundation.server.Server
All Implemented Interfaces:
ConnectionCountMonitor, ServiceFinder

public class Server
extends Object
implements ConnectionCountMonitor, ServiceFinder

The core of an Elko server, holding the run queue, a collection of configuration information extracted from the various Java property settings, as well as access to various important server-intrinsic services (such as port listeners) that are configured by those property settings.


Constructor Summary
Server(BootProperties props, String serverType, Trace appTrace)
          Generate the Server from Java properties.
 
Method Summary
 void connectionCountChange(int delta)
          Track the number of connections, so server can exit gracefully.
 void enqueue(Runnable runnable)
          Drop a runnable onto the main run queue.
 void enqueueSlowTask(Callable<Object> task, ArgRunnable resultHandler)
          Drop a task onto the slow queue.
 void findService(String service, ArgRunnable handler, boolean monitor)
          Issue a request for service information to the broker.
 void findServiceLink(String service, ArgRunnable handler)
          Obtain a message channel to a service.
 List<HostDesc> listeners()
          Get the configured listeners for this server.
 NetworkManager networkManager()
          Get this server's network manager.
 ObjDB openObjectDatabase(String propRoot)
          Open an asynchronous object database whose location (directory path or remote repository host) is specified by properties.
 BootProperties props()
          Get this server's properties.
 void registerLoadWatcher(LoadWatcher watcher)
          Add an object to the collection of objects to be notified when the server samples its load.
 void registerReinitWatcher(ReinitWatcher watcher)
          Add an object to the collection of objects to be notified when the server is being reinitialized.
 void registerService(ServiceDesc service)
          Add a new service offering to the collection of services provided by this server.
 void registerShutdownWatcher(ShutdownWatcher watcher)
          Add an object to the collection of objects to be notified when the server is being shut down.
 void reinit()
          Reinitialize the server.
 String serverName()
          Get this server's name.
 List<ServiceDesc> services()
          Get the services being offered by this server.
 void setServiceRefTable(RefTable serviceRefTable)
          Assign the ref table that will be used to dispatch messages received from connected services.
 void shutdown(boolean kill)
          Shut down the server.
 int startListeners(String propRoot, ServiceFactory serviceFactory)
          Start listening for connections on all the ports that are configured.
 Trace trace()
          Return the application trace object for this server.
 void unregisterLoadWatcher(LoadWatcher watcher)
          Remove an object from the collection of objects that are notified when the server samples its load.
 void unregisterReinitWatcher(ReinitWatcher watcher)
          Remove an object from the collection of objects that are notified when the server is being reinitialized.
 void unregisterShutdownWatcher(ShutdownWatcher watcher)
          Remove an object from the collection of objects that are notified when the server is being shut down.
 String version()
          Return the version ID string for this build.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Server

public Server(BootProperties props,
              String serverType,
              Trace appTrace)
Generate the Server from Java properties.

Parameters:
props - The properties, as determined by the boot process.
serverType - Server type tag (for generating property names).
appTrace - Trace object for event logging.
Method Detail

connectionCountChange

public void connectionCountChange(int delta)
Track the number of connections, so server can exit gracefully.

Specified by:
connectionCountChange in interface ConnectionCountMonitor
Parameters:
delta - An upward or downward adjustment to the connection count.

enqueue

public void enqueue(Runnable runnable)
Drop a runnable onto the main run queue.

Parameters:
runnable - The thing to run.

enqueueSlowTask

public void enqueueSlowTask(Callable<Object> task,
                            ArgRunnable resultHandler)
Drop a task onto the slow queue.

Parameters:
task - Callable that executes the task. This will be executed in a separate thread and so is permitted to block.
resultHandler - Thunk that will be invoked with the result returned by the task. This will be executed on the main run queue.

findService

public void findService(String service,
                        ArgRunnable handler,
                        boolean monitor)
Issue a request for service information to the broker.

Specified by:
findService in interface ServiceFinder
Parameters:
service - The service desired.
handler - Object to receive the asynchronous result(s).
monitor - If true, keep watching for more results after the first.

findServiceLink

public void findServiceLink(String service,
                            ArgRunnable handler)
Obtain a message channel to a service. Services are located using the broker. Note that all services offered by a given server are multiplexed through a single connection: if there is an existing connection to the server providing the service, it is used, but if there is no existing connection to that server, one is created.

Parameters:
service - The service desired
handler - A runnable that will be invoked with a service link to the requested service once the connection is located or created. The handler will be passed a null if no connection was possible.

listeners

public List<HostDesc> listeners()
Get the configured listeners for this server.

Returns:
a read-only list of host information for the currently configured listeners.

networkManager

public NetworkManager networkManager()
Get this server's network manager.

Returns:
the network manager

openObjectDatabase

public ObjDB openObjectDatabase(String propRoot)
Open an asynchronous object database whose location (directory path or remote repository host) is specified by properties.

Parameters:
propRoot - Prefix string for all the properties describing the odb that is to be opened.
Returns:
an object for communicating with the opened odb, or null if the location was not properly specified.

props

public BootProperties props()
Get this server's properties.

Returns:
the properties

registerLoadWatcher

public void registerLoadWatcher(LoadWatcher watcher)
Add an object to the collection of objects to be notified when the server samples its load.

Parameters:
watcher - An object to notify about load samples.

unregisterLoadWatcher

public void unregisterLoadWatcher(LoadWatcher watcher)
Remove an object from the collection of objects that are notified when the server samples its load.

Parameters:
watcher - The object to stop notifying about load samples.

registerReinitWatcher

public void registerReinitWatcher(ReinitWatcher watcher)
Add an object to the collection of objects to be notified when the server is being reinitialized.

Parameters:
watcher - An object to notify at reinitialization time.

unregisterReinitWatcher

public void unregisterReinitWatcher(ReinitWatcher watcher)
Remove an object from the collection of objects that are notified when the server is being reinitialized.

Parameters:
watcher - The object that no longer cares about reinitialization.

registerService

public void registerService(ServiceDesc service)
Add a new service offering to the collection of services provided by this server.

Parameters:
service - Service descriptor describing the service being added.

registerShutdownWatcher

public void registerShutdownWatcher(ShutdownWatcher watcher)
Add an object to the collection of objects to be notified when the server is being shut down.

Parameters:
watcher - An object to notify at shutdown time.

unregisterShutdownWatcher

public void unregisterShutdownWatcher(ShutdownWatcher watcher)
Remove an object from the collection of objects that are notified when the server is being shut down.

Parameters:
watcher - The object that no longer cares about shutdown.

reinit

public void reinit()
Reinitialize the server.


serverName

public String serverName()
Get this server's name.

Returns:
the server name.

services

public List<ServiceDesc> services()
Get the services being offered by this server.

Returns:
a list of ServiceDesc objects describing the services offered by this server.

setServiceRefTable

public void setServiceRefTable(RefTable serviceRefTable)
Assign the ref table that will be used to dispatch messages received from connected services.

Parameters:
serviceRefTable - The ref table to use.

shutdown

public void shutdown(boolean kill)
Shut down the server. Actually, this initiates the shutdown process; the actual shutdown happens in serverExit().

Parameters:
kill - If true, shut down immediately instead of cleaning up.

startListeners

public int startListeners(String propRoot,
                          ServiceFactory serviceFactory)
Start listening for connections on all the ports that are configured.

Parameters:
propRoot - Prefix string for all the properties describing the listeners that are to be started.
serviceFactory - Object to provide message handler factories for the new listeners.
Returns:
the number of ports that were configured.

trace

public Trace trace()
Return the application trace object for this server.


version

public String version()
Return the version ID string for this build.