- java.lang.Object
-
- org.refcodes.component.ConnectionAutomatonImpl<PM>
-
- org.refcodes.serial.AbstractPort<PortMetrics>
-
- org.refcodes.serial.LoopbackPort
-
- All Implemented Interfaces:
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.ConnectionOpenable.ConnectionOpenBuilder<PortMetrics,Port<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<Port<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
- Direct Known Subclasses:
CrossoverLoopbackPort
public class LoopbackPort extends AbstractPort<PortMetrics> implements Port<PortMetrics>
TheLoopbackPortis an in-memory implementation of aPortwhich 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 samePort. For cases using a some kind of frequent handshake between a transmitter and a receiver on the same line please use theCrossoverLoopbackPortas counterpart of aLoopbackPortfor simulating a bidirectional in-memory communication between these two ports.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.AliasAccessor
org.refcodes.mixin.AliasAccessor.AliasBuilder<B extends org.refcodes.mixin.AliasAccessor.AliasBuilder<B>>, org.refcodes.mixin.AliasAccessor.AliasMutator, org.refcodes.mixin.AliasAccessor.AliasProperty
-
Nested classes/interfaces inherited from interface org.refcodes.io.BytesReceiver
org.refcodes.io.BytesReceiver.ReceiverInputStream
-
Nested classes/interfaces inherited from interface org.refcodes.io.BytesTransmitter
org.refcodes.io.BytesTransmitter.TransmitterOutputStream
-
Nested classes/interfaces inherited from interface org.refcodes.component.Closable
org.refcodes.component.Closable.CloseAutomaton, org.refcodes.component.Closable.CloseBuilder<B extends org.refcodes.component.Closable.CloseBuilder<B>>
-
Nested classes/interfaces inherited from interface org.refcodes.component.ClosedAccessor
org.refcodes.component.ClosedAccessor.ClosedMutator, org.refcodes.component.ClosedAccessor.ClosedProperty
-
Nested classes/interfaces inherited from interface org.refcodes.component.ConnectableComponent
org.refcodes.component.ConnectableComponent.ConnectableAutomaton
-
Nested classes/interfaces inherited from interface org.refcodes.component.ConnectionComponent
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>>
-
Nested classes/interfaces inherited from interface org.refcodes.component.ConnectionOpenable
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>>
-
Nested classes/interfaces inherited from interface org.refcodes.component.ConnectionStatusAccessor
org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusMutator, org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusProperty
-
Nested classes/interfaces inherited from interface org.refcodes.component.Flushable
org.refcodes.component.Flushable.FlushBuilder<B extends org.refcodes.component.Flushable.FlushBuilder<B>>
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.InputStreamAccessor
org.refcodes.mixin.InputStreamAccessor.InputStreamBuilder<B extends org.refcodes.mixin.InputStreamAccessor.InputStreamBuilder<?>>, org.refcodes.mixin.InputStreamAccessor.InputStreamMutator, org.refcodes.mixin.InputStreamAccessor.InputStreamProperty
-
Nested classes/interfaces inherited from interface org.refcodes.component.LinkComponent
org.refcodes.component.LinkComponent.LinkAutomaton, org.refcodes.component.LinkComponent.LinkComponentBuilder<B extends org.refcodes.component.LinkComponent.LinkComponentBuilder<B>>
-
Nested classes/interfaces inherited from interface org.refcodes.component.Openable
org.refcodes.component.Openable.OpenAutomaton, org.refcodes.component.Openable.OpenBuilder<B extends org.refcodes.component.Openable.OpenBuilder<B>>
-
Nested classes/interfaces inherited from interface org.refcodes.component.OpenedAccessor
org.refcodes.component.OpenedAccessor.OpenedMutator, org.refcodes.component.OpenedAccessor.OpenedProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.OutputStreamAccessor
org.refcodes.mixin.OutputStreamAccessor.OutputStreamBuilder<B extends org.refcodes.mixin.OutputStreamAccessor.OutputStreamBuilder<?>>, org.refcodes.mixin.OutputStreamAccessor.OutputStreamMutator, org.refcodes.mixin.OutputStreamAccessor.OutputStreamProperty
-
Nested classes/interfaces inherited from interface org.refcodes.serial.PortMetricsAccessor
PortMetricsAccessor.PortMetricsBuilder<PM extends PortMetrics,B extends PortMetricsAccessor.PortMetricsBuilder<PM,B>>, PortMetricsAccessor.PortMetricsMutator<PM extends PortMetrics>, PortMetricsAccessor.PortMetricsProperty<PM extends PortMetrics>
-
Nested classes/interfaces inherited from interface org.refcodes.io.TimeoutInputStreamAccessor
org.refcodes.io.TimeoutInputStreamAccessor.TimeoutInputStreamBuilder<B extends org.refcodes.io.TimeoutInputStreamAccessor.TimeoutInputStreamBuilder<?>>, org.refcodes.io.TimeoutInputStreamAccessor.TimeoutInputStreamMutator, org.refcodes.io.TimeoutInputStreamAccessor.TimeoutInputStreamProperty
-
-
Field Summary
Fields Modifier and Type Field Description protected LoopbackPort_crossoverPortprotected ChunkSequence_transmitSequence-
Fields inherited from class org.refcodes.serial.AbstractPort
_alias, _executorService, _portMetrics
-
-
Constructor Summary
Constructors Constructor Description LoopbackPort(String aAlias)Constructs aLoopbackPort.LoopbackPort(String aAlias, ExecutorService aExecutorService)Constructs aLoopbackPort.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Returns the number of bytes which can be read directly e.g. which are already been stored in an internal buffer.voidclose()Attention: Implementations of this method should do aObject.notifyAll()in order to terminate any pending asynchronous operations such asSegmentReceiver.onReceiveSegment(Segment)orSegmentReceiver.onReceiveSegment(Segment, SegmentConsumer).<SEGMENT extends Segment>
SegmentResult<SEGMENT>doTransmitSegment(SEGMENT aSegment)<SEGMENT extends Segment>
voiddoTransmitSegment(SEGMENT aSegment, SegmentConsumer<SEGMENT> aSegmentConsumer)StringgetAlias()Returns the unambiguous technical name of the TTY-/COM-Port.PortMetricsgetPortMetrics()Retrieves thePortMetricsfrom thePortMetricsproperty.<SEGMENT extends Segment>
SegmentResult<SEGMENT>onReceiveSegment(SEGMENT aSegment)Asynchronously receives aSegment'sSequencedata (does not block this thread) and updates theSegmentby invokingSegment.fromTransmission(Sequence).<SEGMENT extends Segment>
voidonReceiveSegment(SEGMENT aSegment, SegmentConsumer<SEGMENT> aSegmentConsumer)Asynchronously receives aSegment'sSequencedata (does not block this thread) and updates theSegmentby invokingSegment.fromTransmission(Sequence), passing the result to the callbackSegmentConsumer.onSegment(Segment).voidopen()Attention: Implementations of this method should do aObject.notifyAll()in order to terminate any pending asynchronous operations such asSegmentReceiver.onReceiveSegment(Segment)orSegmentReceiver.onReceiveSegment(Segment, SegmentConsumer).voidreceiveBytes(byte[] aBuffer, int aOffset, int aLength)protected voidsetCrossoverPort(LoopbackPort aPort)Hook to set a crossover loopback port in order to attach aLoopbackPortto the other end of the wire and transform a loopback device into two crossover loopback devices.StringtoString()voidtransmitSequence(Sequence aSequence)Sends the number of bytes specified.LoopbackPortwithOpen()LoopbackPortwithOpen(PortMetrics aPortMetrics)LoopbackPortwithOpenUnchecked()LoopbackPortwithOpenUnchecked(PortMetrics aPortMetrics)-
Methods inherited from class org.refcodes.serial.AbstractPort
isOpenable, open, receiveSegment
-
Methods inherited from class org.refcodes.component.ConnectionAutomatonImpl
getConnectionStatus, isClosable, isClosed, isOpenable, isOpened
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.refcodes.io.BytesReceiver
getInputStream, getInputStream, receiveAllBytes, receiveBytesWithin, receiveBytesWithin, receiveByteWithin, skip
-
Methods inherited from interface org.refcodes.component.Closable
closeIn, closeQuietly, closeUnchecked
-
Methods inherited from interface org.refcodes.component.ConnectionOpenable.ConnectionOpenAutomaton
isOpenable
-
Methods inherited from interface org.refcodes.component.ConnectionStatusAccessor
getConnectionStatus, isOpened
-
Methods inherited from interface org.refcodes.serial.SegmentTransmitter
flush
-
Methods inherited from interface org.refcodes.serial.SerialReceiver
receiveByte, receiveBytes, receiveSegmentWithin, receiveSequence, receiveSequenceWithin
-
Methods inherited from interface org.refcodes.serial.SerialTransceiver
receiveSegment, transmitSegment
-
Methods inherited from interface org.refcodes.serial.SerialTransmitter
flush, transmitAllBytes, transmitBytes, transmitSequence
-
-
-
-
Field Detail
-
_transmitSequence
protected ChunkSequence _transmitSequence
-
_crossoverPort
protected LoopbackPort _crossoverPort
-
-
Constructor Detail
-
LoopbackPort
public LoopbackPort(String aAlias)
Constructs aLoopbackPort.- Parameters:
aAlias- The alias to use for this port.
-
LoopbackPort
public LoopbackPort(String aAlias, ExecutorService aExecutorService)
Constructs aLoopbackPort.- Parameters:
aAlias- The alias to use for this port.aExecutorService- TheExecutorServiceto be used when invoking asynchronously working methods.
-
-
Method Detail
-
transmitSequence
public void transmitSequence(Sequence aSequence) throws IOException
Sends the number of bytes specified.- Specified by:
transmitSequencein interfaceSerialTransmitter- Parameters:
aSequence- TheSequencecontaining the data to be send.- Throws:
IOException- thrown in case of I/O issues (e.g. a timeout) while sending
-
onReceiveSegment
public <SEGMENT extends Segment> void onReceiveSegment(SEGMENT aSegment, SegmentConsumer<SEGMENT> aSegmentConsumer) throws IOException
Asynchronously receives aSegment'sSequencedata (does not block this thread) and updates theSegmentby invokingSegment.fromTransmission(Sequence), passing the result to the callbackSegmentConsumer.onSegment(Segment).- Specified by:
onReceiveSegmentin interfaceSegmentReceiver- Overrides:
onReceiveSegmentin classAbstractPort<PortMetrics>- Type Parameters:
SEGMENT- TheSegmenttype describing theSegmentsubclass of implementingSegmenttypes.- Parameters:
aSegment- TheSegmentto be (re-)initialized with the received data.aSegmentConsumer- The callback asynchronously invoked upon having received theSegment.- Throws:
IOException- thrown in case of I/O issues (e.g. a closed connection) while receiving.
-
onReceiveSegment
public <SEGMENT extends Segment> SegmentResult<SEGMENT> onReceiveSegment(SEGMENT aSegment) throws IOException
Asynchronously receives aSegment'sSequencedata (does not block this thread) and updates theSegmentby invokingSegment.fromTransmission(Sequence). The result is provided by the returnedSegmentResultinstance providing the (asynchronously) (re-)initialized providedSegmentinstance.- Specified by:
onReceiveSegmentin interfaceSegmentReceiver- Overrides:
onReceiveSegmentin classAbstractPort<PortMetrics>- Type Parameters:
SEGMENT- TheSegmenttype describing theSegmentsubclass used.- Parameters:
aSegment- TheSegmentto be (re-)initialized with the received data.- Returns:
- The
SegmentResultwhich provides the result (asynchronously). - Throws:
IOException- thrown in case of I/O issues (e.g. a closed connection) while receiving.
-
doTransmitSegment
public <SEGMENT extends Segment> SegmentResult<SEGMENT> doTransmitSegment(SEGMENT aSegment) throws IOException
- Specified by:
doTransmitSegmentin interfaceSegmentTransmitter- Overrides:
doTransmitSegmentin classAbstractPort<PortMetrics>- Type Parameters:
SEGMENT- TheSegmenttype describing theSegmentsubclass used.- Parameters:
aSegment- TheSegmentto be (re-)initialized with the received data.- Returns:
- The
SegmentResultwhich provides the result (asynchronously). - Throws:
IOException- thrown in case of I/O issues (e.g. a closed connection) while sending.
-
doTransmitSegment
public <SEGMENT extends Segment> void doTransmitSegment(SEGMENT aSegment, SegmentConsumer<SEGMENT> aSegmentConsumer) throws IOException
- Specified by:
doTransmitSegmentin interfaceSegmentTransmitter- Overrides:
doTransmitSegmentin classAbstractPort<PortMetrics>- Type Parameters:
SEGMENT- TheSegmenttype describing theSegmentsubclass used.- Parameters:
aSegment- TheSegmentto be (re-)initialized with the received data.aSegmentConsumer- The callback asynchronously invoked upon having received theSegment.- Throws:
IOException- thrown in case of I/O issues (e.g. a closed connection) while sending.
-
receiveBytes
public void receiveBytes(byte[] aBuffer, int aOffset, int aLength) throws IOException- Specified by:
receiveBytesin interfaceorg.refcodes.io.BytesDestination- Throws:
IOException
-
getPortMetrics
public PortMetrics getPortMetrics()
Retrieves thePortMetricsfrom thePortMetricsproperty.- Specified by:
getPortMetricsin interfacePortMetricsAccessor<PortMetrics>- Returns:
- The
PortMetricsstored by thePortMetricsproperty.
-
getAlias
public String getAlias()
Returns the unambiguous technical name of the TTY-/COM-Port.- Specified by:
getAliasin interfaceorg.refcodes.mixin.AliasAccessor- Overrides:
getAliasin classAbstractPort<PortMetrics>- Returns:
- The port's name.
-
available
public int available()
Returns the number of bytes which can be read directly e.g. which are already been stored in an internal buffer. May return (0 or) a value less than 0 (-1) when it is not supported. Similar toInputStream.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."- Specified by:
availablein interfaceorg.refcodes.io.Availability- Specified by:
availablein interfaceSerialReceiver- Specified by:
availablein interfaceorg.refcodes.io.Skippable- Returns:
- The number of available bytes: An estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking or 0 when it reaches the end of the input stream. Throws:
-
open
public void open() throws IOExceptionAttention: Implementations of this method should do aObject.notifyAll()in order to terminate any pending asynchronous operations such asSegmentReceiver.onReceiveSegment(Segment)orSegmentReceiver.onReceiveSegment(Segment, SegmentConsumer).- Specified by:
openin interfaceorg.refcodes.component.Openable- Specified by:
openin interfaceSerialReceiver- Overrides:
openin classAbstractPort<PortMetrics>- Throws:
IOException
-
close
public void close() throws IOExceptionAttention: Implementations of this method should do aObject.notifyAll()in order to terminate any pending asynchronous operations such asSegmentReceiver.onReceiveSegment(Segment)orSegmentReceiver.onReceiveSegment(Segment, SegmentConsumer).- Specified by:
closein interfaceorg.refcodes.component.Closable- Specified by:
closein interfaceSerialReceiver- Overrides:
closein classorg.refcodes.component.ConnectionAutomatonImpl<PortMetrics>- Throws:
IOException
-
withOpen
public LoopbackPort withOpen() throws IOException
- Specified by:
withOpenin interfaceorg.refcodes.component.Openable.OpenBuilder<Port<PortMetrics>>- Throws:
IOException
-
withOpen
public LoopbackPort withOpen(PortMetrics aPortMetrics) throws IOException
- Specified by:
withOpenin interfaceorg.refcodes.component.ConnectionOpenable.ConnectionOpenBuilder<PortMetrics,Port<PortMetrics>>- Throws:
IOException
-
withOpenUnchecked
public LoopbackPort withOpenUnchecked()
- Specified by:
withOpenUncheckedin interfaceorg.refcodes.component.Openable.OpenBuilder<Port<PortMetrics>>
-
withOpenUnchecked
public LoopbackPort withOpenUnchecked(PortMetrics aPortMetrics)
- Specified by:
withOpenUncheckedin interfaceorg.refcodes.component.ConnectionOpenable.ConnectionOpenBuilder<PortMetrics,Port<PortMetrics>>
-
setCrossoverPort
protected void setCrossoverPort(LoopbackPort aPort)
Hook to set a crossover loopback port in order to attach aLoopbackPortto the other end of the wire and transform a loopback device into two crossover loopback devices.- Parameters:
aPort- TheLoopbackPortto act as the crossover loopback device at the other end of the wire.
-
-