01: /*
02: * ProtocolMessageHelper.java
03: *
04: * @author Mike Grogan
05: * Created on August 17, 2007, 3:26 PM
06: */
07:
08: package com.sun.xml.ws.rm.jaxws.runtime.client;
09:
10: import com.sun.xml.ws.rm.RMException;
11: import com.sun.xml.ws.api.pipe.Tube;
12: import com.sun.xml.ws.api.pipe.TubeCloner;
13: import com.sun.xml.ws.api.pipe.Fiber;
14: import com.sun.xml.ws.api.pipe.Engine;
15: import com.sun.istack.NotNull;
16: import com.sun.xml.ws.api.message.Packet;
17:
18: /**
19: * ProtocolMessageHelper is used to execute synchronous protocol message exchanges using
20: * the asynchronous Tubeline architecture.
21: */
22: public class ProtocolMessageHelper {
23:
24: private final Engine engine;
25: private final Tube tube;
26:
27: public ProtocolMessageHelper(Tube tube) {
28: this .tube = tube;
29:
30: Fiber currentFiber = Fiber.current();
31: if (currentFiber == null) {
32: throw new IllegalStateException("No current fiber.");
33: }
34:
35: engine = currentFiber.owner;
36: };
37:
38: /**
39: * Synchronously executes the protocol exchange. The implementation sends
40: * the request through a clone of the stored Tubeline and blocks until a
41: * response is received.
42: */
43: public Packet process(Packet request) throws RMException {
44:
45: try {
46: //we will use a fresh Fiber and Tube for each request. We need to do this
47: //because there may be another request being procesed by the original tube.
48: //This can happen when this ProtocolMessageHelper is being used to resend
49: //messages or send AckRequested's from the maintenance thread. These
50: //things might happen while other requests are being processe.'
51: Fiber fiber = engine.createFiber();
52: Tube tubeline = TubeCloner.clone(tube);
53: return fiber.runSync(tubeline, request);
54: } catch (RuntimeException e) {
55: throw e;
56: }
57:
58: };
59:
60: }
|