Write Service File
/*
*Copyright (c) Jmin. All rights reserved.
*/
package first;
import org.jmin.kernel.framework.ext.J2eeAbstractService;
/**
* service sample.
*
* @author Chris liao
* @version 1.0
*/
public class RPCService extends J2eeAbstractService{
/**
* Here, you need't put down anything.
* It is simple ?
*/
}
Write RPC file
/*
*Copyright (c) jmin Organization. All rights reserved.
*/
package first;
import org.jmin.kernel.aspect.msg.rpc.InvocationAssistant;
/**
* RPC sample
*
* @author Chris liao
* @version 1.0
*/
public class HelloRPCAssistant implements InvocationAssistant{
/**
* RPC method
* @RPC
*/
public void hello(){
System.out.println("Hello World!");
}
/**
* RPC method
* @RPC
*/
public void hello(String name){
System.out.println("Hello," + name);
}
} Define xml description file
//*file:service.xml
<?xml version="1.0"?>
<service id="admin">
<components>
<component id="RPCService" type="service">
<class>first.RPCService</class>
<property name="aspectPool">
<map>
<entry key="helloRPC" class="first.HelloRPCAssistant"/>
</map>
</property>
</component>
</components>
</service>
กก Deploy Service file
Make a jar file include all class files and description
file, then put the jar to Jmin deploy folder
กก Testing /*
*Copyright (c) jmin Organization. All rights reserved.
*/
package first;
import org.jmin.kernel.aspect.msg.rpc.*;
import org.jmin.kernel.aspect.net.*;
import org.jmin.kernel.framework.aspect.J2eeAspectAddress;
/**
* RPC sample
*
* @author Chris liao
* @version 1.0
*/
public class TestHelloService {
public static void main(String args[])throws Exception{
NSRB nsrb = NSRB.init();
NetContext context = nsrb.createNetContext("socket://localhost:9988");
RpcProxy proxy = new RpcProxy();
proxy.bind(context);
J2eeAspectAddress destination = new J2eeAspectAddress();
destination.setServiceID("RPCService");
destination.setAspectName("hello");
Invocation request = new Invocation();
request.setMethodName("hello");
request.setParameters(new Object[]{});
System.out.println("reply " + proxy.invoke(destination,request));
request.setAsyn(true);
request.setParameters(new Object[]{new String("Liao")});
System.out.println("reply " + proxy.invoke(destination,request));
}
}
 |
Copyright © 2006 . All Rights Reserved. |
|