- java.lang.Object
-
- org.refcodes.component.ConnectionAutomatonImpl<PM>
-
- org.refcodes.serial.AbstractPort<PM>
-
- Type Parameters:
PM
- The actualPortMetrics
type to use.
- 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<PM>
,org.refcodes.component.ConnectionComponent.ConnectionAutomaton<PM>
,org.refcodes.component.ConnectionOpenable<PM>
,org.refcodes.component.ConnectionOpenable.ConnectionOpenAutomaton<PM>
,org.refcodes.component.ConnectionOpenable.ConnectionOpenBuilder<PM,Port<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<Port<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
- Direct Known Subclasses:
LoopbackPort
public abstract class AbstractPort<PM extends PortMetrics> extends org.refcodes.component.ConnectionAutomatonImpl<PM> implements Port<PM>, org.refcodes.component.ConnectionComponent.ConnectionAutomaton<PM>
AAbstractPort
is a basePort
implementation
-
-
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 String
_alias
protected ExecutorService
_executorService
protected PM
_portMetrics
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractPort(String aAlias, PM aPortMetrics)
Constructs aAbstractPort
with the given properties.protected
AbstractPort(String aAlias, PM aPortMetrics, ExecutorService aExecutorService)
Constructs aAbstractPort
with the given properties and the givenExecutorService
to be used by asynchronous functionality.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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)
.<SEGMENT extends Segment>
SegmentResult<SEGMENT>doTransmitSegment(SEGMENT aSegment)
<SEGMENT extends Segment>
voiddoTransmitSegment(SEGMENT aSegment, SegmentConsumer<SEGMENT> aSegmentConsumer)
String
getAlias()
Returns the unambiguous technical name of the TTY-/COM-Port.boolean
isOpenable()
<SEGMENT extends Segment>
SegmentResult<SEGMENT>onReceiveSegment(SEGMENT aSegment)
Asynchronously receives aSegment
'sSequence
data (does not block this thread) and updates theSegment
by invokingSegment.fromTransmission(Sequence)
.<SEGMENT extends Segment>
voidonReceiveSegment(SEGMENT aSegment, SegmentConsumer<SEGMENT> aSegmentConsumer)
Asynchronously receives aSegment
'sSequence
data (does not block this thread) and updates theSegment
by invokingSegment.fromTransmission(Sequence)
, passing the result to the callbackSegmentConsumer.onSegment(Segment)
.void
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)
.void
open(PM aConnection)
<HEADER extends Segment>
voidreceiveSegment(HEADER aSegment)
Receives aSegment
(and blocks this thread) till all it'sSequence
data has been received and updates theSegment
by invokingSegment.fromTransmission(Sequence)
.-
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, toString, 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.ConnectionOpenable.ConnectionOpenBuilder
withOpen, withOpenUnchecked
-
Methods inherited from interface org.refcodes.component.ConnectionStatusAccessor
getConnectionStatus, isOpened
-
Methods inherited from interface org.refcodes.component.Openable.OpenBuilder
withOpen, withOpenUnchecked
-
Methods inherited from interface org.refcodes.serial.PortMetricsAccessor
getPortMetrics
-
Methods inherited from interface org.refcodes.serial.SegmentTransmitter
flush
-
Methods inherited from interface org.refcodes.serial.SerialReceiver
available, receiveByte, receiveBytes, receiveSegmentWithin, receiveSequence, receiveSequenceWithin
-
Methods inherited from interface org.refcodes.serial.SerialTransceiver
transmitSegment
-
Methods inherited from interface org.refcodes.serial.SerialTransmitter
flush, transmitAllBytes, transmitBytes, transmitSequence, transmitSequence
-
-
-
-
Field Detail
-
_alias
protected String _alias
-
_portMetrics
protected PM extends PortMetrics _portMetrics
-
_executorService
protected ExecutorService _executorService
-
-
Constructor Detail
-
AbstractPort
protected AbstractPort(String aAlias, PM aPortMetrics)
Constructs aAbstractPort
with 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
protected AbstractPort(String aAlias, PM aPortMetrics, ExecutorService aExecutorService)
Constructs aAbstractPort
with the given properties and the givenExecutorService
to 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
- TheExecutorService
to be used when invoking asynchronously working methods.
-
-
Method Detail
-
getAlias
public String getAlias()
Returns the unambiguous technical name of the TTY-/COM-Port.- Specified by:
getAlias
in interfaceorg.refcodes.mixin.AliasAccessor
- Returns:
- The port's name.
-
isOpenable
public boolean isOpenable()
- Specified by:
isOpenable
in interfaceorg.refcodes.component.Openable.OpenAutomaton
-
open
public void open() throws IOException
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:
open
in interfaceorg.refcodes.component.Openable
- Specified by:
open
in interfaceSerialReceiver
- Throws:
IOException
-
open
public void open(PM aConnection) throws IOException
- Specified by:
open
in interfaceorg.refcodes.component.ConnectionOpenable<PM extends PortMetrics>
- Overrides:
open
in classorg.refcodes.component.ConnectionAutomatonImpl<PM extends PortMetrics>
- Throws:
IOException
-
receiveSegment
public <HEADER extends Segment> void receiveSegment(HEADER aSegment) throws TransmissionException, IOException
Receives aSegment
(and blocks this thread) till all it'sSequence
data has been received and updates theSegment
by invokingSegment.fromTransmission(Sequence)
. This method blocks till all bytes are read.- Specified by:
receiveSegment
in interfaceSegmentDestination
- Specified by:
receiveSegment
in interfaceSerialReceiver
- Specified by:
receiveSegment
in interfaceSerialTransceiver
- Type Parameters:
HEADER
- TheSegment
type describing theSegment
subclass of implementingSegment
types.- Parameters:
aSegment
- TheSegment
to be (re-)initialized with the received data.- Throws:
TransmissionException
- Thrown in case the received data cannot be used to (re-)initialize the givenSegment
.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
'sSequence
data (does not block this thread) and updates theSegment
by invokingSegment.fromTransmission(Sequence)
, passing the result to the callbackSegmentConsumer.onSegment(Segment)
.- Specified by:
onReceiveSegment
in interfaceSegmentReceiver
- Type Parameters:
SEGMENT
- TheSegment
type describing theSegment
subclass of implementingSegment
types.- Parameters:
aSegment
- TheSegment
to 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
'sSequence
data (does not block this thread) and updates theSegment
by invokingSegment.fromTransmission(Sequence)
. The result is provided by the returnedSegmentResult
instance providing the (asynchronously) (re-)initialized providedSegment
instance.- Specified by:
onReceiveSegment
in interfaceSegmentReceiver
- Type Parameters:
SEGMENT
- TheSegment
type describing theSegment
subclass used.- Parameters:
aSegment
- TheSegment
to be (re-)initialized with the received data.- Returns:
- The
SegmentResult
which 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:
doTransmitSegment
in interfaceSegmentTransmitter
- Type Parameters:
SEGMENT
- TheSegment
type describing theSegment
subclass used.- Parameters:
aSegment
- TheSegment
to be sent.- Returns:
- The
SegmentResult
which provides the result of the operation (asynchronously), e.g. theSegment
being sent or anIOException
having 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:
doTransmitSegment
in interfaceSegmentTransmitter
- Type Parameters:
SEGMENT
- TheSegment
type describing theSegment
subclass used.- Parameters:
aSegment
- TheSegment
to 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
public void close() throws IOException
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:
close
in interfaceorg.refcodes.component.Closable
- Specified by:
close
in interfaceSerialReceiver
- Overrides:
close
in classorg.refcodes.component.ConnectionAutomatonImpl<PM extends PortMetrics>
- Throws:
IOException
-
-