com.atomikos.icatch.msg
Class AbstractTransport

java.lang.Object
  extended by com.atomikos.icatch.msg.AbstractTransport
All Implemented Interfaces:
RecoverableResource, Transport
Direct Known Subclasses:
HttpTransport

public abstract class AbstractTransport
extends Object
implements Transport

Author:
guy An abstract Transport class that implements the generic functionality.

Field Summary
 
Fields inherited from interface com.atomikos.icatch.msg.Transport
FTP, HTTP, JMS, SMTP, UNKNOWN_PROTOCOL
 
Constructor Summary
protected AbstractTransport(String name, String participantAddress, String coordinatorAddress, int commitProtocol, int transportProtocol, int format, long defaultTimeout)
           
 
Method Summary
 void close()
          Closes the resource for shutdown.
 CommitMessage createCommitMessage(boolean onephase, String senderURI, String targetURI, Object targetAddress)
          Create a new commit message.
 ErrorMessage createErrorMessage(int code, String senderURI, String targetURI, Object targetAddress)
          Create a new error message.
 ForgetMessage createForgetMessage(String senderURI, String targetURI, Object targetAddress)
          Create a new forget message.
 PreparedMessage createPreparedMessage(boolean readonly, String senderURI, String targetURI, Object targetAddress)
          Create a new prepared message.
 PrepareMessage createPrepareMessage(int globalSiblingCount, CascadeInfo[] cascadeInfo, String senderURI, String targetURI, Object targetAddress)
          Create a new prepare message.
 PrepareMessage createPrepareMessage(String senderURI, String targetURI, Object targetAddress)
          Create a new prepare message.
 RegisteredMessage createRegisteredMessage(String senderURI, String targetURI, Object targetAddress)
          Create a new registration confirmation message.
 RegisterMessage createRegisterMessage(String senderURI, String targetURI, Object targetAddress, boolean for2PC)
          Create a new registration message.
 ReplayMessage createReplayMessage(String senderURI, String targetURI, Object targetAddress)
          Create a new replay message.
 RollbackMessage createRollbackMessage(String senderURI, String targetURI, Object targetAddress)
          Create a new rollback message.
 StateMessage createStateMessage(Boolean committed, String senderURI, String targetURI, Object targetAddress)
          Create a new state message.
 void endRecovery()
          Notifies the resource that recovery is ended.
 int getCommitProtocol()
          The protocol that this transport understands.
 String getCoordinatorAddress()
          Get the address on which this transport is listening for incoming coordinator messages.
 long getDefaultTimeout()
          Get a realistic default timeout for the given transport.
 int getFormat()
          Get the message format that this transport understands.
 String getName()
          Gets the name of the resource.
 String getParticipantAddress()
          Get the address on which this transport is listening for incoming participant messages.
 int getTransportProtocol()
          Get the transport protocol that this transport understands.
 boolean isClosed()
          Tests if the resource is closed.
 boolean isSameRM(RecoverableResource res)
          Tests if a resource is the same as another one.
 boolean recover(Participant participant)
          Recovers the partially reconstructed Participant.
 void registerMessageListener(MessageListener listener)
          Register a message listener for unexpected receivals.
 void registerMessageListener(MessageListener listener, int messageType)
          Register a message listener for incoming messages of the given type.
 void removeMessageListener(MessageListener listener)
          Remove a previously registered listener.
protected  void replyReceived(TransactionMessage reply)
          Notification that a reply has come in.
protected  void requestReceived(TransactionMessage req)
          Notification that a request has come in.
 void send(TransactionMessage msg)
          Send a message.
 TransactionMessage sendAndReceive(TransactionMessage msg, long timeout, int[] expected)
          Send and receive a message for the given target.
 void setRecoveryService(RecoveryService recoveryService)
          Initializes this resource with the recovery service.
 void setSenderPort(SenderPort senderPort)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractTransport

protected AbstractTransport(String name,
                            String participantAddress,
                            String coordinatorAddress,
                            int commitProtocol,
                            int transportProtocol,
                            int format,
                            long defaultTimeout)
Method Detail

replyReceived

protected void replyReceived(TransactionMessage reply)
Notification that a reply has come in. Subclasses should call this method to notify any waiters.

Parameters:
reply - The incoming reply message.

requestReceived

protected void requestReceived(TransactionMessage req)
Notification that a request has come in. Subclasses should call this method to notify any message listeners.

Parameters:
req - The incoming request message.

getCommitProtocol

public int getCommitProtocol()
Description copied from interface: Transport
The protocol that this transport understands.

Specified by:
getCommitProtocol in interface Transport
Returns:
int The protocol, as defined in CommitProtocol.
See Also:
Transport.getCommitProtocol()

getFormat

