Package com.swiftmq.net.protocol
Class ProtocolOutputHandler
- java.lang.Object
-
- java.io.OutputStream
-
- com.swiftmq.net.protocol.ProtocolOutputHandler
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
- Direct Known Subclasses:
RawOutputHandler,SMQPOutputHandler
public abstract class ProtocolOutputHandler extends java.io.OutputStreamA ProtocolOutputHandler is the complement to a ProtocolInputHandler and responsible for protocol specific packaging before data is sent to the network. The ProtocolOutputHandler is an OutputStream and will be used as such from the Swiftlets. These just write to the OutputStream and callflush()at the end which leads to a call tomarkChunkCompleted()and then to an invocation of an registered OutputListener which performs the write to the network. This could be done either blocking or non-blocking. The OutputListener returns the number of bytes written to the network and the invocation continues until all bytes have been written.- Author:
- IIT GmbH, Bremen/Germany, Copyright (c) 2000-2002, All Rights Reserved
-
-
Constructor Summary
Constructors Constructor Description ProtocolOutputHandler()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidaddByte(byte b)Add a byte to the current chunk.protected abstract voidaddBytes(byte[] b, int offset, int len)Adds a number of bytes to the current chunk.abstract ProtocolOutputHandlercreate()Factory method to create a new ProtocolOutputHandler.abstract ProtocolOutputHandlercreate(int bufferSize, int extendSize)Factory method to create a new ProtocolOutputHandler.voidflush()protected abstract byte[]getByteArray()Returns a reference to the byte array of the current chunk to transmit.abstract intgetChunkCount()Returns the number of chunk the handler has stored.protected abstract intgetLength()Returns the number of bytes to transmit, starting at the offset.protected abstract intgetOffset()Returns the offset in the byte array of the current chunk where transmit should start.voidinvokeOutputListener()Invokes the OutputListener.protected abstract voidmarkChunkCompleted()Marks a chunk completed.protected abstract voidsetBytesWritten(int written)Sets the number of bytes written from the OutputListener.voidsetOutputListener(OutputListener listener)Set the OutputListener.voidwrite(byte[] b, int offset, int len)voidwrite(int b)
-
-
-
Method Detail
-
setOutputListener
public final void setOutputListener(OutputListener listener)
Set the OutputListener. The OutputListener is implemented by the Network Swiftlet.- Parameters:
listener- listenr.
-
invokeOutputListener
public final void invokeOutputListener() throws java.io.IOExceptionInvokes the OutputListener. Done by the Netwok Swiftlet.- Throws:
java.io.IOException- on error.
-
write
public void write(int b) throws java.io.IOException- Specified by:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] b, int offset, int len) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException
-
create
public abstract ProtocolOutputHandler create()
Factory method to create a new ProtocolOutputHandler. For example, a RawOutputHandler returns a RawOutputHandler here.- Returns:
- new protocol input handler.
-
create
public abstract ProtocolOutputHandler create(int bufferSize, int extendSize)
Factory method to create a new ProtocolOutputHandler. For example, a RawOutputHandler returns a RawOutputHandler here.- Parameters:
bufferSize- initial buffer sizeextendSize- extend size- Returns:
- new protocol input handler.
-
getChunkCount
public abstract int getChunkCount()
Returns the number of chunk the handler has stored.- Returns:
- number of chunks.
-
markChunkCompleted
protected abstract void markChunkCompleted()
Marks a chunk completed. Called duringflush()If a protocol transmits byte streams with a length field in front, this is the place to determine the length.
-
getByteArray
protected abstract byte[] getByteArray()
Returns a reference to the byte array of the current chunk to transmit. Called duringinvokeOutputListener().- Returns:
- byte array.
-
getOffset
protected abstract int getOffset()
Returns the offset in the byte array of the current chunk where transmit should start. Called duringinvokeOutputListener().- Returns:
- offset.
-
getLength
protected abstract int getLength()
Returns the number of bytes to transmit, starting at the offset. Called duringinvokeOutputListener().- Returns:
- length.
-
setBytesWritten
protected abstract void setBytesWritten(int written)
Sets the number of bytes written from the OutputListener. This is the actual number of bytes written from the OutputListener to the network. The offset then must be set tooffset+writtenand the length tolength-written. If all bytes of the current chunk have been written, the chunk can be destroyed or marked for reuse.- Parameters:
written- number of written bytes.
-
addByte
protected abstract void addByte(byte b)
Add a byte to the current chunk. Called fromwrite(b).- Parameters:
b- byte.
-
addBytes
protected abstract void addBytes(byte[] b, int offset, int len)Adds a number of bytes to the current chunk. Called fromwrite(b[],offset,len).- Parameters:
b- byte array.offset- offset.len- length.
-
-