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 theByteReceiverinterface. As of the prefetching functionality, a separate daemon thread (retrieved via anExecutorService) reads from the providedInputStreamand 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 anAbstractPrefetchInputStreamByteReceiverusing the given datagram queue capacity.AbstractPrefetchInputStreamByteReceiver(int aQueueCapacity, java.util.concurrent.ExecutorService aExecutorService)Creates anAbstractPrefetchInputStreamByteReceiverusing the givenExecutorServicerequired for thread generation in an JEE environment.AbstractPrefetchInputStreamByteReceiver(java.util.concurrent.ExecutorService aExecutorService)Creates anAbstractPrefetchInputStreamByteReceiverusing the givenExecutorServicerequired for thread generation in an JEE environment.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()protected booleanisOpenable(java.io.InputStream aInputStream)Checks if is openable.protected voidopen(java.io.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(java.util.concurrent.ExecutorService aExecutorService)
Creates anAbstractPrefetchInputStreamByteReceiverusing the givenExecutorServicerequired for thread generation in an JEE environment.- Parameters:
aExecutorService- TheExecutorServiceto be used, when null then anExecutorServicesomething lineExecutors.newCachedThreadPool()is then retrieved.
-
AbstractPrefetchInputStreamByteReceiver
public AbstractPrefetchInputStreamByteReceiver(int aQueueCapacity)
Creates anAbstractPrefetchInputStreamByteReceiverusing 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, java.util.concurrent.ExecutorService aExecutorService)Creates anAbstractPrefetchInputStreamByteReceiverusing the givenExecutorServicerequired 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- TheExecutorServiceto be used, when null then anExecutorServicesomething lineExecutors.newCachedThreadPool()is then retrieved.
-
-
Method Detail
-
close
public void close() throws org.refcodes.component.CloseException- Specified by:
closein interfaceorg.refcodes.component.Closable- Overrides:
closein classAbstractByteReceiver- Throws:
org.refcodes.component.CloseException
-
open
protected void open(java.io.InputStream aInputStream) throws org.refcodes.component.OpenExceptionOpen, see alsoConnectionOpenable.open(Object).- Parameters:
aInputStream- the input stream- Throws:
org.refcodes.component.OpenException- the open exception
-
isOpenable
protected boolean isOpenable(java.io.InputStream aInputStream)
Checks if is openable. See alsoConnectionOpenable.ConnectionOpenAutomaton.isOpenable(Object).- Parameters:
aInputStream- the input stream- Returns:
- true, if is openable
-
-