KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ubermq > jms > client > impl > AbstractClientSession


1 package com.ubermq.jms.client.impl;
2
3 import com.ubermq.jms.client.*;
4 import com.ubermq.jms.client.impl.*;
5 import com.ubermq.kernel.*;
6 import java.io.*;
7 import java.nio.channels.*;
8 import org.apache.log4j.*;
9
10 /**
11  * This abstract base client session provides a process wide I/O thread,
12  * a selector, and keeps track of a list of incoming connection requests.
13  * <P>
14  * This client session uses NIO constructs, and so all connections managed
15  * by it must be Channel based.
16  */

17 public abstract class AbstractClientSession
18     implements IClientSession
19 {
20     private static final Logger log = Logger.getLogger(AbstractClientSession.class);
21
22     /**
23      * The process wide i/o thread
24      */

25     private static ReadWriteTransformThread read, write;
26
27     static
28     {
29         try
30         {
31             read = new ReadWriteTransformThread(SelectionKey.OP_READ);
32             read.start();
33
34             write = new ReadWriteTransformThread(SelectionKey.OP_WRITE);
35             write.start();
36         }
37         catch (IOException e) {
38             log.fatal("Unable to start I/O threads", e);
39         }
40     }
41
42     public AbstractClientSession()
43         throws java.io.IOException JavaDoc
44     {
45     }
46
47     /**
48      * Adds the connection to the I/O thread's incoming queue.
49      */

50     public void started(IConnectionInfo c)
51         throws IOException
52     {
53         addConnection((ConnectionInfo)c);
54     }
55
56     /**
57      * Registers the connection with the I/o threads. <P>
58      *
59      * JP note 1/20/04: It is <B>HIGHLY</b> important
60      * to register the write thread prior to registering the read thread. Otherwise,
61      * it is possible to run into situations where the write end is not prepared to respond to
62      * incoming messages that are already in the connection buffer at the time of registration.<P>
63      */

64     public void addConnection(ConnectionInfo conn)
65         throws IOException
66     {
67         write.register(conn, true);
68         read.register(conn, true);
69     }
70 }
71
72
Popular Tags