Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
belaban committed May 17, 2004
1 parent 2789725 commit bfcb66f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 15 deletions.
56 changes: 43 additions & 13 deletions src/org/jgroups/blocks/MethodCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* It includes the name of the method (case sensitive) and a list of arguments.
* A method call is serializable and can be passed over the wire.
* @author Bela Ban
* @version $Revision: 1.5 $
* @version $Revision: 1.6 $
*/
public class MethodCall implements Externalizable {

Expand Down Expand Up @@ -65,6 +65,7 @@ public class MethodCall implements Externalizable {
public MethodCall() {
}


public MethodCall(Method method) {
this(method, null);
}
Expand All @@ -74,6 +75,18 @@ public MethodCall(Method method, Object[] arguments) {
if(arguments != null) args=arguments;
}

/**
*
* @param method_name
* @param args
* @deprecated Use one of the constructors that take class types as arguments
*/
public MethodCall(String method_name, Object[] args) {
this.method_name=method_name;
this.mode=OLD;
this.args=args;
}


public MethodCall(String method_name, Object[] args, Class[] types) {
this.method_name=method_name;
Expand Down Expand Up @@ -140,25 +153,42 @@ public Method getMethod() {


/**
* Returns a method instance for a certain class matching the name and the argument types
* @param target_class - the class that you will invoke the method on
* in this method, not the actual value.
*
* @param target_class
* @return
* @throws Exception
*/
Method findMethod(Class target_class) throws Exception {
int len=args != null? args.length : 0;
Class[] formal_parms=new Class[len];
Method retval;

for(int i=0; i < len; i++) {
formal_parms[i]=args[i].getClass();
Method m;

Method[] methods=target_class.getMethods();
for(int i=0; i < methods.length; i++) {
m=methods[i];
if(m.getName().equals(method_name)) {
if(m.getParameterTypes().length == len)
return m;
}
}

/* getDeclaredMethod() is a bit faster, but only searches for methods in the current
class, not in superclasses */
retval=target_class.getMethod(method_name, formal_parms);
return retval;
return null;
}

// Method findMethod(Class target_class) throws Exception {
// int len=args != null? args.length : 0;
// Class[] formal_parms=new Class[len];
// Method retval;
//
// for(int i=0; i < len; i++) {
// formal_parms[i]=args[i].getClass();
// }
//
// /* getDeclaredMethod() is a bit faster, but only searches for methods in the current
// class, not in superclasses */
// retval=target_class.getMethod(method_name, formal_parms);
// return retval;
// }



/**
Expand Down
12 changes: 10 additions & 2 deletions tests/junit/org/jgroups/tests/MethodCallTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// $Id: MethodCallTest.java,v 1.1 2004/05/15 00:36:47 belaban Exp $
// $Id: MethodCallTest.java,v 1.2 2004/05/17 17:05:53 belaban Exp $

package org.jgroups.tests;

Expand Down Expand Up @@ -32,7 +32,15 @@ public void tearDown() {
}



public void testOld() {
try {
MethodCall mc=new MethodCall("foo", new Object[]{new Integer(22), "Bela"});
assertEquals(mc.invoke(this), Boolean.TRUE);
}
catch(Throwable t) {
fail(t.toString());
}
}

public void testMethod() {
Method m;
Expand Down

0 comments on commit bfcb66f

Please sign in to comment.