org.neociclo.odetteftp.protocol
Class DefaultHandler

java.lang.Object
  extended by org.neociclo.odetteftp.protocol.DefaultHandler
All Implemented Interfaces:
ProtocolHandler
Direct Known Subclasses:
OdetteFtpVer13Handler

public abstract class DefaultHandler
extends Object
implements ProtocolHandler

Version:
$Rev: 807 $ $Date: 2010-10-20 11:26:47 -0200 (Wed, 20 Oct 2010) $
Author:
Rafael Marins

Constructor Summary
DefaultHandler()
           
 
Method Summary
 void abnormalRelease(OdetteFtpSession session, EndSessionReason error, String errorText)
          Terminate current session by sending an End Session command with the specified error and raise the exception for the local user agent.
 void abort(OdetteFtpSession session, EndSessionReason error, String errorText)
           
 void afterStartSession(OdetteFtpSession session)
          Method called after the SSIDs are fully exchanged.
protected abstract  AnswerReasonInfo buildAnswerReasonInfoObject(CommandExchangeBuffer sfna)
           
protected abstract  CommandExchangeBuffer buildDeliveryNotificationCommand(DeliveryNotification notif)
           
protected abstract  CommandExchangeBuffer buildEndFileCommand(long recordCount, long unitCount)
           
protected abstract  CommandExchangeBuffer buildEndFileNegativeAnswerCommand(AnswerReason reason, String reasonText)
           
protected abstract  CommandExchangeBuffer buildEndFilePositiveAnswerCommand(boolean changeDirection)
           
protected abstract  CommandExchangeBuffer buildEndSessionCommand(EndSessionReason reason, String reasonText)
           
protected abstract  EndSessionReasonInfo buildEndSessionReasonInfoObject(CommandExchangeBuffer esid)
           
protected abstract  DeliveryNotification buildEndToEndResponse(CommandExchangeBuffer eerp)
           
protected abstract  DeliveryNotification buildNegativeEndResponse(CommandExchangeBuffer nerp)
           
protected abstract  CommandExchangeBuffer buildReadyToReceiveCommand()
           
protected  CommandExchangeBuffer buildSetCreditCommand()
           
protected abstract  CommandExchangeBuffer buildStartFileCommand(OdetteFtpSession session, VirtualFile vf)
           
protected abstract  CommandExchangeBuffer buildStartFileNegativeAnswerCommand(AnswerReason reason, String reasonText, boolean retryLater)
           
protected abstract  CommandExchangeBuffer buildStartFilePositiveAnswerCommand(long answerCount)
           
protected abstract  CommandExchangeBuffer buildStartSessionCommand(String code, String pswd, String userData, OdetteFtpSession session)
           
protected abstract  DefaultVirtualFile buildVirtualFileObject(OdetteFtpSession session, CommandExchangeBuffer sfid)
           
 void changeDirectionReceived(OdetteFtpSession session)
           
protected  void checkSessionParamsViolation(int ssidsdeb, int ssidcred, TransferMode ssidsr, boolean ssidspec, OdetteFtpSession session)
           
protected  void consumeIncomingCredits(OdetteFtpSession session)
           
protected  void consumeOutgoingCredits(OdetteFtpSession session)
           
 void dataBufferReceived(OdetteFtpSession session, DataExchangeBuffer data)
           
 void endFileNegativeAnswerReceived(OdetteFtpSession session, CommandExchangeBuffer efna)
           
 void endFilePositiveAnswerReceived(OdetteFtpSession session, CommandExchangeBuffer efpa)
           
 void endFileReceived(OdetteFtpSession session, CommandExchangeBuffer efid)
           
 void endSessionReceived(OdetteFtpSession session, CommandExchangeBuffer esid)
           
 void endToEndResponseReceived(OdetteFtpSession session, CommandExchangeBuffer eerp)
           
protected  boolean handleCallback(OdetteFtpSession session, Callback callback)
           
protected  void initiatorStartSessionReceived(OdetteFtpSession session, CommandExchangeBuffer ssid)
          The Initiator handle the returned Start Session Identification command to perform its setup and complete the Start Session Phase.
