From d695618e80925dcc60ac2cb1b4c94d1f4caa8f42 Mon Sep 17 00:00:00 2001 From: Johann Latocha Date: Wed, 25 Jul 2012 19:49:54 +0200 Subject: UNIX -> TCP --- lib/junixsocket-1.3.jar | Bin 16162 -> 0 bytes lib/junixsocket-demo-1.3.jar | Bin 15753 -> 0 bytes lib/junixsocket-mysql-1.3.jar | Bin 1799 -> 0 bytes lib/junixsocket-rmi-1.3.jar | Bin 11598 -> 0 bytes pom.xml | 13 +--------- src/main/java/org/openslx/Test.java | 3 +++ src/main/java/org/openslx/dnbd3/DNBD3Server.java | 30 +++++++---------------- 7 files changed, 13 insertions(+), 33 deletions(-) delete mode 100644 lib/junixsocket-1.3.jar delete mode 100644 lib/junixsocket-demo-1.3.jar delete mode 100644 lib/junixsocket-mysql-1.3.jar delete mode 100644 lib/junixsocket-rmi-1.3.jar diff --git a/lib/junixsocket-1.3.jar b/lib/junixsocket-1.3.jar deleted file mode 100644 index b26e049..0000000 Binary files a/lib/junixsocket-1.3.jar and /dev/null differ diff --git a/lib/junixsocket-demo-1.3.jar b/lib/junixsocket-demo-1.3.jar deleted file mode 100644 index 8fded38..0000000 Binary files a/lib/junixsocket-demo-1.3.jar and /dev/null differ diff --git a/lib/junixsocket-mysql-1.3.jar b/lib/junixsocket-mysql-1.3.jar deleted file mode 100644 index f576e4d..0000000 Binary files a/lib/junixsocket-mysql-1.3.jar and /dev/null differ diff --git a/lib/junixsocket-rmi-1.3.jar b/lib/junixsocket-rmi-1.3.jar deleted file mode 100644 index 37fbd91..0000000 Binary files a/lib/junixsocket-rmi-1.3.jar and /dev/null differ diff --git a/pom.xml b/pom.xml index 127fbde..4acf422 100644 --- a/pom.xml +++ b/pom.xml @@ -15,23 +15,12 @@ - junit junit 3.8.1 test - - - - org.newsclub - junixsocket - 1.3 - system - ${project.basedir}/lib/junixsocket-1.3.jar - - org.jdom @@ -63,7 +52,6 @@ xercesImpl 2.10.0 - @@ -81,4 +69,5 @@ + diff --git a/src/main/java/org/openslx/Test.java b/src/main/java/org/openslx/Test.java index 4e44552..f473df5 100644 --- a/src/main/java/org/openslx/Test.java +++ b/src/main/java/org/openslx/Test.java @@ -13,6 +13,9 @@ public class Test { try { DNBD3Server server = new DNBD3Server(); + // server.doReload(); + // server.doShutdown(); + System.out.println("Exported images (atime, vid, rid, file):"); System.out.println("========================================"); List images = server.getImages(); diff --git a/src/main/java/org/openslx/dnbd3/DNBD3Server.java b/src/main/java/org/openslx/dnbd3/DNBD3Server.java index ce575dd..5cbaa27 100644 --- a/src/main/java/org/openslx/dnbd3/DNBD3Server.java +++ b/src/main/java/org/openslx/dnbd3/DNBD3Server.java @@ -1,10 +1,10 @@ package org.openslx.dnbd3; import java.io.DataOutputStream; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.Socket; import java.util.ArrayList; import java.util.List; @@ -15,32 +15,31 @@ import org.jdom2.filter.Filters; import org.jdom2.input.SAXBuilder; import org.jdom2.xpath.XPathExpression; import org.jdom2.xpath.XPathFactory; -import org.newsclub.net.unix.AFUNIXSocket; -import org.newsclub.net.unix.AFUNIXSocketAddress; public class DNBD3Server { - private final String UNIXSOCK = "/run/dnbd3-server.sock"; - private static final int CMDSTOP = 0; private static final int CMDRELOAD = 1; private static final int CMDINFO = 2; + private static final String HOST = "127.0.0.1"; + private static final int PORT = 5004; + public void doReload() throws IOException { - AFUNIXSocket sock = connect(); + Socket sock = new Socket(HOST, PORT); sendCommand(sock, CMDRELOAD); sock.close(); } public void doShutdown() throws IOException { - AFUNIXSocket sock = connect(); + Socket sock = new Socket(HOST, PORT); sendCommand(sock, CMDSTOP); sock.close(); } public List getImages() throws IOException { List images = new ArrayList(); - AFUNIXSocket sock = connect(); + Socket sock = new Socket(HOST, PORT); sendCommand(sock, CMDINFO); try { @@ -58,7 +57,6 @@ public class DNBD3Server { file = e.getAttributeValue("file"); images.add(new DNBD3Image(atime, vid, rid, file)); } - is.close(); } catch (JDOMException ex) { ex.printStackTrace(); @@ -70,7 +68,7 @@ public class DNBD3Server { public List getClients() throws IOException { List clients = new ArrayList(); - AFUNIXSocket sock = connect(); + Socket sock = new Socket(HOST, PORT); sendCommand(sock, CMDINFO); try { @@ -86,7 +84,6 @@ public class DNBD3Server { image = e.getAttributeValue("file"); clients.add(new DNBD3Client(ip, image)); } - is.close(); } catch (JDOMException ex) { ex.printStackTrace(); @@ -98,19 +95,10 @@ public class DNBD3Server { //////////////////////////////////////////////////////////////////////////////// - private AFUNIXSocket connect() throws IOException { - AFUNIXSocket sock = null; - File socketFile = new File(UNIXSOCK); - sock = AFUNIXSocket.newInstance(); - sock.connect(new AFUNIXSocketAddress(socketFile)); - return sock; - } - - private void sendCommand(AFUNIXSocket sock, int cmd) throws IOException { + private void sendCommand(Socket sock, int cmd) throws IOException { OutputStream os = sock.getOutputStream(); DataOutputStream dos = new DataOutputStream(os); dos.writeInt(cmd); - os.close(); } } -- cgit v1.2.3-55-g7522