public int getFormat()
Description copied from interface: Transport
Get the message format that this transport understands.

Specified by:
getFormat in interface Transport
Returns:
int The message format, as defined in TransactionMessage.
See Also:
Transport.getFormat()

setSenderPort

public void setSenderPort(SenderPort senderPort)

getTransportProtocol

public int getTransportProtocol()
Description copied from interface: Transport
Get the transport protocol that this transport understands.

Specified by:
getTransportProtocol in interface Transport
Returns:
int The transport protocol. One of the predefined constants.
See Also:
Transport.getTransportProtocol()

getDefaultTimeout

public long getDefaultTimeout()
Description copied from interface: Transport
Get a realistic default timeout for the given transport.

Specified by:
getDefaultTimeout in interface Transport
Returns:
long The timeout in milliseconds. After this time, a message may be considered lost in the system.
See Also:
Transport.getDefaultTimeout()

sendAndReceive

public TransactionMessage sendAndReceive(TransactionMessage msg,
                                         long timeout,
                                         int[] expected)
                                  throws TransportException,
                                         IllegalMessageTypeException
Description copied from interface: Transport
Send and receive a message for the given target.

Specified by:
sendAndReceive in interface Transport
Parameters:
msg - The message to send.
timeout - The timeout in milliseconds after which the method will return, received or not.
expected - The types of messages expected. Other messages are ignored. The values should be of TransactionMessage's predefined types.
Returns:
TransactionMessage The message, or null if timedout.
Throws:
IllegalMessageTypeException - If the message sent is of the wrong type.
TransportException
See Also:
Transport.sendAndReceive(com.atomikos.icatch.msg.TransactionMessage, long, int[])

registerMessageListener

public void registerMessageListener(MessageListener listener)
                             throws TransportException
Description copied from interface: Transport
Register a message listener for unexpected receivals. This method should work even before recover is called.

Specified by:
registerMessageListener in interface Transport
Parameters:
listener - The message listener.
Throws:
TransportException - On failure.
See Also:
Transport.registerMessageListener(com.atomikos.icatch.msg.MessageListener)

registerMessageListener

public void registerMessageListener(MessageListener listener,
                                    int messageType)
                             throws TransportException
Description copied from interface: Transport
Register a message listener for incoming messages of the given type. This method should work even before recover is called.

Specified by:
registerMessageListener in interface Transport
Parameters:
listener - The listener.
messageType - The type to listen for.
Throws:
TransportException - On failure.
See Also:
Transport.registerMessageListener(com.atomikos.icatch.msg.MessageListener, int)

removeMessageListener

public void removeMessageListener(MessageListener listener)
                           throws TransportException
Description copied from interface: Transport
Remove a previously registered listener. This method should work even after close.

Specified by:
removeMessageListener in interface Transport
Parameters:
listener - The message listener.
Throws:
TransportException - On failure.
See Also:
Transport.removeMessageListener(com.atomikos.icatch.msg.MessageListener)

recover

public boolean recover(Participant participant)
                throws ResourceException
Description copied from interface: RecoverableResource
Recovers the partially reconstructed Participant.

Specified by:
recover in interface RecoverableResource
Parameters:
participant - A partially recovered Participant.
Returns:
boolean True iff reconstruction was successful. If the resource is not responsible for the given participant, then this will return false. A Participant can use this to iterate over all resources in order to eventually recover itself. This is particularly useful if the Participant instance can not serialize its full state, because some of it is on its backside resource (as, for instance, in XA). This way, the TransactionalResource can be used to assist in reconstruction of the Participant's state.
Throws:
ResourceException - On failure.
See Also:
RecoverableResource.recover(com.atomikos.icatch.Participant)

endRecovery

public void endRecovery()
                 throws ResourceException
Description copied from interface: RecoverableResource
Notifies the resource that recovery is ended. Called by TM at end of recovery; any remaining resourcetransactions (i.e., that have not been associated with any recover call) should be rolled back. This is because if the were not recovered by the TM, then surely they are not supposed to be indoubt (the TM recovers ALL indoubt work!) and should be rolled back.

Specified by:
endRecovery in interface RecoverableResource
Throws:
ResourceException - On failure.
See Also:
RecoverableResource.endRecovery()

close

public void close()
           throws ResourceException
Description copied from interface: RecoverableResource
Closes the resource for shutdown. This notifies the resource that it is no longer needed.

Specified by:
close in interface RecoverableResource
Throws:
ResourceException
See Also:
RecoverableResource.close()

getName

public String getName()
Description copied from interface: RecoverableResource
Gets the name of the resource. Names should be unique within one TM domain.

Specified by:
getName in interface RecoverableResource
Returns:
String The name.
See Also:
RecoverableResource.getName()