protected  VirtualFile normalizeVirtualFile(OdetteFtpSession session, VirtualFile vf)
           
protected abstract  long protocolMaxFileSizeSupported()
           
 void protocolRelease(OdetteFtpSession session, EndSessionReason reason, String reasonText)
           
 void readyMessageReceived(OdetteFtpSession session)
          The Initiator ODETTE-FTP entity receive the Start Session Ready Message sent by the Responder immediately after the network connection has been established, beginning the Start Session Phase.
 void readyToReceiveReceived(OdetteFtpSession session)
          Ready To Receive Command (RTR) received in the SPEAKER state.
protected  void release(OdetteFtpSession session)
           
protected  void resetIncomingCredits(OdetteFtpSession session)
           
protected  void resetOutgoingCredits(OdetteFtpSession session)
           
protected  void responderSendStartSession(OdetteFtpSession session, CommandExchangeBuffer ssid)
           
 void sessionConnected(OdetteFtpSession session)
          Indication that the network connection has been established - occur in both entity states (SPEAKER or LISTENER).
 void setCreditReceived(OdetteFtpSession session, CommandExchangeBuffer cdt)
           
protected  void speakerChangeDirection(OdetteFtpSession session)
           
protected  void speakerChangeDirectionPreventingLoop(OdetteFtpSession session)
          If last command received is not CD, so turn direction.
protected  void speakerDeliveryNotification(OdetteFtpSession session, DeliveryNotification notif)
           
protected  void speakerEndFile(OdetteFtpSession session, VirtualFile virtualFile)
           
protected  void speakerSendData(OdetteFtpSession session)
          Perform data buffer transmission of the file transfer opened.
protected  void speakerStartFile(OdetteFtpSession session, VirtualFile vf)
          Do start file transmission.
protected  void speakerTransmitRequests(OdetteFtpSession session)
           
 void startFileNegativeAnswerReceived(OdetteFtpSession session, CommandExchangeBuffer sfna)
           
 void startFilePositiveAnswerReceived(OdetteFtpSession session, CommandExchangeBuffer sfpa)
           
 void startFileReceived(OdetteFtpSession session, CommandExchangeBuffer sfid)
           
protected  void startSessionPasswordAuthentication(OdetteFtpSession session, CommandExchangeBuffer ssid, boolean mandatory)
           
 void startSessionReceived(OdetteFtpSession session, CommandExchangeBuffer ssid)
          Negotiate the Start Session taking in account the right entity mode's behavior (Initiator or Responder).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.neociclo.odetteftp.ProtocolHandler
authenticationChallengeReceived, authenticationResponseReceived, negativeEndReponseReceived, securityChangeDirectionReceived
 

Constructor Detail

DefaultHandler

public DefaultHandler()
Method Detail

abnormalRelease

public void abnormalRelease(OdetteFtpSession session,
                            EndSessionReason error,
                            String errorText)
                     throws OdetteFtpException
Description copied from interface: ProtocolHandler
Terminate current session by sending an End Session command with the specified error and raise the exception for the local user agent.

Specified by:
abnormalRelease in interface ProtocolHandler
Throws:
EndSessionException - a raising exception for the given End Session error to user agent.
OdetteFtpException

abort

public void abort(OdetteFtpSession session,
                  EndSessionReason error,
                  String errorText)
           throws OdetteFtpException
Specified by:
abort in interface ProtocolHandler
Throws:
OdetteFtpException

startSessionReceived

public void startSessionReceived(OdetteFtpSession session,
                                 CommandExchangeBuffer ssid)
                          throws OdetteFtpException
Description copied from interface: ProtocolHandler
Negotiate the Start Session taking in account the right entity mode's behavior (Initiator or Responder). The Responder use the received SSID (in step 2) to authenticate the peer and determine the average session parameters, meanwhile the Initiator handle the received SSID (in step 3) to complete the Session Setup.

Protocol Sequence

 1. Initiator <-------------SSRM -- Responder   Ready Message
 2.           -- SSID ------------>             Identification
 3.           <------------ SSID --             Identification
 

Specified by:
startSessionReceived in interface ProtocolHandler
Throws:
OdetteFtpException

afterStartSession

