[Cherbot-commit] SF.net SVN: cherbot:[136] trunk/src/prj/net/sf/cherbot/connection
Status: Alpha
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2008-12-14 12:43:47
|
Revision: 136
http://cherbot.svn.sourceforge.net/cherbot/?rev=136&view=rev
Author: christianhujer
Date: 2008-12-14 12:43:43 +0000 (Sun, 14 Dec 2008)
Log Message:
-----------
Renamed AbstractConnection to AbstractNetworkConnection for introducing networkless Connection superclass.
Modified Paths:
--------------
trunk/src/prj/net/sf/cherbot/connection/AbstractCFConnection.java
trunk/src/prj/net/sf/cherbot/connection/IRCConnection.java
Added Paths:
-----------
trunk/src/prj/net/sf/cherbot/connection/AbstractNetworkConnection.java
Removed Paths:
-------------
trunk/src/prj/net/sf/cherbot/connection/AbstractConnection.java
Modified: trunk/src/prj/net/sf/cherbot/connection/AbstractCFConnection.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/AbstractCFConnection.java 2008-12-14 12:39:57 UTC (rev 135)
+++ trunk/src/prj/net/sf/cherbot/connection/AbstractCFConnection.java 2008-12-14 12:43:43 UTC (rev 136)
@@ -20,7 +20,7 @@
/** Common base class for Connections that use Crossfire-style protocols such as Angelion or Daimonin and of course Crossfire itself.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
-public abstract class AbstractCFConnection extends AbstractConnection {
+public abstract class AbstractCFConnection extends AbstractNetworkConnection {
/** The username to authenticate with. */
@NotNull private String username;
Deleted: trunk/src/prj/net/sf/cherbot/connection/AbstractConnection.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/AbstractConnection.java 2008-12-14 12:39:57 UTC (rev 135)
+++ trunk/src/prj/net/sf/cherbot/connection/AbstractConnection.java 2008-12-14 12:43:43 UTC (rev 136)
@@ -1,126 +0,0 @@
-/*
- * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
- * License: GNU General Public License v2.0 or newer.
- * See file COPYING in the root directory of this project.
- */
-
-package net.sf.cherbot.connection;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.Serializable;
-import java.net.Socket;
-import net.sf.japi.io.args.BasicCommand;
-import net.sf.japi.io.args.Option;
-import net.sf.japi.io.args.OptionType;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/** An AbstractConnection represents the connection to a server and has one or more channels.
- * Connections are implemented as command 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>
- * <li>
- * For testing, trying or standalone usage it is possible to "run" a connection as a standalone java program from the command line.
- * </li>
- * </ul>
- * To query whether the connection is open, get the Socket of the connection and check the socket.
- * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
- */
-public abstract class AbstractConnection extends BasicCommand implements Closeable, Serializable {
-
- /** The host to connect to.
- * @serial include
- */
- @Nullable private String host;
-
- /** The port to connect to.
- * @serial include
- */
- private int port;
-
- /** 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.
- */
- @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.
- */
- @Nullable public String getHost() {
- return host;
- }
-
- /** Sets the port of the IRC server to connect to.
- * @param port Port of the IRC server.
- */
- @Option({"port"})
- public void setPort(@NotNull final Integer port) {
- this.port = port;
- }
-
- /** Returns the port to connect to.
- * @return The port to connect to.
- */
- public int getPort() {
- return port;
- }
-
- /** Establishes this connection.
- * Implementations of this method must invoke {@link #setSocket(Socket)}.
- * @return The socket created for this connection.
- * @throws IOException in case of connection problems.
- */
- @NotNull public Socket connect() throws IOException {
- final Socket socket = new Socket(host, port);
- setSocket(socket);
- return socket;
- }
-
- /** {@inheritDoc} */
- public void close() throws IOException {
- try {
- final Socket socket = this.socket;
- if (socket != null) {
- socket.close();
- }
- } finally {
- socket = null;
- }
- }
-
- /** Returns whether this connection is established.
- * @return <code>true</code> if this connection is established, otherwise <code>false</code>.
- * @see Socket#isConnected()
- */
- public boolean isConnected() {
- 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.
- */
- public void setSocket(@NotNull final Socket socket) throws IOException {
- this.socket = socket;
- }
-
- /** Returns the socket for the connection.
- * @return The socket for the connection.
- */
- @Nullable public Socket getSocket() {
- return socket;
- }
-
-} // class AbstractConnection
Copied: trunk/src/prj/net/sf/cherbot/connection/AbstractNetworkConnection.java (from rev 133, trunk/src/prj/net/sf/cherbot/connection/AbstractConnection.java)
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/AbstractNetworkConnection.java (rev 0)
+++ trunk/src/prj/net/sf/cherbot/connection/AbstractNetworkConnection.java 2008-12-14 12:43:43 UTC (rev 136)
@@ -0,0 +1,126 @@
+/*
+ * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
+ * License: GNU General Public License v2.0 or newer.
+ * See file COPYING in the root directory of this project.
+ */
+
+package net.sf.cherbot.connection;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.Socket;
+import net.sf.japi.io.args.BasicCommand;
+import net.sf.japi.io.args.Option;
+import net.sf.japi.io.args.OptionType;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/** An AbstractConnection represents the connection to a server and has one or more channels.
+ * Connections are implemented as command 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>
+ * <li>
+ * For testing, trying or standalone usage it is possible to "run" a connection as a standalone java program from the command line.
+ * </li>
+ * </ul>
+ * To query whether the connection is open, get the Socket of the connection and check the socket.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public abstract class AbstractNetworkConnection extends BasicCommand implements Closeable, Serializable {
+
+ /** The host to connect to.
+ * @serial include
+ */
+ @Nullable private String host;
+
+ /** The port to connect to.
+ * @serial include
+ */
+ private int port;
+
+ /** 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.
+ */
+ @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.
+ */
+ @Nullable public String getHost() {
+ return host;
+ }
+
+ /** Sets the port of the IRC server to connect to.
+ * @param port Port of the IRC server.
+ */
+ @Option({"port"})
+ public void setPort(@NotNull final Integer port) {
+ this.port = port;
+ }
+
+ /** Returns the port to connect to.
+ * @return The port to connect to.
+ */
+ public int getPort() {
+ return port;
+ }
+
+ /** Establishes this connection.
+ * Implementations of this method must invoke {@link #setSocket(Socket)}.
+ * @return The socket created for this connection.
+ * @throws IOException in case of connection problems.
+ */
+ @NotNull public Socket connect() throws IOException {
+ final Socket socket = new Socket(host, port);
+ setSocket(socket);
+ return socket;
+ }
+
+ /** {@inheritDoc} */
+ public void close() throws IOException {
+ try {
+ final Socket socket = this.socket;
+ if (socket != null) {
+ socket.close();
+ }
+ } finally {
+ socket = null;
+ }
+ }
+
+ /** Returns whether this connection is established.
+ * @return <code>true</code> if this connection is established, otherwise <code>false</code>.
+ * @see Socket#isConnected()
+ */
+ public boolean isConnected() {
+ 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.
+ */
+ public void setSocket(@NotNull final Socket socket) throws IOException {
+ this.socket = socket;
+ }
+
+ /** Returns the socket for the connection.
+ * @return The socket for the connection.
+ */
+ @Nullable public Socket getSocket() {
+ return socket;
+ }
+
+} // class AbstractNetworkConnection
Property changes on: trunk/src/prj/net/sf/cherbot/connection/AbstractNetworkConnection.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Modified: trunk/src/prj/net/sf/cherbot/connection/IRCConnection.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/IRCConnection.java 2008-12-14 12:39:57 UTC (rev 135)
+++ trunk/src/prj/net/sf/cherbot/connection/IRCConnection.java 2008-12-14 12:43:43 UTC (rev 136)
@@ -26,7 +26,7 @@
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
* @see <a href="ftp://ftp.rfc-editor.org/in-notes/rfc2812.txt">RFC 2812: Internet Relay Chat: Client Protocol</a>
*/
-public class IRCConnection extends AbstractConnection {
+public class IRCConnection extends AbstractNetworkConnection {
/** Serial Version. */
private static final long serialVersionUID = 1L;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|