isSameRM

public boolean isSameRM(RecoverableResource res)
                 throws ResourceException
Description copied from interface: RecoverableResource
Tests if a resource is the same as another one.

Specified by:
isSameRM in interface RecoverableResource
Throws:
ResourceException
See Also:
RecoverableResource.isSameRM(com.atomikos.datasource.RecoverableResource)

createCommitMessage

public CommitMessage createCommitMessage(boolean onephase,
                                         String senderURI,
                                         String targetURI,
                                         Object targetAddress)
Create a new commit message.

Specified by:
createCommitMessage in interface Transport

createErrorMessage

public ErrorMessage createErrorMessage(int code,
                                       String senderURI,
                                       String targetURI,
                                       Object targetAddress)
Create a new error message.

Specified by:
createErrorMessage in interface Transport

createForgetMessage

public ForgetMessage createForgetMessage(String senderURI,
                                         String targetURI,
                                         Object targetAddress)
Create a new forget message.

Specified by:
createForgetMessage in interface Transport

createPrepareMessage

public PrepareMessage createPrepareMessage(String senderURI,
                                           String targetURI,
                                           Object targetAddress)
Create a new prepare message.

Specified by:
createPrepareMessage in interface Transport

createPrepareMessage

public PrepareMessage createPrepareMessage(int globalSiblingCount,
                                           CascadeInfo[] cascadeInfo,
                                           String senderURI,
                                           String targetURI,
                                           Object targetAddress)
Create a new prepare message.

Specified by:
createPrepareMessage in interface Transport

createPreparedMessage

public PreparedMessage createPreparedMessage(boolean readonly,
                                             String senderURI,
                                             String targetURI,
                                             Object targetAddress)
Create a new prepared message. The option default_rollback is not used by our software, so we do not allow setting it to other than the default value.

Specified by:
createPreparedMessage in interface Transport

createReplayMessage

public ReplayMessage createReplayMessage(String senderURI,
                                         String targetURI,
                                         Object targetAddress)
Create a new replay message.

Specified by:
createReplayMessage in interface Transport

createRollbackMessage

public RollbackMessage createRollbackMessage(String senderURI,
                                             String targetURI,
                                             Object targetAddress)
Create a new rollback message.

Specified by:
createRollbackMessage in interface Transport

createStateMessage

public StateMessage createStateMessage(Boolean committed,
                                       String senderURI,
                                       String targetURI,
                                       Object targetAddress)
Create a new state message.

Specified by:
createStateMessage in interface Transport

createRegisterMessage

public RegisterMessage createRegisterMessage(String senderURI,
                                             String targetURI,
                                             Object targetAddress,
                                             boolean for2PC)
Create a new registration message.

Specified by:
createRegisterMessage in interface Transport

createRegisteredMessage

public RegisteredMessage createRegisteredMessage(String senderURI,
                                                 String targetURI,
                                                 Object targetAddress)
Create a new registration confirmation message.

Specified by:
createRegisteredMessage in interface Transport

getCoordinatorAddress

public String getCoordinatorAddress()
Description copied from interface: Transport
Get the address on which this transport is listening for incoming coordinator messages.

Specified by:
getCoordinatorAddress in interface Transport
Returns:
String The address.
See Also:
getCoordinatorAddress()

getParticipantAddress

public String getParticipantAddress()
Description copied from interface: Transport
Get the address on which this transport is listening for incoming participant messages.

Specified by:
getParticipantAddress in interface Transport
Returns:
String The address.
See Also:
getParticipantAddress()

isClosed

public boolean isClosed()
Description copied from interface: RecoverableResource
Tests if the resource is closed.

Specified by:
isClosed in interface RecoverableResource
Returns:
boolean True if the resource is closed.

setRecoveryService

public void setRecoveryService(RecoveryService recoveryService)
                        throws ResourceException
Description copied from interface: RecoverableResource
Initializes this resource with the recovery service. This method is called by the transaction service during intialization of the transaction service or when the resource is added, whichever comes last. If the resource wants to recover, it should subsequently ask the recoveryService to do so.

Specified by:
setRecoveryService in interface RecoverableResource
Parameters:
recoveryService - The recovery service. This instance can be used by the resource to ask recovery from the transaction engine.
Throws:
ResourceException - On errors.

send

public void send(TransactionMessage msg)
          throws TransportException,
                 IllegalMessageTypeException
Description copied from interface: Transport
Send a message.

Specified by:
send in interface Transport
Parameters:
msg - The message to send.
Throws:
TransportException - On failure.
IllegalMessageTypeException - If the message sent is of the wrong type.
See Also:
Transport.send(com.atomikos.icatch.msg.TransactionMessage)


Copyright © 2012. All Rights Reserved.