source: references/src/main/java/geniusweb/connection/Connection.java@ 2

Last change on this file since 2 was 1, checked in by bart, 5 years ago

Initial Release

File size: 2.2 KB
Line 
1package geniusweb.connection;
2
3import java.io.IOException;
4import java.net.SocketException;
5import java.net.URI;
6
7import geniusweb.references.Reference;
8import tudelft.utilities.listener.Listenable;
9
10/**
11 * A general two-way connection. incoming data is reported through the
12 * {@link Listenable} channel, sending events of the INTYPE.
13 * <p>
14 * If an internal error occurs, eg a socket failure, timeout, or parser error, a
15 * null event is sent into the Listenable and {@link #getError()} can be called
16 * to find out about the error.
17 *
18 * @param <INTYPE> the type of incoming messages. Incoming messages are
19 * received through Listener#not. Incoming messages are usually
20 * asynchronous.
21 * @param <OUTTYPE> the type of outgoing messages. Outgoing messages can be sent
22 * directly with #send.
23 *
24 */
25public interface Connection<INTYPE, OUTTYPE> extends Listenable<INTYPE> {
26
27 /**
28 * Send data out (and flush the output so that there are no excessive delays
29 * in sending the data). This call is assumed to return immediately (never
30 * block, eg on synchronized, Thread.sleep, IO, etc). When this is called
31 * multiple times in sequence, the data should arrive at the receiver end in
32 * the same order.
33 *
34 * @param data the data to be sent.
35 * @throws IOException if the data failed to be sent.
36 */
37 void send(OUTTYPE data) throws IOException;
38
39 /**
40 * @return Reference that was used to create this connection
41 */
42 Reference getReference();
43
44 /**
45 * @return the URI of the remote endpoint that makes up the connection. This
46 * is a URI that uniquely identifies the remote object
47 */
48 URI getRemoteURI();
49
50 /**
51 * Close the connection. Should return immediately (not block). Before
52 * really closing, this should attempt to send out possibly cached messages
53 * before closing the connection.
54 *
55 */
56 void close();
57
58 /**
59 * @return the latest internal error, or null if no error occured. If the
60 * channel is closed, this is set to {@link SocketException} "Socket
61 * closed", even if the close was a "normal" termination eg when
62 * {@link #close()} was called.
63 */
64 Throwable getError();
65}
Note: See TracBrowser for help on using the repository browser.