クラス org.objectweb.cjdbc.controller.core.ControllerServerThread

org.objectweb.cjdbc.controller.core.ControllerServerThreadのコラボレーション図

Collaboration graph
[凡例]
すべてのメンバ一覧

説明

A ControllerServerThread listens for C-JDBC driver connections. It accepts the connection and give them to ControllerWorkerThreads.

参照:
org.objectweb.cjdbc.controller.core.ControllerWorkerThread
作者:
Emmanuel Cecchet

Duncan Smith

バージョン:
1.0

ControllerServerThread.java51 行で定義されています。

Public メソッド

 ControllerServerThread (Controller controller)
void run ()
void shutdown ()
int getControllerServerThreadPendingQueueSize ()
int getIdleWorkerThreads ()
boolean isShuttingDown ()

Protected 変数

Controller controller
ArrayList controllerServerThreadPendingQueue = new ArrayList()
int idleWorkerThreads = 0

スタティック変数

Trace logger

Private 変数

ServerSocket serverSocket
boolean isKilled = false
boolean isShuttingDown = false

Static Private 変数

final SecurityException BLOCKED


コンストラクタとデストラクタ

org.objectweb.cjdbc.controller.core.ControllerServerThread.ControllerServerThread Controller  controller  ) 
 

Creates a new ControllerServerThread that listens on the given port.

引数:
controller The controller which created this thread.
ControllerServerThread.java77 行で定義されています。

参照先 org.objectweb.cjdbc.controller.core.Controller.endOfController(), org.objectweb.cjdbc.controller.core.Controller.getBacklogSize(), org.objectweb.cjdbc.controller.core.Controller.getIPAddress(), org.objectweb.cjdbc.controller.core.Controller.getPortNumber(), org.objectweb.cjdbc.controller.core.Controller.getSecurity(), org.objectweb.cjdbc.controller.core.security.ControllerSecurityManager.getSslConfig(), org.objectweb.cjdbc.controller.core.Controller.isSecurityEnabled(), org.objectweb.cjdbc.controller.core.security.ControllerSecurityManager.isSSLEnabled(), org.objectweb.cjdbc.controller.core.ControllerServerThread.logger, と org.objectweb.cjdbc.controller.core.ControllerServerThread.serverSocket.

00078 { 00079 super("ControllerServerThread"); 00080 this.controller = controller; 00081 00082 try 00083 { 00084 00085 InetAddress bindAddress = InetAddress 00086 .getByName(controller.getIPAddress()); 00087 00088 // Determine if a specific IP address has been requested. 00089 if (!controller.getIPAddress().equals(ControllerConstants.DEFAULT_IP)) 00090 { 00091 00092 // Yes, an IP has been specified that is not localhost... 00093 00094 // Build an InetAddress by passing the requested IP address to the 00095 // InetAddress class constructor. This will validate the sanity of the 00096 // IP by either accepting the requested value or throwing a 00097 // BindException. 00098 if (controller.isSecurityEnabled() 00099 && controller.getSecurity().isSSLEnabled()) 00100 { 00101 ServerSocketFactory sslFact = SocketFactoryFactory 00102 .createServerFactory(controller.getSecurity().getSslConfig()); 00103 serverSocket = sslFact.createServerSocket(controller.getPortNumber(), 00104 controller.getBacklogSize(), bindAddress); 00105 } 00106 else 00107 { 00108 serverSocket = new ServerSocket(controller.getPortNumber(), 00109 controller.getBacklogSize(), bindAddress); 00110 } 00111 } 00112 else 00113 { 00114 00115 // No, an IP was not requested or was left as the default. Create a 00116 // basic local socket. 00117 00118 if (controller.isSecurityEnabled() 00119 && controller.getSecurity().isSSLEnabled()) 00120 { 00121 ServerSocketFactory sslFact = SocketFactoryFactory 00122 .createServerFactory(controller.getSecurity().getSslConfig()); 00123 serverSocket = sslFact.createServerSocket(controller.getPortNumber(), 00124 controller.getBacklogSize()); 00125 } 00126 else 00127 { 00128 serverSocket = new ServerSocket(controller.getPortNumber(), 00129 controller.getBacklogSize()); 00130 } 00131 } 00132 00133 } 00134 catch (java.net.BindException e) 00135 { 00136 00137 // Thrown if an illegal IP address was specified. 00138 logger.fatal(Translate.get("controller.server.thread.illegal.ip", 00139 new String[]{controller.getIPAddress(), e.getMessage()})); 00140 controller.endOfController(e); 00141 } 00142 catch (IOException e) 00143 { 00144 logger.fatal(Translate.get("controller.server.thread.socket.failed", 00145 controller.getPortNumber() + "")); 00146 controller.endOfController(e); 00147 } 00148 catch (SSLException e) 00149 { 00150 logger.fatal(Translate.get("controller.server.thread.socket.failed", 00151 controller.getPortNumber() + "")); 00152 controller.endOfController(e); 00153 } 00154 if (logger.isInfoEnabled()) 00155 { 00156 logger.info(Translate.get("controller.server.thread.waiting.connections", 00157 new String[]{serverSocket.getInetAddress().getHostAddress(), 00158 String.valueOf(serverSocket.getLocalPort())})); 00159 logger.debug(Translate.get("controller.server.thread.backlog.size", "" 00160 + controller.getBacklogSize())); 00161 } 00162 }


メソッド

int org.objectweb.cjdbc.controller.core.ControllerServerThread.getControllerServerThreadPendingQueueSize  ) 
 

戻り値:
Returns the controllerServerThreadPendingQueue size.
ControllerServerThread.java292 行で定義されています。
00293 { 00294 synchronized (controllerServerThreadPendingQueue) 00295 { 00296 return controllerServerThreadPendingQueue.size(); 00297 } 00298 }

int org.objectweb.cjdbc.controller.core.ControllerServerThread.getIdleWorkerThreads  ) 
 

