[Cherbot-commit] SF.net SVN: cherbot:[140] trunk/src/prj/net/sf/cherbot/connection
Status: Alpha
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2008-12-14 17:04:19
|
Revision: 140
http://cherbot.svn.sourceforge.net/cherbot/?rev=140&view=rev
Author: christianhujer
Date: 2008-12-14 17:04:15 +0000 (Sun, 14 Dec 2008)
Log Message:
-----------
Extracted interfaces for Connections to allow the creation of an SPI for Connections.
Modified Paths:
--------------
trunk/src/prj/net/sf/cherbot/connection/AbstractConnection.java
trunk/src/prj/net/sf/cherbot/connection/AbstractNetworkConnection.java
Added Paths:
-----------
trunk/src/prj/net/sf/cherbot/connection/Connection.java
trunk/src/prj/net/sf/cherbot/connection/NetworkConnection.java
Modified: trunk/src/prj/net/sf/cherbot/connection/AbstractConnection.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/AbstractConnection.java 2008-12-14 13:20:47 UTC (rev 139)
+++ trunk/src/prj/net/sf/cherbot/connection/AbstractConnection.java 2008-12-14 17:04:15 UTC (rev 140)
@@ -19,18 +19,6 @@
* </ul>
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
-public abstract class AbstractConnection extends BasicCommand implements Closeable, Serializable {
+public abstract class AbstractConnection extends BasicCommand implements Connection {
- /** Establishes this connection.
- * @throws IOException in case of connection problems.
- */
- public abstract void connect() throws IOException;
-
- /** {@inheritDoc} */
- public abstract void close() throws IOException;
-
- /** Returns whether this connection is established.
- * @return <code>true</code> if this connection is established, otherwise <code>false</code>.
- */
- public abstract boolean isConnected();
}
Modified: trunk/src/prj/net/sf/cherbot/connection/AbstractNetworkConnection.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/AbstractNetworkConnection.java 2008-12-14 13:20:47 UTC (rev 139)
+++ trunk/src/prj/net/sf/cherbot/connection/AbstractNetworkConnection.java 2008-12-14 17:04:15 UTC (rev 140)
@@ -16,7 +16,7 @@
/** An AbstractNetworkConnection represents a Connection to a server and has one or more channels.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
-public abstract class AbstractNetworkConnection extends AbstractConnection {
+public abstract class AbstractNetworkConnection extends AbstractConnection implements NetworkConnection {
/** The host to connect to.
* @serial include
@@ -31,32 +31,24 @@
/** The socket for the connection. */
@Nullable private transient Socket socket;
- /** Sets the host of the IRC server to connect to.
- * @param host Host of the IRC server.
- */
+ /** {@inheritDoc} */
@Option(type = OptionType.REQUIRED, value = {"host"})
public void setHost(@NotNull final String host) {
this.host = host;
}
- /** Returns the host to connect to.
- * @return The host to connect to.
- */
+ /** {@inheritDoc} */
@Nullable public String getHost() {
return host;
}
- /** Sets the port of the IRC server to connect to.
- * @param port Port of the IRC server.
- */
+ /** {@inheritDoc} */
@Option({"port"})
public void setPort(@NotNull final Integer port) {
this.port = port;
}
- /** Returns the port to connect to.
- * @return The port to connect to.
- */
+ /** {@inheritDoc} */
public int getPort() {
return port;
}
@@ -90,18 +82,12 @@
return socket != null && socket.isConnected();
}
- /** Sets the socket for the connection.
- * Use this method if you want to create a connection on an existing socket instead of letting this Connection automatically create its own socket.
- * @param socket Socket for the connection.
- * @throws IOException In case of I/O problems when setting the socket. This is useful for overriding methods which may be interested in using the socket when it's being set.
- */
+ /** {@inheritDoc} */
public void setSocket(@NotNull final Socket socket) throws IOException {
this.socket = socket;
}
- /** Returns the socket for the connection.
- * @return The socket for the connection.
- */
+ /** {@inheritDoc} */
@Nullable public Socket getSocket() {
return socket;
}
Added: trunk/src/prj/net/sf/cherbot/connection/Connection.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/Connection.java (rev 0)
+++ trunk/src/prj/net/sf/cherbot/connection/Connection.java 2008-12-14 17:04:15 UTC (rev 140)
@@ -0,0 +1,40 @@
+package net.sf.cherbot.connection;
+
+import java.io.Closeable;
+import java.io.Serializable;
+import java.io.IOException;
+
+/** A Connection represents a connection of CherBot.
+ * A Connection is implemented as bean.
+ * That means:
+ * <ul>
+ * <li>
+ * An object does not reflect an established connection but has a state.
+ * The connection state can be established or not established.
+ * </li>
+ * </ul>
+ * Additionally it is recommended to implement a Connection as command bean.
+ * That means:
+ * <ul>
+ * <li>
+ * For testing, trying or standalone usage it is possible to "run" a connection as a standalone java program from the command line.
+ * (If the Connection is implemented as command bean.)
+ * </li>
+ * </ul>
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public interface Connection extends Closeable, Serializable {
+
+ /** Establishes this connection.
+ * @throws IOException in case of connection problems.
+ */
+ void connect() throws IOException;
+
+ /** {@inheritDoc} */
+ void close() throws IOException;
+
+ /** Returns whether this connection is established.
+ * @return <code>true</code> if this connection is established, otherwise <code>false</code>.
+ */
+ boolean isConnected();
+}
Property changes on: trunk/src/prj/net/sf/cherbot/connection/Connection.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: trunk/src/prj/net/sf/cherbot/connection/NetworkConnection.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/NetworkConnection.java (rev 0)
+++ trunk/src/prj/net/sf/cherbot/connection/NetworkConnection.java 2008-12-14 17:04:15 UTC (rev 140)
@@ -0,0 +1,47 @@
+package net.sf.cherbot.connection;
+
+import net.sf.japi.io.args.Option;
+import net.sf.japi.io.args.OptionType;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import java.net.Socket;
+import java.io.IOException;
+
+/** A NetworkConnection represents a Connection to a server.
+ * Depending on the server it may have multiple {@link Channel}s.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public interface NetworkConnection extends Connection {
+
+ /** Sets the host of the IRC server to connect to.
+ * @param host Host of the IRC server.
+ */
+ @Option(type = OptionType.REQUIRED, value = {"host"}) void setHost(@NotNull String host);
+
+ /** Returns the host to connect to.
+ * @return The host to connect to.
+ */
+ @Nullable String getHost();
+
+ /** Sets the port of the IRC server to connect to.
+ * @param port Port of the IRC server.
+ */
+ @Option({"port"}) void setPort(@NotNull Integer port);
+
+ /** Returns the port to connect to.
+ * @return The port to connect to.
+ */
+ int getPort();
+
+ /** Sets the socket for the connection.
+ * Use this method if you want to create a connection on an existing socket instead of letting this Connection automatically create its own socket.
+ * @param socket Socket for the connection.
+ * @throws java.io.IOException In case of I/O problems when setting the socket. This is useful for overriding methods which may be interested in using the socket when it's being set.
+ */
+ void setSocket(@NotNull Socket socket) throws IOException;
+
+ /** Returns the socket for the connection.
+ * @return The socket for the connection.
+ */
+ @Nullable Socket getSocket();
+}
Property changes on: trunk/src/prj/net/sf/cherbot/connection/NetworkConnection.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|