1 4 package com.tc.server; 5 6 import org.mortbay.jetty.bio.SocketConnector; 7 8 import java.io.IOException ; 9 import java.io.InputStream ; 10 import java.io.OutputStream ; 11 import java.io.PushbackInputStream ; 12 import java.net.InetAddress ; 13 import java.net.Socket ; 14 import java.net.SocketAddress ; 15 import java.net.SocketException ; 16 import java.nio.channels.SocketChannel ; 17 18 21 public class TerracottaConnector extends SocketConnector { 22 private boolean shutdown = false; 23 24 public void shutdown() { 25 synchronized (this) { 26 shutdown = true; 27 notifyAll(); 28 } 29 } 30 31 public void handleSocketFromDSO(Socket s, byte[] data) throws InterruptedException , IOException { 32 Connection connection = new Connection(new SocketWrapper(s, data)); 33 connection.dispatch(); 34 } 35 36 public void open() { 37 } 39 40 public void accept(int acceptorID) throws InterruptedException { 41 synchronized (this) { 43 while (!shutdown) { 44 wait(); 45 } 46 } 47 } 48 49 52 private static class SocketWrapper extends Socket { 53 54 private final byte[] data; 55 private final Socket s; 56 57 public SocketWrapper(Socket s, byte[] data) { 58 this.s = s; 59 this.data = data; 60 } 61 62 public void bind(SocketAddress bindpoint) throws IOException { 63 s.bind(bindpoint); 64 } 65 66 public void close() throws IOException { 67 s.close(); 68 } 69 70 public void connect(SocketAddress endpoint, int timeout) throws IOException { 71 s.connect(endpoint, timeout); 72 } 73 74 public void connect(SocketAddress endpoint) throws IOException { 75 s.connect(endpoint); 76 } 77 78 public boolean equals(Object obj) { 79 return s.equals(obj); 80 } 81 82 public SocketChannel getChannel() { 83 return s.getChannel(); 84 } 85 86 public InetAddress getInetAddress() { 87 return s.getInetAddress(); 88 } 89 90 public InputStream getInputStream() throws IOException { 91 PushbackInputStream pis = new PushbackInputStream (s.getInputStream(), data.length); 92 pis.unread(data); 93 return pis; 94 } 95 96 public boolean getKeepAlive() throws SocketException { 97 return s.getKeepAlive(); 98 } 99 100 public InetAddress getLocalAddress() { 101 return s.getLocalAddress(); 102 } 103 104 public int getLocalPort() { 105 return s.getLocalPort(); 106 } 107 108 public SocketAddress getLocalSocketAddress() { 109 return s.getLocalSocketAddress(); 110 } 111 112 public boolean getOOBInline() throws SocketException { 113 return s.getOOBInline(); 114 } 115 116 public OutputStream getOutputStream() throws IOException { 117 return s.getOutputStream(); 118 } 119 120 public int getPort() { 121 return s.getPort(); 122 } 123 124 public int getReceiveBufferSize() throws SocketException { 125 return s.getReceiveBufferSize(); 126 } 127 128 public SocketAddress getRemoteSocketAddress() { 129 return s.getRemoteSocketAddress(); 130 } 131 132 public boolean getReuseAddress() throws SocketException { 133 return s.getReuseAddress(); 134 } 135 136 public int getSendBufferSize() throws SocketException { 137 return s.getSendBufferSize(); 138 } 139 140 public int getSoLinger() throws SocketException { 141 return s.getSoLinger(); 142 } 143 144 public int getSoTimeout() throws SocketException { 145 return s.getSoTimeout(); 146 } 147 148 public boolean getTcpNoDelay() throws SocketException { 149 return s.getTcpNoDelay(); 150 } 151 152 public int getTrafficClass() throws SocketException { 153 return s.getTrafficClass(); 154 } 155 156 public int hashCode() { 157 return s.hashCode(); 158 } 159 160 public boolean isBound() { 161 return s.isBound(); 162 } 163 164 public boolean isClosed() { 165 return s.isClosed(); 166 } 167 168 public boolean isConnected() { 169 return s.isConnected(); 170 } 171 172 public boolean isInputShutdown() { 173 return s.isInputShutdown(); 174 } 175 176 public boolean isOutputShutdown() { 177 return s.isOutputShutdown(); 178 } 179 180 public void sendUrgentData(int d) throws IOException { 181 s.sendUrgentData(d); 182 } 183 184 public void setKeepAlive(boolean on) throws SocketException { 185 s.setKeepAlive(on); 186 } 187 188 public void setOOBInline(boolean on) throws SocketException { 189 s.setOOBInline(on); 190 } 191 192 196 public void setReceiveBufferSize(int size) throws SocketException { 197 s.setReceiveBufferSize(size); 198 } 199 200 public void setReuseAddress(boolean on) throws SocketException { 201 s.setReuseAddress(on); 202 } 203 204 public void setSendBufferSize(int size) throws SocketException { 205 s.setSendBufferSize(size); 206 } 207 208 public void setSoLinger(boolean on, int linger) throws SocketException { 209 s.setSoLinger(on, linger); 210 } 211 212 public void setSoTimeout(int timeout) throws SocketException { 213 s.setSoTimeout(timeout); 214 } 215 216 public void setTcpNoDelay(boolean on) throws SocketException { 217 s.setTcpNoDelay(on); 218 } 219 220 public void setTrafficClass(int tc) throws SocketException { 221 s.setTrafficClass(tc); 222 } 223 224 public void shutdownInput() throws IOException { 225 s.shutdownInput(); 226 } 227 228 public void shutdownOutput() throws IOException { 229 s.shutdownOutput(); 230 } 231 232 public String toString() { 233 return s.toString(); 234 } 235 236 } 237 238 } 239 | Popular Tags |