hypercast.adapters
Class SSL_UnicastAdapter

java.lang.Object
  |
  +--hypercast.adapters.SSL_UnicastAdapter
All Implemented Interfaces:
I_IPv4_UnicastAdapter, I_Stats, I_UnicastAdapter

public class SSL_UnicastAdapter
extends java.lang.Object
implements I_IPv4_UnicastAdapter

This class implements the I_UnicastAdapter interface while using SSL links. SSL links are created when necessary to send data. Links are shutdown when not used for TIMEOUT_TIME millseconds. Each link is unidirectional, so upto 2 SSL sockets can exist for each neighbor. To prevent deadlock, when the thread assigned to receive from a link has not read from it in DROP_TIME seconds, a message is dropped from the link.

In implementation, there are 3 threads plus a thread for each incoming link plus a thread for each dropped message. The 3 threads are responsible for (1) accept()ing connections on the server socket, (2) performing the timer functions and (3) detecting deadlocks and timeouts. When a connection is accepted, a new receiving thread is created for the socket. When the deadlock thread computes that data isn't being read from an incoming socket, it creates a thread to drop a single message from the socket. (The thread dies once the one message has been dropped.)

For each incoming socket and outgoing socket, an object is created. For the incoming socket the IncomingSocketObject object is used to synchronize multiple threads trying to read and manages the buffers for reading messages from the socket. For outgoing sockets, the SSL_OutgoingSocketObject is used to synchronize multiple threads trying to write. This class supports INETv4TwoPorts type physical address.


Field Summary
 
Fields inherited from interface hypercast.I_IPv4_UnicastAdapter
MAX_RETRIES_TO_OPEN_SOCKET
 
Fields inherited from interface hypercast.I_UnicastAdapter
CLOSED, STARTED, STARTING, STOPPED, STOPPING
 
Constructor Summary
SSL_UnicastAdapter(hypercast.HyperCastConfig c, hypercast.I_UnicastAdapter scktAdpt, java.lang.String AddrString, java.lang.String prefix)
          Constructs a new SSL_UnicastAdapter object from an HyperCastConfig object.
SSL_UnicastAdapter(hypercast.HyperCastConfig c, java.net.ServerSocket ssock, java.lang.String prefix)
          Constructs a SSL_UnicastAdapter object with a HyperCastConfig and ServerSocket object.
 
