1 24 package org.objectweb.joram.mom.proxies.tcp; 25 26 import java.io.*; 27 import java.net.*; 28 29 import org.objectweb.joram.mom.proxies.*; 30 import org.objectweb.joram.shared.client.MomExceptionReply; 31 32 import fr.dyade.aaa.util.*; 33 34 import org.objectweb.joram.shared.JoramTracing; 35 import org.objectweb.util.monolog.api.BasicLevel; 36 37 42 public class TcpWriter extends Daemon { 43 44 48 private TcpConnection tcpConnection; 49 50 private IOControl ioctrl; 51 52 private AckedQueue replyQueue; 53 54 62 public TcpWriter(IOControl ioctrl, 63 AckedQueue replyQueue, 64 TcpConnection tcpConnection) 65 throws IOException { 66 super("tcpWriter"); 67 this.ioctrl = ioctrl; 68 this.replyQueue = replyQueue; 69 this.tcpConnection = tcpConnection; 70 replyQueue.reset(); 71 } 72 73 public void run() { 74 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.DEBUG)) 75 JoramTracing.dbgProxy.log(BasicLevel.DEBUG, "TcpWriter.run()"); 76 try { 77 while (running) { 78 ProxyMessage msg = 79 (ProxyMessage)replyQueue.get(); 80 if ((msg.getObject() instanceof MomExceptionReply) && 81 (((MomExceptionReply) msg.getObject()).getType() == MomExceptionReply.HBCloseConnection)) { 82 new Thread (new Runnable () { 86 public void run() { 87 tcpConnection.close(); 88 } 89 }).start(); 90 } else { 91 ioctrl.send(msg); 92 } 95 } 96 } catch (Exception exc) { 97 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.DEBUG)) 98 JoramTracing.dbgProxy.log( 99 BasicLevel.DEBUG, "", exc); 100 } 101 } 102 103 protected void shutdown() { 104 close(); 105 } 106 107 protected void close() { 108 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.DEBUG)) 109 JoramTracing.dbgProxy.log( 110 BasicLevel.DEBUG, 111 "TcpWriter.close()", new Exception ()); 112 if (ioctrl != null) 113 ioctrl.close(); 114 ioctrl = null; 115 } 116 } 117 | Popular Tags |