01: /*
02:
03: Derby - Class org.apache.derby.impl.drda.ClientThread
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to You under the Apache License, Version 2.0
09: (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 {
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 ,
40: "NetworkServerThread");
41:
42: parent = nsi;
43: serverSocket = ss;
44: timeSlice = nsi.getTimeSlice();
45: }
46:
47: public void run() {
48:
49: Socket clientSocket = null;
50:
51: for (;;) {
52: try {
53: try {
54: clientSocket = (Socket) AccessController
55: .doPrivileged(new PrivilegedExceptionAction() {
56: public Object run() throws IOException {
57: return serverSocket.accept();
58: }
59: });
60: clientSocket.setKeepAlive(parent.getKeepAlive());
61: //set time out
62: //this looks highly suspect. Why does timeSlice setSoTimeout?
63: if (timeSlice != 0)
64: clientSocket.setSoTimeout(timeSlice);
65: } catch (PrivilegedActionException e) {
66: Exception e1 = e.getException();
67: if (e1 instanceof IOException) {
68: synchronized (parent.getShutdownSync()) {
69: if (!parent.getShutdown())
70: parent
71: .consolePropertyMessage("DRDA_UnableToAccept.S");
72: }
73: } else
74: throw e1;
75: break;
76: } // end priv try/catch block
77:
78: //create a new Session for this session
79: parent.addSession(clientSocket);
80:
81: } catch (Exception e) {
82: if (e instanceof InterruptedException)
83: return;
84: parent.consoleExceptionPrintTrace(e);
85: } // end outer try/catch block
86: } // end for(;;)
87:
88: }// end run()
89: }
|