org.apache.sshd.common
Interface Session

All Known Implementing Classes:
AbstractSession, ClientSessionImpl, ServerSession

public interface Session

Represents an SSH session

Author:
Apache MINA SSHD Project

Nested Class Summary
static class Session.AttributeKey<T>
          Type safe key for storage within the user attributes of AbstractSession.
 
Method Summary
 void addListener(SessionListener listener)
          Add a session |listener|.
 Buffer createBuffer(SshConstants.Message cmd, int estimatedSize)
          Create a new buffer for the specified SSH packet and reserve the needed space (5 bytes) for the packet header.
 void exceptionCaught(Throwable t)
          Handle any exceptions that occured on this session.
<T> T
getAttribute(Session.AttributeKey<T> key)
          Returns the value of the user-defined attribute of this session.
 FactoryManager getFactoryManager()
          Retrieve the FactoryManager that has created this session
 int getIntProperty(String name, int defaultValue)
          Retrieve a configuration property as an integer
 String getUsername()
          Retrieve the name of the user authenticated on this session or null if the session has not been authenticated yet.
 int registerChannel(Channel channel)
          Register a newly created channel with a new unique identifier
 void removeListener(SessionListener listener)
          Remove a session |listener|.
<T,E extends T>
T
setAttribute(Session.AttributeKey<T> key, E value)
          Sets a user-defined attribute.
 void unregisterChannel(Channel channel)
          Remove this channel from the list of managed channels
 org.apache.mina.core.future.WriteFuture writePacket(Buffer buffer)
          Encode and send the given buffer.
 

Method Detail

getAttribute

<T> T getAttribute(Session.AttributeKey<T> key)
Returns the value of the user-defined attribute of this session.

Parameters:
key - the key of the attribute; must not be null.
Returns:
null if there is no attribute with the specified key

setAttribute

<T,E extends T> T setAttribute(Session.AttributeKey<T> key,
                               E value)
Sets a user-defined attribute.

Parameters:
key - the key of the attribute; must not be null.
value - the value of the attribute; must not be null.
Returns:
The old value of the attribute. null if it is new.

getUsername

String getUsername()
Retrieve the name of the user authenticated on this session or null if the session has not been authenticated yet.

Returns:
the user name.

getFactoryManager

FactoryManager getFactoryManager()
Retrieve the FactoryManager that has created this session

Returns:
the factory manager, can not be null.

getIntProperty

int getIntProperty(String name,
                   int defaultValue)
Retrieve a configuration property as an integer

Parameters:
name - the name of the property
defaultValue - the default value
Returns:
the value of the configuration property or the default value if not found

createBuffer

Buffer createBuffer(SshConstants.Message cmd,
                    int estimatedSize)
Create a new buffer for the specified SSH packet and reserve the needed space (5 bytes) for the packet header.

Parameters:
cmd - the SSH command
estimatedSize - estimated number of bytes the buffer will hold, 0 if unknown.
Returns:
a new buffer ready for write

writePacket

org.apache.mina.core.future.WriteFuture writePacket(Buffer buffer)
                                                    throws IOException
Encode and send the given buffer. 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.

Parameters:
buffer - the buffer to encode and send
Returns:
a future that can be used to check when the packet has actually been sent
Throws:
IOException - if an error occured when encoding sending the packet

exceptionCaught

void exceptionCaught(Throwable t)
Handle any exceptions that occured on this session. The session will be closed and a disconnect packet will be sent before if the given exception is an SshException.

Parameters:
t - the exception to process
Throws:
IOException

registerChannel

int registerChannel(Channel channel)
                    throws Exception
Register a newly created channel with a new unique identifier

Parameters:
channel - the channel to register
Returns:
the id of this channel
Throws:
Exception

unregisterChannel

void unregisterChannel(Channel channel)
Remove this channel from the list of managed channels

Parameters:
channel - the channel

addListener

void addListener(SessionListener listener)
Add a session |listener|.

Parameters:
listener - the session listener to add

removeListener

void removeListener(SessionListener listener)
Remove a session |listener|.

Parameters:
listener - the session listener to remove


Copyright © 2008-2012 Apache Software Foundation. All Rights Reserved.