Pourquoi et quand exécuter cette tâche
En fermant les séquences à l'aide
d'un programme, vous limitez le nombre de séquences ouvertes qu'un seul client
doit prendre en charge simultanément dans une machine virtuelle Java.
Pour que votre application client puisse prendre le contrôle par programmation sur des séquences de messagerie fiables, elle
doit pouvoir accéder à une instance WSRMSequenceManager. Pour
ce faire, utilisez le fragment de code suivant :
import com.ibm.wsspi.wsrm.WSRMSequenceManager;
import com.ibm.wsspi.wsrm.WSRMSequenceManagerFactory;
.........
// Get the factory
WSRMSequenceManagerFactory factory = WSRMSequenceManagerFactory
.getInstance();
// Get the sequence manager instance
WSRMSequenceManager sequenceManager = factory.createWSRMSequenceManager();
Toutes
les méthodes
WSRMSequenceManager utilisent les paramètres
suivants :
- L'objet d'instance client.
Il s'agit d'une instance Client
Dispatch ou du Client Dynamic Proxy.
Pour plus de détails sur les types de clients, voir la rubrique Modèle de programmation client JAX-WS.
- L'instance QName de port pour le noeud final cible.
Pour
contrôler par programmation les séquences WS-ReliableMessaging, ajoutez du code à
votre application client comme décrit dans la procédure suivante :
- Ajoutez du code pour créer une
séquence.
Pour définir les propriétés disponibles, utilisez les méthodes suivantes :
/**
* Sets the target provider endpoint.
* A null value will cause a NullPointerException when the WSRMSequenceProperties object is used.
*
* @param providerEndPoint The target service endpoint URI
*/
public void setTargetEndpointUri(String providerEndPoint);
/**
* This is used to indicate that a response flow is required between the provider and requester and the response
* flow will be established at create sequence time
*
* By calling this method it will indicate that a response flow is required.
*/
public void setUseOfferedSequenceId();
/**
* Set the Soap version for RM protocol messages.
* The default value for this property is WSRMSequenceProperties.SOAP_11
*
* @param soapVersion
*/
public void setSoapVersion(int soapVersion);
/**
* If the Sequence Acknowledgement messages are to be sent back asynchronously call this method.
*
*/
public void useAsyncTransport();
Pour créer la séquence de messagerie fiable, utilisez la méthode createNewWSRMSequence sur
WSRMSequenceManager :
/**
* Initiates a new sequence handshake between this client and the target EPR specified in the
* WSRMSequenceProperties instance.
*
* This sequence will only be valid for the client issuing the createNewWSRMSequence call.
*
* When returning from this call, there is no guarantee that the sequence has been established.
*
* @throws NullPointerException if the sequenceProperties object is null, or the target EPR is null
*
* @param clientObject The JAX-WS Dispatch instance, or the Dynamic Proxy client instance.
* @param sequencePropeties The properties for creating the reliable messaging sequence
* @throws WSRMNotEnabledException
* @throws WSRMSequenceAlreadyExistsException
*/
public void createNewWSRMSequence(Object clientObject, QName portQName, WSRMSequenceProperties sequencePropeties)
throws WSRMNotEnabledException,
WSRMSequenceAlreadyExistsException;
- Ajoutez du code pour envoyer une demande d'accusé de réception.
Pour envoyer une demande d'accusé de réception pour une séquence WS-ReliableMessaging, utilisez la méthode suivante sur WSRMSequenceManager :
/**
* Sending an acknowledgement request sends the ACK requested message to the specified target endPointUri.
* The target will respond with a range of messages that can be acknowledged for the current reliable messaging
* sequence.
*
* @param clientObject The JAX-WS Dispatch instance, or the Dynamic Proxy client instance.
* @param portQName
* @param endPointUri The target endpoint uri
* @throws WSRMNotEnabledException
* @throws WSRMSequenceUnknownException
* @throws WSRMSequenceTerminatedException
* @throws WSRMSequenceClosedException
*/
public void sendAcknowledgementRequest(Object clientObject, QName portQName, String endPointUri)
throws WSRMNotEnabledException,
WSRMSequenceUnknownException,
WSRMSequenceTerminatedException,
WSRMSequenceClosedException;
- Ajoutez du code pour fermer une séquence.
Pour fermer une séquence WS-ReliableMessaging, utilisez la méthode suivante sur WSRMSequenceManager :
/**
* Closes the web services reliable messaging session from this application to
* the endpoint url specified.
*
* Throws a WSRMSequenceTerminatedException if the session between this application
* and the target endpoint url is already closed
*
* Throws a WSRMSequenceTerminatedException when the session between this application
* and the target endpoint has already been terminated.
*
* Throws WSRMSequenceUnknownException exception when either reliable messaging is not engaged to
* the specified endpoint url or the sequence has previously been terminated and removed.
*
* @param clientObject The JAX-WS Dispatch instance, or the Dynamic Proxy client instance.
* @param endPointUri The target endpoint url
*
* @throws WSRMNotEnabledException
* @throws WSRMSequenceUnknownException
* @throws WSRMSequenceClosedException
* @throws WSRMSequenceTerminatedException
*/
public void closeSequence(Object clientObject, QName portQName, String endPointUri)
throws WSRMNotEnabledException,
WSRMSequenceUnknownException,
WSRMSequenceClosedException,
WSRMSequenceTerminatedException;
- Ajoutez du code pour terminer une
séquence.
Pour mettre fin à une séquence WS-ReliableMessaging, utilisez la méthode suivante sur WSRMSequenceManager :
/**
* Terminates web services reliable messaging session from this application to
* the endpoint url specified.
*
* Throws a WSRMSequenceTerminatedException when the session between this application
* and the target endpoint has already been terminated.
*
* Throws WSRMSequenceUnknownException exception when either reliable messaging is not engaged to
* the specified endpoint url or the sequence has previously been terminated and removed.
*
* @param clientObject The JAX-WS Dispatch instance, or the Dynamic Proxy client instance.
* @param endPointUri The target endpoint url
* @throws WSRMNotEnabledException
*
* @throws WSRMSequenceTerminatedException
* @throws WSRMSequenceUnknownException
*/
public void terminateSequence(Object clientObject, QName portQName, String endPointUri) throws WSRMNotEnabledException;
- Ajoutez du code pour attendre la fin
d'une séquence.
Pour attendre la fin d'une séquence de
messagerie fiable, utilisez un appel de méthode garantissant l'envoi et l'accusé
de réception de tous les messages par le service cible. Une fois la séquence
terminée, elle prend fin et est nettoyée.
Pour utiliser la méthode waitUntilSequenceCompleted, procédez des deux manières suivantes :
public boolean waitUntilSequenceCompleted(Object clientObject,
QName portQName, String endPointUri, long waitTime)
Cet appel de méthode attend pendant le délai waitTime indiqué pour que la séquence de messagerie fiable prenne fin. Si la séquence ne se termine pas dans le délai indiqué, la méthode renvoie la valeur false. Si la séquence se termine dans le délai indiqué, la méthode renvoie la valeur true.
public boolean waitUntilSequenceCompleted(Object clientObject,
QName portQName, String endPointUri)
Cet appel de méthode n'est pas renvoyé tant que la séquence de messagerie fiable n'est pas terminée.