edu.sdsc.inca
Class Server

java.lang.Object
  extended by edu.sdsc.inca.Component
      extended by edu.sdsc.inca.Server

public class Server
extends Component

Author:
Cathie Olschanowsky, Jim Hayes, Shava Smallen

A multithreaded server that speaks the Inca protocol. Provides the basic implementation for all Java servers within the Inca Framework.
NOTE: All of the set* methods that manipulate Server configuration have no effect if called while the Server is running.

If the server is shut down using SIGINT there is a hook that will shut it down properly. This takes a few seconds, but makes sure that all currently active work is finished before shutdown is completed. On a SIGKILL work may be lost and the state may be unstable.


Nested Class Summary
protected  class Server.ClientDispatcher
          A class that listens on a server socket and adds new client connections to a work queue.
protected  class Server.ServerShutdownHook
          This Class is run in a seperate thread when the server is shut down using ^C or SIGINT.
 
Field Summary
static int ACCEPT_TIMEOUT
           
protected  Server.ClientDispatcher cd
           
static int CLIENT_TIMEOUT
           
protected static org.apache.log4j.Logger logger
           
static java.lang.String SERVER_OPTS
           
protected  java.net.ServerSocket ssocket
           
protected  java.lang.String tempPath
           
protected  int workerCount
           
protected  Worker[] workers
           
protected  WorkQueue workQueue
           
 
Fields inherited from class edu.sdsc.inca.Component
authenticate, cert, certPath, COMPONENT_OPTS, hostname, key, keyPath, logFile, password, port, trusted, trustedPath
 
Constructor Summary
Server()
           
 
Method Summary
 java.lang.String getTempPath()
          Returns the path where the server stores temporary files.
 int getWorkerCount()
          Returns the number of worker threads this server uses.
 boolean isRunning()
          Returns true iff the Server is accepting connections.
static void main(java.lang.String[] args)
          A main function to start a generic server.
 void runServer()
          Start a thread that accepts and dispatches client connections.
 void setConfiguration(java.util.Properties config)
          A convenience function for setting multiple configuration properties at once.
 void setTempPath(java.lang.String path)
          Sets the directory path where the Server stores temporary files.
 void setWorkerCount(int count)
          Sets the number of workers the Server uses to handle incoming messages.
 void shutdown()
          Asks the Server to shutdown.
 
Methods inherited from class edu.sdsc.inca.Component
addTrustedCert, configComponent, createSocket, getAuthenticate, getCertificate, getCertificatePath, getHostname, getKey, getKeyPath, getLogFile, getPassword, getPort, getTrustedCertificates, getTrustedPath, getUri, openResourceStream, readCredentials, readVersion, setAuthenticate, setCertificatePath, setHostname, setKeyPath, setLogFile, setPassword, setPort, setTrustedPath
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACCEPT_TIMEOUT

public static final int ACCEPT_TIMEOUT
See Also:
Constant Field Values

CLIENT_TIMEOUT

public static final int CLIENT_TIMEOUT
See Also:
Constant Field Values

SERVER_OPTS

public static final java.lang.String SERVER_OPTS

logger

protected static org.apache.log4j.Logger logger

tempPath

protected java.lang.String tempPath

workerCount

protected int workerCount

cd

protected Server.ClientDispatcher cd

ssocket

protected java.net.ServerSocket ssocket

workQueue

protected WorkQueue workQueue

workers

protected Worker[] workers
Constructor Detail

Server

public Server()
Method Detail

getTempPath

public java.lang.String getTempPath()
Returns the path where the server stores temporary files.

Returns:
the temp directory path

getWorkerCount

public int getWorkerCount()
Returns the number of worker threads this server uses.

Returns:
the number of worker threads

isRunning

public boolean isRunning()
Returns true iff the Server is accepting connections.

Returns:
true if the server is accepting connections

runServer

public void runServer()
               throws java.lang.Exception
Start a thread that accepts and dispatches client connections.

Throws:
java.lang.Exception - if the server fails to start

setConfiguration

public void setConfiguration(java.util.Properties config)
                      throws ConfigurationException
A convenience function for setting multiple configuration properties at once. In addition to the keys recognized by the superclass, recognizes: "numthreads", * the number of threads in the worker pool; "var", the path to the temporary file dir.

Overrides:
setConfiguration in class Component
Parameters:
config - contains server configuration values
Throws:
ConfigurationException - on a faulty configuration property value

setTempPath

public void setTempPath(java.lang.String path)
                 throws ConfigurationException
Sets the directory path where the Server stores temporary files.

Parameters:
path - the temporary directory path
Throws:
ConfigurationException - if the path can't be read from the classpath

setWorkerCount

public void setWorkerCount(int count)
Sets the number of workers the Server uses to handle incoming messages.

Parameters:
count - The (positive) worker count

shutdown

public void shutdown()
              throws java.lang.InterruptedException
Asks the Server to shutdown. Interrupts the server and each of its workers. The workers will finish their current task; the server shuts down once all workers have finished. This could take a while.

Throws:
java.lang.InterruptedException - if the shutdown is interrupted

main

public static void main(java.lang.String[] args)
A main function to start a generic server. It takes command-line arguments for each Server configuration value:
 usage: java edu.sdsc.inca.Server
-a,--auth yes|no Authenticate the connection? -c,--cert Path to the server certificate -h,--help Prints a short help and usage statement -h,--hostname Hostname of server if different than what Java discovers -i,--init Path to server configuration properties file. -k,--key Path to the server key -n,--numthreads # of worker threads that the server runs -P,--password yes|no Read encryption password from stdin -p,--port The port for the server to listen on -t,--trusted Path to a directory containing all of the trusted certificates. -T,--taskwait # milliseconds for timing out task I/O -v,--var The directory the server should use to save temp files. Must be an absolute path. -V,--version Print program version and exit. -w,--wait # millisecs between shutdown checks

Each of these values may also be specified in the initialization file or in system properties defined via the -D switch. In both of these cases, the configuration name must be prefixed with "inca.server.", e.g., use "inca.server.numthreads" to specify the numthreads value. Command line arguments override any properties specified in this fashion.

Parameters:
args - command line arguments, as above.