KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > net > core > TCConnection


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.net.core;
5
6 import com.tc.net.TCSocketAddress;
7 import com.tc.net.core.event.TCConnectionEventListener;
8 import com.tc.net.protocol.NetworkMessageSink;
9 import com.tc.util.TCTimeoutException;
10
11 import java.io.IOException JavaDoc;
12 import java.net.Socket JavaDoc;
13
14 /**
15  * Common interface for TC network connections
16  *
17  * @author teck
18  */

19 public interface TCConnection extends NetworkMessageSink {
20
21   /**
22    * Returns a long timestamp as reported by <code>Sytem.currentTimeMillis()</code> when this connection was
23    * connected. If <code>connect()</code> has never been called, the return value is undefined
24    */

25   public long getConnectTime();
26
27   /**
28    * Returns a long representing the number of milliseconds this connection has been idle (ie. not data sent or
29    * received)
30    */

31   public long getIdleTime();
32
33   /**
34    * Add the given connection event listener. Re-adding an existing listener will have no effect (ie. the listener will
35    * not be in the list twice).
36    *
37    * @param listener listener to add
38    */

39   public void addListener(TCConnectionEventListener listener);
40
41   /**
42    * Remove the given event listener. Attempting to remove a listener that is not currently in the listeners set has not
43    * effect
44    */

45   public void removeListener(TCConnectionEventListener listener);
46
47   /**
48    * Close this connection. The actual close happens asynchronously to this call.
49    */

50   public void asynchClose();
51
52   /**
53    * Detatch this connection from it's connection manager
54    *
55    * @throws IOException
56    */

57   public Socket JavaDoc detach() throws IOException JavaDoc;
58
59   /**
60    * Close this connection, blocking for at most the given timeout value
61    *
62    * @return true/false whether the connection closed in time
63    */

64   public boolean close(long timeout);
65
66   /**
67    * Connect synchronously to a given destination. If this call fails, connect called be called again. However once a
68    * connection has successfully connected once, it cannot be re-connected
69    *
70    * @param addr the destination address
71    * @param timeout time in milliseconds to wait before throwing a timeout exception
72    * @throws IOException if there is an error connecting to the destination address
73    * @throws TCTimeoutException if a timeout occurs
74    */

75   public void connect(TCSocketAddress addr, int timeout) throws IOException JavaDoc, TCTimeoutException;
76
77   /**
78    * Connect asynchronously to the given destination address
79    *
80    * @param addr the destination address to connect to
81    * @return true if the connection was opened immediately, otherwise false (NOTE: return value of "false" this NOT an
82    * indication of error)
83    * @throws IOException if there is an error connecting to the destination
84    */

85   public boolean asynchConnect(TCSocketAddress addr) throws IOException JavaDoc;
86
87   /**
88    * Whether or not this connection is connected
89    *
90    * @return true iff this connection is connected to the destination address
91    */

92   public boolean isConnected();
93
94   /**
95    * Whether or not this connection is closed
96    *
97    * @return true iff this connection is closed
98    */

99   public boolean isClosed();
100
101   /**
102    * Get local side connection details
103    *
104    * @throws IllegalStateException if connection has never been connected
105    */

106   public TCSocketAddress getLocalAddress();
107
108   /**
109    * Get remote side connection details
110    *
111    * @throws IllegalStateException if connection has never been connected
112    */

113   public TCSocketAddress getRemoteAddress();
114 }
Popular Tags