org.tranche.server
Class Server

java.lang.Object
  extended by java.lang.Thread
      extended by org.tranche.commons.DebuggableThread
          extended by org.tranche.server.Server
All Implemented Interfaces:
java.lang.Runnable

public class Server
extends org.tranche.commons.DebuggableThread

This provides a framework for executing a server that uses the custom XML protocol designed for p2p. Each command in the protocol is broken out in to its own sub-class, similar to the strategy used by the command line client.

Author:
Jayson Falkner - jfalkner@umich.edu, Bryan Smith - bryanesmith@gmail.com, James "Augie" Hill - augman85@gmail.com

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static long DEFAULT_MAX_REQUEST_SIZE
          The maximum amount of incoming data allowed buffered in memory.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Server(TrancheServer dfs, int port)
          Creates a new server that uses the Tranche protocol using a socket bound to the specified port.
Server(TrancheServer dfs, int port, boolean ssl)
          Creates a new server that uses the Tranche protocol optionally tunneled through SSL and using a socket bound to the specified port.
 
Method Summary
protected  void finalize()
          Ensures that the socket is closed.
 int getConnectedClients()
           
 java.lang.String getHostName()
          Determine this server's host name.
 ServerItem getItem(java.lang.String command)
           
 int getMaxConcurrentClients()
           
 long getMaxRequestSize()
           
 int getPort()
          Returns the port that the Tranche server is bound to.
static java.io.File getRedirectOutputFile()
           
 int getRejectedClients()
           
 ServerStartupThread getServerStartupThread()
          Returns the ServerStartupThread object used by Server.
 TrancheServer getTrancheServer()
           
 java.lang.String getURL()
           
 boolean isCore()
           
 boolean isSSL()
           
 boolean isStopped()
           
 void requestShutdown(Signature sig, byte[] nonce)
           
 void run()
          Override of the run method.
 void setMaxRequestSize(int maxRequestSize)
           
static void setRedirectOutputFile(java.io.File redirectOutputFile)
           
 void setRun(boolean run)
          Toggles the state of this server.
 void waitForStartup(long maxTimeToWaitForStartup)
          Wait for startup thread to finish.
 
Methods inherited from class org.tranche.commons.DebuggableThread
debugErr, debugErr, debugOut, isDebug, setDebug
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_MAX_REQUEST_SIZE

public static final long DEFAULT_MAX_REQUEST_SIZE

The maximum amount of incoming data allowed buffered in memory. Protect against a DoS attack.

Right now, them maximum size is setting meta data, so based on it's maximum value plus a MB of elbow room.

See Also:
Constant Field Values
Constructor Detail

Server

public Server(TrancheServer dfs,
              int port)
       throws java.lang.Exception

Creates a new server that uses the Tranche protocol using a socket bound to the specified port.

Parameters:
dfs - The underlying TrancheServer to use.
port - The port that the server's socket should be bound to.
Throws:
java.lang.Exception - All exceptions are thrown.

Server

public Server(TrancheServer dfs,
              int port,
              boolean ssl)
       throws java.lang.Exception

Creates a new server that uses the Tranche protocol optionally tunneled through SSL and using a socket bound to the specified port.

Parameters:
dfs - The underlying TrancheServer to use.
port - The port that the server's socket should be bound to.
ssl - true if the Tranche protocol should be piped through SSL. false if not.
Throws:
java.lang.Exception - All exceptions are thrown.
Method Detail

getURL

public java.lang.String getURL()
Returns:

getItem

public ServerItem getItem(java.lang.String command)
Parameters:
command -
Returns:

getTrancheServer

public TrancheServer getTrancheServer()
Returns:

getConnectedClients

public int getConnectedClients()
Returns:

getRejectedClients

public int getRejectedClients()
Returns:

getMaxConcurrentClients

public int getMaxConcurrentClients()
Returns:

getMaxRequestSize

public long getMaxRequestSize()
Returns:

setMaxRequestSize

public void setMaxRequestSize(int maxRequestSize)
Parameters:
maxRequestSize -

isSSL

public boolean isSSL()
Returns:

getPort

public int getPort()

Returns the port that the Tranche server is bound to.

Returns:
The port that the Tranche server is bound to.

getHostName

public java.lang.String getHostName()

Determine this server's host name.

Returns:
The IP address or host name, as found in internet interface.

isCore

public boolean isCore()
Returns:

isStopped

public boolean isStopped()
Returns:

requestShutdown

public void requestShutdown(Signature sig,
                            byte[] nonce)
                     throws java.lang.Exception
Parameters:
sig -
nonce -
Throws:
java.lang.Exception

setRun

public void setRun(boolean run)

Toggles the state of this server. false turns the server off. true turns the server on.

Parameters:
run - false if the server should be taken off-line. true if it should be kept on-line.

run

public void run()
Override of the run method. Turns the server on.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

finalize

protected void finalize()
                 throws java.lang.Throwable

Ensures that the socket is closed.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

getServerStartupThread

public ServerStartupThread getServerStartupThread()

Returns the ServerStartupThread object used by Server.

Returns:
Null if not set (if TestUtil.isTesting() true and not testing ServerStartupThread); otherwise, returns the ServerStartupThread

waitForStartup

public void waitForStartup(long maxTimeToWaitForStartup)

Wait for startup thread to finish. If not running, returns immediately.

Parameters:
maxTimeToWaitForStartup -

getRedirectOutputFile

public static java.io.File getRedirectOutputFile()
Returns:

setRedirectOutputFile

public static void setRedirectOutputFile(java.io.File redirectOutputFile)
Parameters:
redirectOutputFile -


This code is free for use both commercially and non-commercially as stated in the project's license