com.sshtools.j2ssh.connection
Class ConnectionProtocol

java.lang.Object
  extended by com.sshtools.j2ssh.transport.Service
      extended by com.sshtools.j2ssh.transport.AsyncService
          extended by com.sshtools.j2ssh.connection.ConnectionProtocol
All Implemented Interfaces:
java.lang.Runnable

public class ConnectionProtocol
extends AsyncService

Version:
$Revision: 1.1 $
Author:
$author$

Field Summary
private  java.util.Map activeChannels
           
private  java.util.Map allowedChannels
           
private  java.util.Map globalRequests
           
private static org.apache.commons.logging.Log log
           
private  long nextChannelId
           
private  java.util.HashSet reusableChannels
           
 
Fields inherited from class com.sshtools.j2ssh.transport.AsyncService
thread
 
Fields inherited from class com.sshtools.j2ssh.transport.Service
ACCEPTING_SERVICE, messageStore, REQUESTING_SERVICE, startMode, state, transport
 
Constructor Summary
ConnectionProtocol()
          Creates a new ConnectionProtocol object.
 
Method Summary
 void addChannelFactory(java.lang.String channelName, ChannelFactory cf)
           
 void allowGlobalRequest(java.lang.String requestName, GlobalRequestHandler handler)
           
protected  void closeChannel(Channel channel)
           
 boolean containsChannelFactory(java.lang.String channelName)
           
protected  void freeChannel(Channel channel)
           
protected  int[] getAsyncMessageFilter()
           Implement this method by returning the message ids of the asyncrounous messages your implementation wants to receive.
private  Channel getChannel(long channelId)
           
private  java.lang.Long getChannelId()
           
 boolean isConnected()
           
protected  void onGlobalRequest(java.lang.String requestName, boolean wantReply, byte[] requestData)
           
protected  void onMessageReceived(SshMessage msg)
           Called by the service thread when an asyncronous message is received.
private  void onMsgChannelClose(SshMsgChannelClose msg)
           
private  void onMsgChannelData(SshMsgChannelData msg)
           
private  void onMsgChannelEOF(SshMsgChannelEOF msg)
           
private  void onMsgChannelExtendedData(SshMsgChannelExtendedData msg)
           
private  void onMsgChannelOpen(SshMsgChannelOpen msg)
           
private  void onMsgChannelRequest(SshMsgChannelRequest msg)
           
private  void onMsgChannelWindowAdjust(SshMsgChannelWindowAdjust msg)
           
private  void onMsgGlobalRequest(SshMsgGlobalRequest msg)
           
protected  void onServiceAccept()
           Called when the service is accepted by the remote server.
protected  void onServiceInit(int startMode)
           Called when the service is intialized.
protected  void onServiceRequest()
           
protected  void onStop()
           The service thread calls this method when the thread is exiting.
 boolean openChannel(Channel channel)
           
 boolean openChannel(Channel channel, ChannelEventListener eventListener)
           
 void removeChannelFactory(java.lang.String channelName)
           
 void sendChannelData(Channel channel, byte[] data)
           
 void sendChannelEOF(Channel channel)
           
 void sendChannelExtData(Channel channel, int extendedType, byte[] data)
           
protected  void sendChannelFailure(Channel channel)
           
protected  void sendChannelOpenConfirmation(Channel channel)
           
protected  void sendChannelOpenFailure(long remoteChannelId, long reasonCode, java.lang.String additionalInfo, java.lang.String languageTag)
           
 boolean sendChannelRequest(Channel channel, java.lang.String requestType, boolean wantReply, byte[] requestData)
           
 void sendChannelRequestFailure(Channel channel)
           
 void sendChannelRequestSuccess(Channel channel)
           
 void sendChannelWindowAdjust(Channel channel, long bytesToAdd)
           
 byte[] sendGlobalRequest(java.lang.String requestName, boolean wantReply, byte[] requestData)
           
protected  void sendGlobalRequestFailure()
           
protected  void sendGlobalRequestSuccess(byte[] requestData)
           
 
Methods inherited from class com.sshtools.j2ssh.transport.AsyncService
onStart, run
 
Methods inherited from class com.sshtools.j2ssh.transport.Service
getServiceName, getState, init, sendServiceAccept, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log

reusableChannels

private java.util.HashSet reusableChannels

activeChannels

private java.util.Map activeChannels

allowedChannels

private java.util.Map allowedChannels

globalRequests

private java.util.Map globalRequests

nextChannelId

private long nextChannelId
Constructor Detail

ConnectionProtocol

public ConnectionProtocol()
Creates a new ConnectionProtocol object.

Method Detail

addChannelFactory

public void addChannelFactory(java.lang.String channelName,
                              ChannelFactory cf)
                       throws java.io.IOException
Parameters:
channelName -
cf -
Throws:
java.io.IOException

removeChannelFactory

public void removeChannelFactory(java.lang.String channelName)
Parameters:
channelName -

containsChannelFactory

public boolean containsChannelFactory(java.lang.String channelName)
Parameters:
channelName -
Returns:

allowGlobalRequest

public void allowGlobalRequest(java.lang.String requestName,
                               GlobalRequestHandler handler)
Parameters:
requestName -
handler -

openChannel

public boolean openChannel(Channel channel)
                    throws java.io.IOException
Parameters:
channel -
Returns:
Throws:
java.io.IOException

isConnected

public boolean isConnected()
Returns:

getChannelId

private java.lang.Long getChannelId()

openChannel

public boolean openChannel(Channel channel,
                           ChannelEventListener eventListener)
                    throws java.io.IOException
Parameters:
channel -
eventListener -
Returns:
Throws:
java.io.IOException
SshException

onStop

protected void onStop()
Description copied from class: AsyncService

The service thread calls this method when the thread is exiting.

