Package jadex.bridge.component.streams
Class InputConnection
- java.lang.Object
-
- jadex.bridge.component.streams.AbstractConnection
-
- jadex.bridge.component.streams.InputConnection
-
- All Implemented Interfaces:
IConnection
,IInputConnection
public class InputConnection extends AbstractConnection implements IInputConnection
Input connection implementation for byte streams. Must synchronized its internal data because the connection handler and the connection user (i.e. a component) are using the connection concurrently. - the handler uses addData to forward received data to the connection. - the connection user calls interface methods to read data.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<byte[]>
data
The data.protected SubscriptionIntermediateFuture<byte[]>
ifuture
The read futures.protected int
offset
The offset (startvalue of current first row).protected Future<java.lang.Byte>
ofuture
protected int
position
The position.protected int
size
The size.-
Fields inherited from class jadex.bridge.component.streams.AbstractConnection
ch, closed, closing, id, ini, inited, initiator, input, participant
-
-
Constructor Summary
Constructors Constructor Description InputConnection(IComponentIdentifier sender, IComponentIdentifier receiver, int id, boolean initiator, IAbstractConnectionHandler ch)
Create a new input connection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addData(byte[] data)
Add data to the internal data buffer.ISubscriptionIntermediateFuture<byte[]>
aread()
Asynchronous read.IFuture<java.lang.Byte>
areadNext()
Asynchronous read.int
available()
Get the number of available bytes.protected void
dataRead()
byte[]
getNextByteArray()
Get the next data byte array.int
getStoredDataSize()
Get the size of the stored data.protected int
internalRead()
Non-blocking read.int
read()
Non-blocking read.int
read(byte[] buffer)
Non-blocking read.void
setClosed()
Set the stream to be closed.ISubscriptionIntermediateFuture<java.lang.Long>
writeToOutputStream(java.io.OutputStream os, IExternalAccess component)
Read all data from output stream to the connection.-
Methods inherited from class jadex.bridge.component.streams.AbstractConnection
close, getConnectionHandler, getConnectionId, getInitiator, getNonFunctionalProperties, getParticipant, isClosed, isClosing, isInited, isInitiatorSide, isInputConnection, setClosing, setInited
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jadex.bridge.IConnection
close, getConnectionId, getInitiator, getNonFunctionalProperties, getParticipant
-
-
-
-
Field Detail
-
data
protected java.util.List<byte[]> data
The data.
-
offset
protected int offset
The offset (startvalue of current first row).
-
position
protected int position
The position.
-
size
protected int size
The size.
-
ifuture
protected SubscriptionIntermediateFuture<byte[]> ifuture
The read futures.
-
ofuture
protected Future<java.lang.Byte> ofuture
-
-
Constructor Detail
-
InputConnection
public InputConnection(IComponentIdentifier sender, IComponentIdentifier receiver, int id, boolean initiator, IAbstractConnectionHandler ch)
Create a new input connection.
-
-
Method Detail
-
read
public int read()
Non-blocking read. Tries to read the next byte.- Specified by:
read
in interfaceIInputConnection
- Returns:
- The next byte or -1 if the end of the stream has been reached.
-
read
public int read(byte[] buffer)
Non-blocking read. Tries to fill the buffer from the stream.- Specified by:
read
in interfaceIInputConnection
- Parameters:
buffer
- The buffer to read in.- Returns:
- The number of bytes that could be read into the buffer.
-
internalRead
protected int internalRead()
Non-blocking read. Tries to read the next byte.- Returns:
- The next byte or -1 if none is currently available.
- Throws:
exception
- if end of stream has been reached.
-
getNextByteArray
public byte[] getNextByteArray()
Get the next data byte array.
-
aread
public ISubscriptionIntermediateFuture<byte[]> aread()
Asynchronous read.- Specified by:
aread
in interfaceIInputConnection
- Returns:
- Bytes one by one till end of stream or closed.
-
areadNext
public IFuture<java.lang.Byte> areadNext()
Asynchronous read.- Returns:
- Bytes one by one till end of stream or closed.
-
available
public int available()
Get the number of available bytes.- Specified by:
available
in interfaceIInputConnection
- Returns:
- The number of available bytes.
-
addData
public void addData(byte[] data)
Add data to the internal data buffer.- Parameters:
data
- The data to add. If stream is closed adding data is not allowed.
-
setClosed
public void setClosed()
Set the stream to be closed.- Overrides:
setClosed
in classAbstractConnection
-
getStoredDataSize
public int getStoredDataSize()
Get the size of the stored data.
-
dataRead
protected void dataRead()
-
writeToOutputStream
public ISubscriptionIntermediateFuture<java.lang.Long> writeToOutputStream(java.io.OutputStream os, IExternalAccess component)
Read all data from output stream to the connection. The result is an intermediate future that reports back the size that was read. It can also be used to terminate reading.- Specified by:
writeToOutputStream
in interfaceIInputConnection
- Parameters:
is
- The input stream.component
- The component.
-
-