[Cherbot-commit] SF.net SVN: cherbot:[137] trunk/src/prj/net/sf/cherbot/connection
Status: Alpha
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2008-12-14 12:53:54
|
Revision: 137
http://cherbot.svn.sourceforge.net/cherbot/?rev=137&view=rev
Author: christianhujer
Date: 2008-12-14 12:53:44 +0000 (Sun, 14 Dec 2008)
Log Message:
-----------
Extracted AbstractConnection superclass from AbstractNetworkConnection.
Modified Paths:
--------------
trunk/src/prj/net/sf/cherbot/connection/AbstractNetworkConnection.java
trunk/src/prj/net/sf/cherbot/connection/CrossfireConnection.java
trunk/src/prj/net/sf/cherbot/connection/DaimoninConnection.java
trunk/src/prj/net/sf/cherbot/connection/IRCConnection.java
Added Paths:
-----------
trunk/src/prj/net/sf/cherbot/connection/AbstractConnection.java
Added: trunk/src/prj/net/sf/cherbot/connection/AbstractConnection.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/AbstractConnection.java (rev 0)
+++ trunk/src/prj/net/sf/cherbot/connection/AbstractConnection.java 2008-12-14 12:53:44 UTC (rev 137)
@@ -0,0 +1,36 @@
+package net.sf.cherbot.connection;
+
+import net.sf.japi.io.args.BasicCommand;
+import java.io.Closeable;
+import java.io.Serializable;
+import java.io.IOException;
+
+/** An AbstractConnection represents a connection of CherBot.
+ * 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>
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public abstract class AbstractConnection extends BasicCommand implements Closeable, Serializable {
+
+ /** 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();
+}
Property changes on: trunk/src/prj/net/sf/cherbot/connection/AbstractConnection.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Modified: trunk/src/prj/net/sf/cherbot/connection/AbstractNetworkConnection.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/AbstractNetworkConnection.java 2008-12-14 12:43:43 UTC (rev 136)
+++ trunk/src/prj/net/sf/cherbot/connection/AbstractNetworkConnection.java 2008-12-14 12:53:44 UTC (rev 137)
@@ -6,32 +6,17 @@
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.
+/** 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 BasicCommand implements Closeable, Serializable {
+public abstract class AbstractNetworkConnection extends AbstractConnection {
/** The host to connect to.
* @serial include
@@ -78,13 +63,11 @@
/** 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 {
+ public void connect() throws IOException {
final Socket socket = new Socket(host, port);
setSocket(socket);
- return socket;
}
/** {@inheritDoc} */
Modified: trunk/src/prj/net/sf/cherbot/connection/CrossfireConnection.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/CrossfireConnection.java 2008-12-14 12:43:43 UTC (rev 136)
+++ trunk/src/prj/net/sf/cherbot/connection/CrossfireConnection.java 2008-12-14 12:53:44 UTC (rev 137)
@@ -41,8 +41,9 @@
}
/** {@inheritDoc} */
- @NotNull @Override public Socket connect() throws IOException {
- final Socket socket = super.connect();
+ @Override public void connect() throws IOException {
+ super.connect();
+ final Socket socket = getSocket();
readToNull();
textMsg("version 1023 1023 CherBot");
textMsg("setup bot 1");
@@ -53,7 +54,6 @@
textMsg("reply " + getUsername());
readToNull();
textMsg("reply " + getPassword());
- return socket;
}
/** {@inheritDoc} */
Modified: trunk/src/prj/net/sf/cherbot/connection/DaimoninConnection.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/DaimoninConnection.java 2008-12-14 12:43:43 UTC (rev 136)
+++ trunk/src/prj/net/sf/cherbot/connection/DaimoninConnection.java 2008-12-14 12:53:44 UTC (rev 137)
@@ -41,8 +41,9 @@
}
/** {@inheritDoc} */
- @NotNull @Override public Socket connect() throws IOException {
- final Socket socket = super.connect();
+ @Override public void connect() throws IOException {
+ super.connect();
+ final Socket socket = getSocket();
readToNull(); // "991023 991023 Daimonin Server"
textMsg("version 991023 991023 Daimonin SDL Client"); // we have to cheat or the server won't let us in.
textMsg("setup bot 1"); // We are a bot
@@ -53,7 +54,6 @@
textMsg("reply L" + getUsername());
readToNull(); // 0x00 0x06 0x18 "4 QP0"
textMsg("reply " + getPassword());
- return socket;
}
/** {@inheritDoc} */
Modified: trunk/src/prj/net/sf/cherbot/connection/IRCConnection.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/IRCConnection.java 2008-12-14 12:43:43 UTC (rev 136)
+++ trunk/src/prj/net/sf/cherbot/connection/IRCConnection.java 2008-12-14 12:53:44 UTC (rev 137)
@@ -77,8 +77,9 @@
}
/** {@inheritDoc} */
- @Override @NotNull public Socket connect() throws IOException {
- final Socket socket = super.connect();
+ @Override public void connect() throws IOException {
+ super.connect();
+ final Socket socket = getSocket();
final PrintWriter out = this.out;
assert this.out != null;
out.println("USER " + username + " 0 * :" + realname);
@@ -87,7 +88,6 @@
out.println("PRIVMSG NICKSERV :IDENTIFY " + nickPassword);
}
out.flush();
- return socket;
}
/** {@inheritDoc} */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|