public void afterStartSession(OdetteFtpSession session)
                       throws OdetteFtpException
Method called after the SSIDs are fully exchanged.

Specified by:
afterStartSession in interface ProtocolHandler
Throws:
OdetteFtpException

changeDirectionReceived

public void changeDirectionReceived(OdetteFtpSession session)
                             throws OdetteFtpException
Specified by:
changeDirectionReceived in interface ProtocolHandler
Throws:
OdetteFtpException

startFileReceived

public void startFileReceived(OdetteFtpSession session,
                              CommandExchangeBuffer sfid)
                       throws OdetteFtpException
Specified by:
startFileReceived in interface ProtocolHandler
Throws:
OdetteFtpException

dataBufferReceived

public void dataBufferReceived(OdetteFtpSession session,
                               DataExchangeBuffer data)
                        throws OdetteFtpException
Specified by:
dataBufferReceived in interface ProtocolHandler
Throws:
OdetteFtpException

endFileReceived

public void endFileReceived(OdetteFtpSession session,
                            CommandExchangeBuffer efid)
                     throws OdetteFtpException
Specified by:
endFileReceived in interface ProtocolHandler
Throws:
OdetteFtpException

sessionConnected

public void sessionConnected(OdetteFtpSession session)
                      throws OdetteFtpException
Description copied from interface: ProtocolHandler
Indication that the network connection has been established - occur in both entity states (SPEAKER or LISTENER). Allow handler to take the proper protocol control when the session is connected.

Answer attended calls with a Start Session Ready Message command when this ODETTE FTP entity is the Responder. Otherwise, do nothing else of expecting same command from the peer.

The Start Session phase is entered immediately after the network connection has been established. The ODETTE FTP entity that took the initiative to establish the network connection becomes the Initiator. It's peer becomes the Responder.

The first message must be sent by the Responder.

Protocol Sequence

 1. Initiator <-------------SSRM -- Responder   Ready Message
 2.           -- SSID ------------>             Identification
 3.           <------------ SSID --             Identification
 

Specified by:
sessionConnected in interface ProtocolHandler
Throws:
OdetteFtpException

readyToReceiveReceived

public void readyToReceiveReceived(OdetteFtpSession session)
                            throws OdetteFtpException
Description copied from interface: ProtocolHandler
Ready To Receive Command (RTR) received in the SPEAKER state. Command received to indicate that the End Response (EERP or NERP) sent has been successfully received by the other peer.

In order to avoid congestion between two adjacent nodes caused by a continuous flow of EERPs and NERPs, a Ready To Receive (RTR) command is provided. The RTR acts as an EERP/NERP acknowledgement for flow control but has no end-to-end significance.

Protocol Sequence

 1. Speaker  -- EERP ------------> Listener   End to End Response
 2.          <------------- RTR --            Ready to Receive
 3.          -- EERP ------------>            End to End Response
 4.          <------------- RTR --            Ready to Receive
 5.          -- NERP ------------>            Negative End Response
 6.          <------------- RTR --            Ready to Receive
 7.          -- SFID ------------>            Start File
                         or
 8.          -- CD -------------->            Exchange the turn
 
After sending an EERP or NERP, the Speaker must wait for an RTR before sending any other commands. The only acceptable commands to follow are:
      EERP
      NERP
      SFID or CD (if there are no more EERPs or NERPs to be sent)
 

Specified by:
readyToReceiveReceived in interface ProtocolHandler
Throws:
OdetteFtpException

setCreditReceived

public void setCreditReceived(OdetteFtpSession session,
                              CommandExchangeBuffer cdt)
                       throws OdetteFtpException
Specified by:
setCreditReceived in interface ProtocolHandler
Throws:
OdetteFtpException

speakerStartFile

protected void speakerStartFile(OdetteFtpSession session,
                                VirtualFile vf)
                         throws OdetteFtpException
Do start file transmission.

Parameters:
session -
exchange -
Throws:
OdetteFtpException

normalizeVirtualFile

protected VirtualFile normalizeVirtualFile(OdetteFtpSession session,
                                           VirtualFile vf)

startFilePositiveAnswerReceived

