de.fhg.igd.semoa.net.ship
Class ShipServer

java.lang.Object
  extended byde.fhg.igd.semoa.service.AbstractService
      extended byde.fhg.igd.semoa.net.AbstractServer
          extended byde.fhg.igd.semoa.net.RequestServer
              extended byde.fhg.igd.semoa.net.ship.ShipServer
All Implemented Interfaces:
Runnable, Server, Service, ShipConstants, ShipService

public class ShipServer
extends RequestServer
implements ShipService

Version:
"$Id: ShipServer.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Ulrich Pinsdorf, Patric Kabus

Nested Class Summary
 
Nested classes inherited from class de.fhg.igd.semoa.net.AbstractServer
AbstractServer.Job
 
Field Summary
static int DEFAULT_MAX_PACKET_SIZE
          The maximum supported size of datagrams (4096 Bytes).
static int DEFAULT_SHIP_PORT
          The default UDP port to listen on (47470).
private static String[] DEPEND_
          The dependencies to other objects in the global Environment.
private  ShipRequestHandler handler_
          The handler which actually executes queries.
private static Logger log_
          The Logger instance for this class
private  Name name_
          The distinguished name of this host.
static String PROTOCOL
          The protocol identifier (ship).
private  Random rand_
          Random number generator for packet numbers.
 
Fields inherited from class de.fhg.igd.semoa.net.AbstractServer
bad_, DEFAULT_CAPACITY, good_, MAX_CAPACITY, thread_
 
Fields inherited from class de.fhg.igd.semoa.service.AbstractService
REV_POSTFIX, REV_PREFIX
 
Fields inherited from interface de.fhg.igd.semoa.net.ship.ShipService
WHATIS
 
Fields inherited from interface de.fhg.igd.semoa.net.ship.ShipConstants
COMM_POD_ACL, COMM_POD_URL, COMM_PODS_ACL, COMM_PODS_URL, LOCATION_ADDRESS, LOCATION_CITY, LOCATION_COUNTRY, LOCATION_GPS_LAT, LOCATION_GPS_LONG, LOCATION_ROOM, LOCATION_STATE, LOCATION_ZIP, OWNER_DN, PLATFORM_PURPOSE, TRANSPORT_IN_RAW_MAX, TRANSPORT_IN_RAW_URL, TRANSPORT_IN_RAWS_MAX, TRANSPORT_IN_RAWS_URL
 
Fields inherited from interface de.fhg.igd.semoa.net.Server
BOUND_TO_PORT, ERROR, RUNNING, SHUTDOWN, UNDEFINED
 
Constructor Summary
ShipServer()
          Default constructor.
 
Method Summary
 String author()
          Returns the name of the author of the service.
protected  Request createRequest(Socket con, Request req)
          Creates a Request instance which is ready to be decoded.
private  Socket createSocket(URL url)
           
 String[] dependencies()
          Returns the dependencies of this service as described in Service.
 Set getKeySet()
          Returns a set of all SHIP keys defined by the local SHIP service.
 Set getKeySet(String expr)
          Returns a subset of SHIP keys defined by the local SHIP service.
 Set getKeySet(String expr, URL host)
          Returns a subset of SHIP keys defined by a remote SHIP service.
 Set getKeySet(URL host)
          Returns a set of all SHIP keys defined by a remote SHIP service.
 Map getMap()
          Returns the complete map of key value pairs defined by the local SHIP service.
 Map getMap(String expr)
          Returns a subset of key value pairs defined by the local SHIP service.
 Map getMap(String expr, URL host)
          Returns the a subset of key value pairs by a remote SHIP service.
 Map getMap(URL host)
          Returns the complete map of key value pairs by a remote SHIP service.
 String getValue(String key)
          Returns a specific value selected by a given key defined by the local SHIP service.
 String getValue(String key, URL host)
          Returns a specific value selected by a given key defined by on a remote SHIP service.
protected  void handleConnection(Socket socket)
          Handles incoming SHIP requests.
protected  void handleError(ShipReply reply)
           
 String info()
          Returns the informative string which should describe the service's essence in a sentence.
 boolean isAlive(URL host)
          Checks whether a certain host is alive.
 String localDN()
           
protected  int nextId()
          Calculates the package IDs.
 String protocol()
           
 String revision()
          Returns the revision number of this class as a string.
protected  ShipReply send(ShipRequest request, URL host)
          Initiates a connection to the specified host and sends the given request.
 void setConfig(URL configFile)
          Initializes this ship server.
 String toString()
           
 
Methods inherited from class de.fhg.igd.semoa.net.AbstractServer
bad, createJob, createServerSocket, exceptionInfo, getCapacity, getMaximumSize, getPort, getServerState, good, isEnabled, localURL, rebind, run, serverStateChanged, setCapacity, setEnabled, setMaximumSize, setPort, shutdown, signal
 
