📄 rpcclientimpl.java
字号:
package mina.client;
import java.util.Date;
import java.util.Properties;
import mina.common.Apple;
import mina.common.RpcInterface;
import org.apache.mina.common.ByteBuffer;
public class RpcClientImpl extends AbstractClientImpl implements RpcInterface {
private static String IFNAME = RpcInterface.class.getName();
// public RpcClientImpl(IoSession sess){
// session = sess;
// }
private static RpcClientImpl instance = null;
public static RpcClientImpl getInstance(){
if(instance == null){
instance = new RpcClientImpl();
}
return instance;
}
public String getStringValue(String arg0,int arg1,Apple arg2) {
if(session!=null){
Properties prop = new Properties();
prop.setProperty("interface",IFNAME);
prop.setProperty("method","getStringValue");
prop.setProperty("argc","3");
//prop.put("object",new Object());
prop.put("type0",String.class);
prop.put("arg0",arg0);
prop.put("type1",Integer.TYPE);
prop.put("arg1",arg1);
prop.put("type2",Apple.class);
prop.put("arg2",arg2);
ByteBuffer bb = ByteBuffer.allocate(16);
bb.setAutoExpand( true );
bb.putObject(prop);
bb.flip();
System.out.println("bbb==="+bb.toString());
session.write(bb);
}
try {
System.out.println("handler="+handler);
System.out.println("lock="+handler.lock);
printStamp("1");
synchronized(handler.lock){
printStamp("2");
handler.lock.wait();
printStamp("3");
if(handler.resultObject!=null){
return String.valueOf(handler.resultObject);
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
/*
public String getStringValue() {
if(session!=null){
Properties prop = new Properties();
prop.setProperty("interface",IFNAME);
prop.setProperty("method","getStringValue");
prop.setProperty("args","0");
//prop.put("object",new Object());
prop.put("date",new Date());
prop.put("apple",new Apple());
Vector v = new Vector();
v.add(new Vector());
v.add(new Date());
v.add(new Vector());
v.add(new Apple());
prop.put("multi",v);
ByteBuffer bb = ByteBuffer.allocate(16);
bb.setAutoExpand( true );
bb.putObject(prop);
bb.flip();
System.out.println("bbb==="+bb.toString());
session.write(bb);
}
try {
System.out.println("handler="+handler);
System.out.println("lock="+handler.lock);
printStamp("1");
synchronized(handler.lock){
printStamp("2");
handler.lock.wait();
printStamp("3");
if(handler.resultObject!=null){
return String.valueOf(handler.resultObject);
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
*/
public int getIntValue() {
if(session!=null){
Properties prop = new Properties();
prop.setProperty("interface",IFNAME);
prop.setProperty("method","getIntValue");
prop.setProperty("argc",String.valueOf(Integer.MAX_VALUE));
//prop.put("object",new Object());
ByteBuffer bb = ByteBuffer.allocate(16);
bb.setAutoExpand( true );
bb.putObject(prop);
bb.flip();
System.out.println("bbb==="+bb.toString());
session.write(bb);
}
try {
System.out.println("handler="+handler);
System.out.println("lock="+handler.lock);
printStamp("1");
synchronized(handler.lock){
printStamp("2");
handler.lock.wait();
printStamp("3");
if(handler.resultObject!=null){
return Integer.parseInt(String.valueOf(handler.resultObject));
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
return Integer.MIN_VALUE;
}
public void printStamp(String str){
System.out.println((new Date().toString())+" "+str);
}
public static void main(String[] args){
Class[] clz = RpcClientImpl.class.getInterfaces();
for(int i=0 ;i<clz.length;i++){
System.out.println(clz[i].getName());//输出mina.RpcInterface
}
System.out.println("2="+IFNAME);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -