com.sshtools.j2ssh.transport
Class Service

java.lang.Object
  |
  +--com.sshtools.j2ssh.transport.Service
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
AuthenticationProtocol, ConnectionProtocol

public abstract class Service
extends java.lang.Object
implements java.lang.Runnable

The service class provides a mechanisnm for the ssh services provided by the transport layer. It is itself a thread and contains a message loop in which all registered messages will be routed to onMessageReceived()

Version:
1.0
Author:
Lee David Painter ( lee@sshtools.com )

Constructor Summary
Service(java.lang.String serviceName)
          Constructor for the SshService object
 
Method Summary
protected  byte[] getExchangeHash()
          Gets the exchange hash produced from key exchange
protected  SshMessageStore getMessageStore()
           Gets the service's message store.
 java.lang.String getServiceName()
           Returns the name of the service.
protected  TransportProtocol getTransportLayer()
          Gets the transport mechanism for this service
protected abstract  void onDisconnect(java.lang.String reason)
           Abstract method called by the framework when the remote computer disconnects.
protected abstract  void onMessageReceived(SshMessage msg)
           Abstract method called when a registered message ahs been received.
protected abstract  void onServiceAccept()
           Abstract method called when the service has been accepted by the remote computer.
protected abstract  void onServiceInit()
           Abstract method called when the service is initialized.
protected abstract  void onServiceRequest()
           Abstract method called when the service has been requested.
protected abstract  void onThreadException(java.lang.Exception e)
           Abstract method that is called by the framework whenever an exception occurs in a child thread.
 void run()
           Provides the message loop.
 void start(TransportProtocol transport, ServiceState state, byte[] exchangeHash)
           This method is called by the framework to initialize the service after it has been created.
 void stop()
          Stops the message loop and causes the thread to exit
protected  SshMessage waitForSingleMessage(int[] messageIdFilter)
           Gets or waits for a single message from the message store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Service

public Service(java.lang.String serviceName)
Constructor for the SshService object

Parameters:
serviceName - The service name
Method Detail

start

public final void start(TransportProtocol transport,
                        ServiceState state,
                        byte[] exchangeHash)
                 throws ServiceOperationException

This method is called by the framework to initialize the service after it has been created. Subclasses should implement the abstract method onServiceInit() which is called from this method. Depending upon the state of the service passed to the init method one of the abstract methods onServiceAccept() or onServiceRequest() is then called.

Parameters:
transport - The transport layer object used for communication
state - The state of the service (Accepted/Requested)
exchangeHash - The exchange hash
Throws:
ServiceOperationException - Can be thrown from abstract method implementations

getExchangeHash

protected final byte[] getExchangeHash()
Gets the exchange hash produced from key exchange

Returns:
The exchangeHash value

getTransportLayer

protected final TransportProtocol getTransportLayer()
Gets the transport mechanism for this service

Returns:
The Transport layer object

onServiceInit

protected abstract void onServiceInit()
                               throws ServiceOperationException

Abstract method called when the service is initialized.

NOTE: The message loop is not started until this method has completed.

Throws:
ServiceOperationException - This exception can be thrown by subclasses

onServiceAccept

protected abstract void onServiceAccept()
                                 throws ServiceOperationException

Abstract method called when the service has been accepted by the remote computer.

NOTE: the message loop does not start until this method has completed.

Throws:
ServiceOperationException - This exception can be thrown by subclasses

onServiceRequest

protected abstract void onServiceRequest()
                                  throws ServiceOperationException

Abstract method called when the service has been requested.

Throws:
ServiceOperationException - This exception can be thrown by subclasses

onThreadException

protected abstract void onThreadException(java.lang.Exception e)

Abstract method that is called by the framework whenever an exception occurs in a child thread. This is to avoid any exception being written to System.out.

Parameters:
e - The exception thrown

onDisconnect

protected abstract void onDisconnect(java.lang.String reason)

Abstract method called by the framework when the remote computer disconnects.

Parameters:
reason - The reason for the disconnection.

getMessageStore

protected final SshMessageStore getMessageStore()

Gets the service's message store.

Returns:
The messageStore value

waitForSingleMessage

protected SshMessage waitForSingleMessage(int[] messageIdFilter)
                                   throws TransportProtocolException,
                                          ServiceOperationException

Gets or waits for a single message from the message store. If the message filter is null then the next available message is returned. To filter for specific messages then create an int array containing the message id's for the messages you are prepared to accept.

Parameters:
messageIdFilter - Description of the Parameter
Returns:
Throws:
TransportProtocolException - Description of the Exception
ServiceOperationException - Description of the Exception

run

public final void run()

Provides the message loop.

Specified by:
run in interface java.lang.Runnable

stop

public final void stop()
Stops the message loop and causes the thread to exit


getServiceName

public final java.lang.String getServiceName()

Returns the name of the service.

Returns:
The serviceName value

onMessageReceived

protected abstract void onMessageReceived(SshMessage msg)
                                   throws ServiceOperationException,
                                          TransportProtocolException

Abstract method called when a registered message ahs been received.

Parameters:
msg - The message received
Throws:
ServiceOperationException - Subclasses can throw this exception
TransportProtocolException - Subclasses can throw this exception


Copyright © 2002 Sshtools.com. All Rights Reserved.