Methods inherited from class de.fhg.igd.semoa.service.AbstractService
checkDependencies, docs, doPrivileged, doPrivileged, getACC, getEnvironment, majorVersion, minorVersion
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.fhg.igd.semoa.net.ship.ShipService
localURL
 

Field Detail

log_

private static Logger log_
The Logger instance for this class


PROTOCOL

public static final String PROTOCOL
The protocol identifier (ship).

See Also:
Constant Field Values

DEFAULT_SHIP_PORT

public static final int DEFAULT_SHIP_PORT
The default UDP port to listen on (47470).

See Also:
Constant Field Values

DEFAULT_MAX_PACKET_SIZE

public static final int DEFAULT_MAX_PACKET_SIZE
The maximum supported size of datagrams (4096 Bytes).

See Also:
Constant Field Values

DEPEND_

private static final String[] DEPEND_
The dependencies to other objects in the global Environment. There is none dependency.


handler_

private ShipRequestHandler handler_
The handler which actually executes queries. The handler is associated with the policy file. Hence a call of setConfig(de.fhg.igd.util.URL) results in instantiation of a new handler object.


name_

private Name name_
The distinguished name of this host.


rand_

private Random rand_
Random number generator for packet numbers.

Constructor Detail

ShipServer

public ShipServer()
Default constructor. The constructor initializes the handler for ship requests with null. Use setConfig(de.fhg.igd.util.URL) after instantiation for initializing the service correctly.

Method Detail

author

public String author()
Description copied from class: AbstractService
Returns the name of the author of the service. The format to be used should be John Doe <jdoe@zilch.net>.

Specified by:
author in interface Service
Overrides:
author in class AbstractServer
Returns:
The name of the author of this server.

info

public String info()
Description copied from class: AbstractService
Returns the informative string which should describe the service's essence in a sentence.

Specified by:
info in interface Service
Specified by:
info in class AbstractService
Returns:
the String with the service's short description.

revision

public String revision()
Description copied from class: AbstractService
Returns the revision number of this class as a string. This class provides default implementations of methods majorVersion(), minorVersion based on the assumption that this method returns a revision string as generated by rcs(1) for the template "$Revision: 1.7 $/$Date: 2007-08-08 04:41:53 +0200 (Wed, 08 Aug 2007) $".

Specified by:
revision in class AbstractService

dependencies

public String[] dependencies()
Description copied from class: AbstractService
Returns the dependencies of this service as described in Service. This default implementation returns an array of length 0.

Specified by:
dependencies in interface Service
Overrides:
dependencies in class AbstractService
Returns:
An array of length 0.

protocol

public String protocol()
Specified by:
protocol in interface Server
Specified by:
protocol in class AbstractServer
Returns:
The string identifier of the protocol spoken by this server. Something such as "HTTP" or "RAW".

toString

public String toString()
Overrides:
toString in class AbstractServer
Returns:
A summary of the good and bad connections, and current configuration settings.

localDN

public String localDN()
Specified by:
localDN in interface ShipService
Returns:
The distinguished name that specifies the owner of the host by means of the owner's certificate subject as String (see KeyMaster.AUTH_KEY).

isAlive

public boolean isAlive(URL host)
                throws ShipException
Description copied from interface: ShipService
Checks whether a certain host is alive. Within a LAN this is the job of vicinity. This method is intended to be used with somewhat far hosts. This method a specified time for an answer from the remote host. Iff no result was received or an error occured during pinging the method returns with result false. Hence, a negative result may not be interpreted as if the pinged host is down; the server could just deny answering SHIP requests.

Specified by:
isAlive in interface ShipService
Parameters:
host - denotes the SHIP port of the host to be queried
Returns:
true if host is alive
Throws:
ShipException - if access connection to remote SHIP service fails.

getKeySet

public Set getKeySet(String expr,
                     URL host)
              throws ShipException
Description copied from interface: ShipService
Returns a subset of SHIP keys defined by a remote SHIP service.

Specified by:
getKeySet in interface ShipService
Parameters:
expr - allows wildcards to get just a subset of the map
host - denotes denotes the SHIP port of the host to be queried
Returns:
set of all keys defined at remote host's ship service
Throws:
ShipException - if access connection to remote SHIP service fails.

getKeySet

public Set getKeySet(String expr)
Description copied from interface: ShipService
Returns a subset of SHIP keys defined by the local SHIP service.

Specified by:
getKeySet in interface ShipService
Parameters:
expr - allows wildcards to get just a subset of the map
Returns:
set of all keys defined at remote host's ship service

getKeySet

public Set getKeySet(URL host)
              throws ShipException
