Skip to content
Browse files

Added basic remoting framework & library deps.

  • Loading branch information...
1 parent 2b655b6 commit 0ee997fda6dc3fa4e4597ebfa20b073b8f3fb0bd @labisso labisso committed Oct 1, 2010
View
1 .gitignore
@@ -20,3 +20,4 @@ derby.log
tmp/
workspace.persistence.conf
cloud-client/nimbus-cloud-client-0*
+out/
View
2 .idea/libraries/workspace_service_libs.xml
@@ -16,6 +16,8 @@
<root url="jar://$PROJECT_DIR$/lib/services/jug-2.0.0.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/services/commons-collections-3.2.1.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/services/commons-io-1.4.jar!/" />
+ <root url="jar://$PROJECT_DIR$/lib/services/junixsocket-1.3.jar!/" />
+ <root url="jar://$PROJECT_DIR$/lib/services/junixsocket-rmi-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
View
15 lib/licenses/junixsocket-1.3.LICENSE
@@ -0,0 +1,15 @@
+junixsocket
+
+Copyright (c) 2009,2010 NewsClub, Christian Kohlschütter
+
+The author licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
View
BIN lib/native/libjunixsocket-linux-1.5-amd64.so
Binary file not shown.
View
BIN lib/native/libjunixsocket-linux-1.5-i386.so
Binary file not shown.
View
BIN lib/native/libjunixsocket-macosx-1.5-i386.dylib
Binary file not shown.
View
BIN lib/native/libjunixsocket-macosx-1.5-x86_64.dylib
Binary file not shown.
View
BIN lib/services/junixsocket-1.3.jar
Binary file not shown.
View
BIN lib/services/junixsocket-rmi-1.3.jar
Binary file not shown.
View
76 service/service/java/source/src/org/globus/workspace/remoting/RemotingClient.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 1999-2010 University of Chicago
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package org.globus.workspace.remoting;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.newsclub.net.unix.rmi.AFUNIXNaming;
+import org.springframework.core.io.Resource;
+
+import java.io.File;
+import java.io.IOException;
+import java.rmi.NotBoundException;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.registry.Registry;
+
+public class RemotingClient {
+
+ private static final Log logger =
+ LogFactory.getLog(RemotingClient.class.getName());
+
+ private File socketDirectory;
+ private Registry rmiRegistry;
+
+
+ public void initialize() throws Exception {
+ if (this.socketDirectory == null) {
+ throw new IllegalStateException("socketDirectory must be specified");
+ }
+ if (!this.socketDirectory.isDirectory()) {
+ throw new IllegalStateException("socketDirectory must be an existing directory");
+ }
+
+ AFUNIXNaming naming = AFUNIXNaming.getInstance(this.socketDirectory);
+ logger.debug("Socket directory: " + naming.getSocketFactory().getSocketDir());
+
+ this.rmiRegistry = naming.getRegistry();
+ }
+
+ public Remote lookup(String name) throws RemoteException, NotBoundException {
+ if (name == null) {
+ throw new IllegalArgumentException("name may not be null");
+ }
+
+ if (this.rmiRegistry == null) {
+ throw new IllegalStateException("Remoting client is uninitialized");
+ }
+
+ return this.rmiRegistry.lookup(name);
+ }
+
+ public File getSocketDirectory() {
+ return socketDirectory;
+ }
+
+ public void setSocketDirectory(File socketDirectory) {
+ this.socketDirectory = socketDirectory;
+ }
+
+ public void setSocketResource(Resource socketResource) throws IOException {
+ this.socketDirectory = socketResource.getFile();
+ }
+}
View
90 service/service/java/source/src/org/globus/workspace/remoting/RemotingServer.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 1999-2010 University of Chicago
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package org.globus.workspace.remoting;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.newsclub.net.unix.rmi.AFUNIXNaming;
+import org.springframework.core.io.Resource;
+
+import java.io.File;
+import java.io.IOException;
+import java.rmi.AlreadyBoundException;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.registry.Registry;
+import java.rmi.server.UnicastRemoteObject;
+import java.util.Map;
+
+public class RemotingServer {
+
+ private static final Log logger =
+ LogFactory.getLog(RemotingServer.class.getName());
+
+ private File socketDirectory;
+ private Map<String, Remote> bindings;
+
+ public void initialize() throws RemoteException, AlreadyBoundException {
+ if (this.socketDirectory == null) {
+ throw new IllegalStateException("socketDirectory must be specified");
+ }
+ if (!this.socketDirectory.isDirectory()) {
+ throw new IllegalStateException("socketDirectory must be an existing directory");
+ }
+
+ if (this.bindings == null || this.bindings.isEmpty()) {
+ throw new IllegalStateException("at least one binding must be specified");
+ }
+
+ final AFUNIXNaming naming = AFUNIXNaming.getInstance(this.socketDirectory);
+ logger.debug("Socket directory: " + naming.getSocketFactory().getSocketDir());
+
+ final Registry registry = naming.createRegistry();
+
+ for (final String bindingName : bindings.keySet()) {
+ final Remote obj = bindings.get(bindingName);
+ if (obj == null) {
+ throw new IllegalStateException("Binding object "+ bindingName + "' is null");
+ }
+
+ logger.debug("Binding " + obj.toString() + " to name '"+ bindingName + "'");
+
+ final Remote remote = UnicastRemoteObject.exportObject(obj, 0,
+ naming.getSocketFactory(), naming.getSocketFactory());
+ registry.bind(bindingName, remote);
+ }
+ }
+
+ public File getSocketDirectory() {
+ return socketDirectory;
+ }
+
+ public void setSocketDirectory(File socketDirectory) {
+ this.socketDirectory = socketDirectory;
+ }
+
+ public void setSocketResource(Resource socketResource) throws IOException {
+ this.socketDirectory = socketResource.getFile();
+ }
+
+ public Map<String, Remote> getBindings() {
+ return bindings;
+ }
+
+ public void setBindings(Map<String, Remote> bindings) {
+ this.bindings = bindings;
+ }
+}
View
105 service/service/java/tests/unit/org/globus/workspace/remoting/RemotingTests.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 1999-2010 University of Chicago
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package org.globus.workspace.remoting;
+
+import org.apache.commons.io.FileUtils;
+import static org.testng.Assert.*;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.rmi.Remote;
+import java.util.Collections;
+import java.util.Map;
+
+public class RemotingTests {
+
+ private File socketDir;
+
+ public RemotingTests() {
+ //hmmmm, not sure how to do this..
+ System.setProperty("org.newsclub.net.unix.library.path",
+ "/Users/david/Code/nimbus/lib/native");
+ }
+
+ @Before
+ public void setUp() throws IOException {
+ socketDir = createTempDirectory();
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ FileUtils.deleteDirectory(socketDir);
+ }
+
+ @Test
+ public void testRemoting() throws Exception {
+ final Counter localCounter = new CounterImpl();
+ Map<String,Remote> bindings = Collections.singletonMap("counter",
+ (Remote)localCounter);
+
+ RemotingServer server = new RemotingServer();
+ server.setSocketDirectory(socketDir);
+ server.setBindings(bindings);
+ server.initialize();
+
+ // okay, not really remote
+ RemotingClient client = new RemotingClient();
+ client.setSocketDirectory(socketDir);
+ client.initialize();
+ Counter remoteCounter = (Counter) client.lookup("counter");
+ assertNotSame(remoteCounter, localCounter);
+
+ localCounter.increment();
+ assertEquals(remoteCounter.getCount(), 1);
+ assertEquals(remoteCounter.getCount(), localCounter.getCount());
+
+ remoteCounter.increment();
+ assertEquals(remoteCounter.getCount(), 2);
+ assertEquals(remoteCounter.getCount(), localCounter.getCount());
+ }
+
+ public static File createTempDirectory() throws IOException {
+ final File temp = File.createTempFile("temp", null);
+ if (!(temp.delete())) {
+ throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
+ }
+ if (!(temp.mkdir())) {
+ throw new IOException("Could not create temp directory: " + temp.getAbsolutePath());
+ }
+ return temp;
+ }
+}
+
+interface Counter extends Remote {
+ int getCount() throws IOException;
+ void increment() throws IOException;
+}
+
+class CounterImpl implements Counter {
+
+ private int count = 0;
+
+ public int getCount() {
+ return count;
+ }
+
+ public void increment() {
+ count++;
+ }
+}

0 comments on commit 0ee997f

Please sign in to comment.
Something went wrong with that request. Please try again.