edu.sdsc.inca
Class Server

java.lang.Object
  extended byjava.lang.Thread
      extended byedu.sdsc.inca.Component
          extended byedu.sdsc.inca.Server
All Implemented Interfaces:
java.lang.Runnable

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.
//Run a Server in a separate thread Server server = new Server();
server.setConfiguration(config); server.start();

//Run a Server in this thread
Server server = new Server();
server.setConfiguration(config); server.run();

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.


Field Summary
static int ACCEPT_TIMEOUT
           
static int CLIENT_TIMEOUT
           
protected  java.lang.String hostname
           
protected static org.apache.log4j.Logger logger
           
protected  int port
           
static java.lang.String SERVER_OPTS
           
protected  boolean shutdown
           
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, key, keyPath, logFile, password, trusted, trustedPath
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Server()
           
 
Method Summary
 java.lang.String getHostname()
          Returns the name of the host where this server is running.
 int getPort()
          Returns the port associated with a Server Object.
 java.lang.String getTempPath()
          Returns the path where the server stores temporary files.
 java.lang.String getUri()
          Return the uri for the server.
 int getWorkerCount()
          Returns the number of worker threads this server uses.
 boolean isReady()
          Returns true iff the Server is ready to start accepting connections.
static void main(java.lang.String[] args)
          A main function to start a generic server.
 void run()
          Start listening on the specified port for connections.
 void setConfiguration(java.util.Properties config)
          A convenience function for setting multiple configuration properties at once.
 void setHostname(java.lang.String hostname)
          Sets the name of the host where this server is running.
 void setPort(int port)
          Set the port to bind to.
 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, getKey, getKeyPath, getLogFile, getPassword, getTrustedCertificates, getTrustedPath, openResourceStream, readCredentials, readVersion, setAuthenticate, setCertificatePath, setKeyPath, setLogFile, setPassword, setTrustedPath
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, 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

hostname

protected java.lang.String hostname

port

protected int port

tempPath

protected java.lang.String tempPath

workerCount

protected int workerCount

shutdown

protected boolean shutdown

ssocket

protected java.net.ServerSocket ssocket

workQueue

protected WorkQueue workQueue

workers

protected Worker[] workers
Constructor Detail

Server

public Server()
Method Detail

getHostname

public java.lang.String getHostname()
Returns the name of the host where this server is running.

Returns:
A string containing the hostname of the server

getPort

public int getPort()
Returns the port associated with a Server Object.

Returns:
The port the server is or will be listening on

getTempPath

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

Returns:
the temp directory path

getUri

public java.lang.String getUri()
Return the uri for the server.

Returns:
A string containing the uri of the server

getWorkerCount

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

Returns:
the number of worker threads

isReady

public boolean isReady()
Returns true iff the Server is ready to start accepting connections. Used for testing purposes when you have control of the server and the client.

Returns:
true if the server is listening

run

public void run()
Start listening on the specified port for connections. When a connection is received push it onto the queue and forget about it. This will do the ssl handshake, but NO OTHER AUTHENTICATION.


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: "hostname", the name of the host this server is running on; "numthreads", the number of threads in the worker pool; "port", the server port; "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

setHostname

public void setHostname(java.lang.String hostname)
Sets the name of the host where this server is running.

Parameters:
hostname - A string containing the hostname of the server

setPort

public void setPort(int port)
Set the port to bind to.

Parameters:
port - port number

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 -i,--init Path to server configuration properties file. -k,--key Path to the server key -h,--hostname Hostname of server if different than what Java discovers -n,--numthreads # of worker threads that the server runs -p,--port The port for the server to listen on -P,--password yes|no Read encryption password from stdin -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.