X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=third-party%2Fopenflow-codec%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenflow%2Fcodec%2Fio%2FOFMessageAsyncStream.java;fp=third-party%2Fopenflow-codec%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenflow%2Fcodec%2Fio%2FOFMessageAsyncStream.java;h=0000000000000000000000000000000000000000;hb=64fe0fbca1a6c2b77ad25f568d73a7eb64236d16;hp=035ba6527c70290dc580d7e91620cdd9cdb9703c;hpb=8b9a3ff2bbc83941254b46b818cbbae5cc1a3a5b;p=openflowjava.git diff --git a/third-party/openflow-codec/src/main/java/org/openflow/codec/io/OFMessageAsyncStream.java b/third-party/openflow-codec/src/main/java/org/openflow/codec/io/OFMessageAsyncStream.java deleted file mode 100644 index 035ba652..00000000 --- a/third-party/openflow-codec/src/main/java/org/openflow/codec/io/OFMessageAsyncStream.java +++ /dev/null @@ -1,118 +0,0 @@ -/** - * - */ -package org.openflow.codec.io; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.SocketChannel; -import java.util.List; - -import org.openflow.codec.protocol.OFPMessage; -import org.openflow.codec.protocol.factory.OFPMessageFactory; - -/** - * Asynchronous OpenFlow message marshalling and unmarshalling stream wrapped - * around an NIO SocketChannel - * - * @author Rob Sherwood (rob.sherwood@stanford.edu) - * @author David Erickson (daviderickson@cs.stanford.edu) - * - */ -public class OFMessageAsyncStream implements OFMessageInStream, OFMessageOutStream { - static public int defaultBufferSize = 1048576; // 1MB - - protected ByteBuffer inBuf, outBuf; - protected OFPMessageFactory messageFactory; - protected SocketChannel sock; - protected int partialReadCount = 0; - - public OFMessageAsyncStream(SocketChannel sock, OFPMessageFactory messageFactory) throws IOException { - inBuf = ByteBuffer.allocateDirect(OFMessageAsyncStream.defaultBufferSize); - outBuf = ByteBuffer.allocateDirect(OFMessageAsyncStream.defaultBufferSize); - this.sock = sock; - this.messageFactory = messageFactory; - this.sock.configureBlocking(false); - } - - @Override - public List read() throws IOException { - return this.read(0); - } - - @Override - public List read(int limit) throws IOException { - List l; - int read = sock.read(inBuf); - if (read == -1) - return null; - inBuf.flip(); - IDataBuffer buffer = new ByteDataBuffer(inBuf); - l = messageFactory.parseMessages(buffer, limit); - if (inBuf.hasRemaining()) - inBuf.compact(); - else - inBuf.clear(); - return l; - } - - protected void appendMessageToOutBuf(OFPMessage m) throws IOException { - int msglen = m.getLengthU(); - if (outBuf.remaining() < msglen) { - throw new IOException("Message length exceeds buffer capacity: " + msglen); - } - IDataBuffer buffer = new ByteDataBuffer(outBuf); - m.writeTo(buffer); - } - - /** - * Buffers a single outgoing openflow message - */ - @Override - public void write(OFPMessage m) throws IOException { - appendMessageToOutBuf(m); - } - - /** - * Buffers a list of OpenFlow messages - */ - @Override - public void write(List l) throws IOException { - for (OFPMessage m : l) { - appendMessageToOutBuf(m); - } - } - - /** - * 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 - */ - public void flush() throws IOException { - outBuf.flip(); // swap pointers; lim = pos; pos = 0; - sock.write(outBuf); // write data starting at pos up to lim - outBuf.compact(); - } - - /** - * Is there outgoing buffered data that needs to be flush()'d? - */ - public boolean needsFlush() { - return outBuf.position() > 0; - } - - /** - * @return the messageFactory - */ - public OFPMessageFactory getMessageFactory() { - return messageFactory; - } - - /** - * @param messageFactory - * the messageFactory to set - */ - public void setMessageFactory(OFPMessageFactory messageFactory) { - this.messageFactory = messageFactory; - } -}