source: references/src/main/java/geniusweb/connection/ConnectionEnd.java@ 24

Last change on this file since 24 was 9, checked in by bart, 5 years ago

Release 1.1.0

File size: 2.5 KB
RevLine 
[9]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 * One end of a general two-way connection. incoming data is reported through
12 * the {@link Listenable} channel, sending events of the INTYPE.
13 * <p>
14 *
15 * The connection mechanism assumed here is fundamentally asymmetric. One side
16 * is "Connectable", the other side is a ConnectionEnd created (usually from a
17 * {@link Reference}. This matches the typical client-server system (web
18 * architecture).
19 *
20 * <p>
21 * If an internal error occurs, eg a socket failure, timeout, or parser error, a
22 * null event is sent into the Listenable. {@link #getError()} can be called to
23 * find out about the error.
24 *
25 * @param <INTYPE> the type of incoming messages (incoming for the user of this
26 * connection end). Incoming messages are received through
27 * Listener#not. Incoming messages are usually asynchronous.
28 * @param <OUTTYPE> the type of outgoing messages (outgoing for the user of this
29 * connection end). Outgoing messages can be sent directly with
30 * #send.
31 *
32 */
33public interface ConnectionEnd<INTYPE, OUTTYPE> extends Listenable<INTYPE> {
34
35 /**
36 * Send data out (and flush the output so that there are no excessive delays
37 * in sending the data). This call is assumed to return immediately (never
38 * block, eg on synchronized, Thread.sleep, IO, etc). When this is called
39 * multiple times in sequence, the data should arrive at the receiver end in
40 * the same order.
41 *
42 * @param data the data to be sent.
43 * @throws IOException if the data failed to be sent.
44 */
45 void send(OUTTYPE data) throws IOException;
46
47 /**
48 * @return Reference that was used to create this connection
49 */
50 Reference getReference();
51
52 /**
53 * @return the URI of the remote endpoint that makes up the connection. This
54 * is a URI that uniquely identifies the remote object
55 */
56 URI getRemoteURI();
57
58 /**
59 * Close the connection. Should return immediately (not block). Before
60 * really closing, this should attempt to send out possibly cached messages
61 * before closing the connection.
62 *
63 */
64 void close();
65
66 /**
67 * @return the latest internal error, or null if no error occured. If the
68 * channel is closed, this is set to {@link SocketException} "Socket
69 * closed", even if the close was a "normal" termination eg when
70 * {@link #close()} was called.
71 */
72 Throwable getError();
73}
Note: See TracBrowser for help on using the repository browser.