关于此任务
通过以编程方式关闭序列,可限制单个客户机在单个 JVM 中一次必须支持的打开序列数。
为了使客户机应用程序获取对可靠消息传递序列的程序控制权,它需要对 WSRMSequenceManager 实例的访问权. 使用以下代码片段来实现此目的:
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();
所有
WSRMSequenceManager 方法都接受下列参数:
- 客户机实例对象。这是 Dispatch client 实例或 Dynamic proxy client。有关客户机类型的详细信息,请参阅 JAX-WS 客户机编程模型主题。
- 目标端点的 Port QName 实例。
要以编程方式控制 WS-ReliableMessaging 序列,请根据以下步骤中的描述将代码添加到客户机应用程序:
- 添加代码以创建序列。
要设置可用的属性,可使用下列方法:
/**
* 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();
要创建可靠的消息传递序列,在 WSRMSequenceManager 上使用 createNewWSRMSequence 方法:
/**
* 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;
- 添加代码以发送应答请求。
要对 WS-ReliableMessaging 序列发送应答请求,在 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;
- 添加代码以关闭序列。
要在 WSRMSequenceManager 上使用以下方法来关闭 WS-ReliableMessaging 序列:
/**
* 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;
- 添加代码以终止序列。
要在 WSRMSequenceManager 上使用以下方法来终止 WS-ReliableMessaging 序列:
/**
* 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;
- 添加代码以等待序列完成。
要等待完成某一可靠消息传递序列,请使用一个能够确保目标服务已发送并应答所有消息的方法调用。该序列完成之后,就会终止并被清除。
可以采用以下两种方式来使用 waitUntilSequenceCompleted 方法:
public boolean waitUntilSequenceCompleted(Object clientObject,
QName portQName, String endPointUri, long waitTime)
此方法调用将花费指定的 waitTime 时间来等待可靠消息传递序列完成。如果在指定时间内未完成该序列,那么该方法将返回 false。如果在指定时间内完成了该序列,那么该方法将返回 true。
public boolean waitUntilSequenceCompleted(Object clientObject,
QName portQName, String endPointUri)
在完成可靠消息传递序列之前,此方法调用不会返回。