source: geniuswebcore/geniusweb/connection/ConnectionEnd.py@ 63

Last change on this file since 63 was 59, checked in by Wouter Pasman, 3 years ago

#44 manual commit of first public release, because this will cause the dist directory to move

File size: 2.6 KB
Line 
1from abc import ABC
2from typing import TypeVar, Generic, List
3
4from tudelft.utilities.listener.Listenable import Listenable
5from geniusweb.references.Reference import Reference
6
7INTYPE = TypeVar('INTYPE')
8OUTTYPE = TypeVar('OUTTYPE')
9
10class ConnectionEnd(Listenable[INTYPE], Generic[INTYPE,OUTTYPE]):
11 '''
12 One end of a general two-way connection. incoming data is reported through
13 the {@link Listenable} channel, sending events of the INTYPE.
14 <p>
15
16 The connection mechanism assumed here is fundamentally asymmetric. One side
17 is "Connectable", the other side is a ConnectionEnd created (usually from a
18 {@link Reference}. This matches the typical client-server system (web
19 architecture).
20
21 <p>
22 If an internal error occurs, eg a socket failure, timeout, or parser error, a
23 null event is sent into the Listenable. {@link #getError()} can be called to
24 find out about the error.
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
33 def send(self,data:OUTTYPE ):
34 '''
35 Send data out (and flush the output so that there are no excessive delays
36 in sending the data). This call is assumed to return immediately (never
37 block, eg on synchronized, Thread.sleep, IO, etc). When this is called
38 multiple times in sequence, the data should arrive at the receiver end in
39 the same order.
40
41 @param data the data to be sent.
42 @throws IOException if the data failed to be sent.
43 '''
44
45 def getReference(self) -> Reference:
46 '''
47 @return Reference that was used to create this connection
48 '''
49
50 def getRemoteURI(self)->str:
51 '''
52 @return the URI of the remote endpoint that makes up the connection. This
53 is a URI that uniquely identifies the remote object.
54 HACK for now we return str instead of URI.
55 '''
56
57 def close(self):
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 def getError(self) -> Exception:
64 '''
65 @return the latest internal error, or null if no error occured. If the
66 channel is closed, this is set to {@link SocketException} "Socket
67 closed", even if the close was a "normal" termination eg when
68 {@link #close()} was called.
69 '''
70
Note: See TracBrowser for help on using the repository browser.