X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2Fserver%2FConnectActionClient.java;h=cb6bef3988c94e8f07d0306a8714ff85f3a9b1d8;hb=ebac96b0184f044a4b2db35cb8f445aeb048d743;hp=db06a9f247544cef1d210531d7db45429af1a78b;hpb=f4053377fa15da2f11e82955bfab86e673fa371c;p=fanfix.git diff --git a/src/be/nikiroo/utils/serial/server/ConnectActionClient.java b/src/be/nikiroo/utils/serial/server/ConnectActionClient.java deleted file mode 100644 index db06a9f..0000000 --- a/src/be/nikiroo/utils/serial/server/ConnectActionClient.java +++ /dev/null @@ -1,156 +0,0 @@ -package be.nikiroo.utils.serial.server; - -import java.io.IOException; -import java.net.Socket; -import java.net.UnknownHostException; - -import be.nikiroo.utils.Version; - -/** - * Base class used for the client basic handling. - *

- * It represents a single action: a client is expected to only execute one - * action. - * - * @author niki - */ -abstract class ConnectActionClient { - /** - * The underlying {@link ConnectAction}. - *

- * Cannot be NULL. - */ - protected ConnectAction action; - - /** - * Create a new {@link ConnectActionClient} with the current application - * version (see {@link Version#getCurrentVersion()}) as the client version. - * - * @param s - * the socket to bind to - */ - public ConnectActionClient(Socket s) { - this(s, Version.getCurrentVersion()); - } - - /** - * Create a new {@link ConnectActionClient} with the current application - * version (see {@link Version#getCurrentVersion()}) as the client version. - * - * @param host - * the host to bind to - * @param port - * the port to bind to - * @param ssl - * TRUE for an SSL connection, FALSE for plain text - * - * @throws IOException - * in case of I/O error - * @throws UnknownHostException - * if the host is not known - * @throws IllegalArgumentException - * if the port parameter is outside the specified range of valid - * port values, which is between 0 and 65535, inclusive - */ - public ConnectActionClient(String host, int port, boolean ssl) - throws IOException { - this(Server.createSocket(host, port, ssl), Version.getCurrentVersion()); - } - - /** - * Create a new {@link ConnectActionClient}. - * - * @param host - * the host to bind to - * @param port - * the port to bind to - * @param ssl - * TRUE for an SSL connection, FALSE for plain text - * @param version - * the client version - * - * @throws IOException - * in case of I/O error - * @throws UnknownHostException - * if the host is not known - * @throws IllegalArgumentException - * if the port parameter is outside the specified range of valid - * port values, which is between 0 and 65535, inclusive - */ - public ConnectActionClient(String host, int port, boolean ssl, - Version version) throws IOException { - this(Server.createSocket(host, port, ssl), version); - } - - /** - * Create a new {@link ConnectActionClient}. - * - * @param s - * the socket to bind to - * @param version - * the client version - */ - public ConnectActionClient(Socket s, Version version) { - action = new ConnectAction(s, false, version) { - @Override - protected void action(Version serverVersion) throws Exception { - ConnectActionClient.this.action(serverVersion); - } - - @Override - protected void onError(Exception e) { - ConnectActionClient.this.onError(e); - } - - @Override - protected Version negotiateVersion(Version clientVersion) { - new Exception("Should never be called on a client") - .printStackTrace(); - return null; - } - }; - } - - /** - * Actually start the process and call the action (synchronous). - */ - public void connect() { - action.connect(); - } - - /** - * Actually start the process and call the action (asynchronous). - */ - public void connectAsync() { - new Thread(new Runnable() { - @Override - public void run() { - connect(); - } - }).start(); - } - - /** - * Method that will be called when an action is performed on the client. - * - * @param serverVersion - * the server version - * - * @throws Exception - * in case of I/O error - */ - @SuppressWarnings("unused") - public void action(Version serverVersion) throws Exception { - } - - /** - * Handler called when an unexpected error occurs in the code. - *

- * Will just ignore the error by default. - * - * @param e - * the exception that occurred - */ - protected void onError(@SuppressWarnings("unused") Exception e) { - } -} \ No newline at end of file