org.kaariboga.domainserver
Class DomainServer

java.lang.Object
  |
  +--org.kaariboga.domainserver.DomainServer
All Implemented Interfaces:
KbMessageHandler, SimpleTimerListener

public class DomainServer
extends java.lang.Object
implements KbMessageHandler, SimpleTimerListener

A class to build up domains for kaariboga servers. This class manages a list of all servers connected to the domain and provides the means for other servers to get this information. In addition, an agent server may use this domain server to determine it's own IP address. Servers who get their IP address dynamically may have problems of determing their own address, because in pure Java it is not possible to get the IP address for a specific device. Incoming Messages: BASE_ONLINE sent by an agent server when the agent server wants to connect to this domain. BASE_OFFLINE sent by an agent server when the agent server wants to disconnect from this domain. GET_BASES sent by an agent server to get a list of all servers connected to this domain. GET_MY_IP_ADDRESS sent by an agent server, who wants to know it's own IP address. This is useful for servers who get their IP address dynamically. Outgoing Messages: BASES sent by this server to nodify an agent server of all other servers connected. YOUR_IP_ADDRESS sent by this server as an respond to GET_MY_IP_ADDRESS


Field Summary
(package private)  KaaribogaAddress address
          Address of this server
(package private)  java.util.Hashtable baseEntries
          Bases connected to this domain plus some extra information
(package private)  java.util.Hashtable bases
          Bases connected to this domain
(package private)  DeliveryService deliveryService
          Service for message transportation across network
(package private)  long interval
          time interval in millis after which old entries are deleted
(package private)  int port
          port on which to listen
(package private)  SimpleTimer timer
          timer, that triggers cleaning of old entries.
 
Fields inherited from interface org.kaariboga.io.KbMessageHandler
AGENT_NOT_REACHABLE, BASE_NOT_REACHABLE, BASE_OFFLINE
 
Constructor Summary
DomainServer(int port, long interval)
           
 
Method Summary
protected  void addBase(java.lang.String hashcode, KaaribogaAddress base)
          Adds a new KaaribogaBase to this domain
 void handleMessage(KaaribogaMessage message)
          Called when a message for the DeliveryServiceUser has arrived.
 void messageDeliveryError(int errorCode, KaaribogaMessage message)
          Called in case a message could not be delivered.
 void onSimpleTimer()
          Removes old base entries from the list of bases connected to the domain.
protected  void removeBase(java.lang.String hashcode)
          Removes a base from this domain.
 void sendBasesList(KaaribogaAddress receiver)
          Sends a list of all bases connected to the domain to a specified server.
 void terminate()
          terminates this server
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

port

int port
port on which to listen

address

KaaribogaAddress address
Address of this server

deliveryService

DeliveryService deliveryService
Service for message transportation across network

interval

long interval
time interval in millis after which old entries are deleted

timer

SimpleTimer timer
timer, that triggers cleaning of old entries.

baseEntries

java.util.Hashtable baseEntries
Bases connected to this domain plus some extra information

bases

java.util.Hashtable bases
Bases connected to this domain
Constructor Detail

DomainServer

public DomainServer(int port,
                    long interval)
Parameters:
port - port on which to listen
Method Detail

handleMessage

public void handleMessage(KaaribogaMessage message)
Called when a message for the DeliveryServiceUser has arrived.
Specified by:
handleMessage in interface KbMessageHandler
Parameters:
message - The message, that has arrived for the user.

messageDeliveryError

public void messageDeliveryError(int errorCode,
                                 KaaribogaMessage message)
Called in case a message could not be delivered. It is not guaranteed, that this method is called in every case, for example if a DeliveryService is offline, it may decide to store incoming messages until it is online again.
Specified by:
messageDeliveryError in interface KbMessageHandler
Parameters:
errorCode - Delivery error code. At the moment the following codes exit: BASE_NOT_REACHABLE, AGENT_NOT_REACHABLE, BASE_OFFLINE
message - The message, that could not be delivered. Note, that this may be null if the message no longer exists on the sending host. Future versions of KaaribogaMessage may include a global unique identifier.

onSimpleTimer

public void onSimpleTimer()
Removes old base entries from the list of bases connected to the domain. An entry is an old entry, if it's last update time is older than the given interval. Not suited for heavy load, but should work well enough for small domains
Specified by:
onSimpleTimer in interface SimpleTimerListener

terminate

public void terminate()
terminates this server

addBase

protected void addBase(java.lang.String hashcode,
                       KaaribogaAddress base)
Adds a new KaaribogaBase to this domain
Parameters:
hashcode - Hashcode, that should be used to store the base.
base - KaaribogaBase to add

removeBase

protected void removeBase(java.lang.String hashcode)
Removes a base from this domain.
Parameters:
hashcode - Hashcode, that should be used to store the base.

sendBasesList

public void sendBasesList(KaaribogaAddress receiver)
Sends a list of all bases connected to the domain to a specified server.
Parameters:
receiver - the server that receives the list