KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ubermq > jms > client > unicast > PipeSession


1 package com.ubermq.jms.client.unicast;
2
3 import com.ubermq.jms.client.*;
4 import com.ubermq.kernel.*;
5
6 import com.ubermq.jms.client.impl.AbstractClientSession;
7 import java.io.IOException JavaDoc;
8 import java.nio.channels.Pipe JavaDoc;
9
10 public class PipeSession
11     extends AbstractClientSession
12     implements IClientSession
13 {
14     private IDatagramFactory factory;
15
16     /**
17      * Creates a pipe session with the given datagram factory to handle processing.
18      * @param f the datagram factory to use.
19      */

20     public PipeSession(IDatagramFactory f)
21         throws java.io.IOException JavaDoc
22     {
23         super();
24         this.factory = f;
25     }
26
27     /**
28      * Creates a connection as described by the ConnectionDescriptor,
29      * using a particular message processor and associated with a JMS
30      * connection object.
31      * @param cxn the JMS connection object to associate with the new
32      * connection.
33      * @param descriptor provides information to the session on how
34      * to connect to the destination.
35      * @param proc the message processor to handle datagrams from the
36      * new connection.
37      */

38     public IConnectionInfo connect(javax.jms.Connection JavaDoc cxn,
39                                    ConnectionDescriptor descriptor,
40                                    IMessageProcessor proc) throws IOException JavaDoc
41     {
42         PipeConnection.ObjectConnectionDescriptor ocd = (PipeConnection.ObjectConnectionDescriptor)descriptor;
43
44         // create two pipes, one upstream and one downstream
45
Pipe JavaDoc toserver = Pipe.open(), fromserver = Pipe.open();
46         ocd.s.connectPipes(toserver, fromserver, factory);
47
48         // create my connection info, for client-side registration
49
IConnectionInfo connInfo = new PipeConnectionInfo(fromserver.source(),
50                                                           toserver.sink(),
51                                                           factory,
52                                                           proc);
53
54         // attach the connection info to the client processor.
55
proc.accept(connInfo);
56         return connInfo;
57     }
58 }
59
Popular Tags