Class AbstractPort<PM extends PortMetrics>
java.lang.Object
org.refcodes.component.ConnectionAutomatonImpl<PM>
org.refcodes.serial.AbstractPort<PM>
- Type Parameters:
PM- The actualPortMetricstype to use.
- All Implemented Interfaces:
Flushable, Comparable<Port<?>>, Closable, Closable.CloseAutomaton, ClosedAccessor, ConnectableComponent, ConnectableComponent.ConnectableAutomaton, ConnectionComponent<PM>, ConnectionComponent.ConnectionAutomaton<PM>, ConnectionOpenable<PM>, ConnectionOpenable.ConnectionOpenAutomaton<PM>, ConnectionOpenable.ConnectionOpenBuilder<PM,Port<PM>>, ConnectionStatusAccessor, Flushable, LinkComponent, LinkComponent.LinkAutomaton, Openable, Openable.OpenAutomaton, Openable.OpenBuilder<Port<PM>>, OpenedAccessor, Availability, ByteDestination, ByteReceiver, BytesDestination, ByteSource, BytesReceiver, BytesSource, BytesTransceiver, BytesTransmitter, ByteTransceiver, ByteTransmitter, Receivable, Skippable, TimeoutInputStreamAccessor, Transmittable, AliasAccessor, InputStreamAccessor, OutputStreamAccessor, Port<PM>, PortMetricsAccessor<PM>, SegmentDestination, SegmentReceiver, SegmentSource, SegmentTransceiver, SegmentTransmitter, SerialReceiver, SerialTransceiver, SerialTransmitter
- Direct Known Subclasses:
LoopbackPort
public abstract class AbstractPort<PM extends PortMetrics>
extends ConnectionAutomatonImpl<PM>
implements Port<PM>
A
AbstractPort is a base Port implementation.-
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 ConnectionAutomatonImpl
_connectionComponent -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractPort(String aAlias, PM aPortMetrics) Constructs aAbstractPortwith the given properties.protectedAbstractPort(String aAlias, PM aPortMetrics, ExecutorService aExecutorService) Constructs aAbstractPortwith the given properties and the givenExecutorServiceto be used by asynchronous functionality. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()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) getAlias()Returns the unambiguous technical name of the TTY-/COM-Port.boolean<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).void<HEADER extends Segment>
voidreceiveSegment(HEADER aSegment) Receives aSegment(and blocks this thread) till all it'sSequencedata has been received and updates theSegmentby invokingSegment.fromTransmission(Sequence).Methods inherited from class ConnectionAutomatonImpl
getConnectionStatus, isClosable, isClosed, isOpenable, isOpenedMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Availability
hasAvailableMethods inherited from interface BytesDestination
receiveBytesMethods 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 ConnectionOpenable.ConnectionOpenBuilder
withOpen, withOpenUncheckedMethods inherited from interface ConnectionStatusAccessor
getConnectionStatus, isOpenedMethods inherited from interface Flushable
flushUnchecked, isFlushableMethods inherited from interface Openable
openUncheckedMethods inherited from interface Openable.OpenBuilder
withOpen, withOpenUncheckedMethods inherited from interface PortMetricsAccessor
getPortMetricsMethods inherited from interface SegmentTransmitter
flushMethods inherited from interface SerialReceiver
available, receiveByte, receiveBytes, receiveSegmentWithin, receiveSequence, receiveSequenceWithinMethods inherited from interface SerialTransceiver
transmitSegmentMethods inherited from interface SerialTransmitter
flush, transmitBytes, transmitBytes, transmitSequence, transmitSequenceMethods inherited from interface Skippable
available, skipAvailable, skipAvailableExcept, skipAvailableTill, skipAvailableTillSilenceFor, skipAvailableTillSilenceFor, skipAvailableWithin, skipAvailableWithin, skipAvailableWithin
-
Field Details
-
_alias
-
_portMetrics
-
_executorService
-
-
Constructor Details
-
AbstractPort
Constructs aAbstractPortwith the given properties. The alias corresponds to the underlying TTY-/COM-Port's name.- Parameters:
aAlias- The unambiguous technical name for thisAbstractPort.aPortMetrics- The metrics of theAbstractPort.
-
AbstractPort
Constructs aAbstractPortwith the given properties and the givenExecutorServiceto be used by asynchronous functionality. The alias corresponds to the underlying TTY-/COM-Port's name.- Parameters:
aAlias- The unambiguous technical name for thisAbstractPort.aPortMetrics- The metrics of theAbstractPort.aExecutorService- TheExecutorServiceto be used when invoking asynchronously working methods.
-
-
Method Details
-
getAlias
Returns the unambiguous technical name of the TTY-/COM-Port.- Specified by:
getAliasin interfaceAliasAccessor- Returns:
- The port's name.
-
isOpenable
public boolean isOpenable()- Specified by:
isOpenablein interfaceOpenable.OpenAutomaton
-
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- Throws:
IOException
-
open
- Specified by:
openin interfaceConnectionOpenable<PM extends PortMetrics>- Overrides:
openin classConnectionAutomatonImpl<PM extends PortMetrics>- Throws:
IOException
-
receiveSegment
Receives aSegment(and blocks this thread) till all it'sSequencedata has been received and updates theSegmentby invokingSegment.fromTransmission(Sequence). This method blocks till all bytes are read.- Specified by:
receiveSegmentin interfaceSegmentDestination- Specified by:
receiveSegmentin interfaceSerialReceiver- Specified by:
receiveSegmentin interfaceSerialTransceiver- Type Parameters:
HEADER- TheSegmenttype describing theSegmentsubclass of implementingSegmenttypes.- Parameters:
aSegment- TheSegmentto be (re-)initialized with the received data.- Throws:
IOException- thrown in case of I/O issues (e.g. a timeout) while receiving.
-
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- 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- 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- Type Parameters:
SEGMENT- TheSegmenttype describing theSegmentsubclass used.- Parameters:
aSegment- TheSegmentto be sent.- Returns:
- The
SegmentResultwhich provides the result of the operation (asynchronously), e.g. theSegmentbeing sent or anIOExceptionhaving occurred. - Throws:
IOException- thrown in case of I/O issues (e.g. a closed connection upon the time of invocation).
-
doTransmitSegment
public <SEGMENT extends Segment> void doTransmitSegment(SEGMENT aSegment, SegmentConsumer<SEGMENT> aSegmentConsumer) throws IOException - Specified by:
doTransmitSegmentin interfaceSegmentTransmitter- Type Parameters:
SEGMENT- TheSegmenttype describing theSegmentsubclass used.- Parameters:
aSegment- TheSegmentto be sent.aSegmentConsumer- The callback asynchronously invoked upon having sent theSegment.- Throws:
IOException- thrown in case of I/O issues (e.g. a closed connection upon the time of invocation).
-
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 classConnectionAutomatonImpl<PM extends PortMetrics>- Throws:
IOException
-