org.objectweb.jonas.discovery
Class DiscoveryHelper

java.lang.Object
  extended by org.objectweb.jonas.discovery.DiscoveryHelper

public class DiscoveryHelper
extends java.lang.Object

This class helps creating a byte[] to be sent in a datagram when sending a DiscMessage, and helps reading the sent DiscMessage on receiving an object when this object is actually a DiscMessage.

Author:
Adriana Danes

Constructor Summary
DiscoveryHelper()
           
 
Method Summary
protected static java.lang.Object bytesToObject(byte[] bytes)
           
protected static byte[] objectToBytes(java.lang.Object obj)
          Construct a byte[] containing type info about a DiscMessage object to be sent, plus the content of this message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DiscoveryHelper

public DiscoveryHelper()
Method Detail

objectToBytes

protected static byte[] objectToBytes(java.lang.Object obj)
                               throws java.io.IOException
Construct a byte[] containing type info about a DiscMessage object to be sent, plus the content of this message.

Parameters:
obj - Object to be send. Only supported DiscMessage objects.
Returns:
Null if the object is not an instance of DiscMessage or one of its subclasses.
Throws:
java.io.IOException - Could not create an ObjectOutputStream to write into the underlying ByteArrayOutputStream.

bytesToObject

protected static java.lang.Object bytesToObject(byte[] bytes)
                                         throws java.io.IOException,
                                                java.lang.ClassNotFoundException
Parameters:
bytes - byte[] containing a received message
Returns:
Null if the object in the received message is not of one of the known types, or the object which have been sent.
Throws:
java.io.IOException - Could not create an ObjectInputStream to read in it
java.lang.ClassNotFoundException - Class of a serialized object cannot be found