Method Summary
 void Adapter_Inilization(hypercast.HyperCastConfig c, java.lang.String prefix)
          Finish the initialization for this SSL_UnicastAdapter object, except initializing the ServerSocket.
 void clearTimer(java.lang.Object timerid)
          Clear a Timer event.
 void close()
          Close stops the adapter if it has not already been stopped.
 hypercast.I_PhysicalAddress createPhysicalAddress()
          Creates a new physical address.
 hypercast.I_PhysicalAddress createPhysicalAddress(byte[] byteAddressAndPort, int offset)
          Creates physical address from a byte array of address - the inverse of toByteArray.
 hypercast.I_PhysicalAddress createPhysicalAddress(java.lang.String addrString)
          Creates physical address object from a string.
 hypercast.I_UnderlayAddress createUnderlayAddress()
          Creates a new underlay address.
 hypercast.I_UnderlayAddress createUnderlayAddress(byte[] byteAddressAndPort, int offset)
          Creates underlay address from a byte array of address - the inverse of toByteArray.
 hypercast.I_UnderlayAddress createUnderlayAddress(java.lang.String addrString)
          Creates underlay address object from a string.
 long getCurrentTime()
          Get current system time.
 java.lang.Object getInfo()
          Get information of this adapter.
 java.lang.String getIPString(java.net.InetAddress addr)
          Get string representation of IP address in a InetAddress object.
 int getPhysicalAddressSize()
          Returns the size of physical address, when carried in a packet, recognized by this adapter.
 org.w3c.dom.Element[] getReadSchema(org.w3c.dom.Document doc, org.apache.xpath.XPath xpath)
          Return the schema element which represents the root of the sub-tree, specified by the given xpath, in read schema tree.
 org.w3c.dom.Element[] getStats(org.w3c.dom.Document doc, org.apache.xpath.XPath xpath)
          Return the result of query for the statistics specified by the given xpath.
 java.lang.String getStatsName()
          Gets the element name of this I_Stats instance.
 java.lang.String getStatsValue(java.lang.String name)
          Gets the information of a scalar statistics from an object which implements this interface.
 long getTimer(java.lang.Object timerid)
          Get a Timer event.
 int getUnderlayAddressSize()
          Returns the size of underlay address, when carried in a packet, of an I_UnicastAdapter object.
 long getUReceivedBytes()
          Get the number of bytes received by this Adapter.
 long getUReceivedPackets()
          Get the number of packets recerved by this Adapter.
 long getUSentBytes()
          Get the number of bytes sent by this Adapter.
 long getUSentPackets()
          Get the number of packets sent by this Adapter.
 org.w3c.dom.Element[] getWriteSchema(org.w3c.dom.Document doc, org.apache.xpath.XPath xpath)
          Return the schema element which represents the root of the sub-tree, specified by the given xpath, in write schema tree.
 boolean Reset(java.lang.Object SocketObj)
          Resets the local unicast socket with a ServerSocket object.
 void sendUnicastMessage(hypercast.I_NetworkAddress dstaddr, hypercast.I_Message msg)
          Sends a message to a unicast address.
 void setCallback(hypercast.I_AdapterCallback cb)
          Set I_Callback object of this adapter.
 org.w3c.dom.Element[] setStats(org.w3c.dom.Document doc, org.apache.xpath.XPath xpath, org.w3c.dom.Element newValue)
          Set the statistics specified by the given xpath.
 void setStatsName(java.lang.String name)
          Assigns a name to this I_Stats instance.
 java.lang.String setStatsValue(java.lang.String name, java.lang.String newValue)
          Sets the information of s writable scalar statistics to an object which implements this interface.
 void setTimer(java.lang.Object timer_id, long time_ms)
          Set a Timer event.
 void Start()
          Start this SSLAdapter.
 void Stop()
          Stop this SSLAdapter.
 void Stop(long delay)
          Stop this SSLAdapter after a delay.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SSL_UnicastAdapter

public SSL_UnicastAdapter(hypercast.HyperCastConfig c,
                          hypercast.I_UnicastAdapter scktAdpt,
                          java.lang.String AddrString,
                          java.lang.String prefix)
Constructs a new SSL_UnicastAdapter object from an HyperCastConfig object.

Parameters:
c - a HyperCastConfig object.
scktAdpt - object representing the Socket Adapter.
AddrString - string containing physical address information.
prefix - property prefix.

SSL_UnicastAdapter

public SSL_UnicastAdapter(hypercast.HyperCastConfig c,
                          java.net.ServerSocket ssock,
                          java.lang.String prefix)
Constructs a SSL_UnicastAdapter object with a HyperCastConfig and ServerSocket object.

Parameters:
c - a HyperCastConfig object.
ssock - a ServerSocket object.
prefix - property prefix.
Method Detail

Adapter_Inilization

public void Adapter_Inilization(hypercast.HyperCastConfig c,
                                java.lang.String prefix)
Finish the initialization for this SSL_UnicastAdapter object, except initializing the ServerSocket.

Parameters:
c - a HyperCastConfig object.
prefix - property prefix.

getIPString

public java.lang.String getIPString(java.net.InetAddress addr)
Get string representation of IP address in a InetAddress object.

Parameters:
addr - An InetAddress object.

getInfo

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

Specified by:
getInfo in interface I_UnicastAdapter

Reset

public boolean Reset(java.lang.Object SocketObj)
Resets the local unicast socket with a ServerSocket object.

Specified by:
Reset in interface I_UnicastAdapter
Parameters:
SocketObj - object containing information used to finish reset.

setCallback

public void setCallback(hypercast.I_AdapterCallback cb)
Set I_Callback object of this adapter.

Specified by:
setCallback in interface I_UnicastAdapter
Parameters:
cb - an object of type I_AdapterCallback
Throws:
IllegalStateException.

setTimer

public void setTimer(java.lang.Object timer_id,
                     long time_ms)
Set a Timer event.

Specified by:
setTimer in interface I_UnicastAdapter
Parameters:
timer_id - a time event ID.
time_ms - a time in ms.
Throws:
IllegalStateException.

getTimer

public long getTimer(java.lang.Object timerid)
Get a Timer event.

