hypercast
Interface I_UnicastAdapter

All Superinterfaces:
I_Stats
All Known Subinterfaces:
I_IPv4_UnicastAdapter, I_MulticastAdapter
All Known Implementing Classes:
SecurityProcessor, SSL_UnicastAdapter, TCP_UDP_Adapter, TCP_UnicastAdapter, UDP_MulticastAdapter, UDP_UnicastAdapter

public interface I_UnicastAdapter
extends I_Stats

This interface defines functions that an unicast adapter should implement. An adapter provides timers and a network interface. It can send and receive messages. (Messages received are passed to an object implementing I_AdapterCallback.) The adapter keeps its own clock for the timers. It is important that any objects implementing I_AdapterCallback uses this clock, so that their code will work with a simulated network. It is implemented by the class UDP_UnicastAdapter.


Field Summary
static int CLOSED
          value for state.
static int STARTED
          value for state.
static int STARTING
          value for state.
static int STOPPED
          value for state.
static int STOPPING
          value for state.
 
Method Summary
 void clearTimer(java.lang.Object timer_id)
          Clears a timer.
 void close()
          Close stops the adapter if it has not already been stopped.
 hypercast.I_PhysicalAddress createPhysicalAddress()
          Create a physical address.
 hypercast.I_PhysicalAddress createPhysicalAddress(byte[] byteaddr, int offset)
          Creates an instance of an I_PhysicalAddress from a byte array.
 hypercast.I_PhysicalAddress createPhysicalAddress(java.lang.String addrString)
          Creates IP_Address object from a string.
 hypercast.I_UnderlayAddress createUnderlayAddress()
          Create a physical address.
 hypercast.I_UnderlayAddress createUnderlayAddress(byte[] byteaddr, int offset)
          Creates an instance of an I_UnderlayAddress from a byte array.
 hypercast.I_UnderlayAddress createUnderlayAddress(java.lang.String addrString)
          Creates I_UnderlayAddress object from a string.
 long getCurrentTime()
          USE THIS - DO NOT USE System.currentTimeMillis()! This returns the time according to the adapter.
 java.lang.Object getInfo()
          Get information of this adapter.
 int getPhysicalAddressSize()
          Returns the size of physical address, when carried in a packet, of an I_UnicastAdapter object.
 long getTimer(java.lang.Object timer_id)
          Returns expect delay until the timer goes off.
 int getUnderlayAddressSize()
          Returns the size of physical address, when carried in a packet, of an I_UnicastAdapter object.
 boolean Reset(java.lang.Object socketObj)
          Reset the adapter with a Object;
 void sendUnicastMessage(hypercast.I_NetworkAddress dst, hypercast.I_Message msg)
          Sends an I_Message to a specified destination from this Adapter.
 void setCallback(hypercast.I_AdapterCallback node)
          Sets a Callback object to this Adapter.
 void setTimer(java.lang.Object timer_id, long delay_ms)
          Sets a timer.
 void Start()
          Starts all the threads except timer thread in the UnicastAdapter.
 void Stop()
          Stops all the threads in the UnicastAdapter.
 void Stop(long delay)
          Stops all the threads in the UnicastAdapter after a delay When stop returns, the adapter is stopped.
 
Methods inherited from interface hypercast.I_Stats
getReadSchema, getStats, getStatsName, getWriteSchema, setStats, setStatsName
 

Field Detail

STOPPED

public static final int STOPPED
value for state.

See Also:
Constant Field Values

STARTING

public static final int STARTING
value for state.

See Also:
Constant Field Values

STARTED

public static final int STARTED
value for state.

See Also:
Constant Field Values

STOPPING

public static final int STOPPING
value for state.

See Also:
Constant Field Values

CLOSED

public static final int CLOSED
value for state.

See Also:
Constant Field Values
Method Detail

Start

public void Start()
Starts all the threads except timer thread in the UnicastAdapter.

Throws:
java.lang.IllegalStateException - if the adapter is already running.
java.lang.IllegalStateException - if setCallback has not been called.

Stop

public void Stop()
Stops all the threads in the UnicastAdapter. When stop returns, the adapter is stopped. Any further calls (e.g. send, setTimer, clearTimer, etc.) will call an exception. Stop() may take a while to return. During that time, Callback functions may be called. Stop() will only return when all threads have returned from the Callback functions and are guaranteed never to enter a Callback function.

