1 3 package org.jgroups.stack; 4 5 6 import org.jgroups.*; 7 import org.jgroups.blocks.MethodCall; 8 import org.jgroups.util.RspList; 9 import org.jgroups.util.Util; 10 11 import java.util.Vector ; 12 13 14 15 16 20 public class RpcProtocol extends MessageProtocol { 21 22 23 public String getName() { 24 return "RpcProtocol"; 25 } 26 27 28 29 public RspList callRemoteMethods(Vector dests, String method_name, Object [] args, 30 Class [] types, int mode, long timeout) { 31 MethodCall method_call=new MethodCall(method_name, args, types); 32 return callRemoteMethods(dests, method_call, mode, timeout); 33 } 34 35 public RspList callRemoteMethods(Vector dests, String method_name, Object [] args, 36 String [] signature, int mode, long timeout) { 37 MethodCall method_call=new MethodCall(method_name, args, signature); 38 return callRemoteMethods(dests, method_call, mode, timeout); 39 } 40 41 42 public RspList callRemoteMethods(Vector dests, MethodCall method_call, int mode, long timeout) { 43 byte[] buf=null; 44 Message msg=null; 45 46 try { 47 buf=Util.objectToByteBuffer(method_call); 48 } 49 catch(Exception e) { 50 if(log.isErrorEnabled()) log.error("exception=" + e); 51 return null; 52 } 53 54 msg=new Message(null, null, buf); 55 return castMessage(dests, msg, mode, timeout); 56 } 57 58 59 public Object callRemoteMethod(Address dest, String method_name, int mode, long timeout) 60 throws TimeoutException, SuspectedException { 61 return callRemoteMethod(dest, method_name, new Object []{}, new Class []{}, mode, timeout); 62 } 63 64 65 public Object callRemoteMethod(Address dest, String method_name, Object [] args, 66 Class [] types, int mode, long timeout) 67 throws TimeoutException, SuspectedException { 68 MethodCall method_call=new MethodCall(method_name, args, types); 69 return callRemoteMethod(dest, method_call, mode, timeout); 70 } 71 72 public Object callRemoteMethod(Address dest, String method_name, Object [] args, 73 String [] signature, int mode, long timeout) 74 throws TimeoutException, SuspectedException { 75 MethodCall method_call=new MethodCall(method_name, args, signature); 76 return callRemoteMethod(dest, method_call, mode, timeout); 77 } 78 79 80 public Object callRemoteMethod(Address dest, MethodCall method_call, int mode, long timeout) 81 throws TimeoutException, SuspectedException { 82 byte[] buf=null; 83 Message msg=null; 84 85 try { 86 buf=Util.objectToByteBuffer(method_call); 87 } 88 catch(Exception e) { 89 if(log.isErrorEnabled()) log.error("exception=" + e); 90 return null; 91 } 92 93 msg=new Message(dest, null, buf); 94 return sendMessage(msg, mode, timeout); 95 } 96 97 98 102 public Object handle(Message req) { 103 Object body=null; 104 MethodCall method_call; 105 106 if(req == null || req.getLength() == 0) { 107 if(log.isErrorEnabled()) log.error("message or message buffer is null"); 108 return null; 109 } 110 111 try { 112 body=req.getObject(); 113 } 114 catch(Exception e) { 115 if(log.isErrorEnabled()) log.error("exception=" + e); 116 return e; 117 } 118 119 if(body == null || !(body instanceof MethodCall)) { 120 if(log.isErrorEnabled()) log.error("message does not contain a MethodCall object"); 121 return null; 122 } 123 124 method_call=(MethodCall)body; 125 try { 126 return method_call.invoke(this); 127 } 128 catch(Throwable x) { 129 if(log.isErrorEnabled()) log.error(Util.getStackTrace(x)); 130 return x; 131 } 132 } 133 134 135 138 public boolean handleUpEvent(Event evt) { 139 return true; 140 } 141 142 143 146 public boolean handleDownEvent(Event evt) { 147 return true; 148 } 149 150 151 } 152 | Popular Tags |