Package org.refcodes.io
Class AbstractPrefetchInputStreamByteReceiver
- java.lang.Object
-
- org.refcodes.io.AbstractByteProvider
-
- org.refcodes.io.AbstractByteReceiver
-
- org.refcodes.io.AbstractPrefetchInputStreamByteReceiver
-
- All Implemented Interfaces:
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.ConnectionStatusAccessor
,org.refcodes.component.OpenedAccessor
,ByteBlockProvider
,ByteBlockReceiver
,ByteDatagramProvider
,ByteDatagramReceiver
,ByteProvider
,ByteReceiver
,Receivable
,org.refcodes.mixin.Loggable
,org.refcodes.mixin.Releaseable
- Direct Known Subclasses:
PrefetchBidirectionalStreamConnectionByteTransceiverImpl
,PrefetchInputStreamConnectionByteReceiverImpl
public abstract class AbstractPrefetchInputStreamByteReceiver extends AbstractByteReceiver implements org.refcodes.mixin.Loggable
Abstract implementation of theByteReceiver
interface. As of the prefetching functionality, a separate daemon thread (retrieved via anExecutorService
) reads from the providedInputStream
and places the datagrams into a datagram queue until the datagram queue's capacity is reached. Datagrams are read by theAbstractByteReceiver.readDatagram()
(AbstractByteReceiver.readDatagrams()
) by them methods popping the datagrams from the datagram queue. If the queue is empty, then theAbstractByteReceiver.readDatagram()
(AbstractByteReceiver.readDatagrams()
) method is blocked until the daemon thread places new datagrams into the queue.- See Also:
AbstractByteReceiver
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.refcodes.io.AbstractByteReceiver
AbstractByteReceiver.ConnectableAutomaton
-
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
-
-
Field Summary
-
Fields inherited from class org.refcodes.io.AbstractByteProvider
_datagramQueue, DATAGRAM_QUEUE_SIZE
-
Fields inherited from class org.refcodes.io.AbstractByteReceiver
_automaton
-
-
Constructor Summary
Constructors Constructor Description AbstractPrefetchInputStreamByteReceiver()
Creates anAbstractPrefetchInputStreamByteReceiver
.AbstractPrefetchInputStreamByteReceiver(int aQueueCapacity)
Creates anAbstractPrefetchInputStreamByteReceiver
using the given datagram queue capacity.AbstractPrefetchInputStreamByteReceiver(int aQueueCapacity, ExecutorService aExecutorService)
Creates anAbstractPrefetchInputStreamByteReceiver
using the givenExecutorService
required for thread generation in an JEE environment.AbstractPrefetchInputStreamByteReceiver(ExecutorService aExecutorService)
Creates anAbstractPrefetchInputStreamByteReceiver
using the givenExecutorService
required for thread generation in an JEE environment.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
protected boolean
isOpenable(InputStream aInputStream)
Checks if is openable.protected void
open(InputStream aInputStream)
Open, see alsoConnectionOpenable.open(Object)
.-
Methods inherited from class org.refcodes.io.AbstractByteProvider
pushDatagram, pushDatagrams, pushDatagrams
-
Methods inherited from class org.refcodes.io.AbstractByteReceiver
getConnectionStatus, hasDatagram, isClosable, isClosed, isOpenable, isOpened, open, readDatagram, readDatagrams, readDatagrams, releaseAll, setConnectionStatus
-
Methods inherited from interface org.refcodes.component.Closable
closeIn, closeQuietly, closeUnchecked
-
-
-
-
Constructor Detail
-
AbstractPrefetchInputStreamByteReceiver
public AbstractPrefetchInputStreamByteReceiver()
Creates anAbstractPrefetchInputStreamByteReceiver
.
-
AbstractPrefetchInputStreamByteReceiver
public AbstractPrefetchInputStreamByteReceiver(ExecutorService aExecutorService)
Creates anAbstractPrefetchInputStreamByteReceiver
using the givenExecutorService
required for thread generation in an JEE environment.- Parameters:
aExecutorService
- TheExecutorService
to be used, when null then anExecutorService
something lineExecutors.newCachedThreadPool()
is then retrieved.
-
AbstractPrefetchInputStreamByteReceiver
public AbstractPrefetchInputStreamByteReceiver(int aQueueCapacity)
Creates anAbstractPrefetchInputStreamByteReceiver
using the given datagram queue capacity.- Parameters:
aQueueCapacity
- The capacity of the prefetch queue before it blocks until data is read viaAbstractByteReceiver.readDatagram()
(AbstractByteReceiver.readDatagrams()
).
-
AbstractPrefetchInputStreamByteReceiver
public AbstractPrefetchInputStreamByteReceiver(int aQueueCapacity, ExecutorService aExecutorService)
Creates anAbstractPrefetchInputStreamByteReceiver
using the givenExecutorService
required for thread generation in an JEE environment.- Parameters:
aQueueCapacity
- The capacity of the prefetch queue before it blocks until data is read viaAbstractByteReceiver.readDatagram()
(AbstractByteReceiver.readDatagrams()
).aExecutorService
- TheExecutorService
to be used, when null then anExecutorService
something lineExecutors.newCachedThreadPool()
is then retrieved.
-
-
Method Detail
-
close
public void close() throws org.refcodes.component.CloseException
- Specified by:
close
in interfaceorg.refcodes.component.Closable
- Overrides:
close
in classAbstractByteReceiver
- Throws:
org.refcodes.component.CloseException
-
open
protected void open(InputStream aInputStream) throws org.refcodes.component.OpenException
Open, see alsoConnectionOpenable.open(Object)
.- Parameters:
aInputStream
- the input stream- Throws:
org.refcodes.component.OpenException
- the open exception
-
isOpenable
protected boolean isOpenable(InputStream aInputStream)
Checks if is openable. See alsoConnectionOpenable.ConnectionOpenAutomaton.isOpenable(Object)
.- Parameters:
aInputStream
- the input stream- Returns:
- true, if is openable
-
-