Specified by:
getTimer in interface I_UnicastAdapter
Parameters:
timerid - a time event ID.
Returns:
time in ms.
Throws:
IllegalStateException.

clearTimer

public void clearTimer(java.lang.Object timerid)
Clear a Timer event.

Specified by:
clearTimer in interface I_UnicastAdapter
Parameters:
timerid - a time event ID
Throws:
IllegalStateException.

getCurrentTime

public long getCurrentTime()
Get current system time.

Specified by:
getCurrentTime in interface I_UnicastAdapter
Returns:
current system in ms.

createPhysicalAddress

public hypercast.I_PhysicalAddress createPhysicalAddress(byte[] byteAddressAndPort,
                                                         int offset)
Creates physical address from a byte array of address - the inverse of toByteArray. The first 4 bytes reprsent the IP address, and the last 8 bytes represent the Node Adapter port number and Socket Adapter port number.

Specified by:
createPhysicalAddress in interface I_UnicastAdapter
Parameters:
byteAddressAndPort - an byte array containing a physical address
offset - the position in byteAddressAndPort from where availabe data is read.
Returns:
a new instance of INETv4TwoPorts
See Also:
INETv4TwoPorts.toByteArray()

createPhysicalAddress

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

Specified by:
createPhysicalAddress in interface I_UnicastAdapter
Parameters:
addrString - an string representing a physical address.
Returns:
a new instance of INETv4TwoPorts

createPhysicalAddress

public hypercast.I_PhysicalAddress createPhysicalAddress()
Creates a new physical address.

Specified by:
createPhysicalAddress in interface I_UnicastAdapter
Returns:
a new instance of INETv4TwoPorts

getPhysicalAddressSize

public int getPhysicalAddressSize()
Returns the size of physical address, when carried in a packet, recognized by this adapter.

Specified by:
getPhysicalAddressSize in interface I_UnicastAdapter

createUnderlayAddress

public hypercast.I_UnderlayAddress createUnderlayAddress(byte[] byteAddressAndPort,
                                                         int offset)
Creates underlay address from a byte array of address - the inverse of toByteArray. The first 4 bytes reprsent the IP address, and the last 4 bytes represent the port number.

Specified by:
createUnderlayAddress in interface I_UnicastAdapter
Parameters:
byteAddressAndPort - an byte array containing a physical address
offset - the position in byteAddressAndPort from where availabe data is read.
Returns:
a new instance of INETv4AndOnePort
See Also:
INETv4OnePort.toByteArray()

createUnderlayAddress

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

Specified by:
createUnderlayAddress in interface I_UnicastAdapter
Parameters:
addrString - an string representing a physical address.
Returns:
a new instance of INETv4AndOnePort

createUnderlayAddress

public hypercast.I_UnderlayAddress createUnderlayAddress()
Creates a new underlay address.

Specified by:
createUnderlayAddress in interface I_UnicastAdapter
Returns:
a new instance of INETv4AndOnePort

getUnderlayAddressSize

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

Specified by:
getUnderlayAddressSize in interface I_UnicastAdapter

sendUnicastMessage

public void sendUnicastMessage(hypercast.I_NetworkAddress dstaddr,
                               hypercast.I_Message msg)
Sends a message to a unicast address. A SSL connection may have to be created before the packet is sent.

Specified by:
sendUnicastMessage in interface I_UnicastAdapter
Parameters:
dstaddr - destination address.
msg - message to be sent.
Throws:
IllegalStateException.

Start

public void Start()
Start this SSLAdapter.

Specified by:
Start in interface I_UnicastAdapter
Throws:
IllegalStateException.

Stop

public void Stop()
Stop this SSLAdapter. This may take time to complete. During that time, callbacks may occur. When the call to Stop() completes, no further callbacks will be made.

Specified by:
Stop in interface I_UnicastAdapter
Throws:
IllegalStateException.

Stop

public void Stop(long delay)
Stop this SSLAdapter after a delay. During that time, callbacks may occur. When the call to Stop() completes, no further callbacks will be made.

Specified by:
Stop in interface I_UnicastAdapter
Parameters:
delay - delay in milliseconds
Throws:
IllegalStateException.

close

public void close()
Description copied from interface: I_UnicastAdapter
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.

Specified by:
close in interface I_UnicastAdapter

getUReceivedPackets

