1 7 package org.jboss.remoting.transport.socket; 8 9 import java.io.BufferedInputStream ; 10 import java.io.BufferedOutputStream ; 11 import java.io.EOFException ; 12 import java.io.IOException ; 13 import java.io.ObjectInputStream ; 14 import java.io.ObjectOutputStream ; 15 import java.net.Socket ; 16 import org.jboss.logging.Logger; 17 18 21 public class ServerSocketWrapper extends ClientSocketWrapper 22 { 23 final static private Logger log = Logger.getLogger(ServerSocketWrapper.class); 24 25 public ServerSocketWrapper(Socket socket) throws Exception 26 { 27 super(socket); 28 } 29 30 protected ObjectInputStream createInputStream(Socket socket) throws IOException 31 { 32 BufferedInputStream bin = new BufferedInputStream (socket.getInputStream()); 33 ObjectInputStream oin = new ObjectInputStream (bin); 34 return oin; 35 } 36 37 protected ObjectOutputStream createOutputStream(Socket socket) 38 throws IOException 39 { 40 BufferedOutputStream bout = new BufferedOutputStream (socket.getOutputStream()); 41 ObjectOutputStream oout = new ObjectOutputStream (bout); 42 oout.flush(); 43 return oout; 44 } 45 46 public void checkConnection() throws IOException 47 { 48 byte ACK = 0; 51 long startWait = System.currentTimeMillis(); 52 try 53 { 54 ACK = ((ObjectInputStream ) getInputStream()).readByte(); 55 } 56 catch(EOFException eof) 57 { 58 if(log.isTraceEnabled()) 59 { 60 log.trace("socket timeout is set to : " + getTimeout()); 61 log.trace("EOFException waiting on ACK in readByte(). Time waited was " + (System.currentTimeMillis() - startWait)); 62 } 63 throw eof; 64 } 65 catch(IOException e) 66 { 67 log.trace("IOException when reading in ACK", e); 68 throw e; 69 } 70 71 if(log.isTraceEnabled()) 72 { 73 log.trace("***acknowledge read byte" + Thread.currentThread()); 74 } 75 76 ObjectOutputStream out = (ObjectOutputStream ) getOutputStream(); 77 out.writeByte(ACK); 78 out.flush(); 79 out.reset(); 80 } 81 } 82 83 | Popular Tags |