PM
- The actual PortMetrics
type to use.Flushable
, org.refcodes.component.Closable
, org.refcodes.component.Closable.CloseAutomaton
, org.refcodes.component.ClosedAccessor
, org.refcodes.component.ConnectableComponent
, org.refcodes.component.ConnectableComponent.ConnectableAutomaton
, org.refcodes.component.ConnectionComponent<PM>
, org.refcodes.component.ConnectionComponent.ConnectionAutomaton<PM>
, org.refcodes.component.ConnectionOpenable<PM>
, org.refcodes.component.ConnectionOpenable.ConnectionOpenAutomaton<PM>
, org.refcodes.component.ConnectionStatusAccessor
, org.refcodes.component.Flushable
, org.refcodes.component.LinkComponent
, org.refcodes.component.LinkComponent.LinkAutomaton
, org.refcodes.component.Openable
, org.refcodes.component.Openable.OpenAutomaton
, org.refcodes.component.Openable.OpenBuilder<PM>
, org.refcodes.component.OpenedAccessor
, org.refcodes.io.Availability
, org.refcodes.io.ByteDestination
, org.refcodes.io.ByteReceiver
, org.refcodes.io.BytesDestination
, org.refcodes.io.ByteSource
, org.refcodes.io.BytesReceiver
, org.refcodes.io.BytesSource
, org.refcodes.io.BytesTransceiver
, org.refcodes.io.BytesTransmitter
, org.refcodes.io.ByteTransceiver
, org.refcodes.io.ByteTransmitter
, org.refcodes.io.Receivable
, org.refcodes.io.Skippable
, org.refcodes.io.TimeoutInputStreamAccessor
, org.refcodes.io.Transmittable
, org.refcodes.mixin.AliasAccessor
, org.refcodes.mixin.InputStreamAccessor
, org.refcodes.mixin.OutputStreamAccessor
, Port<PM>
, PortMetricsAccessor<PM>
, SegmentDestination
, SegmentReceiver
, SegmentSource
, SegmentTransceiver
, SegmentTransmitter
, SerialReceiver
, SerialTransceiver
, SerialTransmitter
FullDuplexPacketPortDecorator
, FullDuplexTxPortDecorator
public class AbstractPortDecorator<PM extends PortMetrics> extends Object implements Port<PM>
org.refcodes.mixin.AliasAccessor.AliasBuilder<B extends org.refcodes.mixin.AliasAccessor.AliasBuilder<B>>, org.refcodes.mixin.AliasAccessor.AliasMutator, org.refcodes.mixin.AliasAccessor.AliasProperty
org.refcodes.io.BytesReceiver.ReceiverInputStream
org.refcodes.io.BytesTransmitter.TransmitterOutputStream
org.refcodes.component.Closable.CloseAutomaton, org.refcodes.component.Closable.CloseBuilder<B extends org.refcodes.component.Closable.CloseBuilder<B>>
org.refcodes.component.ConnectionComponent.ConnectionAutomaton<CON extends Object>, org.refcodes.component.ConnectionComponent.ConnectionComponentBuilder<CON extends Object,B extends org.refcodes.component.ConnectionComponent.ConnectionComponentBuilder<CON,B>>
org.refcodes.component.ConnectionOpenable.ConnectionOpenAutomaton<CON extends Object>, org.refcodes.component.ConnectionOpenable.ConnectionOpenBuilder<CON extends Object,B extends org.refcodes.component.ConnectionOpenable.ConnectionOpenBuilder<CON,B>>
org.refcodes.mixin.InputStreamAccessor.InputStreamBuilder<B extends org.refcodes.mixin.InputStreamAccessor.InputStreamBuilder<?>>, org.refcodes.mixin.InputStreamAccessor.InputStreamMutator, org.refcodes.mixin.InputStreamAccessor.InputStreamProperty
org.refcodes.component.LinkComponent.LinkAutomaton, org.refcodes.component.LinkComponent.LinkComponentBuilder<B extends org.refcodes.component.LinkComponent.LinkComponentBuilder<B>>
org.refcodes.component.Openable.OpenAutomaton, org.refcodes.component.Openable.OpenBuilder<B extends org.refcodes.component.Openable.OpenBuilder<B>>
org.refcodes.mixin.OutputStreamAccessor.OutputStreamBuilder<B extends org.refcodes.mixin.OutputStreamAccessor.OutputStreamBuilder<?>>, org.refcodes.mixin.OutputStreamAccessor.OutputStreamMutator, org.refcodes.mixin.OutputStreamAccessor.OutputStreamProperty
PortMetricsAccessor.PortMetricsBuilder<PM extends PortMetrics,B extends PortMetricsAccessor.PortMetricsBuilder<PM,B>>, PortMetricsAccessor.PortMetricsMutator<PM extends PortMetrics>, PortMetricsAccessor.PortMetricsProperty<PM extends PortMetrics>
org.refcodes.io.TimeoutInputStreamAccessor.TimeoutInputStreamBuilder<B extends org.refcodes.io.TimeoutInputStreamAccessor.TimeoutInputStreamBuilder<?>>, org.refcodes.io.TimeoutInputStreamAccessor.TimeoutInputStreamMutator, org.refcodes.io.TimeoutInputStreamAccessor.TimeoutInputStreamProperty
Constructor | Description |
---|---|
AbstractPortDecorator(Port<PM> aPort) |
Decorates the given
Port with the according functionality. |
Modifier and Type | Method | Description |
---|---|---|
int |
available() |
Returns the number of bytes which can be read directly e.g. which are
already been stored in an internal buffer.
|
void |
close() |
Attention: Implementations of this method should do a
Object.notifyAll() in order to terminate any pending asynchronous
operations such as SegmentReceiver.onReceiveSegment(Segment) or
SegmentReceiver.onReceiveSegment(Segment, SegmentConsumer) . |
void |
closeIn(int aCloseInMillis) |
|
void |
closeQuietly() |
|
void |
closeUnchecked() |
|
<SEGMENT extends Segment> |
doTransmitSegment(SEGMENT aSegment) |
|
<SEGMENT extends Segment> |
doTransmitSegment(SEGMENT aSegment,
SegmentConsumer<SEGMENT> aSegmentConsumer) |
|
void |
flush() |
|
void |
flushUnchecked() |
|
String |
getAlias() |
|
org.refcodes.component.ConnectionStatus |
getConnectionStatus() |
|
InputStream |
getInputStream() |
|
org.refcodes.io.TimeoutInputStream |
getInputStream(long aTimeoutInMs) |
|
OutputStream |
getOutputStream() |
|
PM |
getPortMetrics() |
Retrieves the
PortMetrics from the PortMetrics property. |
boolean |
hasAvailable() |
|
boolean |
isClosable() |
|
boolean |
isClosed() |
|
boolean |
isFlushable() |
|
boolean |
isOpenable() |
|
boolean |
isOpenable(PM aPortMetrics) |
|
boolean |
isOpened() |
|
<SEGMENT extends Segment> |
onReceiveSegment(SEGMENT aSegment) |
Asynchronously receives a
Segment 's Sequence data (does
not block this thread) and updates the Segment by invoking
Segment.fromTransmission(Sequence) . |
<SEGMENT extends Segment> |
onReceiveSegment(SEGMENT aSegment,
SegmentConsumer<SEGMENT> aSegmentConsumer) |
Asynchronously receives a
Segment 's Sequence data (does
not block this thread) and updates the Segment by invoking
Segment.fromTransmission(Sequence) , passing the result to the
callback SegmentConsumer.onSegment(Segment) . |
void |
open() |
Attention: Implementations of this method should do a
Object.notifyAll() in order to terminate any pending asynchronous
operations such as SegmentReceiver.onReceiveSegment(Segment) or
SegmentReceiver.onReceiveSegment(Segment, SegmentConsumer) . |
void |
open(PM aPortMetrics) |
|
void |
openUnchecked() |
|
byte[] |
receiveAllBytes() |
|
byte |
receiveByte() |
|
void |
receiveBytes(byte[] aBuffer,
int aOffset,
int aLength) |
|
byte[] |
receiveBytes(int aMaxLength) |
|
void |
receiveBytesWithin(long aTimeoutInMs,
byte[] aBuffer,
int aOffset,
int aLength) |
|
byte[] |
receiveBytesWithin(long aTimeoutInMs,
int aLength) |
|
byte |
receiveByteWithin(long aTimeoutInMs) |
|
<SEGMENT extends Segment> |
receiveSegment(SEGMENT aSegment) |
Receives a
Segment (and blocks this thread) till all it's
Sequence data has been received and updates the Segment
by invoking Segment.fromTransmission(Sequence) . |
<SEGMENT extends Segment> |
receiveSegmentWithin(long aTimeoutInMs,
SEGMENT aSegment) |
Receives a
Segment (and blocks this thread) till all it's
Sequence data has been received and updates the Segment
by invoking Segment.fromTransmission(Sequence) . |
Sequence |
receiveSequence(int aLength) |
Receives a
Sequence with the number of bytes specified.This
method blocks till all bytes are read. |
Sequence |
receiveSequenceWithin(long aTimeoutInMs,
int aLength) |
Receives a
Sequence with the number of bytes specified. |
long |
skip(long aLength) |
|
void |
skipAvailable() |
|
void |
skipAvailableExcept(int aLength) |
|
void |
skipAvailableTill(long aSkipTimeSpanInMs) |
|
void |
skipAvailableTillSilenceFor(long aSilenceTimeSpanInMs) |
|
void |
skipAvailableTillSilenceFor(long aSilenceTimeSpanInMs,
long aTimeoutInMs) |
|
void |
skipAvailableWithin(long aSkipTimeSpanInMs) |
|
void |
skipAvailableWithin(long aSkipTimeSpanInMs,
long aTimeoutInMs) |
|
void |
transmitAllBytes(byte[] aBytes) |
|
void |
transmitByte(byte aByte) |
|
void |
transmitBytes(byte[] aBytes,
int aOffset,
int aLength) |
|
<SEGMENT extends Segment> |
transmitSegment(SEGMENT aSegment) |
Transmits a
AllocSectionDecoratorSegment (and blocks this thread) till
all it's Sequence data (as of
AbstractLengthDecoratorSegment.toTransmission() ) has been sent. |
void |
transmitSequence(Sequence aSequence) |
Sends the number of bytes specified.
|
void |
transmitSequence(Sequence aSequence,
int aOffset,
int aLength) |
Transmits a
Sequence . |
Port<PM> |
withOpen() |
|
Port<PM> |
withOpenUnchecked() |
public <SEGMENT extends Segment> void receiveSegment(SEGMENT aSegment) throws TransmissionException, IOException
Segment
(and blocks this thread) till all it's
Sequence
data has been received and updates the Segment
by invoking Segment.fromTransmission(Sequence)
. This method
blocks till all bytes are read.receiveSegment
in interface SegmentDestination
receiveSegment
in interface SerialReceiver
receiveSegment
in interface SerialTransceiver
SEGMENT
- The Segment
type describing the Segment
subclass of implementing Segment
types.aSegment
- The Segment
to be (re-)initialized with the
received data.TransmissionException
- Thrown in case the received data cannot be
used to (re-)initialize the given Segment
.IOException
- thrown in case of I/O issues (e.g. a timeout) while
receiving.public <SEGMENT extends Segment> void transmitSegment(SEGMENT aSegment) throws IOException
AllocSectionDecoratorSegment
(and blocks this thread) till
all it's Sequence
data (as of
AbstractLengthDecoratorSegment.toTransmission()
) has been sent.transmitSegment
in interface SegmentSource
transmitSegment
in interface SerialTransceiver
transmitSegment
in interface SerialTransmitter
SEGMENT
- The Segment
type describing the Segment
subclass used.aSegment
- The AllocSectionDecoratorSegment
's data to be sent with.IOException
- thrown in case of I/O issues (e.g. a timeout) while
sending.public void transmitBytes(byte[] aBytes, int aOffset, int aLength) throws IOException
transmitBytes
in interface org.refcodes.io.BytesSource
transmitBytes
in interface org.refcodes.io.BytesTransmitter
transmitBytes
in interface SerialTransmitter
IOException
public OutputStream getOutputStream()
getOutputStream
in interface org.refcodes.io.BytesTransmitter
getOutputStream
in interface org.refcodes.mixin.OutputStreamAccessor
public <SEGMENT extends Segment> void receiveSegmentWithin(long aTimeoutInMs, SEGMENT aSegment) throws TransmissionException, IOException
Segment
(and blocks this thread) till all it's
Sequence
data has been received and updates the Segment
by invoking Segment.fromTransmission(Sequence)
. This method
blocks till all bytes are read or the timeout has been reached.receiveSegmentWithin
in interface SegmentReceiver
receiveSegmentWithin
in interface SerialReceiver
SEGMENT
- The Segment
type describing the Segment
subclass of implementing Segment
types.aTimeoutInMs
- The default timeout for read operations not
explicitly called with a timeout argument. With a value of -1
timeout handling is disabled (blocking mode) or a technical
timeout occurs (implementation depended).aSegment
- The Segment
to be (re-)initialized with the
received data.TransmissionException
- Thrown in case the received data cannot be
used to (re-)initialize the given Segment
.IOException
- thrown in case of I/O issues (e.g. a timeout) while
receiving.public Sequence receiveSequenceWithin(long aTimeoutInMs, int aLength) throws IOException
Sequence
with the number of bytes specified. This
method blocks till all bytes are read or the timeout has been reached.receiveSequenceWithin
in interface SerialReceiver
aTimeoutInMs
- The default timeout for read operations not
explicitly called with a timeout argument. With a value of -1
timeout handling is disabled (blocking mode) or a technical
timeout occurs (implementation depended).aLength
- The number of bytes to receive.Sequence
containing the accordingly received bytes.IOException
- thrown in case of I/O issues (e.g. a timeout) while
receiving.public <SEGMENT extends Segment> void onReceiveSegment(SEGMENT aSegment, SegmentConsumer<SEGMENT> aSegmentConsumer) throws IOException
Segment
's Sequence
data (does
not block this thread) and updates the Segment
by invoking
Segment.fromTransmission(Sequence)
, passing the result to the
callback SegmentConsumer.onSegment(Segment)
.onReceiveSegment
in interface SegmentReceiver
SEGMENT
- The Segment
type describing the Segment
subclass of implementing Segment
types.aSegment
- The Segment
to be (re-)initialized with the
received data.aSegmentConsumer
- The callback asynchronously invoked upon having
received the Segment
.IOException
- thrown in case of I/O issues (e.g. a closed
connection) while receiving.public <SEGMENT extends Segment> SegmentResult<SEGMENT> onReceiveSegment(SEGMENT aSegment) throws IOException
Segment
's Sequence
data (does
not block this thread) and updates the Segment
by invoking
Segment.fromTransmission(Sequence)
. The result is provided by the
returned SegmentResult
instance providing the (asynchronously)
(re-)initialized provided Segment
instance.onReceiveSegment
in interface SegmentReceiver
SEGMENT
- The Segment
type describing the Segment
subclass used.aSegment
- The Segment
to be (re-)initialized with the
received data.SegmentResult
which provides the result
(asynchronously).IOException
- thrown in case of I/O issues (e.g. a closed
connection) while receiving.public Sequence receiveSequence(int aLength) throws IOException
Sequence
with the number of bytes specified.This
method blocks till all bytes are read.receiveSequence
in interface SerialReceiver
aLength
- The number of bytes to receive.Sequence
containing the accordingly received bytes.IOException
- thrown in case of I/O issues (e.g. a timeout) while
receiving.public void close() throws IOException
Object.notifyAll()
in order to terminate any pending asynchronous
operations such as SegmentReceiver.onReceiveSegment(Segment)
or
SegmentReceiver.onReceiveSegment(Segment, SegmentConsumer)
.close
in interface org.refcodes.component.Closable
close
in interface SerialReceiver
IOException
public void closeUnchecked()
closeUnchecked
in interface org.refcodes.component.Closable
public void closeQuietly()
closeQuietly
in interface org.refcodes.component.Closable
public void closeIn(int aCloseInMillis)
closeIn
in interface org.refcodes.component.Closable
public String getAlias()
getAlias
in interface org.refcodes.mixin.AliasAccessor
public void open() throws IOException
Object.notifyAll()
in order to terminate any pending asynchronous
operations such as SegmentReceiver.onReceiveSegment(Segment)
or
SegmentReceiver.onReceiveSegment(Segment, SegmentConsumer)
.open
in interface org.refcodes.component.Openable
open
in interface SerialReceiver
IOException
public void openUnchecked()
openUnchecked
in interface org.refcodes.component.Openable
public long skip(long aLength) throws IOException
skip
in interface org.refcodes.io.BytesReceiver
skip
in interface org.refcodes.io.Skippable
IOException
public InputStream getInputStream()
getInputStream
in interface org.refcodes.io.BytesReceiver
getInputStream
in interface org.refcodes.mixin.InputStreamAccessor
public org.refcodes.io.TimeoutInputStream getInputStream(long aTimeoutInMs)
getInputStream
in interface org.refcodes.io.BytesReceiver
getInputStream
in interface org.refcodes.io.TimeoutInputStreamAccessor
public byte[] receiveAllBytes() throws IOException
receiveAllBytes
in interface org.refcodes.io.BytesDestination
receiveAllBytes
in interface org.refcodes.io.BytesReceiver
IOException
public byte[] receiveBytes(int aMaxLength) throws IOException
receiveBytes
in interface org.refcodes.io.BytesDestination
receiveBytes
in interface org.refcodes.io.BytesReceiver
receiveBytes
in interface SerialReceiver
IOException
public byte receiveByteWithin(long aTimeoutInMs) throws IOException
receiveByteWithin
in interface org.refcodes.io.BytesReceiver
IOException
public byte[] receiveBytesWithin(long aTimeoutInMs, int aLength) throws IOException
receiveBytesWithin
in interface org.refcodes.io.BytesReceiver
IOException
public void receiveBytesWithin(long aTimeoutInMs, byte[] aBuffer, int aOffset, int aLength) throws IOException
receiveBytesWithin
in interface org.refcodes.io.BytesReceiver
IOException
public void flush() throws IOException
flush
in interface org.refcodes.io.ByteTransmitter
flush
in interface Flushable
flush
in interface org.refcodes.component.Flushable
flush
in interface SegmentTransmitter
flush
in interface SerialTransmitter
IOException
public boolean isOpened()
isOpened
in interface org.refcodes.component.ConnectionStatusAccessor
isOpened
in interface org.refcodes.component.OpenedAccessor
public int available() throws IOException
InputStream.available()
: "Returns an estimate of the number of
bytes that can be read (or skipped over) from this input stream without
blocking by the next invocation of a method for this input stream. The
next invocation might be the same thread or another thread. A single read
or skip of this many bytes will not block, but may read or skip fewer
bytes. Note that while some implementations of InputStream will return
the total number of bytes in the stream, many will not. It is never
correct to use the return value of this method to allocate a buffer
intended to hold all data in this stream. A subclass' implementation of
this method may choose to throw an IOException if this input stream has
been closed by invoking the close() method. The available method for
class InputStream always returns 0. This method should be overridden by
subclasses."available
in interface org.refcodes.io.Availability
available
in interface SerialReceiver
available
in interface org.refcodes.io.Skippable
IOException
- - if an I/O error occurs.public boolean hasAvailable() throws IOException
hasAvailable
in interface org.refcodes.io.Availability
IOException
public org.refcodes.component.ConnectionStatus getConnectionStatus()
getConnectionStatus
in interface org.refcodes.component.ConnectionStatusAccessor
public PM getPortMetrics()
PortMetrics
from the PortMetrics
property.getPortMetrics
in interface PortMetricsAccessor<PM extends PortMetrics>
PortMetrics
stored by the PortMetrics
property.public <SEGMENT extends Segment> void doTransmitSegment(SEGMENT aSegment, SegmentConsumer<SEGMENT> aSegmentConsumer) throws IOException
doTransmitSegment
in interface SegmentTransmitter
SEGMENT
- The Segment
type describing the Segment
subclass used.aSegment
- The Segment
to be (re-)initialized with the
received data.aSegmentConsumer
- The callback asynchronously invoked upon having
received the Segment
.IOException
- thrown in case of I/O issues (e.g. a closed
connection) while sending.public <SEGMENT extends Segment> SegmentResult<SEGMENT> doTransmitSegment(SEGMENT aSegment) throws IOException
doTransmitSegment
in interface SegmentTransmitter
SEGMENT
- The Segment
type describing the Segment
subclass used.aSegment
- The Segment
to be (re-)initialized with the
received data.SegmentResult
which provides the result
(asynchronously).IOException
- thrown in case of I/O issues (e.g. a closed
connection) while sending.public void transmitSequence(Sequence aSequence, int aOffset, int aLength) throws IOException
Sequence
.transmitSequence
in interface SerialTransmitter
aSequence
- The Sequence
containing the data to be send.aOffset
- The offset from where to take the chunk data.aLength
- The number of bytes to take, beginning at the provided
offset.IOException
- thrown in case of I/O issues (e.g. a timeout) while
sendingpublic void transmitSequence(Sequence aSequence) throws IOException
transmitSequence
in interface SerialTransmitter
aSequence
- The Sequence
containing the data to be send.IOException
- thrown in case of I/O issues (e.g. a timeout) while
sendingpublic boolean isClosable()
isClosable
in interface org.refcodes.component.Closable.CloseAutomaton
public boolean isClosed()
isClosed
in interface org.refcodes.component.ClosedAccessor
public void flushUnchecked()
flushUnchecked
in interface org.refcodes.component.Flushable
public boolean isFlushable()
isFlushable
in interface org.refcodes.component.Flushable
public void skipAvailable() throws IOException
skipAvailable
in interface org.refcodes.io.Skippable
IOException
public void skipAvailableWithin(long aSkipTimeSpanInMs) throws IOException
skipAvailableWithin
in interface org.refcodes.io.Skippable
IOException
public void skipAvailableWithin(long aSkipTimeSpanInMs, long aTimeoutInMs) throws IOException
skipAvailableWithin
in interface org.refcodes.io.Skippable
IOException
public void skipAvailableTill(long aSkipTimeSpanInMs) throws IOException
skipAvailableTill
in interface org.refcodes.io.Skippable
IOException
public void skipAvailableTillSilenceFor(long aSilenceTimeSpanInMs) throws IOException
skipAvailableTillSilenceFor
in interface org.refcodes.io.Skippable
IOException
public void skipAvailableTillSilenceFor(long aSilenceTimeSpanInMs, long aTimeoutInMs) throws IOException, org.refcodes.exception.TimeoutIoException
skipAvailableTillSilenceFor
in interface org.refcodes.io.Skippable
IOException
org.refcodes.exception.TimeoutIoException
public void skipAvailableExcept(int aLength) throws IOException
skipAvailableExcept
in interface org.refcodes.io.Skippable
IOException
public byte receiveByte() throws IOException
receiveByte
in interface org.refcodes.io.ByteDestination
receiveByte
in interface org.refcodes.io.BytesDestination
receiveByte
in interface SerialReceiver
IOException
public void receiveBytes(byte[] aBuffer, int aOffset, int aLength) throws IOException
receiveBytes
in interface org.refcodes.io.BytesDestination
IOException
public boolean isOpenable()
isOpenable
in interface org.refcodes.component.Openable.OpenAutomaton
public void transmitByte(byte aByte) throws IOException
transmitByte
in interface org.refcodes.io.ByteSource
transmitByte
in interface org.refcodes.io.BytesSource
IOException
public void transmitAllBytes(byte[] aBytes) throws IOException
transmitAllBytes
in interface org.refcodes.io.BytesSource
transmitAllBytes
in interface SerialTransmitter
IOException
public Port<PM> withOpen() throws IOException
withOpen
in interface org.refcodes.component.Openable.OpenBuilder<PM extends PortMetrics>
IOException
public Port<PM> withOpenUnchecked()
withOpenUnchecked
in interface org.refcodes.component.Openable.OpenBuilder<PM extends PortMetrics>
public void open(PM aPortMetrics) throws IOException
open
in interface org.refcodes.component.ConnectionOpenable<PM extends PortMetrics>
IOException
public boolean isOpenable(PM aPortMetrics)
isOpenable
in interface org.refcodes.component.ConnectionOpenable.ConnectionOpenAutomaton<PM extends PortMetrics>
Copyright © 2021. All rights reserved.