Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,10 @@ public void verify_jvm_agent_with_options() throws Exception {
public void verify_jvm_agent_multiple_agents() throws Exception {
super.verify_jvm_agent_multiple_agents();
}

@Test
@Override
public void verify_transparent_proxy_over_classes() throws Exception {
super.verify_transparent_proxy_over_classes();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,10 @@ public void verify_exit_code_is_available() throws Exception {
public void verify_exit_code_is_reported() {
super.verify_exit_code_is_reported();
}

@Test
@Override
public void verify_transparent_proxy_over_classes() throws Exception {
super.verify_transparent_proxy_over_classes();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,10 @@ public void verify_lifecycle_listener_with_invalid_arg() throws Exception {
public void verify_exit_code_is_reported() {
super.verify_exit_code_is_reported();
}

@Test
@Override
public void verify_transparent_proxy_over_classes() throws Exception {
super.verify_transparent_proxy_over_classes();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,10 @@ public void test_classpath_limiting() throws MalformedURLException, URISyntaxExc
public void test_annonimous_primitive_in_args() {
super.test_annonimous_primitive_in_args();
}

@Test
@Override
public void verify_transparent_proxy_over_classes() throws Exception {
super.verify_transparent_proxy_over_classes();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,10 @@ public void test_classpath_limiting() throws MalformedURLException, URISyntaxExc
public void test_annonimous_primitive_in_args() {
super.test_annonimous_primitive_in_args();
}

@Test
@Override
public void verify_transparent_proxy_over_classes() throws Exception {
super.verify_transparent_proxy_over_classes();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ public void verify_lifecycle_listener_with_invalid_arg() throws Exception {
super.verify_lifecycle_listener_with_invalid_arg();
}

@Test
@Override
public void verify_transparent_proxy_over_classes() throws Exception {
super.verify_transparent_proxy_over_classes();
}

@Test
@Override
public void verify_jvm_agent_multiple_agents() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,19 @@ public void verify_jvm_agent_with_options() throws Exception {

@Test
@Override
public void verify_jvm_agent_multiple_agents() throws Exception {
super.verify_jvm_agent_with_options();
}

@Test
@Override
public void verify_exit_code_is_reported() {
super.verify_exit_code_is_reported();
}
}
public void verify_jvm_agent_multiple_agents() throws Exception {
super.verify_jvm_agent_with_options();
}

@Test
@Override
public void verify_exit_code_is_reported() {
super.verify_exit_code_is_reported();
}

@Test
@Override
public void verify_transparent_proxy_over_classes() throws Exception {
super.verify_transparent_proxy_over_classes();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,44 @@ public void verify_lifecycle_listener_with_invalid_arg() throws Exception {
pll.waitNodeExitCode(node.toString(), 1);
}

public void verify_transparent_proxy_over_classes() throws Exception {
// marked with Remote interfaces
class TestForProxyRemote implements Remote {
public String greet() {
return "Hello";
}
}

final TestForProxyRemote testForProxyRemote = new TestForProxyRemote();

ViNode node = cloud.node(testName.getMethodName());
Assert.assertEquals("Hello",
node.exec(new Callable<String>() {
@Override
public String call() {
return testForProxyRemote.greet();
}
})
);

// marked with cloud.createRmiProxy
class TestForProxy {
public String greet() {
return "Hello";
}
}
final TestForProxy testForProxy = cloud.createRmiProxy(new TestForProxy());

Assert.assertEquals("Hello",
node.exec(new Callable<String>() {
@Override
public String call() {
return testForProxy.greet();
}
})
);
}

private static String readMarkerFromResources() throws IOException {
URL url = IsolateNodeFeatureTest.class.getResource("/marker.txt");
Assert.assertNotNull(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,10 @@ public void verify_jvm_agent_with_options() throws Exception {
public void verify_jvm_agent_multiple_agents() throws Exception {
super.verify_jvm_agent_multiple_agents();
}

@Test
@Override
public void verify_transparent_proxy_over_classes() throws Exception {
super.verify_transparent_proxy_over_classes();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.gridkit.nanocloud.Cloud;
import org.gridkit.nanocloud.CloudFactory;
import org.gridkit.vicluster.ViNode;
import org.gridkit.zerormi.SmartRmiMarshaler;
import org.junit.rules.ExternalResource;

public class DisposableCloud extends ExternalResource implements CloudRule {
Expand Down Expand Up @@ -35,4 +36,9 @@ public Collection<ViNode> listNodes(String nameOrSelector) {
public void shutdown() {
cloud.shutdown();
}

@Override
public <T> T createRmiProxy(T object){
return SmartRmiMarshaler.wrapForRmiProxy(object);
}
}
7 changes: 7 additions & 0 deletions vicluster-core/src/main/java/org/gridkit/nanocloud/Cloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ public interface Cloud {

public void shutdown();

/**
* Replaced class with instances that eligible to transparent-rmi.
* If result of this call will be passed to remote side, proxy will be created at remote side, and
* all method invocations will be passed to original object.
*/
public <T> T createRmiProxy(T object);

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.gridkit.zerormi.RemoteExecutorAsynAdapter;
import org.gridkit.zerormi.RemoteExecutor;
import org.gridkit.zerormi.RemoteStub;
import org.gridkit.zerormi.SmartRmiMarshaler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -240,7 +241,12 @@ public void run() {
}
provider.shutdown();
}


@Override
public <T> T createRmiProxy(T object){
return SmartRmiMarshaler.wrapForRmiProxy(object);
}

public synchronized void resetDeadNode() {
ensureAlive();
deadNodes.clear();
Expand Down
44 changes: 43 additions & 1 deletion zerormi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.14.5</version>
</dependency>
<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>3.3</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -85,7 +96,38 @@
<configuration>
<forkMode>always</forkMode>
</configuration>
</plugin>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>net.bytebuddy</pattern>
<shadedPattern>org.gridkit.internal.net.bytebuddy</shadedPattern>
</relocation>
<relocation>
<pattern>org.objenesis</pattern>
<shadedPattern>org.gridkit.internal.org.objenesis</shadedPattern>
</relocation>
</relocations>
<artifactSet>
<includes>
<include>net.bytebuddy:*</include>
<include>org.objenesis:*</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.gridkit.zerormi;

/**
* Marker interface, classes wrapped with Cloud::createRmiProxy will be marked with it.
* Not intended for direct use in client code.
*/
public interface CreateRemoteProxy {
}
16 changes: 8 additions & 8 deletions zerormi/src/main/java/org/gridkit/zerormi/Exported.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
*/
public class Exported {

private Class<?>[] interfaces;
private Object object;

public Exported(Object object, Class<?>... interfaces) {
this.object = object;
this.interfaces = interfaces;
}
private final Class<?> originalClass;

public Class<?>[] getInterfaces() {
return interfaces;
public Exported(Object object, Class<?> originalClass) {
this.object = object;
this.originalClass = originalClass;
}

public Object getObject() {
return object;
}

public Class<?> getOriginalClass() {
return originalClass;
}
}
20 changes: 10 additions & 10 deletions zerormi/src/main/java/org/gridkit/zerormi/RemoteInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,32 @@ public final class RemoteInstance implements Serializable {
private static final long serialVersionUID = 20090415L;

String instanceId;
String[] interfaces;
String className;

public String[] getInterfaces() {
return interfaces;
public String getClassName() {
return className;
}

public String getInstanceId() {
return instanceId;
}

public RemoteInstance(String instanceId, String[] interfaces) {
public RemoteInstance(String instanceId, String className) {
if (instanceId == null) {
throw new NullPointerException("instanceId cannot be null");
}
if (interfaces == null) {
throw new NullPointerException("interfaces cannot be null");
if (className == null) {
throw new NullPointerException("className cannot be null");
}
this.instanceId = instanceId;
this.interfaces = interfaces;
this.className = className;
}

@Override
public boolean equals(Object obj) {
if (obj instanceof RemoteInstance) {
RemoteInstance ri = (RemoteInstance) obj;
return instanceId.equals(ri.instanceId) && Arrays.equals(interfaces, ri.interfaces);
return instanceId.equals(ri.instanceId) && className.equals(ri.className);
}
return false;
}
Expand All @@ -64,6 +64,6 @@ public int hashCode() {

@Override
public String toString() {
return "${" + instanceId +"}" + Arrays.toString(interfaces);
return "${" + instanceId +"}" + className;
}
}
Loading