sds
Class DistributedServerObject

java.lang.Object
  extended by sds.DistributedObject
      extended by sds.DistributedServerObject
Direct Known Subclasses:
Daemon, Manager

public abstract class DistributedServerObject
extends DistributedObject

Provides server-oriented distributed objects functionalities. A server-oriented distributed object waits for incoming messages on its allocated port number

Author:
ncottin

Constructor Summary
DistributedServerObject(boolean requiresSignature)
           Creates a server-oriented distributed object.
 
Method Summary
abstract  void execute()
           Defines this server's default behaviour (i.e. while not receiving messages from other distributed objects)
 boolean isSignatureRequired()
           
abstract  void processError(SdsException error)
           Automatically called when receive(Message) returns false or when an SdsException while processing an incoming request
abstract  boolean receive(Message msg)
           Defines the server behavior when a message is received
 void run(int port, boolean daemon)
           Executes this distributed object as a server.
 boolean runsAsServer()
           Checks if this distributed object can receive message
 void terminate()
           Called by the hosting daemon when asked (by a manager) to kill its running distributed objects.
abstract  void terminateServer()
           Automatically called by terminate()
 
Methods inherited from class sds.DistributedObject
createReference, deliver, deliver, getExpectedResponseInfo, getManager, getReference, run, setDefaultReference, setManager, setReference
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DistributedServerObject

public DistributedServerObject(boolean requiresSignature)

Creates a server-oriented distributed object. A default reference is automatically created. This distributed object is not associated with a manager

Parameters:
requiresSignature - true if all incoming non digitally signed (and authenticated) messages must be rejected
Method Detail

isSignatureRequired

public final boolean isSignatureRequired()

runsAsServer

public final boolean runsAsServer()

Checks if this distributed object can receive message

Specified by:
runsAsServer in class DistributedObject
Returns:
true as this distributed object is designed to behave as a server

run

public final void run(int port,
                      boolean daemon)
               throws SdsException
Description copied from class: DistributedObject

Executes this distributed object as a server. This operation must be non-blocking. A default reference is created if not initialized before (DistributedObject.getReference() returns null)

Specified by:
run in class DistributedObject
Parameters:
port - the port to be used by this distributed object when running as a server
daemon - tells this server to run as a daemon or a normal server
Throws:
SdsException - raised if the port is already reserved or when this distributed object has no server ability

execute

public abstract void execute()

Defines this server's default behaviour (i.e. while not receiving messages from other distributed objects)


terminate

public final void terminate()

Called by the hosting daemon when asked (by a manager) to kill its running distributed objects. Allows to perform tasks before an effective closing (along with freeing this distributed object). This operation must not be called within a thread (mainly from receive(Message)) as it would lead to wait indefinitely (until the current thread stops, which never occurs!)

Specified by:
terminate in class DistributedObject

terminateServer

public abstract void terminateServer()

Automatically called by terminate()


receive

public abstract boolean receive(Message msg)
                         throws SdsException

Defines the server behavior when a message is received

Parameters:
msg - received message. Must not be null (no checking is necessary when implementing this operation)
Returns:
true if request message content is successfully handled
Throws:
SdsException - an error occurred when retrieving information from the message (or cast)

processError

public abstract void processError(SdsException error)

Automatically called when receive(Message) returns false or when an SdsException while processing an incoming request

Parameters:
error -