1 22 package org.objectweb.joram.mom.proxies.tcp; 23 24 import org.objectweb.joram.mom.proxies.*; 25 26 import java.net.*; 27 import java.io.*; 28 29 import org.objectweb.joram.shared.JoramTracing; 30 31 import org.objectweb.util.monolog.api.BasicLevel; 32 33 import fr.dyade.aaa.agent.AgentId; 34 35 45 public class TcpConnection { 46 47 private IOControl ioctrl; 48 49 private AgentId proxyId; 50 51 private int key; 52 53 private AckedQueue replyQueue; 54 55 59 private TcpReader tcpReader; 60 61 65 private TcpWriter tcpWriter; 66 67 71 private TcpProxyService proxyService; 72 73 private boolean closeConnection; 74 75 81 public TcpConnection( 82 IOControl ioctrl, 83 AgentId proxyId, 84 AckedQueue replyQueue, 85 int key, 86 TcpProxyService proxyService, 87 boolean closeConnection) { 88 this.ioctrl = ioctrl; 89 this.proxyId = proxyId; 90 this.replyQueue = replyQueue; 91 this.key = key; 92 this.proxyService = proxyService; 93 this.closeConnection = closeConnection; 94 } 95 96 public final AgentId getProxyId() { 97 return proxyId; 98 } 99 100 public final int getKey() { 101 return key; 102 } 103 104 107 void start() throws Exception { 108 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.DEBUG)) 109 JoramTracing.dbgProxy.log( 110 BasicLevel.DEBUG, 111 "TcpConnection.start()"); 112 try { 113 tcpWriter = new TcpWriter( 114 ioctrl, 115 replyQueue, 116 this); 117 tcpReader = new TcpReader( 118 ioctrl, 119 proxyId, 120 this, 121 closeConnection); 122 proxyService.registerConnection(this); 123 tcpWriter.start(); 124 tcpReader.start(); 125 } catch (Exception exc) { 126 close(); 127 throw exc; 128 } 129 } 130 131 136 void close() { 137 if (tcpWriter != null) 138 tcpWriter.stop(); 139 if (tcpReader != null) 140 tcpReader.stop(); 141 if (ioctrl != null) 142 ioctrl.close(); 143 ioctrl = null; 144 proxyService.unregisterConnection( 145 TcpConnection.this); 146 } 147 148 } 149 | Popular Tags |