org.mockftpserver.core.session
Class DefaultSession

java.lang.Object
  extended by org.mockftpserver.core.session.DefaultSession
All Implemented Interfaces:
Runnable, Session

public class DefaultSession
extends Object
implements Session

Default implementation of the Session interface.

Version:
$Revision: 264 $ - $Date: 2012-07-17 21:19:23 -0400 (Tue, 17 Jul 2012) $
Author:
Chris Mair

Field Summary
protected static int DEFAULT_CLIENT_DATA_PORT
           
protected  ServerSocketFactory serverSocketFactory
           
protected  SocketFactory socketFactory
           
 
Constructor Summary
DefaultSession(Socket controlSocket, Map commandHandlers)
          Create a new initialized instance
 
Method Summary
 void close()
          Close the session, closing the underlying sockets
 void closeDataConnection()
          Close the data connection
 Object getAttribute(String name)
          Return the attribute value for the specified name.
 Set getAttributeNames()
          Return the Set of names under which attributes have been stored on this session.
 InetAddress getClientHost()
          Return the InetAddress representing the client host for this session
 InetAddress getServerHost()
          Return the InetAddress representing the server host for this session
 void openDataConnection()
          Open the data connection, attaching to the predefined port number on the client
 byte[] readData()
          Read data from the client across the data connection
 byte[] readData(int numBytes)
          Read and return (up to) numBytes of data from the client across the data connection
 void removeAttribute(String name)
          Remove the attribute value for the specified name.
 void run()
           
 void sendData(byte[] data, int numBytes)
          Write the specified data using the data connection
 void sendReply(int code, String text)
          Send the specified reply code and text across the control connection.
 void setAttribute(String name, Object value)
          Store the value under the specified attribute name.
 void setClientDataHost(InetAddress clientHost)
           
 void setClientDataPort(int dataPort)
           
 int switchToPassiveMode()
          Switch to passive mode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CLIENT_DATA_PORT

protected static final int DEFAULT_CLIENT_DATA_PORT
See Also:
Constant Field Values

socketFactory

protected SocketFactory socketFactory

serverSocketFactory

protected ServerSocketFactory serverSocketFactory
Constructor Detail

DefaultSession

public DefaultSession(Socket controlSocket,
                      Map commandHandlers)
Create a new initialized instance

Parameters:
controlSocket - - the control connection socket
commandHandlers - - the Map of command name -> CommandHandler. It is assumed that the command names are all normalized to upper case. See Command.normalizeName(String).
Method Detail

getClientHost

public InetAddress getClientHost()
Return the InetAddress representing the client host for this session

Specified by:
getClientHost in interface Session
Returns:
the client host
See Also:
Session.getClientHost()

getServerHost

public InetAddress getServerHost()
Return the InetAddress representing the server host for this session

Specified by:
getServerHost in interface Session
Returns:
the server host
See Also:
Session.getServerHost()

sendReply

public void sendReply(int code,
                      String text)
Send the specified reply code and text across the control connection. The reply text is trimmed before being sent.

Specified by:
sendReply in interface Session
Parameters:
code - - the reply code
text - - the reply text to send; may be null

openDataConnection

public void openDataConnection()
Description copied from interface: Session
Open the data connection, attaching to the predefined port number on the client

Specified by:
openDataConnection in interface Session
See Also:
Session.openDataConnection()

switchToPassiveMode

public int switchToPassiveMode()
Switch to passive mode

Specified by:
switchToPassiveMode in interface Session
Returns:
the local port to be connected to by clients for data transfers
See Also:
Session.switchToPassiveMode()

closeDataConnection

public void closeDataConnection()
Description copied from interface: Session
Close the data connection

Specified by:
closeDataConnection in interface Session
See Also:
Session.closeDataConnection()

close

public void close()
Description copied from interface: Session
Close the session, closing the underlying sockets

Specified by:
close in interface Session
See Also:
Session.close()

sendData

public void sendData(byte[] data,
                     int numBytes)
Description copied from interface: Session
Write the specified data using the data connection

Specified by:
sendData in interface Session
Parameters:
data - - the data to write
numBytes - - the number of bytes from data to send
See Also:
Session.sendData(byte[], int)

readData

public byte[] readData()
Description copied from interface: Session
Read data from the client across the data connection

Specified by:
readData in interface Session
Returns:
the data that was read
See Also:
Session.readData()

readData

public byte[] readData(int numBytes)
Description copied from interface: Session
Read and return (up to) numBytes of data from the client across the data connection

Specified by:
readData in interface Session
Returns:
the data that was read; the byte[] will be up to numBytes bytes long
See Also:
Session.readData()

setClientDataHost

public void setClientDataHost(InetAddress clientHost)
Specified by:
setClientDataHost in interface Session
Parameters:
clientHost - - the client host for the data connection
See Also:
Session.setClientDataHost(java.net.InetAddress)

setClientDataPort

public void setClientDataPort(int dataPort)
Specified by:
setClientDataPort in interface Session
Parameters:
dataPort - - the port number on the client side for the data connection
See Also:
Session.setClientDataPort(int)

run

public void run()
Specified by:
run in interface Runnable
See Also:
Runnable.run()

getAttribute

public Object getAttribute(String name)
Return the attribute value for the specified name. Return null if no attribute value exists for that name or if the attribute value is null.

Specified by:
getAttribute in interface Session
Parameters:
name - - the attribute name; may not be null
Returns:
the value of the attribute stored under name; may be null
See Also:
Session.getAttribute(java.lang.String)

setAttribute

public void setAttribute(String name,
                         Object value)
Store the value under the specified attribute name.

Specified by:
setAttribute in interface Session
Parameters:
name - - the attribute name; may not be null
value - - the attribute value; may be null
See Also:
Session.setAttribute(java.lang.String, java.lang.Object)

getAttributeNames

public Set getAttributeNames()
Return the Set of names under which attributes have been stored on this session. Returns an empty Set if no attribute values are stored.

Specified by:
getAttributeNames in interface Session
Returns:
the Set of attribute names
See Also:
Session.getAttributeNames()

removeAttribute

public void removeAttribute(String name)
Remove the attribute value for the specified name. Do nothing if no attribute value is stored for the specified name.

Specified by:
removeAttribute in interface Session
Parameters:
name - - the attribute name; may not be null
Throws:
AssertFailedException - - if name is null
See Also:
Session.removeAttribute(java.lang.String)


Copyright © 2014. All rights reserved.