2
* JBoss, Home of Professional Open Source
3
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* full listing of individual contributors.
7
* This is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this software; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
24
* Created on Jul 22, 2005
27
package org.jboss.remoting.transport.multiplex;
29
import org.jboss.logging.Logger;
31
import java.io.IOException;
32
import java.io.InputStream;
33
import java.io.OutputStream;
34
import java.net.InetAddress;
35
import java.net.InetSocketAddress;
36
import java.net.Socket;
37
import java.net.SocketAddress;
38
import java.net.SocketException;
39
import java.net.SocketImpl;
40
import java.net.SocketTimeoutException;
41
import java.net.UnknownHostException;
42
import java.nio.channels.SocketChannel;
43
import java.util.HashMap;
44
import java.util.HashSet;
45
import java.util.Iterator;
50
* <code>VirtualSocket</code> represents an endpoint on a virtual connection created by the
51
* Multiplex system. It extends <code>java.net.Socket</code> and reimplements nearly all of
52
* the methods in <code>java.net.Socket</code>. For information about method behavior, please
53
* see the <code>java.net.Socket</code> javadoc. For more information about the nature of
54
* virtual sockets, please see the Multiplex documentation at the labs.jboss.org
60
* @author <a href="mailto:r.sigal@computer.org">Ron Sigal</a>
62
* @deprecated As of release 2.4.0 the multiplex transport will no longer be actively supported.
64
public class VirtualSocket extends Socket
66
protected static final Logger log = Logger.getLogger(VirtualSocket.class);
67
protected static Thread closingThread;
69
private Map configuration = new HashMap();
70
private MultiplexingManager manager;
71
private Protocol protocol;
72
private Socket actualSocket;
73
private SocketId remoteSocketId;
74
private SocketId localSocketId;
75
private MultiplexingInputStream inputStream;
76
private MultiplexingOutputStream outputStream;
77
private Set disconnectListeners = new HashSet();
79
private boolean bound = false;
80
private boolean closed = false;
81
private boolean connected = false;
82
private boolean inputShutdown = false;
83
private boolean outputShutdown = false;
84
private boolean receivedDisconnectMessage = false;
87
private Socket dummySocket;
89
private boolean functional = true;
91
private boolean trace;
92
private boolean debug;
97
* A class that implements <code>DisconnectListener</code> can register to
98
* be notified if the remote peer of this <code>VirtualSocket</code> has
101
public interface DisconnectListener
103
void notifyDisconnected(VirtualSocket virtualSocket);
107
public VirtualSocket(MultiplexingManager manager, SocketId remoteSocketId, Map configuration) throws IOException
109
this.manager = manager;
110
this.actualSocket = manager.getSocket();
111
this.remoteSocketId = remoteSocketId;
112
this.configuration.putAll(configuration);
113
protocol = manager.getProtocol();
114
localSocketId = new SocketId();
115
inputStream = manager.registerSocket(this);
116
// outputStream = new MultiplexingOutputStream(manager, this, remoteSocketId);
117
outputStream = manager.getAnOutputStream(this, remoteSocketId);
121
trace = log.isTraceEnabled();
122
debug = log.isDebugEnabled();
123
info = log.isInfoEnabled();
124
if (debug) log.debug("created virtual socket on port: " + localSocketId.getPort());
128
public VirtualSocket(Map configuration)
130
this.configuration.putAll(configuration);
134
//////////////////////////////////////////////////////////////////////////////////////////////////
135
/// The following constructors duplicate those of the parent class Socket '///
136
//////////////////////////////////////////////////////////////////////////////////////////////////
139
* See superclass javadoc.
141
public VirtualSocket()
143
log.debug("created unbound virtual socket");
148
* See superclass javadoc.
150
public VirtualSocket(String host, int port) throws UnknownHostException, IOException
152
InetSocketAddress address = null;
155
address = new InetSocketAddress(InetAddress.getByName(null), port);
157
address = new InetSocketAddress(host, port);
160
if (debug) log.debug("created virtual socket on port: " + localSocketId.getPort());
165
* See superclass javadoc.
169
* @throws java.io.IOException
171
public VirtualSocket(String host, int port, boolean stream) throws IOException
175
throw new SocketException("Deprecated: use DataGramSocket instead of stream = false");
178
InetSocketAddress address = null;
181
address = new InetSocketAddress(InetAddress.getByName(null), port);
183
address = new InetSocketAddress(host, port);
186
if (debug) log.debug("created virtual socket on port: " + localSocketId.getPort());
191
* See superclass javadoc.
194
* @throws java.io.IOException
196
public VirtualSocket(InetAddress address, int port) throws IOException
198
connect(new InetSocketAddress(address, port));
199
if (debug) log.debug("created virtual socket on port: " + localSocketId.getPort());
204
* See superclass javadoc.
208
* @throws java.io.IOException
210
public VirtualSocket(InetAddress host, int port, boolean stream) throws IOException
214
throw new SocketException("Deprecated: use DataGramSocket instead of stream = false");
217
connect(new InetSocketAddress(host, port));
218
if (debug) log.debug("created virtual socket on port: " + localSocketId.getPort());
223
* This constuctor is not implemented.
226
* @throws java.net.SocketException in all cases
228
public VirtualSocket(SocketImpl impl) throws SocketException
230
throw new SocketException("VirtualSocket does not use SocketImpl");
235
* See superclass javadoc.
240
* @throws java.io.IOException
242
public VirtualSocket(String host, int port, InetAddress localAddr, int localPort) throws IOException
244
this(InetAddress.getByName(host), port, localAddr, localPort);
249
* See superclass javadoc.
254
* @throws java.io.IOException
256
public VirtualSocket(InetAddress address, int port, InetAddress localAddr, int localPort) throws IOException
259
connect(new InetSocketAddress(address, port), new InetSocketAddress(localAddr, localPort), 0);
260
if (debug) log.debug("created virtual socket on port: " + localSocketId.getPort());
265
//////////////////////////////////////////////////////////////////////////////////////////////////
266
/// The following methods are required of all Socket's '///
267
//////////////////////////////////////////////////////////////////////////////////////////////////
270
/*************************************************************************************************
271
* public methods in Socket class
273
ok: public void connect(SocketAddress endpoint) throws IOException;
274
ok: public void connect(SocketAddress endpoint, int timeout) throws IOException;
275
ok: public void bind(SocketAddress bindpoint) throws IOException;
276
ok: public InetAddress getInetAddress();
277
ok: public InetAddress getLocalAddress();
278
ok: public int getPort();
279
ok: public int getLocalPort();
280
ok: public SocketAddress getRemoteSocketAddress();
281
ok: public SocketAddress getLocalSocketAddress();
282
ok: public SocketChannel getChannel();
283
ok: public InputStream getInputStream() throws IOException;
284
ok: public OutputStream getOutputStream() throws IOException;
285
ok: public void setTcpNoDelay(boolean on) throws SocketException;
286
ok: public boolean getTcpNoDelay() throws SocketException;
287
ok: public void setSoLinger(boolean on, int linger) throws SocketException;
288
ok: public int getSoLinger() throws SocketException;
289
ok: public void sendUrgentData(int data) throws IOException;
290
ok: public void setOOBInline(boolean on) throws SocketException;
291
ok: public boolean getOOBInline() throws SocketException;
292
ok: public void setSoTimeout(int timeout) throws SocketException;
293
ok: public int getSoTimeout() throws SocketException;
294
ok: public void setSendBufferSize(int size) throws SocketException;
295
ok: public int getSendBufferSize() throws SocketException;
296
ok: public void setReceiveBufferSize(int size) throws SocketException;
297
ok: public int getReceiveBufferSize() throws SocketException;
298
ok: public void setKeepAlive(boolean on) throws SocketException;
299
ok: public boolean getKeepAlive() throws SocketException;
300
ok: public void setTrafficClass(int tc) throws SocketException;
301
ok: public int getTrafficClass() throws SocketException;
302
ok: public void setReuseAddress(boolean on) throws SocketException;
303
ok: public boolean getReuseAddress() throws SocketException;
304
ok: public void close() throws IOException;
305
ok: public void shutdownInput() throws IOException;
306
ok: public void shutdownOutput() throws IOException;
307
ok: public String toString();
308
ok: public boolean isConnected();
309
ok: public boolean isBound();
310
ok: public boolean isClosed();
311
ok: public boolean isInputShutdown();
312
ok: public boolean isOutputShutdown();
313
*************************************************************************************************/
317
* See superclass javadoc.
319
public void bind(SocketAddress address) throws IOException
322
throw new SocketException("Socket is closed");
325
throw new SocketException("Already bound");
327
if (address != null && (!(address instanceof InetSocketAddress)))
328
throw new IllegalArgumentException("Unsupported address type");
330
InetSocketAddress inetAddress = (InetSocketAddress) address;
332
if (inetAddress != null && inetAddress.isUnresolved())
333
throw new SocketException("Unresolved address");
335
manager = MultiplexingManager.getaManagerByLocalAddress(inetAddress, configuration);
336
actualSocket = manager.getSocket();
337
localSocketId = new SocketId();
338
if (debug) log.debug("bound virtual socket to port: " + localSocketId.getPort());
344
* See superclass javadoc.
346
public void close() throws IOException
351
log.debug("closing: " + localSocketId);
354
if (connected && !receivedDisconnectMessage)
355
protocol.disconnect(remoteSocketId);
357
if (inputStream != null)
360
if (outputStream != null)
362
outputStream.flush();
363
outputStream.close();
366
if (localSocketId != null)
367
localSocketId.releasePort();
369
// This VirtualSocket might have been unregistered when connect() failed.
370
if (manager.isSocketRegistered(this.localSocketId))
372
MultiplexingManager.addToPendingActions(new PendingClose(this));
375
if (debug) log.debug("virtual socket closed on port: " + localSocketId.getPort());
380
* See superclass javadoc.
382
public void connect(SocketAddress socketAddress) throws IOException
384
connect(socketAddress, null, timeout);
389
* See superclass javadoc.
391
public void connect(SocketAddress socketAddress, int timeout) throws IOException
393
connect(socketAddress, null, timeout);
398
* See superclass javadoc.
400
public SocketChannel getChannel()
407
* See superclass javadoc.
409
public InetAddress getInetAddress()
411
if (actualSocket == null)
414
return actualSocket.getInetAddress();
419
* See superclass javadoc.
421
public InputStream getInputStream() throws IOException
424
throw new SocketException("Socket is closed");
426
if (actualSocket == null || !connected)
427
throw new SocketException("Socket is not connected");
429
if (isInputShutdown())
430
throw new SocketException("Socket input is shutdown");
437
* See superclass javadoc.
439
public boolean getKeepAlive() throws SocketException
441
if (actualSocket == null)
444
return actualSocket.getKeepAlive();
449
* See superclass javadoc.
450
* Note. <code>Socket.getLocalAddress()</code> returns "wildcard" address for an unbound socket.
452
public InetAddress getLocalAddress()
454
if (actualSocket == null)
456
if (dummySocket == null)
457
dummySocket = new Socket();
459
return dummySocket.getLocalAddress();
462
// The following is a workaround for a problem in NIO sockets, which sometimes
463
// return "0.0.0.0" instead of "127.0.0.1".
464
InetAddress address = actualSocket.getLocalAddress();
467
if ("0.0.0.0".equals(address.getHostAddress()))
468
return InetAddress.getByName("localhost");
470
catch (UnknownHostException e)
480
* See superclass javadoc.
482
public int getLocalPort()
484
if (actualSocket == null)
487
return actualSocket.getLocalPort();
492
* See superclass javadoc.
494
public SocketAddress getLocalSocketAddress()
496
if (actualSocket == null)
499
SocketAddress address = actualSocket.getLocalSocketAddress();
500
InetSocketAddress socketAddress = null;
502
// The following is a workaround for a problem in NIO sockets, which sometimes
503
// return "0.0.0.0" instead of "127.0.0.1".
504
if (address instanceof InetSocketAddress)
506
socketAddress = (InetSocketAddress) address;
507
if ("0.0.0.0".equals(socketAddress.getHostName()) ||
508
socketAddress.getAddress() == null)
509
return new InetSocketAddress("localhost", socketAddress.getPort());
517
* See superclass javadoc.
519
public boolean getOOBInline() throws SocketException
526
* See superclass javadoc.
528
public OutputStream getOutputStream() throws IOException
531
throw new SocketException("Socket is closed");
533
if (actualSocket == null || !connected)
534
throw new SocketException("Socket is not connected");
536
if (isOutputShutdown())
537
throw new SocketException("Socket output is shutdown");
539
// TODO: return distinct output streams? See PlainSocketImpl.
540
//return new SocketOutputStream(this);
546
* See superclass javadoc.
550
if (actualSocket == null)
553
return actualSocket.getPort();
558
* See superclass javadoc.
560
public int getReceiveBufferSize() throws SocketException
562
if (actualSocket == null)
564
if (dummySocket == null)
565
dummySocket = new Socket();
567
return dummySocket.getReceiveBufferSize();
570
return actualSocket.getReceiveBufferSize();
575
* See superclass javadoc.
577
public SocketAddress getRemoteSocketAddress()
579
if (actualSocket == null)
582
return actualSocket.getRemoteSocketAddress();
587
* See superclass javadoc.
589
public boolean getReuseAddress() throws SocketException
591
if (actualSocket == null)
594
return actualSocket.getReuseAddress();
599
* See superclass javadoc.
601
public int getSendBufferSize() throws SocketException
603
if (actualSocket == null)
605
if (dummySocket == null)
606
dummySocket = new Socket();
608
return dummySocket.getSendBufferSize();
611
return actualSocket.getSendBufferSize();
616
* See superclass javadoc.
618
public int getSoLinger() throws SocketException
620
if (actualSocket == null)
623
return actualSocket.getSoLinger();
628
* See superclass javadoc.
630
public int getSoTimeout() throws SocketException
633
throw new SocketException("Socket is closed");
640
* See superclass javadoc.
642
public boolean getTcpNoDelay() throws SocketException
644
if (actualSocket == null)
647
return actualSocket.getTcpNoDelay();
652
* See superclass javadoc.
654
public int getTrafficClass() throws SocketException
656
if (actualSocket == null)
659
return actualSocket.getTrafficClass();
664
* See superclass javadoc.
666
public boolean isBound()
673
* See superclass javadoc.
675
public boolean isClosed()
682
* See superclass javadoc.
684
public boolean isConnected()
691
* See superclass javadoc.
693
public boolean isInputShutdown()
695
return inputShutdown;
700
* See superclass javadoc.
702
public boolean isOutputShutdown()
704
return outputShutdown;
709
* This method is not implemented.
711
* See superclass javadoc.
713
public void sendUrgentData(int data) throws IOException
715
log.warn("sendUrgentData() called: ignored");
718
throw new IOException("Socket Closed");
723
* See superclass javadoc.
725
public void setKeepAlive(boolean on) throws SocketException
727
if (actualSocket != null)
728
actualSocket.setKeepAlive(on);
735
public void setOOBInline(boolean on) throws SocketException
737
log.warn("setOOBInLine() called: ignored");
740
throw new SocketException("Socket is closed");
745
* See superclass javadoc.
747
public void setReceiveBufferSize(int size) throws SocketException
749
if (actualSocket != null)
750
actualSocket.setReceiveBufferSize(size);
755
* See superclass javadoc.
757
public void setReuseAddress(boolean on) throws SocketException
759
if (actualSocket != null)
760
actualSocket.setReuseAddress(on);
765
* See superclass javadoc.
767
public void setSendBufferSize(int size) throws SocketException
769
if (actualSocket != null)
770
actualSocket.setSendBufferSize(size);
775
* See superclass javadoc.
777
public void setSoLinger(boolean on, int linger) throws SocketException
779
if (actualSocket != null)
780
actualSocket.setSoLinger(on, linger);
785
* See superclass javadoc.
787
public void setSoTimeout(int timeout) throws SocketException
790
throw new SocketException("Socket is closed");
793
throw new IllegalArgumentException("timeout can't be negative");
795
this.timeout = timeout;
797
if (inputStream != null)
798
inputStream.setTimeout(timeout);
803
* See superclass javadoc.
805
public void setTcpNoDelay(boolean on) throws SocketException
807
if (actualSocket != null)
808
actualSocket.setTcpNoDelay(on);
813
* See superclass javadoc.
815
public void setTrafficClass(int tc) throws SocketException
817
if (actualSocket != null)
818
actualSocket.setTrafficClass(tc);
823
* See superclass javadoc.
825
public void shutdownInput() throws IOException
828
throw new SocketException("Socket is closed");
831
throw new SocketException("Socket is not connected");
833
if (isInputShutdown())
834
throw new SocketException("Socket input is already shutdown");
836
inputStream.setEOF();
837
inputShutdown = true;
838
// protocol.notifyInputShutdown(localSocketId);
843
* See superclass javadoc.
845
public void shutdownOutput() throws IOException
848
throw new SocketException("Socket is closed");
851
throw new SocketException("Socket is not connected");
853
if (isOutputShutdown())
854
throw new SocketException("Socket output is already shutdown");
856
outputStream.shutdown();
857
outputShutdown = true;
858
protocol.notifyOutputShutdown(remoteSocketId);
863
* See superclass javadoc.
865
public String toString()
867
StringBuffer answer = new StringBuffer().append("VirtualSocket[");
869
if (actualSocket == null)
870
answer.append("unbound");
872
answer.append(actualSocket.toString());
874
return answer.append("]").toString();
877
//////////////////////////////////////////////////////////////////////////////////////////////////
878
/// The following methods are specific to VirtualSockets ///
879
//////////////////////////////////////////////////////////////////////////////////////////////////
884
public void addDisconnectListener(DisconnectListener listener)
886
disconnectListeners.add(listener);
893
public void connect(SocketAddress remoteAddress, SocketAddress localAddress, int timeout) throws IOException
895
log.debug("entering connect()");
896
long start = System.currentTimeMillis();
899
if (remoteAddress == null)
900
throw new IllegalArgumentException("connect: The address can't be null");
903
throw new IllegalArgumentException("connect: timeout can't be negative");
906
throw new SocketException("Socket is closed");
909
throw new SocketException("already connected");
911
if (!(remoteAddress instanceof InetSocketAddress))
912
throw new IllegalArgumentException("Unsupported address type");
914
InetSocketAddress remoteInetSocketAddress = (InetSocketAddress) remoteAddress;
915
SecurityManager security = System.getSecurityManager();
917
if (security != null)
919
if (remoteInetSocketAddress.isUnresolved())
920
security.checkConnect(remoteInetSocketAddress.getHostName(), remoteInetSocketAddress.getPort());
922
security.checkConnect(remoteInetSocketAddress.getAddress().getHostAddress(), remoteInetSocketAddress.getPort());
926
if ((timeLeft = timeout - (int) (System.currentTimeMillis() - start)) <= 0)
927
throw new SocketTimeoutException("connect timed out");
931
if (localAddress == null)
932
manager = MultiplexingManager.getaShareableManager(remoteInetSocketAddress, timeLeft, configuration);
935
InetSocketAddress localInetSocketAddress = (InetSocketAddress) localAddress;
936
manager = MultiplexingManager.getaShareableManagerByAddressPair(remoteInetSocketAddress,
937
localInetSocketAddress,
946
if ((timeLeft = timeout - (int) (System.currentTimeMillis() - start)) <= 0)
947
throw new SocketTimeoutException("connect timed out");
949
manager.connect(remoteInetSocketAddress, timeLeft);
950
actualSocket = manager.getSocket();
951
protocol = manager.getProtocol();
955
localSocketId = new SocketId();
959
inputStream = manager.registerSocket(this);
960
inputStream.setTimeout(timeout);
963
if ((timeLeft = timeout - (int) (System.currentTimeMillis() - start)) <= 0)
964
throw new SocketTimeoutException("connect timed out");
966
remoteSocketId = protocol.connect(inputStream, localSocketId, timeLeft);
967
outputStream = new MultiplexingOutputStream(manager, this, remoteSocketId);
969
catch (IOException e)
971
// Calling unRegisterSocket() will lead to this VirtualSocket being closed.
974
manager.unRegisterSocket(this);
976
catch (IOException ignored)
978
// May not be registered yet.
981
if (e instanceof SocketTimeoutException)
982
throw new SocketTimeoutException("connect timed out");
988
if (inputStream != null)
989
inputStream.setTimeout(this.timeout);
996
public MultiplexingManager getMultiplexingManager()
1002
public int getVirtualPort()
1004
return remoteSocketId.getPort();
1008
public int getLocalVirtualPort()
1010
return localSocketId.getPort();
1018
public SocketId getLocalSocketId()
1020
return localSocketId;
1027
public Socket getRealSocket()
1029
return actualSocket;
1037
public SocketId getRemoteSocketId()
1039
return localSocketId;
1044
* Returns true if and only if has not received notification of error state
1045
* on actual connection.
1047
* @return true if and only if has not received notification of error state
1048
* on actual connection
1050
public boolean isFunctional()
1059
public void removeDisconnectListener(DisconnectListener listener)
1061
if (!disconnectListeners.remove(listener))
1062
log.error("attempt to remove unregistered DisconnectListener: " + listener);
1067
* @param configuration
1069
public void setConfiguration(Map configuration)
1071
this.configuration.putAll(configuration);
1073
//////////////////////////////////////////////////////////////////////////////////////////////////
1074
/// Protected getters and setters '///
1075
//////////////////////////////////////////////////////////////////////////////////////////////////
1078
* @return Returns the actualSocket.
1080
protected Socket getActualSocket()
1082
return actualSocket;
1086
* @param actualSocket The actualSocket to set.
1088
protected void setActualSocket(Socket actualSocket)
1090
this.actualSocket = actualSocket;
1093
// in socket API section
1095
// * @return Returns the bound.
1097
// public boolean isBound()
1103
* @param bound The bound to set.
1105
protected void setBound(boolean bound)
1111
* @param closed The closed to set.
1113
protected void setClosed(boolean closed)
1115
this.closed = closed;
1119
* @param connected The connected to set.
1121
protected void setConnected(boolean connected)
1123
this.connected = connected;
1127
* @param inputShutdown The inputShutdown to set.
1129
protected void setInputShutdown(boolean inputShutdown)
1131
this.inputShutdown = inputShutdown;
1135
* @param inputStream The inputStream to set.
1137
protected void setInputStream(MultiplexingInputStream inputStream)
1139
this.inputStream = inputStream;
1143
* @param localSocketId The localSocketId to set.
1145
protected void setLocalSocketId(SocketId localSocketId)
1147
this.localSocketId = localSocketId;
1154
protected MultiplexingManager getManager()
1160
* @param manager The manager to set.
1162
protected void setManager(MultiplexingManager manager)
1164
this.manager = manager;
1168
* @param outputShutdown The outputShutdown to set.
1170
protected void setOutputShutdown(boolean outputShutdown)
1172
this.outputShutdown = outputShutdown;
1176
* @param outputStream The outputStream to set.
1178
protected void setOutputStream(MultiplexingOutputStream outputStream)
1180
this.outputStream = outputStream;
1184
* @return Returns the protocol.
1186
protected Protocol getProtocol()
1192
* @param protocol The protocol to set.
1194
protected void setProtocol(Protocol protocol)
1196
this.protocol = protocol;
1203
protected boolean hasReceivedDisconnectMessage()
1205
return receivedDisconnectMessage;
1210
* @param receivedDisconnectMessage
1212
protected void setReceivedDisconnectMessage(boolean receivedDisconnectMessage)
1214
this.receivedDisconnectMessage = receivedDisconnectMessage;
1218
* @param remoteSocketId The remoteSocketId to set.
1220
protected void setRemoteSocketId(SocketId remoteSocketId)
1222
this.remoteSocketId = remoteSocketId;
1227
//////////////////////////////////////////////////////////////////////////////////////////////////
1228
/// Other protected methods '///
1229
//////////////////////////////////////////////////////////////////////////////////////////////////
1235
protected void doClose()
1237
if (debug) log.debug("doClose()" + this.localSocketId.getPort());
1240
// if (connected && !receivedDisconnectMessage)
1241
// protocol.disconnect(remoteSocketId);
1243
// This VirtualSocket might have been unregistered when connect() failed.
1244
if (manager.isSocketRegistered(getLocalSocketId()))
1245
manager.unRegisterSocket(this);
1247
if (debug) log.debug("virtual socket closed on port: " + remoteSocketId.getPort());
1251
log.error("error closing socket: " + this);
1260
* @throws IOException
1262
protected void handleRemoteOutputShutDown() throws IOException
1267
inputStream.handleRemoteShutdown();
1269
catch (NullPointerException ignored)
1277
* @throws IOException
1279
protected void handleRemoteDisconnect() throws IOException
1284
if (debug) log.debug("remote virtual socket disconnecting: local port: " + getLocalVirtualPort());
1285
receivedDisconnectMessage = true;
1288
if (inputStream != null)
1289
inputStream.handleRemoteShutdown();
1292
if (outputStream != null)
1294
outputStream.flush();
1295
outputStream.handleRemoteDisconnect();
1298
MultiplexingManager.addToPendingActions(new PendingRemoteDisconnect(this));
1300
log.debug("handleRemoteDisconnect(): done.");
1302
// connected = false;
1303
// inputShutdown = true;
1304
// outputShutdown = true;
1309
* Indicate error condition on actual connection.
1311
protected void notifyOfException()
1316
protected class PendingRemoteDisconnect extends PendingAction
1318
public PendingRemoteDisconnect(Object o)
1325
VirtualSocket vs = (VirtualSocket) o;
1326
Set disconnectListeners = vs.disconnectListeners;
1328
Iterator it = disconnectListeners.iterator();
1329
while (it.hasNext())
1330
((DisconnectListener) it.next()).notifyDisconnected(vs);
1335
protected class PendingClose extends PendingAction
1337
public PendingClose(Object o)
1342
public void doAction()
1344
((VirtualSocket)o).doClose();
b'\\ No newline at end of file'