Class AbstractChannel
- java.lang.Object
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.nio.channels.Channel
,AttributeRepository
,AttributeStore
,Channel
,ChannelListenerManager
,ChannelStreamWriterResolver
,ChannelStreamWriterResolverManager
,Closeable
,PropertyResolver
,SessionContextHolder
,SessionHolder<Session>
,ExecutorServiceCarrier
- Direct Known Subclasses:
AbstractClientChannel
,AbstractServerChannel
public abstract class AbstractChannel extends AbstractInnerCloseable implements Channel, ExecutorServiceCarrier
Provides common client/server channel functionality
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
AbstractChannel.GracefulChannelCloseable
protected static class
AbstractChannel.GracefulState
-
Nested classes/interfaces inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
AbstractCloseable.State
-
Nested classes/interfaces inherited from interface org.apache.sshd.common.AttributeRepository
AttributeRepository.AttributeKey<T>
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<AttributeRepository.AttributeKey<?>,java.lang.Object>
attributes
protected ChannelListener
channelListenerProxy
protected java.util.Collection<ChannelListener>
channelListeners
Channel events listenerprivate ChannelStreamWriterResolver
channelStreamPacketWriterResolver
protected java.util.concurrent.atomic.AtomicBoolean
eofReceived
protected java.util.concurrent.atomic.AtomicBoolean
eofSent
private CloseableExecutorService
executor
protected DefaultCloseFuture
gracefulFuture
protected java.util.concurrent.atomic.AtomicReference<AbstractChannel.GracefulState>
gracefulState
private int
id
protected java.util.concurrent.atomic.AtomicBoolean
initialized
private Window
localWindow
private java.util.Map<java.lang.String,java.util.Date>
pendingRequests
AMap
of sent requests - key = request name, value = timestamp when request was sent.private java.util.Map<java.lang.String,java.lang.Object>
properties
private int
recipient
private Window
remoteWindow
private java.util.List<RequestHandler<Channel>>
requestHandlers
static java.util.function.IntUnaryOperator
RESPONSE_BUFFER_GROWTH_FACTOR
Default growth factor function used to resize response buffersprotected ConnectionService
service
private Session
sessionInstance
-
Fields inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
closeFuture, futureLock, state
-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
Fields inherited from interface org.apache.sshd.common.channel.Channel
CHANNEL_EXEC, CHANNEL_SHELL, CHANNEL_SUBSYSTEM
-
Fields inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolver
NONE
-
Fields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTY
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractChannel(boolean client)
protected
AbstractChannel(boolean client, java.util.Collection<? extends RequestHandler<Channel>> handlers)
protected
AbstractChannel(java.lang.String discriminator, boolean client)
protected
AbstractChannel(java.lang.String discriminator, boolean client, java.util.Collection<? extends RequestHandler<Channel>> handlers, CloseableExecutorService executorService)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addChannelListener(ChannelListener listener)
Add a channel listenerprotected java.util.Date
addPendingRequest(java.lang.String request, boolean wantReply)
Add a channel request to the tracked pending ones if reply is expectedvoid
addRequestHandler(RequestHandler<Channel> handler)
java.util.Collection<AttributeRepository.AttributeKey<?>>
attributeKeys()
void
clearAttributes()
Removes all currently stored user-defined attributes<T> T
computeAttributeIfAbsent(AttributeRepository.AttributeKey<T> key, java.util.function.Function<? super AttributeRepository.AttributeKey<T>,? extends T> resolver)
If the specified key is not already associated with a value (or is mapped tonull
), attempts to compute its value using the given mapping function and enters it into this map unlessnull
.protected void
configureWindow()
protected abstract void
doWriteData(byte[] data, int off, long len)
protected abstract void
doWriteExtendedData(byte[] data, int off, long len)
<T> T
getAttribute(AttributeRepository.AttributeKey<T> key)
Returns the value of the user-defined attribute.int
getAttributesCount()
ChannelListener
getChannelListenerProxy()
ChannelStreamWriterResolver
getChannelStreamWriterResolver()
CloseableExecutorService
getExecutorService()
int
getId()
protected Closeable
getInnerCloseable()
Window
getLocalWindow()
PropertyResolver
getParentPropertyResolver()
java.util.Map<java.lang.String,java.lang.Object>
getProperties()
A map of properties that can be used to configure the SSH server or client.int
getRecipient()
Window
getRemoteWindow()
java.util.List<RequestHandler<Channel>>
getRequestHandlers()
Session
getSession()
protected void
handleChannelRequest(java.lang.String req, boolean wantReply, Buffer buffer)
void
handleClose()
Invoked whenSSH_MSG_CHANNEL_CLOSE
receivedvoid
handleData(Buffer buffer)
Invoked whenSSH_MSG_CHANNEL_DATA
receivedvoid
handleEof()
Invoked whenSSH_MSG_CHANNEL_EOF
receivedvoid
handleExtendedData(Buffer buffer)
Invoked whenSSH_MSG_CHANNEL_EXTENDED_DATA
receivedvoid
handleFailure()
Invoked whenSSH_MSG_CHANNEL_FAILURE
receivedprotected RequestHandler.Result
handleInternalRequest(java.lang.String req, boolean wantReply, Buffer buffer)
Called byhandleUnknownChannelRequest(String, boolean, Buffer)
in order to allow channel request handling if none of the registered handlers processed the request - last chance.void
handleRequest(Buffer buffer)
Invoked whenSSH_MSG_CHANNEL_REQUEST
receivedvoid
handleSuccess()
Invoked whenSSH_MSG_CHANNEL_SUCCESS
receivedprotected void
handleUnknownChannelRequest(java.lang.String req, boolean wantReply, Buffer buffer)
Called when none of the register request handlers reported handling the requestvoid
handleWindowAdjust(Buffer buffer)
Invoked whenSSH_MSG_CHANNEL_WINDOW_ADJUST
receivedvoid
init(ConnectionService service, Session session, int id)
Invoked when the local channel is initial createdprotected void
invokeChannelSignaller(Invoker<ChannelListener,java.lang.Void> invoker)
boolean
isEofSent()
boolean
isEofSignalled()
boolean
isInitialized()
protected void
notifyStateChanged(java.lang.String hint)
protected void
notifyStateChanged(ChannelListener listener, java.lang.String hint)
protected void
preClose()
preClose is guaranteed to be called before doCloseGracefully or doCloseImmediately.<T> T
removeAttribute(AttributeRepository.AttributeKey<T> key)
Removes the user-defined attributevoid
removeChannelListener(ChannelListener listener)
Remove a channel listenerprotected java.util.Date
removePendingRequest(java.lang.String request)
Removes a channel request from the tracked onesvoid
removeRequestHandler(RequestHandler<Channel> handler)
ChannelStreamWriterResolver
resolveChannelStreamWriterResolver()
protected IoWriteFuture
sendEof()
SendsSSH_MSG_CHANNEL_EOF
provided not already sent and current channel state allows it.protected IoWriteFuture
sendResponse(Buffer buffer, java.lang.String req, RequestHandler.Result result, boolean wantReply)
protected void
sendWindowAdjust(long len)
<T> T
setAttribute(AttributeRepository.AttributeKey<T> key, T value)
Sets a user-defined attribute.void
setChannelStreamWriterResolver(ChannelStreamWriterResolver resolver)
protected void
setRecipient(int recipient)
void
signalChannelClosed(java.lang.Throwable reason)
protected void
signalChannelClosed(ChannelListener listener, java.lang.Throwable reason)
protected void
signalChannelInitialized()
protected void
signalChannelInitialized(ChannelListener listener)
protected void
signalChannelOpenFailure(java.lang.Throwable reason)
protected void
signalChannelOpenFailure(ChannelListener listener, java.lang.Throwable reason)
protected void
signalChannelOpenSuccess()
protected void
signalChannelOpenSuccess(ChannelListener listener)
java.lang.String
toString()
protected long
validateIncomingDataSize(int cmd, long len)
IoWriteFuture
writePacket(Buffer buffer)
Encode and send the given buffer.-
Methods inherited from class org.apache.sshd.common.util.closeable.AbstractInnerCloseable
doCloseGracefully, doCloseImmediately
-
Methods inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListener
-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.sshd.common.channel.Channel
addRequestHandlers, handleOpenFailure, handleOpenSuccess, open, removeRequestHandlers, resolveAttribute
-
Methods inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolverManager
resolveChannelStreamWriter
-
Methods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListener
-
Methods inherited from interface org.apache.sshd.common.PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getString, getStringProperty
-
Methods inherited from interface org.apache.sshd.common.session.SessionHolder
getSessionContext
-
-
-
-
Field Detail
-
RESPONSE_BUFFER_GROWTH_FACTOR
public static final java.util.function.IntUnaryOperator RESPONSE_BUFFER_GROWTH_FACTOR
Default growth factor function used to resize response buffers
-
service
protected ConnectionService service
-
initialized
protected final java.util.concurrent.atomic.AtomicBoolean initialized
-
eofReceived
protected final java.util.concurrent.atomic.AtomicBoolean eofReceived
-
eofSent
protected final java.util.concurrent.atomic.AtomicBoolean eofSent
-
gracefulState
protected java.util.concurrent.atomic.AtomicReference<AbstractChannel.GracefulState> gracefulState
-
gracefulFuture
protected final DefaultCloseFuture gracefulFuture
-
channelListeners
protected final java.util.Collection<ChannelListener> channelListeners
Channel events listener
-
channelListenerProxy
protected final ChannelListener channelListenerProxy
-
id
private int id
-
recipient
private int recipient
-
sessionInstance
private Session sessionInstance
-
executor
private CloseableExecutorService executor
-
requestHandlers
private final java.util.List<RequestHandler<Channel>> requestHandlers
-
localWindow
private final Window localWindow
-
remoteWindow
private final Window remoteWindow
-
channelStreamPacketWriterResolver
private ChannelStreamWriterResolver channelStreamPacketWriterResolver
-
pendingRequests
private final java.util.Map<java.lang.String,java.util.Date> pendingRequests
AMap
of sent requests - key = request name, value = timestamp when request was sent.
-
properties
private final java.util.Map<java.lang.String,java.lang.Object> properties
-
attributes
private final java.util.Map<AttributeRepository.AttributeKey<?>,java.lang.Object> attributes
-
-
Constructor Detail
-
AbstractChannel
protected AbstractChannel(boolean client)
-
AbstractChannel
protected AbstractChannel(boolean client, java.util.Collection<? extends RequestHandler<Channel>> handlers)
-
AbstractChannel
protected AbstractChannel(java.lang.String discriminator, boolean client)
-
AbstractChannel
protected AbstractChannel(java.lang.String discriminator, boolean client, java.util.Collection<? extends RequestHandler<Channel>> handlers, CloseableExecutorService executorService)
-
-
Method Detail
-
getRequestHandlers
public java.util.List<RequestHandler<Channel>> getRequestHandlers()
- Specified by:
getRequestHandlers
in interfaceChannel
-
addRequestHandler
public void addRequestHandler(RequestHandler<Channel> handler)
- Specified by:
addRequestHandler
in interfaceChannel
-
removeRequestHandler
public void removeRequestHandler(RequestHandler<Channel> handler)
- Specified by:
removeRequestHandler
in interfaceChannel
-
getRecipient
public int getRecipient()
- Specified by:
getRecipient
in interfaceChannel
- Returns:
- Remote channel identifier
-
setRecipient
protected void setRecipient(int recipient)
-
getLocalWindow
public Window getLocalWindow()
- Specified by:
getLocalWindow
in interfaceChannel
-
getRemoteWindow
public Window getRemoteWindow()
- Specified by:
getRemoteWindow
in interfaceChannel
-
getSession
public Session getSession()
- Specified by:
getSession
in interfaceSessionHolder<Session>
-
getParentPropertyResolver
public PropertyResolver getParentPropertyResolver()
- Specified by:
getParentPropertyResolver
in interfacePropertyResolver
- Returns:
- The parent resolver that can be used to query for missing properties -
null
if no parent
-
getExecutorService
public CloseableExecutorService getExecutorService()
- Specified by:
getExecutorService
in interfaceExecutorServiceCarrier
- Returns:
- The
CloseableExecutorService
to use
-
getChannelStreamWriterResolver
public ChannelStreamWriterResolver getChannelStreamWriterResolver()
- Specified by:
getChannelStreamWriterResolver
in interfaceChannelStreamWriterResolverManager
-
setChannelStreamWriterResolver
public void setChannelStreamWriterResolver(ChannelStreamWriterResolver resolver)
- Specified by:
setChannelStreamWriterResolver
in interfaceChannelStreamWriterResolverManager
-
resolveChannelStreamWriterResolver
public ChannelStreamWriterResolver resolveChannelStreamWriterResolver()
- Specified by:
resolveChannelStreamWriterResolver
in interfaceChannelStreamWriterResolverManager
-
addPendingRequest
protected java.util.Date addPendingRequest(java.lang.String request, boolean wantReply)
Add a channel request to the tracked pending ones if reply is expected- Parameters:
request
- The request typewantReply
-true
if reply is expected- Returns:
- The allocated
Date
timestamp -null
if no reply is expected (in which case the request is not tracked) - Throws:
java.lang.IllegalArgumentException
- If the request is already being tracked- See Also:
removePendingRequest(String)
-
removePendingRequest
protected java.util.Date removePendingRequest(java.lang.String request)
Removes a channel request from the tracked ones- Parameters:
request
- The request type- Returns:
- The allocated
Date
timestamp -null
if the specified request type is not being tracked or has not been added to the tracked ones to begin with - See Also:
addPendingRequest(String, boolean)
-
handleRequest
public void handleRequest(Buffer buffer) throws java.io.IOException
Description copied from interface:Channel
Invoked whenSSH_MSG_CHANNEL_REQUEST
received- Specified by:
handleRequest
in interfaceChannel
- Parameters:
buffer
- The rest of the message dataBuffer
after decoding the channel identifiers- Throws:
java.io.IOException
- If failed to handle the message
-
handleChannelRequest
protected void handleChannelRequest(java.lang.String req, boolean wantReply, Buffer buffer) throws java.io.IOException
- Throws:
java.io.IOException
-
handleUnknownChannelRequest
protected void handleUnknownChannelRequest(java.lang.String req, boolean wantReply, Buffer buffer) throws java.io.IOException
Called when none of the register request handlers reported handling the request- Parameters:
req
- The request typewantReply
- Whether reply is requestedbuffer
- TheBuffer
containing extra request-specific data- Throws:
java.io.IOException
- If failed to send the response (if needed)- See Also:
handleInternalRequest(String, boolean, Buffer)
-
handleInternalRequest
protected RequestHandler.Result handleInternalRequest(java.lang.String req, boolean wantReply, Buffer buffer) throws java.io.IOException
Called byhandleUnknownChannelRequest(String, boolean, Buffer)
in order to allow channel request handling if none of the registered handlers processed the request - last chance.- Parameters:
req
- The request typewantReply
- Whether reply is requestedbuffer
- TheBuffer
containing extra request-specific data- Returns:
- The handling result - if
null
orUnsupported
and reply is required then a failure message will be sent - Throws:
java.io.IOException
- If failed to process the request internally
-
sendResponse
protected IoWriteFuture sendResponse(Buffer buffer, java.lang.String req, RequestHandler.Result result, boolean wantReply) throws java.io.IOException
- Throws:
java.io.IOException
-
init
public void init(ConnectionService service, Session session, int id) throws java.io.IOException
Description copied from interface:Channel
Invoked when the local channel is initial created- Specified by:
init
in interfaceChannel
- Parameters:
service
- TheConnectionService
through which the channel is initializedsession
- TheSession
associated with the channelid
- The locally assigned channel identifier- Throws:
java.io.IOException
- If failed to process the initialization
-
signalChannelInitialized
protected void signalChannelInitialized() throws java.io.IOException
- Throws:
java.io.IOException
-
signalChannelInitialized
protected void signalChannelInitialized(ChannelListener listener)
-
signalChannelOpenSuccess
protected void signalChannelOpenSuccess()
-
signalChannelOpenSuccess
protected void signalChannelOpenSuccess(ChannelListener listener)
-
isInitialized
public boolean isInitialized()
- Specified by:
isInitialized
in interfaceChannel
- Returns:
true
if call toChannel.init(ConnectionService, Session, int)
was successfully completed
-
signalChannelOpenFailure
protected void signalChannelOpenFailure(java.lang.Throwable reason)
-
signalChannelOpenFailure
protected void signalChannelOpenFailure(ChannelListener listener, java.lang.Throwable reason)
-
notifyStateChanged
protected void notifyStateChanged(java.lang.String hint)
-
notifyStateChanged
protected void notifyStateChanged(ChannelListener listener, java.lang.String hint)
-
addChannelListener
public void addChannelListener(ChannelListener listener)
Description copied from interface:ChannelListenerManager
Add a channel listener- Specified by:
addChannelListener
in interfaceChannelListenerManager
- Parameters:
listener
- TheChannelListener
to add - notnull
-
removeChannelListener
public void removeChannelListener(ChannelListener listener)
Description copied from interface:ChannelListenerManager
Remove a channel listener- Specified by:
removeChannelListener
in interfaceChannelListenerManager
- Parameters:
listener
- TheChannelListener
to remove
-
getChannelListenerProxy
public ChannelListener getChannelListenerProxy()
- Specified by:
getChannelListenerProxy
in interfaceChannelListenerManager
- Returns:
- A (never
null
proxyChannelListener
that represents all the currently registered listeners. Any method invocation on the proxy is replicated to the currently registered listeners
-
handleClose
public void handleClose() throws java.io.IOException
Description copied from interface:Channel
Invoked whenSSH_MSG_CHANNEL_CLOSE
received- Specified by:
handleClose
in interfaceChannel
- Throws:
java.io.IOException
- If failed to handle the message
-
getInnerCloseable
protected Closeable getInnerCloseable()
- Specified by:
getInnerCloseable
in classAbstractInnerCloseable
-
preClose
protected void preClose()
Description copied from class:AbstractCloseable
preClose is guaranteed to be called before doCloseGracefully or doCloseImmediately. When preClose() is called, isClosing() == true- Overrides:
preClose
in classAbstractCloseable
-
signalChannelClosed
public void signalChannelClosed(java.lang.Throwable reason)
-
signalChannelClosed
protected void signalChannelClosed(ChannelListener listener, java.lang.Throwable reason)
-
invokeChannelSignaller
protected void invokeChannelSignaller(Invoker<ChannelListener,java.lang.Void> invoker) throws java.lang.Throwable
- Throws:
java.lang.Throwable
-
writePacket
public IoWriteFuture writePacket(Buffer buffer) throws java.io.IOException
Description copied from interface:Channel
Encode and send the given buffer. Note: for session packets the buffer has to have 5 bytes free at the beginning to allow the encoding to take place. Also, the write position of the buffer has to be set to the position of the last byte to write.- Specified by:
writePacket
in interfaceChannel
- Parameters:
buffer
- the buffer to encode and send. NOTE: the buffer must not be touched until the returned write future is completed.- Returns:
- An
IoWriteFuture
that can be used to check when the packet has actually been sent - Throws:
java.io.IOException
- if an error occurred when encoding or sending the packet
-
handleData
public void handleData(Buffer buffer) throws java.io.IOException
Description copied from interface:Channel
Invoked whenSSH_MSG_CHANNEL_DATA
received- Specified by:
handleData
in interfaceChannel
- Parameters:
buffer
- The rest of the message dataBuffer
after decoding the channel identifiers- Throws:
java.io.IOException
- If failed to handle the message
-
handleExtendedData
public void handleExtendedData(Buffer buffer) throws java.io.IOException
Description copied from interface:Channel
Invoked whenSSH_MSG_CHANNEL_EXTENDED_DATA
received- Specified by:
handleExtendedData
in interfaceChannel
- Parameters:
buffer
- The rest of the message dataBuffer
after decoding the channel identifiers- Throws:
java.io.IOException
- If failed to handle the message
-
validateIncomingDataSize
protected long validateIncomingDataSize(int cmd, long len)
-
handleEof
public void handleEof() throws java.io.IOException
Description copied from interface:Channel
Invoked whenSSH_MSG_CHANNEL_EOF
received
-
isEofSignalled
public boolean isEofSignalled()
- Specified by:
isEofSignalled
in interfaceChannel
- Returns:
true
if the peer signaled that it will not send any more data- See Also:
- RFC 4254 - section 5.3 - SSH_MSG_CHANNEL_EOF
-
handleWindowAdjust
public void handleWindowAdjust(Buffer buffer) throws java.io.IOException
Description copied from interface:Channel
Invoked whenSSH_MSG_CHANNEL_WINDOW_ADJUST
received- Specified by:
handleWindowAdjust
in interfaceChannel
- Parameters:
buffer
- The rest of the message dataBuffer
after decoding the channel identifiers- Throws:
java.io.IOException
- If failed to handle the message
-
handleSuccess
public void handleSuccess() throws java.io.IOException
Description copied from interface:Channel
Invoked whenSSH_MSG_CHANNEL_SUCCESS
received- Specified by:
handleSuccess
in interfaceChannel
- Throws:
java.io.IOException
- If failed to handle the message
-
handleFailure
public void handleFailure() throws java.io.IOException
Description copied from interface:Channel
Invoked whenSSH_MSG_CHANNEL_FAILURE
received- Specified by:
handleFailure
in interfaceChannel
- Throws:
java.io.IOException
- If failed to handle the message
-
doWriteData
protected abstract void doWriteData(byte[] data, int off, long len) throws java.io.IOException
- Throws:
java.io.IOException
-
doWriteExtendedData
protected abstract void doWriteExtendedData(byte[] data, int off, long len) throws java.io.IOException
- Throws:
java.io.IOException
-
sendEof
protected IoWriteFuture sendEof() throws java.io.IOException
SendsSSH_MSG_CHANNEL_EOF
provided not already sent and current channel state allows it.- Returns:
- The
IoWriteFuture
of the sent packet -null
if message not sent due to channel state (or already sent) - Throws:
java.io.IOException
- If failed to send the packet
-
isEofSent
public boolean isEofSent()
-
getProperties
public java.util.Map<java.lang.String,java.lang.Object> getProperties()
Description copied from interface:PropertyResolver
A map of properties that can be used to configure the SSH server or client. This map will never be changed by either the server or client and is not supposed to be changed at runtime (changes are not bound to have any effect on a running client or server), though it may affect the creation of sessions later as these values are usually not cached.
Note: the type of the mapped property should match the expected configuration value type -
Long, Integer, Boolean, String
, etc.... If it doesn't, thetoString()
result of the mapped value is used to convert it to the required type. E.g., if the mapped value is the string "1234" and the expected value is along
then it will be parsed into one. Also, if the mapped value is anInteger
but along
is expected, then it will be converted into one.- Specified by:
getProperties
in interfacePropertyResolver
- Returns:
- a valid
Map
containing configuration values, nevernull
. Note: may be immutable.
-
getAttributesCount
public int getAttributesCount()
- Specified by:
getAttributesCount
in interfaceAttributeRepository
- Returns:
- Current number of user-defined attributes stored in the repository
-
getAttribute
public <T> T getAttribute(AttributeRepository.AttributeKey<T> key)
Description copied from interface:AttributeRepository
Returns the value of the user-defined attribute.- Specified by:
getAttribute
in interfaceAttributeRepository
- Type Parameters:
T
- The generic attribute type- Parameters:
key
- The key of the attribute; must not benull
.- Returns:
null
if there is no value associated with the specified key
-
attributeKeys
public java.util.Collection<AttributeRepository.AttributeKey<?>> attributeKeys()
- Specified by:
attributeKeys
in interfaceAttributeRepository
- Returns:
- A
Collection
snapshot of all the currently registered attributes in the repository
-
computeAttributeIfAbsent
public <T> T computeAttributeIfAbsent(AttributeRepository.AttributeKey<T> key, java.util.function.Function<? super AttributeRepository.AttributeKey<T>,? extends T> resolver)
Description copied from interface:AttributeStore
If the specified key is not already associated with a value (or is mapped tonull
), attempts to compute its value using the given mapping function and enters it into this map unlessnull
.- Specified by:
computeAttributeIfAbsent
in interfaceAttributeStore
- Type Parameters:
T
- The generic attribute type- Parameters:
key
- The key of the attribute; must not benull
.resolver
- The (nevernull
) mapping function to use if value not already mapped. If returnsnull
then value is not mapped to the provided key.- Returns:
- The resolved value -
null
if value not mapped and resolver did not return a non-null
value for it
-
setAttribute
public <T> T setAttribute(AttributeRepository.AttributeKey<T> key, T value)
Description copied from interface:AttributeStore
Sets a user-defined attribute.- Specified by:
setAttribute
in interfaceAttributeStore
- Type Parameters:
T
- The generic attribute type- Parameters:
key
- The key of the attribute; must not benull
.value
- The value of the attribute; must not benull
.- Returns:
- The old value of the attribute;
null
if it is new.
-
removeAttribute
public <T> T removeAttribute(AttributeRepository.AttributeKey<T> key)
Description copied from interface:AttributeStore
Removes the user-defined attribute- Specified by:
removeAttribute
in interfaceAttributeStore
- Type Parameters:
T
- The generic attribute type- Parameters:
key
- The key of the attribute; must not benull
.- Returns:
- The removed value;
null
if no previous value
-
clearAttributes
public void clearAttributes()
Description copied from interface:AttributeStore
Removes all currently stored user-defined attributes- Specified by:
clearAttributes
in interfaceAttributeStore
-
configureWindow
protected void configureWindow()
-
sendWindowAdjust
protected void sendWindowAdjust(long len) throws java.io.IOException
- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-