public void startFilePositiveAnswerReceived(OdetteFtpSession session,
                                            CommandExchangeBuffer sfpa)
                                     throws OdetteFtpException
Specified by:
startFilePositiveAnswerReceived in interface ProtocolHandler
Throws:
OdetteFtpException

startFileNegativeAnswerReceived

public void startFileNegativeAnswerReceived(OdetteFtpSession session,
                                            CommandExchangeBuffer sfna)
                                     throws OdetteFtpException
Specified by:
startFileNegativeAnswerReceived in interface ProtocolHandler
Throws:
OdetteFtpException

speakerSendData

protected void speakerSendData(OdetteFtpSession session)
                        throws OdetteFtpException
Perform data buffer transmission of the file transfer opened.

Parameters:
session -
Throws:
OdetteFtpException

speakerEndFile

protected void speakerEndFile(OdetteFtpSession session,
                              VirtualFile virtualFile)
                       throws OdetteFtpException
Throws:
OdetteFtpException

endFileNegativeAnswerReceived

public void endFileNegativeAnswerReceived(OdetteFtpSession session,
                                          CommandExchangeBuffer efna)
                                   throws OdetteFtpException
Specified by:
endFileNegativeAnswerReceived in interface ProtocolHandler
Throws:
OdetteFtpException

endFilePositiveAnswerReceived

public void endFilePositiveAnswerReceived(OdetteFtpSession session,
                                          CommandExchangeBuffer efpa)
                                   throws OdetteFtpException
Specified by:
endFilePositiveAnswerReceived in interface ProtocolHandler
Throws:
OdetteFtpException

readyMessageReceived

public void readyMessageReceived(OdetteFtpSession session)
                          throws OdetteFtpException
Description copied from interface: ProtocolHandler
The Initiator ODETTE-FTP entity receive the Start Session Ready Message sent by the Responder immediately after the network connection has been established, beginning the Start Session Phase.

Thus, the both negotiate session authentication and parameters exchanging the SSID command.

Protocol Sequence

 1. Initiator <-------------SSRM -- Responder   Ready Message
 2.           -- SSID ------------>             Identification
 3.           <------------ SSID --             Identification
 

Specified by:
readyMessageReceived in interface ProtocolHandler
Throws:
OdetteFtpException

speakerDeliveryNotification

protected void speakerDeliveryNotification(OdetteFtpSession session,
                                           DeliveryNotification notif)
                                    throws OdetteFtpException
Throws:
OdetteFtpException

endToEndResponseReceived

public void endToEndResponseReceived(OdetteFtpSession session,
                                     CommandExchangeBuffer eerp)
                              throws OdetteFtpException
Specified by:
endToEndResponseReceived in interface ProtocolHandler
Throws:
OdetteFtpException

protocolRelease

public void protocolRelease(OdetteFtpSession session,
                            EndSessionReason reason,
                            String reasonText)
Specified by:
protocolRelease in interface ProtocolHandler

endSessionReceived

public void endSessionReceived(OdetteFtpSession session,
                               CommandExchangeBuffer esid)
                        throws OdetteFtpException
Specified by:
endSessionReceived in interface ProtocolHandler
Throws:
OdetteFtpException

initiatorStartSessionReceived

protected void initiatorStartSessionReceived(OdetteFtpSession session,
                                             CommandExchangeBuffer ssid)
                                      throws OdetteFtpException
The Initiator handle the returned Start Session Identification command to perform its setup and complete the Start Session Phase.

Throws:
OdetteFtpException

checkSessionParamsViolation

protected void checkSessionParamsViolation(int ssidsdeb,
                                           int ssidcred,
                                           TransferMode ssidsr,
                                           boolean ssidspec,
                                           OdetteFtpSession session)
                                    throws OdetteFtpException
Throws:
OdetteFtpException

responderSendStartSession

protected void responderSendStartSession(OdetteFtpSession session,
                                         CommandExchangeBuffer ssid)
                                  throws OdetteFtpException
Throws:
OdetteFtpException

buildStartFileNegativeAnswerCommand

protected abstract CommandExchangeBuffer buildStartFileNegativeAnswerCommand(AnswerReason reason,
                                                                             String reasonText,
                                                                             boolean retryLater)

