01: package org.objectweb.celtix.bus.ws.rm;
02:
03: import java.util.ArrayList;
04: import java.util.Collection;
05: import java.util.List;
06:
07: import org.objectweb.celtix.bindings.AbstractBindingBase;
08: import org.objectweb.celtix.bindings.Request;
09: import org.objectweb.celtix.bus.ws.addressing.AddressingPropertiesImpl;
10: import org.objectweb.celtix.bus.ws.addressing.ContextUtils;
11: import org.objectweb.celtix.bus.ws.addressing.VersionTransformer;
12: import org.objectweb.celtix.transports.Transport;
13: import org.objectweb.celtix.ws.addressing.AddressingProperties;
14: import org.objectweb.celtix.ws.addressing.AttributedURIType;
15: import org.objectweb.celtix.ws.addressing.v200408.EndpointReferenceType;
16: import org.objectweb.celtix.ws.rm.AckRequestedType;
17: import org.objectweb.celtix.ws.rm.persistence.RMDestinationSequence;
18:
19: public class SequenceInfoRequest extends Request {
20:
21: public SequenceInfoRequest(AbstractBindingBase b, Transport t,
22: EndpointReferenceType to) {
23: this (b, t, VersionTransformer.convert(to));
24: }
25:
26: public SequenceInfoRequest(AbstractBindingBase b, Transport t,
27: org.objectweb.celtix.ws.addressing.EndpointReferenceType to) {
28:
29: super (b, t, b.createObjectContext());
30:
31: if (to != null) {
32: ContextUtils.storeTo(to, getObjectMessageContext());
33: }
34:
35: ContextUtils.storeUsingAddressing(true,
36: getObjectMessageContext());
37:
38: getObjectMessageContext().setRequestorRole(true);
39: AddressingProperties maps = new AddressingPropertiesImpl();
40: AttributedURIType actionURI = ContextUtils.WSA_OBJECT_FACTORY
41: .createAttributedURIType();
42: actionURI.setValue(RMUtils.getRMConstants()
43: .getSequenceInfoAction());
44: maps.setAction(actionURI);
45: ContextUtils.storeMAPs(maps, getObjectMessageContext(), true,
46: true, true, true);
47:
48: setOneway(true);
49:
50: // NOTE: Not storing a method in the context causes BindingContextUtils.isOnewayMethod
51: // to always return false (although effectively all standalone requests based on the
52: // the SequenceInfo request are oneway requests).
53: // An important implication of this is that we don't expect partial
54: // responses sent in response to such messages, which is fine as we normally only piggyback
55: // sequence acknowledgements onto application messages.
56: }
57:
58: public void requestAcknowledgement(Collection<SourceSequence> seqs) {
59: List<AckRequestedType> requested = new ArrayList<AckRequestedType>();
60: for (AbstractSequenceImpl seq : seqs) {
61: AckRequestedType ar = RMUtils.getWSRMFactory()
62: .createAckRequestedType();
63: ar.setIdentifier(seq.getIdentifier());
64: requested.add(ar);
65: }
66: RMPropertiesImpl rmps = new RMPropertiesImpl();
67: rmps.setAcksRequested(requested);
68: }
69:
70: public void acknowledge(RMDestinationSequence seq) {
71: AddressingProperties maps = ContextUtils.retrieveMAPs(
72: getObjectMessageContext(), true, true);
73: maps.getAction().setValue(
74: RMUtils.getRMConstants()
75: .getSequenceAcknowledgmentAction());
76: AttributedURIType toAddress = ContextUtils.WSA_OBJECT_FACTORY
77: .createAttributedURIType();
78: toAddress.setValue(seq.getAcksTo().getAddress().getValue());
79: maps.setTo(toAddress);
80: // rm properties will be created (and actual acknowledgments added)
81: // by rm handler upon outbound processing of this message
82: }
83:
84: public void lastMessage(SourceSequence seq) {
85: AddressingProperties maps = ContextUtils.retrieveMAPs(
86: getObjectMessageContext(), true, true);
87: maps.getAction().setValue(
88: RMUtils.getRMConstants().getLastMessageAction());
89: RMPropertiesImpl rmps = new RMPropertiesImpl();
90: seq.nextAndLastMessageNumber();
91: rmps.setSequence(seq);
92: assert seq.isLastMessage();
93: RMContextUtils.storeRMProperties(getObjectMessageContext(),
94: rmps, true);
95: }
96: }
|