KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > drda > ClientThread


1 /*
2
3    Derby - Class org.apache.derby.impl.drda.ClientThread
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.drda;
23
24 import java.io.*;
25 import java.net.*;
26 import java.security.*;
27
28 final class ClientThread extends Thread JavaDoc {
29
30     NetworkServerControlImpl parent;
31     ServerSocket serverSocket;
32     private int timeSlice;
33     private int connNum;
34
35         ClientThread (NetworkServerControlImpl nsi, ServerSocket ss) {
36
37             // Create a more meaningful name for this thread (but preserve its
38
// thread id from the default name).
39
NetworkServerControlImpl.setUniqueThreadName(this, "NetworkServerThread");
40
41             parent=nsi;
42             serverSocket=ss;
43             timeSlice=nsi.getTimeSlice();
44         }
45             
46         public void run()
47         {
48
49             Socket clientSocket = null;
50
51
52             for (;;)
53             {
54                 try {
55                     try{
56                             clientSocket = (Socket) AccessController.doPrivileged(
57                         new PrivilegedExceptionAction() {
58                             public Object JavaDoc run() throws IOException
59                             {
60                                 return serverSocket.accept();
61                             }
62                         }
63                      );
64                             clientSocket.setKeepAlive(parent.getKeepAlive());
65                     //set time out
66
//this looks highly suspect. Why does timeSlice setSoTimeout?
67
if (timeSlice != 0)
68                         clientSocket.setSoTimeout(timeSlice);
69                 } catch (PrivilegedActionException e) {
70                     Exception JavaDoc e1 = e.getException();
71                             if (e1 instanceof IOException){
72                         synchronized(parent.getShutdownSync()) {
73                             if (!parent.getShutdown())
74                                         parent.consolePropertyMessage("DRDA_UnableToAccept.S");
75                             }
76                     } else throw e1;
77                             break;
78                 } // end priv try/catch block
79

80                 //create a new Session for this session
81
parent.addSession(clientSocket);
82
83                 }catch (Exception JavaDoc e) {
84                     if (e instanceof InterruptedException JavaDoc)
85                         return;
86                     parent.consoleExceptionPrintTrace(e);
87                 } // end outer try/catch block
88
} // end for(;;)
89

90         }// end run()
91
}
92
93
94
95
96
97
98
99
Popular Tags