home *** CD-ROM | disk | FTP | other *** search
- package com.everyware.tango.jas;
-
- import java.io.IOException;
- import java.io.InterruptedIOException;
- import java.net.InetAddress;
- import java.net.ServerSocket;
- import java.net.SocketException;
- import java.net.UnknownHostException;
-
- public class ConnectionManager extends Thread {
- private JAS jas;
- private ThreadManager threadManager;
- private ServerSocket serverSocket;
-
- public ConnectionManager(JAS var1, ThreadManager var2) {
- this.jas = var1;
- this.threadManager = var2;
- if (var1.isTracing) {
- var1.traceM.trace("CM: Attempting to create server socket");
- }
-
- try {
- this.createServerSocket();
- } catch (Exception var3) {
- if (var1.isTracing) {
- var1.traceM.trace("CM: Could not create server socket");
- }
-
- var1.finalize();
- }
- }
-
- public void run() {
- while(true) {
- if (!this.threadManager.hasFreeResources()) {
- if (this.jas.isTracing) {
- this.jas.traceM.trace("CM: TM has no free resources, releasing control...");
- }
-
- try {
- Thread.sleep(5L);
- } catch (InterruptedException var2) {
- }
- } else {
- try {
- if (this.jas.isTracing) {
- this.jas.traceM.trace("CM: Waiting for new requests");
- }
-
- this.threadManager.newRequest(this.serverSocket.accept());
- if (this.jas.isTracing) {
- this.jas.traceM.trace("CM: Passed new request to ThreadManager");
- }
- } catch (InterruptedIOException var3) {
- if (this.jas.isTracing) {
- this.jas.traceM.trace("CM: No messages received within required server socket timeout");
- }
-
- this.jas.finalize();
- } catch (IOException var4) {
- if (this.jas.isTracing) {
- this.jas.traceM.trace("CM: IOException caught: " + var4);
- }
- }
- }
- }
- }
-
- private void createServerSocket() throws Exception {
- String var1 = this.jas.getHostName();
-
- try {
- InetAddress var7 = null;
- if (var1 != null) {
- var7 = InetAddress.getByName(var1);
- }
-
- this.serverSocket = new ServerSocket(this.jas.getPort(), this.jas.getMaxNumBacklog(), var7);
- } catch (UnknownHostException var4) {
- String var6 = "CM: Could not obtain address for host " + (var1 == null ? "(null)" : var1);
- if (this.jas.isTracing) {
- this.jas.traceM.trace(var6);
- }
-
- throw new Exception(var6);
- } catch (IOException var5) {
- String var2 = "CM: Could not instantiate server socket";
- if (this.jas.isTracing) {
- this.jas.traceM.trace(var2);
- }
-
- throw new Exception(var2);
- }
-
- try {
- this.serverSocket.setSoTimeout(this.jas.getServerSocketTimeout() * 1000);
- } catch (SocketException var3) {
- String var8 = "CM: Could not set keep server socket timeout duration";
- if (this.jas.isTracing) {
- this.jas.traceM.trace(var8);
- }
-
- throw new Exception(var8);
- }
-
- if (this.jas.isTracing) {
- this.jas.traceM.trace("CM: Server socket ready on hostname " + (var1 == null ? "(null)" : var1) + ", port " + this.jas.getPort() + ", max backlog " + this.jas.getMaxNumBacklog());
- }
-
- }
- }
-