戻り値:
Returns the idleWorkerThreads.
ControllerServerThread.java303 行で定義されています。
00304 { 00305 synchronized (controllerServerThreadPendingQueue) 00306 { 00307 return idleWorkerThreads; 00308 } 00309 }

boolean org.objectweb.cjdbc.controller.core.ControllerServerThread.isShuttingDown  ) 
 

Returns the isShuttingDown value.

戻り値:
Returns the isShuttingDown.
ControllerServerThread.java316 行で定義されています。
00317 { 00318 return isShuttingDown; 00319 }

void org.objectweb.cjdbc.controller.core.ControllerServerThread.run  ) 
 

Accepts connections from drivers, read the virtual database name and returns the connection point. ControllerServerThread.java168 行で定義されています。

参照先 org.objectweb.cjdbc.common.stream.CJDBCOutputStream.flush(), と org.objectweb.cjdbc.common.stream.CJDBCOutputStream.writeObject().

00169 { 00170 if (controller == null) 00171 { 00172 logger.error(Translate.get("controller.server.thread.controller.null")); 00173 isKilled = true; 00174 } 00175 00176 Socket clientSocket = null; 00177 while (!isKilled && !isShuttingDown) 00178 { 00179 try 00180 { 00181 // Accept a connection 00182 clientSocket = serverSocket.accept(); 00183 if (isKilled || isShuttingDown) 00184 break; 00185 if (controller.isSecurityEnabled() 00186 && !controller.getSecurity().allowConnection(clientSocket)) 00187 { 00188 logger.warn(Translate.get( 00189 "controller.server.thread.connection.refused", clientSocket 00190 .getInetAddress().getHostName())); 00191 CJDBCOutputStream out = new CJDBCOutputStream(clientSocket); 00192 out.writeObject(BLOCKED); 00193 out.flush(); 00194 clientSocket = null; 00195 continue; 00196 } 00197 else 00198 { 00199 if (logger.isDebugEnabled()) 00200 logger.debug(Translate.get( 00201 "controller.server.thread.connection.accept", clientSocket 00202 .getInetAddress().getHostName())); 00203 } 00204 boolean createThread = false; 00205 if (isKilled || isShuttingDown) 00206 break; 00207 synchronized (controllerServerThreadPendingQueue) 00208 { 00209 // Add the connection to the queue 00210 controllerServerThreadPendingQueue.add(clientSocket); 00211 // Check if we need to create a new thread or just wake up an 00212 // existing one 00213 if (idleWorkerThreads == 0) 00214 createThread = true; 00215 else 00216 // Here we notify all threads else if one thread doesn't wake up 00217 // after the first notify() we will send a second notify() and 00218 // one signal will be lost. So the safe way is to wake up everybody 00219 // and that worker threads go back to sleep if there is no job. 00220 controllerServerThreadPendingQueue.notifyAll(); 00221 } 00222 if (createThread) 00223 { // Start a new worker thread if needed 00224 ControllerWorkerThread thread = new ControllerWorkerThread(this); 00225 thread.start(); 00226 if (logger.isDebugEnabled()) 00227 logger.debug(Translate.get("controller.server.thread.starting")); 00228 } 00229 } 00230 catch (IOException e) 00231 { 00232 if (!isShuttingDown) 00233 { 00234 logger.warn(Translate.get( 00235 "controller.server.thread.new.connection.error", e),e); 00236 } 00237 } 00238 } 00239 if (logger.isInfoEnabled()) 00240 logger.info(Translate.get("controller.server.thread.terminating")); 00241 }

void org.objectweb.cjdbc.controller.core.ControllerServerThread.shutdown  ) 
 

Refuse new connection to clients and finish transaction ControllerServerThread.java246 行で定義されています。

参照元 org.objectweb.cjdbc.controller.core.shutdown.ControllerShutdownThread.shutdownServerConnectionThread().

00247 { 00248 isShuttingDown = true; 00249 // Shutting down server thread 00250 try 00251 { 00252 serverSocket.close(); 00253 } 00254 catch (Exception e) 00255 { 00256 logger.warn(Translate.get("controller.shutdown.server.socket.exception"), 00257 e); 00258 } 00259 int nbSockets = controllerServerThreadPendingQueue.size(); 00260 Socket socket = null; 00261 for (int i = 0; i < nbSockets; i++) 00262 { 00263 socket = (Socket) controllerServerThreadPendingQueue.get(i); 00264 logger.info(Translate.get("controller.shutdown.client.socket", socket 00265 .getInetAddress().toString())); 00266 // try 00267 // { 00268 // // This is not a key part of shutting down. We don't want to accept any 00269 // // connection and we are blocking connections that have not started 00270 // // transactions 00271 // CJDBCOutputStream out = new 00272 // CJDBCOutputStream(socket.getOutputStream()); 00273 // out.writeObject(new SQLException(Translate 00274 // .get("controller.shutdown.server.is.shutting.down"))); 00275 // out.flush(); 00276 // socket.shutdownInput(); 00277 // socket.shutdownOutput(); 00278 // socket.close(); 00279 // } 00280 // catch (Exception e) 00281 // { 00282 // // logger.warn(Translate 00283 // // .get("controller.shutdown.server.socket.exception"), e); 00284 // } 00285 } 00286 this.controllerServerThreadPendingQueue = null; 00287 }


変数

final SecurityException org.objectweb.cjdbc.controller.core.ControllerServerThread.BLOCKED [static, private]
 

初期値:

new SecurityException( Translate .get("controller.server.thread.security.connection.refused"))
ControllerServerThread.java54 行で定義されています。

Controller org.objectweb.cjdbc.controller.core.ControllerServerThread.controller [protected]
 

ControllerServerThread.java59 行で定義されています。

参照元 org.objectweb.cjdbc.controller.core.ControllerWorkerThread.run().

ArrayList org.objectweb.cjdbc.controller.core.ControllerServerThread.controllerServerThreadPendingQueue = new ArrayList() [protected]
 

Pending queue of client (driver) socket connections ControllerServerThread.java61 行で定義されています。

参照元 org.objectweb.cjdbc.controller.core.ControllerWorkerThread.run().

int org.objectweb.cjdbc.controller.core.ControllerServerThread.idleWorkerThreads = 0 [protected]
 

Number of idle ControllerWorkerThread. Access to this variable must be synchronized using pendingQueue. ControllerServerThread.java66 行で定義されています。

参照元 org.objectweb.cjdbc.controller.core.ControllerWorkerThread.run().

boolean org.objectweb.cjdbc.controller.core.ControllerServerThread.isKilled = false [private]
 

ControllerServerThread.java57 行で定義されています。

boolean org.objectweb.cjdbc.controller.core.ControllerServerThread.isShuttingDown = false [private]
 

ControllerServerThread.java58 行で定義されています。

参照元 org.objectweb.cjdbc.controller.core.ControllerWorkerThread.run(), と org.objectweb.cjdbc.controller.core.shutdown.ControllerShutdownThread.shutdownServerConnectionThread().

Trace org.objectweb.cjdbc.controller.core.ControllerServerThread.logger [static, package]
 

初期値:

Trace .getLogger("org.objectweb.cjdbc.controller.core.Controller")
Logger instance. ControllerServerThread.java69 行で定義されています。

参照元 org.objectweb.cjdbc.controller.core.ControllerServerThread.ControllerServerThread().

ServerSocket org.objectweb.cjdbc.controller.core.ControllerServerThread.serverSocket [private]
 

ControllerServerThread.java53 行で定義されています。

参照元 org.objectweb.cjdbc.controller.core.ControllerServerThread.ControllerServerThread().


このクラスの説明は次のファイルから生成されました:
CJDBCversion1.0.4に対してTue Oct 12 15:16:41 2004に生成されました。 doxygen 1.3.8