1 package net.pterodactylus.irc;
3 import java.io.IOException;
4 import java.time.Duration;
5 import java.util.Optional;
8 * A connection to an IRC server.
10 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
12 public interface Connection {
15 * Returns the hostname of the remote end of the connection.
17 * @return The remote’s hostname
22 * Returns the port number of the remote end of the connection.
24 * @return The remote’s port number
29 * Returns whether this connection has already been established.
31 * @return {@code true} as long as this connection is established, {@code
34 boolean established();
37 * Returns the nickname that is currently in use by this connection. The
38 * nickname is only available once the connection has been {@link #start()}ed.
40 * @return The current nickname
45 * Sets the username to use.
49 * @return This connection
51 Connection username(String username);
54 * Sets the real name to use.
57 * The real name to use
58 * @return This connection
60 Connection realName(String realName);
63 * Sets the optional password for the connection.
66 * The password for the connection
67 * @return This connection
69 Connection password(String password);
72 * Returns the current rate of the connection’s incoming side.
74 * @return The current input rate (in bytes per second)
79 * Returns the current rate of the connection’s outgoing side.
81 * @return The current output rate (in bytes per second)
86 * Checks whether the given source is the client represented by this
91 * @return {@code true} if this connection represents the given source, {@code
94 boolean isSource(Source source);
97 * Joins the given channel.
100 * The channel to join
101 * @throws IOException
102 * if an I/O error occurs
104 void joinChannel(String channel) throws IOException;
107 * Sends a message to the given recipient, which may be a channel or another
111 * The recipient of the message
114 * @throws IOException
115 * if an I/O error occurs
117 void sendMessage(String recipient, String message) throws IOException;
120 * Sends a DCC RESUME request to the given recipient.
123 * The recipient of the request
125 * The name of the file to resume
127 * The port number from the original DCC SEND request
129 * The position at which to resume the transfer
130 * @throws IOException
131 * if an I/O error occurs
133 void sendDccResume(String recipient, String filename, int port, long position)
137 * Opens the connection and starts processing messages from the other side.
142 * Closes this connection.
144 * @throws IOException
145 * if an I/O error occurs
147 void close() throws IOException;
149 Optional<Duration> getUptime();