public final class ChannelListeners extends Object
Modifier and Type | Method and Description |
---|---|
static ChannelExceptionHandler<Channel> |
closingChannelExceptionHandler()
Get a channel exception handler which closes the channel upon exception.
|
static ChannelListener<Channel> |
closingChannelListener()
Get a channel listener which closes the channel when notified.
|
static <T extends Channel> |
closingChannelListener(ChannelListener<T> delegate,
Closeable... resources)
Get a channel listener which closes the given resource when notified.
|
static <T extends Channel> |
closingChannelListener(ChannelListener<T> delegate,
Closeable resource)
Get a channel listener which closes the given resource when notified.
|
static ChannelListener<Channel> |
closingChannelListener(Closeable... resources)
Get a channel listener which closes the given resources when notified.
|
static ChannelListener<Channel> |
closingChannelListener(Closeable resource)
Get a channel listener which closes the given resource when notified.
|
static <T extends Channel> |
delegatingChannelListener(ChannelListener<? super T> delegate)
A delegating channel listener which passes an event to another listener of the same or a super type.
|
static <C extends Channel,T extends Channel> |
delegatingChannelListener(T channel,
ChannelListener.SimpleSetter<T> setter)
A delegating channel listener which passes an event to the listener stored in the given setter.
|
static <T extends StreamSourceChannel> |
drainListener(long bytes,
ChannelListener<? super T> finishListener,
ChannelExceptionHandler<? super T> exceptionHandler)
Create a channel listener which automatically drains the given number of bytes from the channel and then calls
a listener.
|
static <T extends Channel> |
executorChannelListener(ChannelListener<T> listener,
Executor executor)
Get a channel listener which executes a delegate channel listener via an executor.
|
static <T extends StreamSourceChannel> |
fileReceivingChannelListener(FileChannel target,
long position,
long count,
ChannelListener<? super T> delegate,
ChannelExceptionHandler<? super T> exceptionHandler)
A file-receiving channel listener.
|
static <T extends StreamSinkChannel> |
fileSendingChannelListener(FileChannel source,
long position,
long count,
ChannelListener<? super T> delegate,
ChannelExceptionHandler<? super T> exceptionHandler)
A file-sending channel listener.
|
static <T extends SuspendableWriteChannel> |
flushingChannelListener(ChannelListener<? super T> delegate,
ChannelExceptionHandler<? super T> exceptionHandler)
A flushing channel listener.
|
static <T extends Channel> |
getChannelListenerTask(T channel,
ChannelListener.SimpleSetter<T> setter)
Get a task which invokes the given channel listener on the given channel via its setter.
|
static <T extends Channel> |
getChannelListenerTask(T channel,
ChannelListener<? super T> channelListener)
Get a task which invokes the given channel listener on the given channel.
|
static <T extends Channel> |
getDelegatingSetter(ChannelListener.Setter<? extends Channel> target,
T realChannel)
Get a channel listener setter which delegates to the given target setter with a different channel type.
|
static <T extends Channel> |
getSetter(AtomicReference<ChannelListener<? super T>> atomicReference)
Get a setter based on an atomic reference.
|
static <T extends Channel,C> |
getSetter(C channel,
AtomicReferenceFieldUpdater<C,ChannelListener> updater)
Deprecated.
Not recommended as a security manager will enforce unreasonable restrictions on the updater.
|
static <I extends StreamSourceChannel,O extends StreamSinkChannel> |
initiateTransfer(I source,
O sink,
Pool<ByteBuffer> pool)
Initiate a low-copy transfer between two stream channels.
|
static <I extends StreamSourceChannel,O extends StreamSinkChannel> |
initiateTransfer(long count,
I source,
O sink,
ChannelListener<? super I> sourceListener,
ChannelListener<? super O> sinkListener,
ChannelExceptionHandler<? super I> readExceptionHandler,
ChannelExceptionHandler<? super O> writeExceptionHandler,
Pool<ByteBuffer> pool)
Initiate a low-copy transfer between two stream channels.
|
static <T extends Channel> |
invokeChannelExceptionHandler(T channel,
ChannelExceptionHandler<? super T> exceptionHandler,
IOException exception)
Safely invoke a channel exception handler, logging any errors.
|
static <T extends Channel> |
invokeChannelListener(Executor executor,
T channel,
ChannelListener<? super T> channelListener)
Invoke a channel listener on a given channel, logging any errors, using the given executor.
|
static <T extends Channel> |
invokeChannelListener(T channel,
ChannelListener<? super T> channelListener)
Invoke a channel listener on a given channel, logging any errors.
|
static ChannelListener<Channel> |
nullChannelListener()
Get a channel listener which does nothing.
|
static <T extends Channel> |
nullSetter()
Get a channel listener setter which does nothing.
|
static <C extends ConnectedChannel> |
openListenerAdapter(ChannelListener<? super C> openListener)
Create an open listener adapter which automatically accepts connections and invokes an open listener.
|
static <T extends SuspendableReadChannel> |
readSuspendingChannelListener(ChannelListener<? super T> delegate)
A read-suspending channel listener.
|
static <T extends WritableMessageChannel> |
sendingChannelListener(Pooled<ByteBuffer> pooled,
ChannelListener<? super T> delegate,
ChannelExceptionHandler<? super T> exceptionHandler)
A sending channel listener.
|
static <T extends SuspendableWriteChannel> |
writeShutdownChannelListener(ChannelListener<? super T> delegate,
ChannelExceptionHandler<? super T> exceptionHandler)
A write shutdown channel listener.
|
static <T extends SuspendableWriteChannel> |
writeSuspendingChannelListener(ChannelListener<? super T> delegate)
A write-suspending channel listener.
|
static <T extends StreamSinkChannel> |
writingChannelListener(Pooled<ByteBuffer> pooled,
ChannelListener<? super T> delegate,
ChannelExceptionHandler<? super T> exceptionHandler)
A writing channel listener.
|
public static <T extends Channel> boolean invokeChannelListener(T channel, ChannelListener<? super T> channelListener)
T
- the channel typechannel
- the channelchannelListener
- the channel listenertrue
if the listener completed successfully, or false
if it failedpublic static <T extends Channel> void invokeChannelListener(Executor executor, T channel, ChannelListener<? super T> channelListener)
T
- the channel typeexecutor
- the executorchannel
- the channelchannelListener
- the channel listenerpublic static <T extends Channel> void invokeChannelExceptionHandler(T channel, ChannelExceptionHandler<? super T> exceptionHandler, IOException exception)
T
- the exception typechannel
- the channelexceptionHandler
- the exception handlerexception
- the exception to pass inpublic static <T extends Channel> Runnable getChannelListenerTask(T channel, ChannelListener<? super T> channelListener)
T
- the channel typechannel
- the channelchannelListener
- the channel listenerpublic static <T extends Channel> Runnable getChannelListenerTask(T channel, ChannelListener.SimpleSetter<T> setter)
T
- the channel typechannel
- the channelsetter
- the setter for the channel listenerpublic static ChannelListener<Channel> closingChannelListener()
public static ChannelListener<Channel> closingChannelListener(Closeable resource)
resource
- the resource to closepublic static ChannelListener<Channel> closingChannelListener(Closeable... resources)
resources
- the resources to closepublic static <T extends Channel> ChannelListener<T> closingChannelListener(ChannelListener<T> delegate, Closeable resource)
delegate
- the listener to call nextresource
- the resource to closepublic static <T extends Channel> ChannelListener<T> closingChannelListener(ChannelListener<T> delegate, Closeable... resources)
delegate
- the listener to call nextresources
- the resource to closepublic static ChannelListener<Channel> nullChannelListener()
public static ChannelExceptionHandler<Channel> closingChannelExceptionHandler()
public static <C extends ConnectedChannel> ChannelListener<AcceptingChannel<C>> openListenerAdapter(ChannelListener<? super C> openListener)
C
- the connected channel typeopenListener
- the channel open listener@Deprecated public static <T extends Channel,C> ChannelListener.Setter<T> getSetter(C channel, AtomicReferenceFieldUpdater<C,ChannelListener> updater)
T
- the channel typeC
- the holding classchannel
- the channelupdater
- the updaterpublic static <T extends Channel> ChannelListener.Setter<T> getSetter(AtomicReference<ChannelListener<? super T>> atomicReference)
T
- the channel typeatomicReference
- the atomic referencepublic static <T extends Channel> ChannelListener.Setter<T> getDelegatingSetter(ChannelListener.Setter<? extends Channel> target, T realChannel)
T
- the real channel typetarget
- the target setterrealChannel
- the channel to send in to the listenerpublic static <T extends Channel> ChannelListener.Setter<T> nullSetter()
T
- the channel typepublic static <T extends Channel> ChannelListener<T> executorChannelListener(ChannelListener<T> listener, Executor executor)
T
- the channel typelistener
- the listener to invokeexecutor
- the executor with which to invoke the listenerpublic static <T extends SuspendableWriteChannel> ChannelListener<T> flushingChannelListener(ChannelListener<? super T> delegate, ChannelExceptionHandler<? super T> exceptionHandler)
The returned listener is stateless and may be reused on any number of channels concurrently or sequentially.
T
- the channel typedelegate
- the delegate listenerexceptionHandler
- the exception handlerpublic static <T extends SuspendableWriteChannel> ChannelListener<T> writeShutdownChannelListener(ChannelListener<? super T> delegate, ChannelExceptionHandler<? super T> exceptionHandler)
T
- the channel typedelegate
- the delegate listenerexceptionHandler
- the exception handlerpublic static <T extends StreamSinkChannel> ChannelListener<T> writingChannelListener(Pooled<ByteBuffer> pooled, ChannelListener<? super T> delegate, ChannelExceptionHandler<? super T> exceptionHandler)
The returned listener is stateful and will not execute properly if reused.
T
- the channel typepooled
- the buffer to writedelegate
- the delegate listenerexceptionHandler
- the exception handlerpublic static <T extends WritableMessageChannel> ChannelListener<T> sendingChannelListener(Pooled<ByteBuffer> pooled, ChannelListener<? super T> delegate, ChannelExceptionHandler<? super T> exceptionHandler)
The returned listener is stateful and will not execute properly if reused.
T
- the channel typepooled
- the buffer to senddelegate
- the delegate listenerexceptionHandler
- the exception handlerpublic static <T extends StreamSinkChannel> ChannelListener<T> fileSendingChannelListener(FileChannel source, long position, long count, ChannelListener<? super T> delegate, ChannelExceptionHandler<? super T> exceptionHandler)
The returned listener is stateful and will not execute properly if reused.
T
- the channel typesource
- the file to read fromposition
- the position in the source file to read fromcount
- the number of bytes to readdelegate
- the listener to call when the file is sentexceptionHandler
- the exception handler to call if a problem occurspublic static <T extends StreamSourceChannel> ChannelListener<T> fileReceivingChannelListener(FileChannel target, long position, long count, ChannelListener<? super T> delegate, ChannelExceptionHandler<? super T> exceptionHandler)
The returned listener is stateful and will not execute properly if reused.
T
- the channel typetarget
- the file to write toposition
- the position in the target file to write tocount
- the number of bytes to writedelegate
- the listener to call when the file is sentexceptionHandler
- the exception handler to call if a problem occurspublic static <T extends Channel> ChannelListener<T> delegatingChannelListener(ChannelListener<? super T> delegate)
T
- the channel typedelegate
- the delegate channel listenerpublic static <C extends Channel,T extends Channel> ChannelListener<C> delegatingChannelListener(T channel, ChannelListener.SimpleSetter<T> setter)
C
- the listener channel typeT
- the passed in channel typechannel
- the channel to pass insetter
- the channel listener setterpublic static <T extends SuspendableWriteChannel> ChannelListener<T> writeSuspendingChannelListener(ChannelListener<? super T> delegate)
delegate
- the delegate channel listenerpublic static <T extends SuspendableReadChannel> ChannelListener<T> readSuspendingChannelListener(ChannelListener<? super T> delegate)
delegate
- the delegate channel listenerpublic static <I extends StreamSourceChannel,O extends StreamSinkChannel> void initiateTransfer(I source, O sink, Pool<ByteBuffer> pool)
I
- the source stream typeO
- the sink stream typesource
- the source channelsink
- the target channelpool
- the pool from which the transfer buffer should be allocatedpublic static <I extends StreamSourceChannel,O extends StreamSinkChannel> void initiateTransfer(long count, I source, O sink, ChannelListener<? super I> sourceListener, ChannelListener<? super O> sinkListener, ChannelExceptionHandler<? super I> readExceptionHandler, ChannelExceptionHandler<? super O> writeExceptionHandler, Pool<ByteBuffer> pool)
count
- the number of bytes to transfer, or Long.MAX_VALUE
to transfer all remaining bytessource
- the source channelsink
- the target channelsourceListener
- the source listener to set and call when the transfer is complete, or null
to clear the listener at that timesinkListener
- the target listener to set and call when the transfer is complete, or null
to clear the listener at that timereadExceptionHandler
- the read exception handler to call if an error occurs during a read operationwriteExceptionHandler
- the write exception handler to call if an error occurs during a write operationpool
- the pool from which the transfer buffer should be allocatedpublic static <T extends StreamSourceChannel> ChannelListener<T> drainListener(long bytes, ChannelListener<? super T> finishListener, ChannelExceptionHandler<? super T> exceptionHandler)
T
- the channel typebytes
- the number of bytes to drain, or Long.MAX_VALUE
to drain the channel completelyfinishListener
- the listener to call when the drain is completeexceptionHandler
- the handler to call if the drain failsCopyright © 2016 JBoss by Red Hat. All rights reserved.