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

Last change on this file since 88 was 88, checked in by Bart Vastenhouw, 3 years ago

Added python SimpleRunner GUI

File size: 2.6 KB
Line 
1from abc import ABC
2from typing import TypeVar, Generic, List, Optional
3
4from tudelft.utilities.listener.Listenable import Listenable
5from uri.uri import URI
6
7from geniusweb.references.Reference import Reference
8
9
10INTYPE = TypeVar('INTYPE')
11OUTTYPE = TypeVar('OUTTYPE')
12
13class ConnectionEnd(Listenable[INTYPE], Generic[INTYPE,OUTTYPE]):
14 '''
15 One end of a general two-way connection. incoming data is reported through
16 the {@link Listenable} channel, sending events of the INTYPE.
17 <p>
18
19 The connection mechanism assumed here is fundamentally asymmetric. One side
20 is "Connectable", the other side is a ConnectionEnd created (usually from a
21 {@link Reference}. This matches the typical client-server system (web
22 architecture).
23
24 <p>
25 If an internal error occurs, eg a socket failure, timeout, or parser error, a
26 null event is sent into the Listenable. {@link #getError()} can be called to
27 find out about the error.
28 @param <INTYPE> the type of incoming messages (incoming for the user of this
29 connection end). Incoming messages are received through
30 Listener#not. Incoming messages are usually asynchronous.
31 @param <OUTTYPE> the type of outgoing messages (outgoing for the user of this
32 connection end). Outgoing messages can be sent directly with
33 #send.
34 '''
35
36 def send(self,data:OUTTYPE ):
37 '''
38 Send data out (and flush the output so that there are no excessive delays
39 in sending the data). This call is assumed to return immediately (never
40 block, eg on synchronized, Thread.sleep, IO, etc). When this is called
41 multiple times in sequence, the data should arrive at the receiver end in
42 the same order.
43
44 @param data the data to be sent.
45 @throws ConnectionError if the data failed to be sent.
46 '''
47
48 def getReference(self) -> Reference:
49 '''
50 @return Reference that was used to create this connection
51 '''
52
53 def getRemoteURI(self)->URI:
54 '''
55 @return the URI of the remote endpoint that makes up the connection. This
56 is a URI that uniquely identifies the remote object.
57 '''
58
59 def close(self):
60 '''
61 Close the connection. Should return immediately (not block). Before
62 really closing, this should attempt to send out possibly cached messages
63 before closing the connection.
64 '''
65 def getError(self) -> Optional[Exception]:
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
Note: See TracBrowser for help on using the repository browser.