Description copied from interface: ShipService
Returns a set of all SHIP keys defined by a remote SHIP service.

Specified by:
getKeySet in interface ShipService
Parameters:
host - denotes denotes the SHIP port of the host to be queried
Returns:
set of all keys defined at remote host's ship service
Throws:
ShipException - if access connection to remote SHIP service fails.

getKeySet

public Set getKeySet()
Description copied from interface: ShipService
Returns a set of all SHIP keys defined by the local SHIP service.

Specified by:
getKeySet in interface ShipService
Returns:
set of all keys defined at remote host's ship service

getValue

public String getValue(String key,
                       URL host)
                throws ShipException
Description copied from interface: ShipService
Returns a specific value selected by a given key defined by on a remote SHIP service.

Specified by:
getValue in interface ShipService
Parameters:
key - defines a specific value
host - denotes the SHIP port of the host to be queried
Returns:
the value according to the given key, if key is existent.
Throws:
ShipException - if access connection to remote SHIP service fails.

getValue

public String getValue(String key)
Description copied from interface: ShipService
Returns a specific value selected by a given key defined by the local SHIP service.

Specified by:
getValue in interface ShipService
Parameters:
key - defines a specific value
Returns:
the value according to the given key, if key is existent, null otherwise.

getMap

public Map getMap(String expr,
                  URL host)
           throws ShipException
Description copied from interface: ShipService
Returns the a subset of key value pairs by a remote SHIP service.

Specified by:
getMap in interface ShipService
Parameters:
expr - allows wildcards to get just a subset of the map
host - denotes the SHIP port of the host to be queried
Returns:
set of all keys defined at remote host's ship service
Throws:
ShipException - if access connection to remote SHIP service fails.

getMap

public Map getMap(String expr)
Description copied from interface: ShipService
Returns a subset of key value pairs defined by the local SHIP service.

Specified by:
getMap in interface ShipService
Parameters:
expr - allows wildcards to get just a subset of the map
Returns:
set of all keys defined at remote host's ship service

getMap

public Map getMap(URL host)
           throws ShipException
Description copied from interface: ShipService
Returns the complete map of key value pairs by a remote SHIP service. The method calls getMap(".*", host).

Specified by:
getMap in interface ShipService
Parameters:
host - denotes the SHIP port of the host to be queried
Returns:
set of all keys defined at remote host's ship service
Throws:
ShipException - if access connection to remote SHIP service fails.

getMap

public Map getMap()
Description copied from interface: ShipService
Returns the complete map of key value pairs defined by the local SHIP service. Calls getMap(".*")

Specified by:
getMap in interface ShipService
Returns:
set of all keys defined at remote host's ship service

handleConnection

protected void handleConnection(Socket socket)
                         throws Exception
Handles incoming SHIP requests. This implementation overrides AbstractServer.handleConnection(java.net.Socket) as is automatically called when a remote host sends a ship request. The request will be read and processed. The resulting reply is sent back via the still open socket.

Overrides:
handleConnection in class RequestServer
Parameters:
socket - a socket to the calling ship server.
Throws:
Exception - this methods hands back all occuring exceptions to the caller.
See Also:
AbstractServer

createRequest

protected Request createRequest(Socket con,
                                Request req)
Description copied from class: RequestServer
Creates a Request instance which is ready to be decoded.

Specified by:
createRequest in class RequestServer
Parameters:
con - The socket connection that must be handled by the Request generated by this method.
req - The previous Request or null if this is the first call for the given connection.
Returns:
A Request instance that can be decoded, and which is subsequently invoked to handle the decoded request.

send

protected ShipReply send(ShipRequest request,
                         URL host)
                  throws ShipException
Initiates a connection to the specified host and sends the given request. The host URL should contain a port number, otherwise DEFAULT_SHIP_PORT is used.

Parameters:
request - the ship request to be sent.
host - the url of the target host to be queried.
Returns:
the reply to actually sent request
Throws:
NullPointerException - if request is null.
NullPointerException - if host is null.
ShipException

setConfig

public void setConfig(URL configFile)
Initializes this ship server. The given configuration file should contain key value pairs as defined in Properties.

The SeMoA shell allows to re-init an always running server with a new or altered configuration file. This is done by means of the following statement:

 Publish -key ${WhatIs:SHIP} ; -setConfig ship.conf
 

Parameters:
configFile - the pathname of the ship configuration file.

createSocket

private Socket createSocket(URL url)
                     throws IOException
Throws:
IOException

nextId

protected int nextId()
Calculates the package IDs. The IDs are calculated by means of a random number generator. The values are between 0 and Integer.MAX_VALUE/2. This guarantees positive values of a certain precision.

Returns:
packet ID

handleError

protected void handleError(ShipReply reply)
                    throws ShipException
Throws:
ShipException


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.