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<PortMetrics>
, org.refcodes.component.ConnectionComponent.ConnectionAutomaton<PortMetrics>
, org.refcodes.component.ConnectionOpenable<PortMetrics>
, org.refcodes.component.ConnectionOpenable.ConnectionOpenAutomaton<PortMetrics>
, 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<PortMetrics>
, 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<PortMetrics>
, PortMetricsAccessor<PortMetrics>
, SegmentDestination
, SegmentReceiver
, SegmentSource
, SegmentTransceiver
, SegmentTransmitter
, SerialReceiver
, SerialTransceiver
, SerialTransmitter
CrossoverLoopbackPort
public class LoopbackPort extends AbstractPort<PortMetrics> implements Port<PortMetrics>
LoopbackPort
is an in-memory implementation of a Port
which loops its output directly back to its input. This is suitable for
straight forward cases where data is first transmitted to be received in the
next step by the same Port
. For cases using a some kind of frequent
handshake between a transmitter and a receiver on the same line please use
the CrossoverLoopbackPort
as counterpart of a LoopbackPort
for simulating a bidirectional in-memory communication between these two
ports.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
Modifier and Type | Field | Description |
---|---|---|
protected LoopbackPort |
_crossoverPort |
|
protected ChunkSequence |
_transmitSequence |
_alias, _executorService, _portMetrics
Constructor | Description |
---|---|
LoopbackPort(String aAlias) |
Constructs a
LoopbackPort . |
LoopbackPort(String aAlias,
ExecutorService aExecutorService) |
Constructs a
LoopbackPort . |
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) . |
<SEGMENT extends Segment> |
doTransmitSegment(SEGMENT aSegment) |
|
<SEGMENT extends Segment> |
doTransmitSegment(SEGMENT aSegment,
SegmentConsumer<SEGMENT> aSegmentConsumer) |
|
String |
getAlias() |
Returns the unambiguous technical name of the TTY-/COM-Port.
|
PortMetrics |
getPortMetrics() |
Retrieves the
PortMetrics from the PortMetrics property. |
<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 |
receiveBytes(byte[] aBuffer,
int aOffset,
int aLength) |
|
protected void |
setCrossoverPort(LoopbackPort aPort) |
Hook to set a crossover loopback port in order to attach a
LoopbackPort to the other end of the wire and transform a
loopback device into two crossover loopback devices. |
String |
toString() |
|
void |
transmitSequence(Sequence aSequence) |
Sends the number of bytes specified.
|
LoopbackPort |
withOpen() |
isOpenable, open, receiveSegment
getInputStream, getInputStream, receiveAllBytes, receiveBytesWithin, receiveBytesWithin, receiveByteWithin, skip
closeIn, closeQuietly, closeUnchecked
getConnectionStatus, isClosable, isClosed, isOpenable, isOpened
isOpenable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
receiveByte, receiveBytes, receiveSegmentWithin, receiveSequence, receiveSequenceWithin
receiveSegment, transmitSegment
flush, transmitAllBytes, transmitBytes, transmitSequence
protected ChunkSequence _transmitSequence
protected LoopbackPort _crossoverPort
public LoopbackPort(String aAlias)
LoopbackPort
.aAlias
- The alias to use for this port.public LoopbackPort(String aAlias, ExecutorService aExecutorService)
LoopbackPort
.aAlias
- The alias to use for this port.aExecutorService
- The ExecutorService
to be used when
invoking asynchronously working methods.public 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 <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
onReceiveSegment
in class AbstractPort<PortMetrics>
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
onReceiveSegment
in class AbstractPort<PortMetrics>
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 <SEGMENT extends Segment> SegmentResult<SEGMENT> doTransmitSegment(SEGMENT aSegment) throws IOException
doTransmitSegment
in interface SegmentTransmitter
doTransmitSegment
in class AbstractPort<PortMetrics>
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 <SEGMENT extends Segment> void doTransmitSegment(SEGMENT aSegment, SegmentConsumer<SEGMENT> aSegmentConsumer) throws IOException
doTransmitSegment
in interface SegmentTransmitter
doTransmitSegment
in class AbstractPort<PortMetrics>
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 void receiveBytes(byte[] aBuffer, int aOffset, int aLength) throws IOException
receiveBytes
in interface org.refcodes.io.BytesDestination
IOException
public PortMetrics getPortMetrics()
PortMetrics
from the PortMetrics
property.getPortMetrics
in interface PortMetricsAccessor<PortMetrics>
PortMetrics
stored by the PortMetrics
property.public String getAlias()
getAlias
in interface org.refcodes.mixin.AliasAccessor
getAlias
in class AbstractPort<PortMetrics>
public int available()
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
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
open
in class AbstractPort<PortMetrics>
IOException
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
close
in class org.refcodes.component.ConnectionAutomatonImpl<PortMetrics>
IOException
public LoopbackPort withOpen() throws IOException
withOpen
in interface org.refcodes.component.Openable.OpenBuilder<PortMetrics>
IOException
protected void setCrossoverPort(LoopbackPort aPort)
LoopbackPort
to the other end of the wire and transform a
loopback device into two crossover loopback devices.aPort
- The LoopbackPort
to act as the crossover loopback
device at the other end of the wire.Copyright © 2021. All rights reserved.