buildEndFileNegativeAnswerCommand

protected abstract CommandExchangeBuffer buildEndFileNegativeAnswerCommand(AnswerReason reason,
                                                                           String reasonText)

buildStartFilePositiveAnswerCommand

protected abstract CommandExchangeBuffer buildStartFilePositiveAnswerCommand(long answerCount)

buildStartFileCommand

protected abstract CommandExchangeBuffer buildStartFileCommand(OdetteFtpSession session,
                                                               VirtualFile vf)

buildEndFilePositiveAnswerCommand

protected abstract CommandExchangeBuffer buildEndFilePositiveAnswerCommand(boolean changeDirection)

buildEndFileCommand

protected abstract CommandExchangeBuffer buildEndFileCommand(long recordCount,
                                                             long unitCount)

buildStartSessionCommand

protected abstract CommandExchangeBuffer buildStartSessionCommand(String code,
                                                                  String pswd,
                                                                  String userData,
                                                                  OdetteFtpSession session)

buildEndSessionCommand

protected abstract CommandExchangeBuffer buildEndSessionCommand(EndSessionReason reason,
                                                                String reasonText)

buildDeliveryNotificationCommand

protected abstract CommandExchangeBuffer buildDeliveryNotificationCommand(DeliveryNotification notif)

buildReadyToReceiveCommand

protected abstract CommandExchangeBuffer buildReadyToReceiveCommand()

buildVirtualFileObject

protected abstract DefaultVirtualFile buildVirtualFileObject(OdetteFtpSession session,
                                                             CommandExchangeBuffer sfid)
                                                      throws OdetteFtpException
Throws:
OdetteFtpException

buildEndToEndResponse

protected abstract DeliveryNotification buildEndToEndResponse(CommandExchangeBuffer eerp)

buildNegativeEndResponse

protected abstract DeliveryNotification buildNegativeEndResponse(CommandExchangeBuffer nerp)
                                                          throws OdetteFtpException
Throws:
OdetteFtpException

buildAnswerReasonInfoObject

protected abstract AnswerReasonInfo buildAnswerReasonInfoObject(CommandExchangeBuffer sfna)
                                                         throws OdetteFtpException
Throws:
OdetteFtpException

buildEndSessionReasonInfoObject

protected abstract EndSessionReasonInfo buildEndSessionReasonInfoObject(CommandExchangeBuffer esid)
                                                                 throws OdetteFtpException
Throws:
OdetteFtpException

release

protected void release(OdetteFtpSession session)
                throws OdetteFtpException
Throws:
OdetteFtpException

protocolMaxFileSizeSupported

protected abstract long protocolMaxFileSizeSupported()

speakerChangeDirection

protected void speakerChangeDirection(OdetteFtpSession session)
                               throws OdetteFtpException
Throws:
OdetteFtpException

startSessionPasswordAuthentication

protected void startSessionPasswordAuthentication(OdetteFtpSession session,
                                                  CommandExchangeBuffer ssid,
                                                  boolean mandatory)
                                           throws OdetteFtpException
Throws:
OdetteFtpException

handleCallback

protected boolean handleCallback(OdetteFtpSession session,
                                 Callback callback)

speakerTransmitRequests

protected void speakerTransmitRequests(OdetteFtpSession session)
                                throws OdetteFtpException
Throws:
OdetteFtpException

speakerChangeDirectionPreventingLoop

protected void speakerChangeDirectionPreventingLoop(OdetteFtpSession session)
                                             throws OdetteFtpException
If last command received is not CD, so turn direction. Otherwise, do a normal end session termination.

Parameters:
session -
Throws:
OdetteFtpException

resetOutgoingCredits

protected final void resetOutgoingCredits(OdetteFtpSession session)

resetIncomingCredits

protected final void resetIncomingCredits(OdetteFtpSession session)

consumeOutgoingCredits

protected final void consumeOutgoingCredits(OdetteFtpSession session)

consumeIncomingCredits

protected final void consumeIncomingCredits(OdetteFtpSession session)

buildSetCreditCommand

protected CommandExchangeBuffer buildSetCreditCommand()


ACCORD