KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ubermq > kernel > PipeConnectionInfo


1 package com.ubermq.kernel;
2
3 import java.nio.*;
4 import java.nio.channels.*;
5 import java.nio.charset.Charset JavaDoc;
6
7
8 /**
9  * An extension of the ConnectionInfo class encapsulating
10  * information about a Pipe.<P>
11  *
12  * This implementation uses a Pipe's source and sink for input and
13  * output, respectively.
14  *
15  */

16 public class PipeConnectionInfo
17     extends ConnectionInfo
18 {
19     private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(PipeConnectionInfo.class);
20     private IConnectionInfo originalConnection;
21     
22     /**
23      * Creates a pipe connection record object that
24      * reads from the given Pipe.SourceChannel and writes to a
25      * Pipe.SinkChannel. These will generally not be channels
26      * on the same Pipe object.
27      * <P>
28      * A typical implementation uses two pipes to form a bidirectional pipe
29      * with client on one end and server on the other.
30      * <P>
31      * @param in the source channel to read from.
32      * @param out the sink channel to write to.
33      */

34     public PipeConnectionInfo(Pipe.SourceChannel in,
35                               Pipe.SinkChannel out,
36                               IDatagramFactory f,
37                               IMessageProcessor proc)
38     {
39         super(proc, f);
40         attach(in, out);
41     }
42     
43     /**
44      * Certain pipe connections are internal proxies for external socket connections.
45      * If this is the case for this pipe connection, the original connection info
46      * can be stored here for retrieval.
47      * <P>
48      *
49      * @return the original connection info if this pipe is a proxy for a real physical
50      * connection, or null if this pipe does not represent another connection.
51      */

52     public IConnectionInfo getOriginalConnection()
53     {
54         return originalConnection;
55     }
56     
57     /**
58      * Sets original connection information, if this pipe connection represents
59      * an actual physical connection from elsewhere.
60      * <P>
61      *
62      * @param originalConnection the original connection info
63      */

64     public void setOriginalConnection(IConnectionInfo originalConnection)
65     {
66         this.originalConnection = originalConnection;
67     }
68     
69     public String JavaDoc toString()
70     {
71         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("Pipe ");
72         sb.append(super.getId());
73         if (originalConnection != null)
74         {
75             sb.append(" representing ");
76             sb.append(originalConnection.toString());
77         }
78         
79         return sb.toString();
80     }
81
82     public void close()
83     {
84         super.close();
85         try
86         {
87             out().close();
88             in().close();
89         }
90         catch (java.io.IOException JavaDoc e)
91         {
92             log.debug("", e);
93         }
94     }
95 }
96
Popular Tags