Specified by:
onStop in class AsyncService

sendChannelData

public void sendChannelData(Channel channel,
                            byte[] data)
                     throws java.io.IOException
Parameters:
channel -
data -
Throws:
java.io.IOException

sendChannelEOF

public void sendChannelEOF(Channel channel)
                    throws java.io.IOException
Parameters:
channel -
Throws:
java.io.IOException

sendChannelExtData

public void sendChannelExtData(Channel channel,
                               int extendedType,
                               byte[] data)
                        throws java.io.IOException
Parameters:
channel -
extendedType -
data -
Throws:
java.io.IOException

sendChannelRequest

public boolean sendChannelRequest(Channel channel,
                                  java.lang.String requestType,
                                  boolean wantReply,
                                  byte[] requestData)
                           throws java.io.IOException
Parameters:
channel -
requestType -
wantReply -
requestData -
Returns:
Throws:
java.io.IOException
SshException

sendChannelRequestFailure

public void sendChannelRequestFailure(Channel channel)
                               throws java.io.IOException
Parameters:
channel -
Throws:
java.io.IOException

sendChannelRequestSuccess

public void sendChannelRequestSuccess(Channel channel)
                               throws java.io.IOException
Parameters:
channel -
Throws:
java.io.IOException

sendChannelWindowAdjust

public void sendChannelWindowAdjust(Channel channel,
                                    long bytesToAdd)
                             throws java.io.IOException
Parameters:
channel -
bytesToAdd -
Throws:
java.io.IOException

sendGlobalRequest

public byte[] sendGlobalRequest(java.lang.String requestName,
                                boolean wantReply,
                                byte[] requestData)
                         throws java.io.IOException
Parameters:
requestName -
wantReply -
requestData -
Returns:
Throws:
java.io.IOException
SshException

getAsyncMessageFilter

protected int[] getAsyncMessageFilter()
Description copied from class: AsyncService

Implement this method by returning the message ids of the asyncrounous messages your implementation wants to receive.

Specified by:
getAsyncMessageFilter in class AsyncService
Returns:

closeChannel

protected void closeChannel(Channel channel)
                     throws java.io.IOException
Parameters:
channel -
Throws:
java.io.IOException

onGlobalRequest

protected void onGlobalRequest(java.lang.String requestName,
                               boolean wantReply,
                               byte[] requestData)
                        throws java.io.IOException
Parameters:
requestName -
wantReply -
requestData -
Throws:
java.io.IOException

onMessageReceived

protected void onMessageReceived(SshMessage msg)
                          throws java.io.IOException
Description copied from class: AsyncService

Called by the service thread when an asyncronous message is received.

Specified by:
onMessageReceived in class AsyncService
Parameters:
msg -
Throws:
java.io.IOException

onServiceAccept

protected void onServiceAccept()
Description copied from class: Service

Called when the service is accepted by the remote server.

Specified by:
onServiceAccept in class Service

onServiceInit

protected void onServiceInit(int startMode)
                      throws java.io.IOException
Description copied from class: Service

Called when the service is intialized.

Specified by:
onServiceInit in class Service
Parameters:
startMode -
Throws:
java.io.IOException

onServiceRequest

protected void onServiceRequest()
Specified by:
onServiceRequest in class Service

sendChannelFailure

protected void sendChannelFailure(Channel channel)
                           throws java.io.IOException
Parameters:
channel -
Throws:
java.io.IOException

sendChannelOpenConfirmation

protected void sendChannelOpenConfirmation(Channel channel)
                                    throws java.io.IOException
Parameters:
channel -
Throws:
java.io.IOException

sendChannelOpenFailure

protected void sendChannelOpenFailure(long remoteChannelId,
                                      long reasonCode,
                                      java.lang.String additionalInfo,
                                      java.lang.String languageTag)
                               throws java.io.IOException
Parameters:
remoteChannelId -
reasonCode -
additionalInfo -
languageTag -
Throws:
java.io.IOException

sendGlobalRequestFailure

protected void sendGlobalRequestFailure()
                                 throws java.io.IOException
Throws:
java.io.IOException

sendGlobalRequestSuccess

protected void sendGlobalRequestSuccess(byte[] requestData)
                                 throws java.io.IOException
Parameters:
requestData -
Throws:
java.io.IOException

getChannel

private Channel getChannel(long channelId)
                    throws java.io.IOException
Throws:
java.io.IOException

onMsgChannelClose

private void onMsgChannelClose(SshMsgChannelClose msg)
                        throws java.io.IOException
Throws:
java.io.IOException

onMsgChannelData

private void onMsgChannelData(SshMsgChannelData msg)
                       throws java.io.IOException
Throws:
java.io.IOException

onMsgChannelEOF

private void onMsgChannelEOF(SshMsgChannelEOF msg)
                      throws java.io.IOException
Throws:
java.io.IOException

onMsgChannelExtendedData

private void onMsgChannelExtendedData(SshMsgChannelExtendedData msg)
                               throws java.io.IOException
Throws:
java.io.IOException

onMsgChannelOpen

private void onMsgChannelOpen(SshMsgChannelOpen msg)
                       throws java.io.IOException
Throws:
java.io.IOException

onMsgChannelRequest

private void onMsgChannelRequest(SshMsgChannelRequest msg)
                          throws java.io.IOException
Throws:
java.io.IOException

onMsgChannelWindowAdjust

private void onMsgChannelWindowAdjust(SshMsgChannelWindowAdjust msg)
                               throws java.io.IOException
Throws:
java.io.IOException

onMsgGlobalRequest

private void onMsgGlobalRequest(SshMsgGlobalRequest msg)
                         throws java.io.IOException
Throws:
java.io.IOException

freeChannel

protected void freeChannel(Channel channel)
Parameters:
channel -