Class LoopbackPort
- All Implemented Interfaces:
Flushable, Comparable<Port<?>>, Closable, Closable.CloseAutomaton, ClosedAccessor, ConnectableComponent, ConnectableComponent.ConnectableAutomaton, ConnectionComponent<PortMetrics>, ConnectionComponent.ConnectionAutomaton<PortMetrics>, ConnectionOpenable<PortMetrics>, ConnectionOpenable.ConnectionOpenAutomaton<PortMetrics>, ConnectionOpenable.ConnectionOpenBuilder<PortMetrics, Port<PortMetrics>>, ConnectionStatusAccessor, Flushable, LinkComponent, LinkComponent.LinkAutomaton, Openable, Openable.OpenAutomaton, Openable.OpenBuilder<Port<PortMetrics>>, OpenedAccessor, Availability, ByteDestination, ByteReceiver, BytesDestination, ByteSource, BytesReceiver, BytesSource, BytesTransceiver, BytesTransmitter, ByteTransceiver, ByteTransmitter, Receivable, Skippable, TimeoutInputStreamAccessor, Transmittable, AliasAccessor, InputStreamAccessor, OutputStreamAccessor, Port<PortMetrics>, PortMetricsAccessor<PortMetrics>, SegmentDestination, SegmentReceiver, SegmentSource, SegmentTransceiver, SegmentTransmitter, SerialReceiver, SerialTransceiver, SerialTransmitter
- Direct Known Subclasses:
CrossoverLoopbackPort
The
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.-
Nested Class Summary
Nested classes/interfaces inherited from interface AliasAccessor
AliasAccessor.AliasBuilder<B>, AliasAccessor.AliasMutator, AliasAccessor.AliasPropertyNested classes/interfaces inherited from interface BytesReceiver
BytesReceiver.ReceiverInputStreamNested classes/interfaces inherited from interface BytesTransmitter
BytesTransmitter.TransmitterOutputStreamNested classes/interfaces inherited from interface Closable
Closable.CloseAutomaton, Closable.CloseBuilder<B>Nested classes/interfaces inherited from interface ClosedAccessor
ClosedAccessor.ClosedMutator, ClosedAccessor.ClosedPropertyNested classes/interfaces inherited from interface ConnectableComponent
ConnectableComponent.ConnectableAutomatonNested classes/interfaces inherited from interface ConnectionComponent
ConnectionComponent.ConnectionAutomaton<CON>, ConnectionComponent.ConnectionComponentBuilder<CON,B> Nested classes/interfaces inherited from interface ConnectionOpenable
ConnectionOpenable.ConnectionOpenAutomaton<CON>, ConnectionOpenable.ConnectionOpenBuilder<CON,B> Nested classes/interfaces inherited from interface ConnectionStatusAccessor
ConnectionStatusAccessor.ConnectionStatusMutator, ConnectionStatusAccessor.ConnectionStatusPropertyNested classes/interfaces inherited from interface Flushable
Flushable.FlushBuilder<B>Nested classes/interfaces inherited from interface InputStreamAccessor
InputStreamAccessor.InputStreamBuilder<B>, InputStreamAccessor.InputStreamMutator, InputStreamAccessor.InputStreamPropertyNested classes/interfaces inherited from interface LinkComponent
LinkComponent.LinkAutomaton, LinkComponent.LinkComponentBuilder<B>Nested classes/interfaces inherited from interface Openable
Openable.OpenAutomaton, Openable.OpenBuilder<B>Nested classes/interfaces inherited from interface OpenedAccessor
OpenedAccessor.OpenedMutator, OpenedAccessor.OpenedPropertyNested classes/interfaces inherited from interface OutputStreamAccessor
OutputStreamAccessor.OutputStreamBuilder<B>, OutputStreamAccessor.OutputStreamMutator, OutputStreamAccessor.OutputStreamPropertyNested classes/interfaces inherited from interface PortMetricsAccessor
PortMetricsAccessor.PortMetricsBuilder<PM,B>, PortMetricsAccessor.PortMetricsMutator<PM>, PortMetricsAccessor.PortMetricsProperty<PM> Nested classes/interfaces inherited from interface TimeoutInputStreamAccessor
TimeoutInputStreamAccessor.TimeoutInputStreamBuilder<B>, TimeoutInputStreamAccessor.TimeoutInputStreamMutator, TimeoutInputStreamAccessor.TimeoutInputStreamProperty -
Field Summary
FieldsFields inherited from class AbstractPort
_alias, _executorService, _portMetricsFields inherited from class ConnectionAutomatonImpl
_connectionComponent -
Constructor Summary
ConstructorsConstructorDescriptionLoopbackPort(String aAlias) Constructs aLoopbackPort.LoopbackPort(String aAlias, ExecutorService aExecutorService) Instantiates the classLoopbackPort. -
Method Summary
Modifier and TypeMethodDescriptionintReturns 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).getAlias()Returns the unambiguous technical name of the TTY-/COM-Port.Retrieves thePortMetricsfrom thePortMetricsproperty.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.toString()voidtransmitSequence(Sequence aSequence) Transmits aSequence(and blocks this thread) till all it's data has been sent.withOpen()withOpen(PortMetrics aPortMetrics) withOpenUnchecked(PortMetrics aPortMetrics) Methods inherited from class AbstractPort
doTransmitSegment, doTransmitSegment, isOpenable, onReceiveSegment, onReceiveSegment, open, receiveSegmentMethods inherited from class ConnectionAutomatonImpl
getConnectionStatus, isClosable, isClosed, isOpenable, isOpenedMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Availability
hasAvailableMethods inherited from interface BytesReceiver
getInputStream, getInputStream, receiveAllBytes, receiveBytesWithin, receiveBytesWithin, receiveByteWithin, skipMethods inherited from interface BytesSource
transmitByteMethods inherited from interface BytesTransmitter
getOutputStreamMethods inherited from interface Closable
closeIn, closeQuietly, closeUncheckedMethods inherited from interface Closable.CloseAutomaton
isClosableMethods inherited from interface ClosedAccessor
isClosedMethods inherited from interface ConnectionOpenable
openUncheckedMethods inherited from interface ConnectionOpenable.ConnectionOpenAutomaton
isOpenableMethods inherited from interface ConnectionStatusAccessor
getConnectionStatus, isOpenedMethods inherited from interface Flushable
flushUnchecked, isFlushableMethods inherited from interface Openable
openUncheckedMethods inherited from interface SegmentTransmitter
flushMethods inherited from interface SerialReceiver
receiveByte, receiveBytes, receiveSegmentWithin, receiveSequence, receiveSequenceWithinMethods inherited from interface SerialTransceiver
transmitSegmentMethods inherited from interface SerialTransmitter
flush, transmitBytes, transmitBytes, transmitSequenceMethods inherited from interface Skippable
skipAvailable, skipAvailableExcept, skipAvailableTill, skipAvailableTillSilenceFor, skipAvailableTillSilenceFor, skipAvailableWithin, skipAvailableWithin, skipAvailableWithin
-
Field Details
-
_transmitSequence
-
_crossoverPort
-
-
Constructor Details
-
LoopbackPort
Constructs aLoopbackPort.- Parameters:
aAlias- The alias to use for this port.
-
LoopbackPort
Instantiates the classLoopbackPort.- Parameters:
aAlias- the aliasaExecutorService- the executor service- See Also:
-
-
Method Details
-
transmitSequence
Transmits aSequence(and blocks this thread) till all it's data has been sent.- Parameters:
aSequence- TheSequencecontaining the data to be send.- Throws:
IOException- thrown in case of I/O issues (e.g. a timeout) while sending
-
receiveBytes
- Throws:
IOException
-
getPortMetrics
Retrieves thePortMetricsfrom thePortMetricsproperty.- Returns:
- The
PortMetricsstored by thePortMetricsproperty.
-
getAlias
Returns the unambiguous technical name of the TTY-/COM-Port.- Specified by:
getAliasin interfaceAliasAccessor- 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."- 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
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).- Specified by:
openin interfaceOpenable- Specified by:
openin interfaceSerialReceiver- Overrides:
openin classAbstractPort<PortMetrics>- Throws:
IOException
-
close
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).- Specified by:
closein interfaceClosable- Specified by:
closein interfaceSerialReceiver- Overrides:
closein classAbstractPort<PortMetrics>- Throws:
IOException
-
withOpen
- Throws:
IOException
-
withOpen
- Throws:
IOException
-
withOpenUnchecked
-
withOpenUnchecked
-
toString
-
setCrossoverPort
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.
-