IncomingMessageHandler

public class IncomingMessageHandler extends SFRMComponent

The incoming message handler is the core class for handling all incoming SFRM segment. It also handles:

  1. Allocation of disk space for HANDSHAKING segment.
  2. Insertion of data content to specified file for PAYLOAD segment.
  3. RECEIPT Response handling
  4. RECOVERY when data integrity check fails.
  5. Error Definition and handling

For details, read processIncomingMessage(SFRMMessage,Object[]) as the entry point for knowing how this class work. Creation Date: 11/10/2006

Author:Twinsen Tsang

Methods

extractPartnership

public SFRMPartnershipDVO extractPartnership(SFRMMessage incomingMessage)

Validate whether the partnership for the incoming message is exist and return that partnership as return value. [SINGLE-THREADED].

Parameters:
  • incomingMessage – The incoming SFRM message.
Throws:
  • MalformedURLException – throw if the partnership does not found or any other database error.
Returns:

A SFRM partnership record.

getInstance

public static IncomingMessageHandler getInstance()
Returns:an instnace of IncomingMessageHandler.

init

protected void init()

Invoked for initialization. The IMH has serval properties :

  1. maxActive: The number of parallel threads for handling incoming segments. The default value is 10. [Integer]

initGuardForSegment

public boolean initGuardForSegment(SFRMMessage incomingMessage)

initalize the Guard so that there is ONLY ONE THREAD working per the incomingMessage.

Parameters:
  • incomgMessage – The incoming SFRM Message.

isDuplicateSegment

public boolean isDuplicateSegment(SFRMMessage incomingMessage)

Validate whether the incoming segment message has been received once.

Parameters:
  • incomingMessage – The incoming SFRM message.
Throws:
  • DAOException – throw if there is any kind of database error.
Returns:

true if it is a duplicated (received already).

isNotEnoughRoom

public boolean isNotEnoughRoom(SFRMMessage incomingMessage, long threshold)

Validate whether the harddisk has enough space for this message. The validation formula is liked this:

 pS  : total payload size
 T   : threshold (the minimum hard disk space)
 HDDS: the remaining hard disk space

true iff (HDDS >= pS + T)
false iff (HDDS < ps + T)
Parameters:
  • incomingMessage – The incoming SFRM message.
  • threshold – The remaining disk space threshold. if the remaining disk space is lower than (this value + the payload size), in this case, it always return false.
Returns:

true if there is enough hard disk space or the associated payloads is created already in the harddisk. vice versa.

isProcessingMessage

public boolean isProcessingMessage(SFRMMessage incomingMessage)

Validate whether the associated message of this incoming segment is processing. Any state except SFRMConstant.MSGS_PROCESSING return false for this method invocation. If the message record does not exist in receiver, we treat this as failure because every segment should has handshaking steps before sending.

Parameters:
  • incomingMessage – The incoming SFRM message.
Throws:
  • DAOException – throw if there is any kind of database error.
  • SFRMMesageException
Returns:

true if it is processing.

logMessage

protected void logMessage(SFRMMessage incomingMessage)

Log the whole message for debug purpose.

Parameters:
  • incomingMessage – The incoming sfrm message.

logMessageType

protected void logMessageType(String type)

Log the message type for debug purpose. The message type currently support for this version is META, PAYLOAD ,RECEIPT and RECOVERY.

Parameters:
  • type – The message type.

processAcknowledgement

public SFRMMessage processAcknowledgement(SFRMMessage msg, SFRMPartnershipDVO pDVO)

processHandshakingMessage

public SFRMMessage processHandshakingMessage(SFRMMessage rawMessage, Object[] params)

Process handshaking for a new message. [SINGLE-THREADED]. The message segment is also META type. In the handshaking steps, it create the message record and check whether it has enough space for receiving the message. This method does not block and return immediately to let the sender know does the receiver is available to receive this message.

Parameters:
  • rawMessage – The incoming SFRM Message.
  • params – RESERVED.
Throws:
Returns:

RESERVED.

processIncomingMessage

public SFRMMessage processIncomingMessage(SFRMMessage incomingMessage, Object[] params)

Process all kind of incoming SFRM message.. This method is invoked when the received HTTP request is transformed to SFRM Message from the SFRM inbound listener.

Parameters:
  • incomingMessage – The incoming SFRM Message.
  • params – RESERVED
Throws:
Returns:

A SFRM message for response message.

processMetaMessage

public SFRMMessage processMetaMessage(SFRMMessage inputMessage, SFRMPartnershipDVO partnershipDVO, Object[] params)

Process all meta-typed message segment. [MULTI-THREADED]. This method pre-allocates the payload and it blocks until the file has been created.

Parameters:
  • inputMessage – The incoming SFRM Message. (unsigned and decrypted)
  • partnershipDVO – The partnership DVO for this incoming message.
  • params – RESERVED.
Throws:
Returns:

RESERVED.

processPDFAck

public String processPDFAck(SFRMMessageDVO mDVO)

Process the acknowledgement with PDF status

Parameters:
  • messageId – message ID
Throws:
Returns:

the acknowledgement response content

processPPSAck

public String processPPSAck(SFRMMessageDVO mDVO)

Process the acknowledgement with PPS status

Parameters:
  • messageId – message ID
Throws:
Returns:

the acknowledgement response content

processPRAck

public String processPRAck(SFRMMessageDVO mDVO, SFRMAcknowledgementParser parser)

Process the acknowledgement request with PR status

Parameters:
  • messageId – message id
  • parser – parser that content the acknowledgement request parsing
Throws:
Returns:

the acknowledgement response content

processPRSAck

public String processPRSAck(SFRMMessageDVO mDVO)

Process the acknowledgement with PRS status

Parameters:
  • messageId – message ID
Throws:
Returns:

the acknowledgement response content

processPSDAck

public String processPSDAck(SFRMMessageDVO mDVO)

Process the acknowledgement with PSD status

Parameters:
  • messageId – message ID
Throws:
Returns:

the acknowledgement response content

processSegmentMessage

public SFRMMessage processSegmentMessage(SFRMMessage rawMessage, Object[] params)

Process payload-typed segment message. What the method has done:

  • Create a segment file in the incoming segment repository.
  • Create a inbox message segment record for the incoming message.
Parameters:
  • inputMessage – The packed SFRMMessage.
  • rawMessage – The unpacked SFRM Message. (i.e. no sign and encrypt here)
  • params – RESERVED
Returns:

A SFRM message for response message.

releaseGuardForSegment

public boolean releaseGuardForSegment(SFRMMessage incomingMessage)

Release the ONE THREAD working GUARD for incomingMessage

Parameters:
  • incomingMessage – The incoming SFRM Message.

resolveGuardOwnerForSegment

public boolean resolveGuardOwnerForSegment(SFRMMessage incomingMessage)

Resolve the guard for the incomingMessage to the new owner (another thread that process the incomingMessage.

Parameters:
  • incomingMesasge – The incoming SFRM Message.

unpackIncomingMessage

public void unpackIncomingMessage(SFRMMessage message, SFRMPartnershipDVO partnershipDVO)

Unpack the SMIME (secure MIME) message to become raw SFRM Message.

Parameters:
  • incomingMessage – The incoming SFRM Message.
  • partnershipDVO – The partnership to valid against to.
Throws:
Returns:

The raw SFRM Message.