KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > server > ss > provider > ASServerSocketChannel


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.server.ss.provider;
24
25 import java.io.*;
26 import java.net.*;
27 import java.nio.*;
28 import java.nio.channels.*;
29 import java.nio.channels.spi.*;
30
31 import java.util.logging.Logger JavaDoc;
32 import java.util.logging.Level JavaDoc;
33 import com.sun.enterprise.server.ss.ASSocketService;
34 import com.sun.enterprise.server.ss.spi.ASSocketFacadeUtils;
35 import com.sun.logging.LogDomains;
36
37 class ASServerSocketChannel extends ServerSocketChannel implements ASChannel {
38     private static Logger JavaDoc logger = LogDomains.getLogger(LogDomains.CORE_LOGGER);
39
40     private ServerSocketChannel ssc = null;
41     private ServerSocket ssocket = null;
42     private int port = 0;
43
44     ASServerSocketChannel(ServerSocketChannel ssc, SelectorProvider p) {
45         super(p);
46         this.ssc = ssc;
47         // initialize the server port. It may be -1.
48
port = ssc.socket().getLocalPort();
49     }
50
51     public ServerSocket socket() {
52         try {
53             if (ssocket == null) {
54                 ServerSocket ss = ssc.socket();
55                 ssocket = new ASServerSocket(ss, this);
56             }
57         } catch (Exception JavaDoc e ) {
58             throw new RuntimeException JavaDoc(e);
59         }
60         return ssocket;
61     }
62
63     public SocketChannel accept() throws IOException {
64
65     SocketChannel sc = ssc.accept();
66         if ( logger.isLoggable(Level.FINE) ) {
67              Socket s = sc.socket();
68              logger.fine("In ASServerSocketChannel.accept got connection, s.port=" +
69              s.getPort()+" s.localPort="+s.getLocalPort());
70         }
71
72         ASSocketFacadeUtils.getASSocketService().waitOnAccept(sc);
73
74         return sc;
75     }
76
77     public void implConfigureBlocking(boolean b) throws IOException {
78         ssc.configureBlocking(b);
79     }
80
81     /**
82      * This is the place where a serversocket in socket service finally
83      * gets closed.
84      *
85      * Some services [eg. MQ] closes and recreates the serversocket
86      * while starting itself. However this can break, socket service
87      * logic, since the waiting connections can get a "connection reset"
88      * exception.
89      */

90     public void implCloseSelectableChannel() throws IOException {
91         ASSocketFacadeUtils.getASSocketService().close(port, null, ssc);
92     }
93
94
95     public SelectableChannel getActualChannel() {
96         return ssc;
97
98     }
99
100     void setPortNumber(int port) {
101         this.port = port;
102     }
103
104     int getPortNumber() {
105         return this.port;
106     }
107
108     void setServerSocketChannel(ServerSocketChannel ssc) {
109         this.ssc = ssc;
110     }
111
112     // The ORB needs this for logging.
113
public String JavaDoc toString()
114     {
115     return "ASServerSocketChannel[" + ssc.toString() + "]";
116     }
117 }
118
119 // End of file.
120

121
122
Popular Tags