public long getUReceivedPackets()
Get the number of packets recerved by this Adapter.


getUReceivedBytes

public long getUReceivedBytes()
Get the number of bytes received by this Adapter.


getUSentPackets

public long getUSentPackets()
Get the number of packets sent by this Adapter.


getUSentBytes

public long getUSentBytes()
Get the number of bytes sent by this Adapter.


getStatsName

public java.lang.String getStatsName()
Description copied from interface: I_Stats
Gets the element name of this I_Stats instance. The element name is originally assigned from the attribute StstsName in the configuration file, and can be changed by this method.

Specified by:
getStatsName in interface I_Stats
See Also:
I_Stats.getStatsName()

setStatsName

public void setStatsName(java.lang.String name)
Description copied from interface: I_Stats
Assigns a name to this I_Stats instance. The assigned name becomes the tag of the element associated to this I_Stats instance on the statistics tree.

Specified by:
setStatsName in interface I_Stats
Parameters:
name - the name assigned to the I_Stats instance.
See Also:
I_Stats.setStatsName(String)

getStatsValue

public java.lang.String getStatsValue(java.lang.String name)
                               throws HyperCastStatsException
Gets the information of a scalar statistics from an object which implements this interface.

Throws:
HyperCastStatsException - if the statistics with given name is not supported by the object.

setStatsValue

public java.lang.String setStatsValue(java.lang.String name,
                                      java.lang.String newValue)
                               throws HyperCastStatsException
Sets the information of s writable scalar statistics to an object which implements this interface.

Throws:
HyperCastStatsException - if the statistics with given name is not supported by the object or read-only, or if value does not conform with expected format.

getStats

public org.w3c.dom.Element[] getStats(org.w3c.dom.Document doc,
                                      org.apache.xpath.XPath xpath)
                               throws HyperCastStatsException
Return the result of query for the statistics specified by the given xpath.

Specified by:
getStats in interface I_Stats
Parameters:
doc - Document used for create new elements or nodes.
xpath - XPath instance represents the statistics to be queried.
Throws:
HyperCastStatsException - If the xpath does not specify a valid subtree.
See Also:
I_Stats.getStats(org.w3c.dom.Document, org.apache.xpath.XPath)

setStats

public org.w3c.dom.Element[] setStats(org.w3c.dom.Document doc,
                                      org.apache.xpath.XPath xpath,
                                      org.w3c.dom.Element newValue)
                               throws HyperCastStatsException
Set the statistics specified by the given xpath. The value actually set is returned.

Specified by:
setStats in interface I_Stats
Parameters:
doc - Document used for create new elements or nodes.
xpath - XPath instance represents the statistics to be queried.
newValue - Element representing the value or sub-tree to be set.
Throws:
HyperCastStatsException - If the xpath does not specify a valid subtree or if any part of the the subtree is read-only, or if the newValue does not conform with the expected format.
See Also:
I_Stats.setStats(org.w3c.dom.Document, org.apache.xpath.XPath, org.w3c.dom.Element)

getReadSchema

public org.w3c.dom.Element[] getReadSchema(org.w3c.dom.Document doc,
                                           org.apache.xpath.XPath xpath)
                                    throws HyperCastStatsException
Return the schema element which represents the root of the sub-tree, specified by the given xpath, in read schema tree.

Specified by:
getReadSchema in interface I_Stats
Parameters:
doc - Document used for create new elements or nodes.
xpath - XPath instance representing the statistics which is the root of the sub-tree to be queried.
Throws:
HyperCastStatsException - If some part of the specified subtree does not correctly implement this interface method.
See Also:
I_Stats.getReadSchema(Document, XPath)

getWriteSchema

public org.w3c.dom.Element[] getWriteSchema(org.w3c.dom.Document doc,
                                            org.apache.xpath.XPath xpath)
                                     throws HyperCastStatsException
Return the schema element which represents the root of the sub-tree, specified by the given xpath, in write schema tree.

Specified by:
getWriteSchema in interface I_Stats
Parameters:
doc - Document used for create new elements or nodes.
xpath - XPath instance representing the statistics which is the root of the sub-tree to be queried.
Throws:
HyperCastStatsException - If some part of the specified subtree does not correctly implement this interface method.
See Also:
I_Stats.getWriteSchema(Document, XPath)