Skip to content

Commit 16e394e

Browse files
author
Maik Scheibler
committed
APIdoc added
Signed-off-by: Maik Scheibler <eclipse@scheibler-family.de>
1 parent 5b34f5a commit 16e394e

1 file changed

Lines changed: 52 additions & 6 deletions

File tree

  • org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal/NetworkModule.java

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,74 @@
2424
/**
2525
* A NetworkModule provides access to a specific transport to the broker. This may be a plain socket, a TLS secured
2626
* connection, a serial line, etc.
27+
*
28+
* <h3>Lifecycle</h3>
29+
* Each NetworkModule instance has a lifecycle with the following logical states:
30+
* <ul>
31+
* <li><b>CREATED</b> - the instance holds no connection to its broker, no network resources are allocated and the
32+
* {@code get...Stream}-methods may return {@code null} or throw an {@link IOException}.
33+
* <li><b>CONNECTED</b> - the instance has an active connection to its broker, underlaying network ressources (e.g.
34+
* socket)
35+
* are allocated, the {@code get...Stream}-methods return open streams for reading and writing.</li>
36+
* <li><b>DISCONNECTED</b> - the instance holds no connection to its broker, underlaying network resources are closed
37+
* and
38+
* released, the {@code get...Stream}-methods will always throw an {@link IOException}.</li>
39+
* </ul>
2740
* <p>
28-
* TODO: Provide description about the reusability of the NetworkModule.
41+
* The following transitions may occure:
42+
* <ul>
43+
* <li>{@code CREATED -> CONNECTED} - if {@link #start()} succeeded</li>
44+
* <li>{@code CREATED -> CREATED} - if {@link #start()} failed</li>
45+
* <li>{@code CONNECTED -> DISCONNECTED} - when {@link #stop()} is called; If an {@link IOException} occures on one of
46+
* the input /
47+
* output streams the {@code stop()}-method will be called.</li>
48+
* <li>{@code DISCONNECTED -> CONNECTED} - if {@link #start()} succeeded during a re-connect attempt</li>
49+
* </ul>
50+
* The {@link #start()}-method of a NetworkModule instance may only be called multiple times if either the previous call
51+
* resulted in an exception or {@link #stop()} has been called in between. The objects returned by
52+
* {@link #getInputStream()} und {@link #getOutputStream()} are most likely different instances each time
53+
* {@link #start()} had been called.
2954
*/
3055
public interface NetworkModule {
56+
3157
/**
32-
* Open the transport to the broker.
58+
* Open the transport to the broker. The streams provided by {@link #getInputStream()} and
59+
* {@link #getOutputStream()} are expected to be open for read / write operations after this method succeed.
3360
*
34-
* @throws IOException
35-
* @throws MqttException
61+
* @throws IOException of any underlaying transport
62+
* @throws MqttException if the server connection cannot be established, e.g. the connection is being refused
3663
*/
3764
public void start() throws IOException, MqttException;
3865

66+
/**
67+
* Returns the input stream to be used for receiving messages. This method is usually called once directly after
68+
* {@link #start()}. The returned input stream will be used in the CommsReceiver of the client connection.
69+
*
70+
* @return the input stream to be used for receiving messages ({@code null} may be returned if {@link #start()} had
71+
* never been sucessfully called on this instance)
72+
* @throws IOException if an I/O error occurs when creating the input stream or the broker connection is not
73+
* established
74+
*/
3975
public InputStream getInputStream() throws IOException;
4076

77+
/**
78+
* Returns the output stream to be used for sending messages. This method is usually called once directly after
79+
* {@link #start()}. The returned output stream will be used in the CommsSender of the client connection.
80+
*
81+
* @return output stream to be used for sending messages ({@code null} may be returned if {@link #start()} had never
82+
* been sucessfully called on this instance)
83+
* @throws IOException if an I/O error occurs when creating the output stream or the broker connection is not
84+
* established
85+
*/
4186
public OutputStream getOutputStream() throws IOException;
4287

4388
/**
44-
* Close the transport to the broker.
89+
* Close the transport to the broker. The streams provided by {@link #getInputStream()} and
90+
* {@link #getOutputStream()} should be closed after this method returns.
4591
* <p>
4692
* TODO: Check whether the input and output streams are to be closed as well?
4793
*
48-
* @throws IOException
94+
* @throws IOException if an I/O error occurs when closing the transport
4995
*/
5096
public void stop() throws IOException;
5197

0 commit comments

Comments
 (0)