org.openflow.io
Class OFMessageAsyncStream

java.lang.Object
  extended by org.openflow.io.OFMessageAsyncStream
All Implemented Interfaces:
OFMessageInStream, OFMessageOutStream

public class OFMessageAsyncStream
extends java.lang.Object
implements OFMessageInStream, OFMessageOutStream

Asynchronous OpenFlow message marshalling and unmarshalling stream wrapped around an NIO SocketChannel

Author:
Rob Sherwood (rob.sherwood@stanford.edu), David Erickson (daviderickson@cs.stanford.edu)

Field Summary
static int defaultBufferSize
           
protected  java.nio.ByteBuffer inBuf
           
protected  OFMessageFactory messageFactory
           
protected  java.nio.ByteBuffer outBuf
           
protected  int partialReadCount
           
protected  java.nio.channels.SocketChannel sock
           
 
Constructor Summary
OFMessageAsyncStream(java.nio.channels.SocketChannel sock, OFMessageFactory messageFactory)
           
 
Method Summary
protected  void appendMessageToOutBuf(OFMessage m)
           
 void flush()
          Flush buffered outgoing data.
 OFMessageFactory getMessageFactory()
          Returns the OFMessageFactory used to create messages on this stream
 boolean needsFlush()
          Is there outgoing buffered data that needs to be flush()'d?
 java.util.List<OFMessage> read()
          Read OF messages from the stream
 java.util.List<OFMessage> read(int limit)
          Read OF messages from the stream
 void setMessageFactory(OFMessageFactory messageFactory)
          Sets the OFMessageFactory used to create messages on this stream
 void write(java.util.List<OFMessage> l)
          Buffers a list of OpenFlow messages
 void write(OFMessage m)
          Buffers a single outgoing openflow message
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultBufferSize

public static int defaultBufferSize

inBuf

protected java.nio.ByteBuffer inBuf

outBuf

protected java.nio.ByteBuffer outBuf

messageFactory

protected OFMessageFactory messageFactory

sock

protected java.nio.channels.SocketChannel sock

partialReadCount

protected int partialReadCount
Constructor Detail

OFMessageAsyncStream

public OFMessageAsyncStream(java.nio.channels.SocketChannel sock,
                            OFMessageFactory messageFactory)
                     throws java.io.IOException
Throws:
java.io.IOException
Method Detail

read

public java.util.List<OFMessage> read()
                               throws java.io.IOException
Description copied from interface: OFMessageInStream
Read OF messages from the stream

Specified by:
read in interface OFMessageInStream
Returns:
a list of OF Messages, empty if no complete messages are available, null if the stream has closed
Throws:
java.io.IOException

read

public java.util.List<OFMessage> read(int limit)
                               throws java.io.IOException
Description copied from interface: OFMessageInStream
Read OF messages from the stream

Specified by:
read in interface OFMessageInStream
Parameters:
limit - The maximum number of messages to read: 0 means all that are buffered
Returns:
a list of OF Messages, empty if no complete messages are available, null if the stream has closed
Throws:
java.io.IOException

appendMessageToOutBuf

protected void appendMessageToOutBuf(OFMessage m)
                              throws java.io.IOException
Throws:
java.io.IOException

write

public void write(OFMessage m)
           throws java.io.IOException
Buffers a single outgoing openflow message

Specified by:
write in interface OFMessageOutStream
Parameters:
m - An OF Message
Throws:
java.io.IOException

write

public void write(java.util.List<OFMessage> l)
           throws java.io.IOException
Buffers a list of OpenFlow messages

Specified by:
write in interface OFMessageOutStream
Parameters:
l - A list of OF Messages
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Flush buffered outgoing data. Keep flushing until needsFlush() returns false. Each flush() corresponds to a SocketChannel.write(), so this is designed for one flush() per select() event

Specified by:
flush in interface OFMessageOutStream
Throws:
java.io.IOException

needsFlush

public boolean needsFlush()
Is there outgoing buffered data that needs to be flush()'d?

Specified by:
needsFlush in interface OFMessageOutStream
Returns:
true if there is buffered data and flush() should be called

getMessageFactory

public OFMessageFactory getMessageFactory()
Description copied from interface: OFMessageInStream
Returns the OFMessageFactory used to create messages on this stream

Specified by:
getMessageFactory in interface OFMessageInStream
Returns:
the messageFactory

setMessageFactory

public void setMessageFactory(OFMessageFactory messageFactory)
Description copied from interface: OFMessageInStream
Sets the OFMessageFactory used to create messages on this stream

Specified by:
setMessageFactory in interface OFMessageInStream
Parameters:
messageFactory - the messageFactory to set