org.demac.transport
Class TransportService

java.lang.Object
  extended by org.demac.transport.TransportService
All Implemented Interfaces:
Service
Direct Known Subclasses:
FluctNetTransportService, OldTransportServiceImpl, TransportServiceImpl

public abstract class TransportService
extends java.lang.Object
implements Service

This class represents the transport layer of the DEMAC framework. It provides an asynchronous message delivering service and abstracts from the used delivering mechanism like TCP/IP, Bluetooth etc. The addressing schema basis on handles for devices and messages. The transport service selects one of the available lower transport services which are associated with the receiving device. Sent and received messages are implementations of the TransportMessage interface. To be notified of incomming messages the interested object must implement the org.demac.transport.TransportListener interface and register itself at the transport service.

The transport service also provides methods to inquire DEMAC devices in the neighbourhood.


Constructor Summary
TransportService()
           
 
Method Summary
abstract  void addDevice(Device device)
          Method to add a device manually to the transport service.
abstract  void addTransportListener(TransportListener listener)
          Method to register an object which implements the org.demac.transport.TransportListener interface at the service.
abstract  void detectDevices()
          Method to start the inquiary for devices in the neigbourhood.
abstract  TransportMessage extractMessage(MessageHandle handle)
          Method to get a message from the transport service which has arrived from foreign devices and remove it immediately.
abstract  java.util.Enumeration getAllDevices()
          Method to get all devices which are known by the transport service.
abstract  DeviceHandle getLocalDeviceHandle()
          Method to get the org.demac.transport.DeviceHandle of the local device.
abstract  java.lang.String getLocalName()
          Method to get a user-friendly name of the local device.
static TransportService getTransportService()
          Method to get an instance of the DEMAC transport service.
abstract  TransportMessage receiveMessage(MessageHandle handle)
          Method to get a message from the the transport service which has arrived from foreign devices.
abstract  void removeDevice(Device device)
          Method to remove a device manually from the transport service.
abstract  void removeMessage(MessageHandle handle)
          Method to remove a message from the transport service.
abstract  void removeTransportListener(TransportListener listener)
          Method to remove a registered listener from the transport service.
abstract  void sendMessage(TransportMessage msg)
          Method to send a message to a device.
abstract  void sendMessage(TransportMessage msg, Constraint[] constraints)
          Method to send a message to a device under a set of constraints.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.demac.Service
isStarted, start, stop
 

Constructor Detail

TransportService

public TransportService()
Method Detail

getTransportService

public static TransportService getTransportService()
Method to get an instance of the DEMAC transport service. As mobile devices are mostly limited in their computing power the TransportService should be implemented as a singleton. This method should provide access to the instance of the transport service.

Returns:
the instance of the transport service.

getAllDevices

public abstract java.util.Enumeration getAllDevices()
                                             throws TransportException
Method to get all devices which are known by the transport service.

Returns:
an enumeration of org.demac.transport.Device[s]
Throws:
TransportException - if the service has not been started before invoking this method

detectDevices

public abstract void detectDevices()
                            throws TransportException
Method to start the inquiary for devices in the neigbourhood.

Throws:
TransportException - if the inquiary can not be started

sendMessage

public abstract void sendMessage(TransportMessage msg)
                          throws TransportException
Method to send a message to a device. The message must be an implementation of the org.demac.transport.TransportMessage interface. Sender, receiver and the message itself are referenced in the message.

Parameters:
msg - the message which is to be sent
Throws:
TransportException - if the message can not be sent of if the service has not been started.

sendMessage

public abstract void sendMessage(TransportMessage msg,
                                 Constraint[] constraints)
                          throws TransportException
Method to send a message to a device under a set of constraints. The message must be an implementation of the org.demac.transport.TransportMessage interface and the set of constraints is build up of implementations of the org.demac.transport.Constraint interface. Sender, receiver and the message itself are referenced in the message.

Parameters:
msg - the message which is to be sent
constraints - the set of constraints to fulfill
Throws:
TransportException - if the message can not be sent

addTransportListener

public abstract void addTransportListener(TransportListener listener)
Method to register an object which implements the org.demac.transport.TransportListener interface at the service.

Parameters:
listener - the listener which is to be registerd

removeTransportListener

public abstract void removeTransportListener(TransportListener listener)
Method to remove a registered listener from the transport service.

Parameters:
listener - the listener which is to be removed

receiveMessage

public abstract TransportMessage receiveMessage(MessageHandle handle)
                                         throws MessageNotAvailableException
Method to get a message from the the transport service which has arrived from foreign devices. The reference for the message can be obtained via the org.demac.transport.TransportListener interface.

Parameters:
handle - the reference of the message
Returns:
the message associated with the org.demac.transport.MessageHandle
Throws:
MessageNotAvailableException - if the message is not available (any more)

removeMessage

public abstract void removeMessage(MessageHandle handle)
                            throws MessageNotAvailableException
Method to remove a message from the transport service. The reference to the message can be obtained via the org.demac.transport.TransportListener interface.

Parameters:
handle - the org.demac.transport.MessageHandleassociated to the message
Throws:
MessageNotAvailableException - if the message is not available (any more)

extractMessage

public abstract TransportMessage extractMessage(MessageHandle handle)
                                         throws MessageNotAvailableException
Method to get a message from the transport service which has arrived from foreign devices and remove it immediately. Can be seen as a combination of receiveMessage(MessageHandle handle) and removeMessage(MessageHandle handle)

Parameters:
handle - the reference of the message
Returns:
the message associated with the org.demac.transport.MessageHandle
Throws:
MessageNotAvailableException - if the message is not available (any more)

getLocalDeviceHandle

public abstract DeviceHandle getLocalDeviceHandle()
                                           throws TransportException
Method to get the org.demac.transport.DeviceHandle of the local device.

Returns:
the handle of the local device
Throws:
TransportException - if the service has not been started before invoking this method

getLocalName

public abstract java.lang.String getLocalName()
                                       throws TransportException
Method to get a user-friendly name of the local device.

Returns:
the name of the local device
Throws:
TransportException - if the service has not been started before invoking this method

addDevice

public abstract void addDevice(Device device)
                        throws TransportException
Method to add a device manually to the transport service.

Parameters:
device - the device which is to be registered
Throws:
TransportException - if the service has not been started before invoking this method

removeDevice

public abstract void removeDevice(Device device)
                           throws TransportException
Method to remove a device manually from the transport service.

Parameters:
device - the device which is to be removed
Throws:
TransportException - if the service has not been started before invoking this method