Throws:
java.lang.IllegalStateException - if the adapter is already stopped.

Stop

public void Stop(long delay)
Stops all the threads in the UnicastAdapter after a delay When stop returns, the adapter is stopped. Any further calls (e.g. send, setTimer, clearTimer, etc.) will call an exception. Stop() may take a while to return. During that time, Callback functions may be called. Stop() will only return when all threads have returned from the Callback functions and are guaranteed never to enter a Callback function.

Parameters:
delay - delay in milliseconds
Throws:
java.lang.IllegalStateException - if the adapter is already stopped.

close

public void close()
Close stops the adapter if it has not already been stopped. It then closes the physical sockets. This should only be called if the adapter will no longer be used. After a close call, any further calls to adapter methods will return an IllegalStateException. If a delayed stop was called before the close method is called, then close will block until that delayed stop is completed. A closed adapter is always stopped as well.

Throws:
java.lang.IllegalStateException - if the adapter is already closed

sendUnicastMessage

public void sendUnicastMessage(hypercast.I_NetworkAddress dst,
                               hypercast.I_Message msg)
Sends an I_Message to a specified destination from this Adapter.

Throws:
java.lang.IllegalStateException - if adapter is not running.

createPhysicalAddress

public hypercast.I_PhysicalAddress createPhysicalAddress(byte[] byteaddr,
                                                         int offset)
Creates an instance of an I_PhysicalAddress from a byte array.

Throws:
java.lang.IllegalArgumentException - if byte[] is corrupted
java.lang.ArrayIndexOutOfBoundsException - if byte[] is too small.

createPhysicalAddress

public hypercast.I_PhysicalAddress createPhysicalAddress(java.lang.String addrString)
Creates IP_Address object from a string.

Parameters:
addrString - an string representing a physical address.

createPhysicalAddress

public hypercast.I_PhysicalAddress createPhysicalAddress()
Create a physical address.


getPhysicalAddressSize

public int getPhysicalAddressSize()
Returns the size of physical address, when carried in a packet, of an I_UnicastAdapter object.


createUnderlayAddress

public hypercast.I_UnderlayAddress createUnderlayAddress(byte[] byteaddr,
                                                         int offset)
Creates an instance of an I_UnderlayAddress from a byte array.

Throws:
java.lang.IllegalArgumentException - if byte[] is corrupted
java.lang.ArrayIndexOutOfBoundsException - if byte[] is too small.

createUnderlayAddress

public hypercast.I_UnderlayAddress createUnderlayAddress(java.lang.String addrString)
Creates I_UnderlayAddress object from a string.

Parameters:
addrString - an string representing a underlay address.

createUnderlayAddress

public hypercast.I_UnderlayAddress createUnderlayAddress()
Create a physical address.


getUnderlayAddressSize

public int getUnderlayAddressSize()
Returns the size of physical address, when carried in a packet, of an I_UnicastAdapter object.


Reset

public boolean Reset(java.lang.Object socketObj)
Reset the adapter with a Object;

Parameters:
socketObj - object passed to do reset.

getInfo

public java.lang.Object getInfo()
Get information of this adapter.


setCallback

public void setCallback(hypercast.I_AdapterCallback node)
Sets a Callback object to this Adapter. This must be done only when the Adapter is stopped, and must be performed before the Adapter is started.

Throws:
java.lang.IllegalStateException - if called after adapter has been started.

setTimer

public void setTimer(java.lang.Object timer_id,
                     long delay_ms)
Sets a timer. If timer with that id has already be set, this resets it.

Throws:
java.lang.IllegalStateException - if adapter is not running.

clearTimer

public void clearTimer(java.lang.Object timer_id)
Clears a timer.

Throws:
java.lang.IllegalStateException - if adapter is not running.

getTimer

public long getTimer(java.lang.Object timer_id)
Returns expect delay until the timer goes off.

Throws:
java.lang.IllegalStateException - if adapter is not running.

getCurrentTime

public long getCurrentTime()
USE THIS - DO NOT USE System.currentTimeMillis()! This returns the time according to the adapter. It is important that all code use this function and not the system clock so that the code will work with a simulator (which may be paused and restarted).