KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.ubermq.kernel;
2
3 import java.net.*;
4 import java.nio.channels.*;
5 import sun.security.krb5.internal.crypto.*;
6
7
8 /**
9  * An extension of the ConnectionInfo class encapsulating
10  * information about a set of I/O channels. <P>
11  *
12  * This implementation uses a SocketChannel for both input and
13  * output.
14  *
15  */

16 public class SocketChannelConnectionInfo
17     extends ConnectionInfo
18     implements SocketConnectionInfo
19 {
20     private SocketChannel sc;
21     private String JavaDoc remote;
22
23     public SocketChannelConnectionInfo(SocketChannel channel,
24                                 IDatagramFactory f,
25                                 IMessageProcessor proc)
26     {
27         super(proc, f);
28         this.sc = channel;
29         attach(sc, sc);
30
31         // get the remote address
32
this.remote = sc.socket().getRemoteSocketAddress().toString();
33     }
34     
35     public Socket getSocket()
36     {
37         return getSocketChannel().socket();
38     }
39     
40     public SocketChannel getSocketChannel()
41     {
42         return sc;
43     }
44
45     public String JavaDoc toString()
46     {
47         return super.getId() + "[remote=" + remote + "]";
48     }
49
50     public void close()
51     {
52         super.close();
53         try
54         {
55             sc.socket().shutdownOutput();
56             sc.socket().shutdownInput();
57             sc.socket().close();
58         }
59         catch (java.io.IOException JavaDoc e) {/*we are closing anyway*/}
60     }
61 }
62
Popular Tags