ch.ethz.iks.r_osgi.messages
Class RemoteOSGiMessage

java.lang.Object
  extended by ch.ethz.iks.r_osgi.messages.RemoteOSGiMessage
Direct Known Subclasses:
DeliverServiceMessage, FetchServiceMessage, InvokeMethodMessage, LeaseMessage, LeaseUpdateMessage, MethodResultMessage, RemoteEventMessage, StreamRequestMessage, StreamResultMessage, TimeOffsetMessage

public abstract class RemoteOSGiMessage
extends Object

Abstract base class for all Messages.

Since:
0.1
Author:
Jan S. Rellermeyer, ETH Zurich

Field Summary
static short DELIVER_BUNDLE
          Deprecated.  
static short DELIVER_SERVICE
          type code for deliver service messages.
static short FETCH_SERVICE
          type code for fetch service messages.
static short INVOKE_METHOD
          type code for invoke method messages.
static short LEASE
          type code for lease messages.
static short LEASE_UPDATE
          type code for service attribute updates.
static short METHOD_RESULT
          type code for method result messages.
static short REMOTE_EVENT
          type code for remote event messages.
static short STREAM_REQUEST
          type code for stream request messages.
static short STREAM_RESULT
          type code for stream result messages.
static short TIME_OFFSET
          type code for time offset messages.
protected  short xid
          the transaction id.
 
Method Summary
 short getFuncID()
          Get the function ID (type code) of the message.
 short getXID()
          get the transaction ID.
static RemoteOSGiMessage parse(ObjectInputStream input)
          reads in a network packet and constructs the corresponding subtype of RemoteOSGiMessage from it.
protected static byte[] readBytes(ObjectInputStream input)
          reads the bytes encoded as SLP string.
protected static String[] readStringArray(ObjectInputStream in)
          read a string array.
 void send(ObjectOutputStream out)
          write the RemoteOSGiMessage to an output stream.
 void setXID(short xid)
          set the xid.
protected abstract  void writeBody(ObjectOutputStream output)
          write the body of a RemoteOSGiMessage.
protected static void writeBytes(ObjectOutputStream out, byte[] bytes)
          writes a byte array.
protected static void writeStringArray(ObjectOutputStream out, String[] strings)
          write a string array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEASE

public static final short LEASE
type code for lease messages.

See Also:
Constant Field Values

FETCH_SERVICE

public static final short FETCH_SERVICE
type code for fetch service messages.

See Also:
Constant Field Values

DELIVER_SERVICE

public static final short DELIVER_SERVICE
type code for deliver service messages.

See Also:
Constant Field Values

DELIVER_BUNDLE

public static final short DELIVER_BUNDLE
Deprecated. 
type code for deliver bundle messages.

See Also:
Constant Field Values

INVOKE_METHOD

public static final short INVOKE_METHOD
type code for invoke method messages.

See Also:
Constant Field Values

METHOD_RESULT

public static final short METHOD_RESULT
type code for method result messages.

See Also:
Constant Field Values

REMOTE_EVENT

public static final short REMOTE_EVENT
type code for remote event messages.

See Also:
Constant Field Values

TIME_OFFSET

public static final short TIME_OFFSET
type code for time offset messages.

See Also:
Constant Field Values

LEASE_UPDATE

public static final short LEASE_UPDATE
type code for service attribute updates.

See Also:
Constant Field Values

STREAM_REQUEST

public static final short STREAM_REQUEST
type code for stream request messages.

See Also:
Constant Field Values

STREAM_RESULT

public static final short STREAM_RESULT
type code for stream result messages.

See Also:
Constant Field Values

xid

protected short xid
the transaction id.

Method Detail

getXID

public final short getXID()
get the transaction ID.

Returns:
the xid.
Since:
0.6
See Also:
ch.ethz.iks.r_osgi.RemoteOSGiMessage#getXID()

setXID

public void setXID(short xid)
set the xid.

Parameters:
xid - set the xid.

getFuncID

public final short getFuncID()
Get the function ID (type code) of the message.

Returns:
the type code.
Since:
0.6
See Also:
ch.ethz.iks.r_osgi.RemoteOSGiMessage#getFuncID()

parse

public static RemoteOSGiMessage parse(ObjectInputStream input)
                               throws IOException
reads in a network packet and constructs the corresponding subtype of RemoteOSGiMessage from it. The header is:
   0                   1                   2                   3
   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |    Version    |         Function-ID           |     XID       |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |    XID cntd.  | 
  +-+-+-+-+-+-+-+-+
 
the body is processed by the subtype class.

Parameters:
input - the DataInput providing the network packet.
Returns:
the RemoteOSGiMessage.
Throws:
SocketException - if something goes wrong.
IOException

send

public final void send(ObjectOutputStream out)
                throws IOException
write the RemoteOSGiMessage to an output stream.

Parameters:
out - the ObjectOutputStream.
Throws:
IOException - in case of IO failures.

writeBody

protected abstract void writeBody(ObjectOutputStream output)
                           throws IOException
write the body of a RemoteOSGiMessage.

Parameters:
output - the output stream.
Throws:
IOException - in case of IO failures.

readBytes

protected static byte[] readBytes(ObjectInputStream input)
                           throws IOException
reads the bytes encoded as SLP string.

Parameters:
input - the DataInput.
Returns:
the byte array.
Throws:
IOException - in case of IO failures.

writeBytes

protected static void writeBytes(ObjectOutputStream out,
                                 byte[] bytes)
                          throws IOException
writes a byte array.

Parameters:
out - the output stream.
bytes - the bytes.
Throws:
IOException - in case of IO failures.

writeStringArray

protected static void writeStringArray(ObjectOutputStream out,
                                       String[] strings)
                                throws IOException
write a string array.

Parameters:
out - the output stream.
strings - the string array.
Throws:
IOException - in case of IO failures.

readStringArray

protected static String[] readStringArray(ObjectInputStream in)
                                   throws IOException
read a string array.

Parameters:
in - the input stream
Returns:
the read string array.
Throws:
IOException - in case of IO failures.