KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > marshall > MethodCall


1 /*
2  * JBoss, Home of Professional Open Source
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.cache.marshall;
8
9 import java.lang.reflect.Method JavaDoc;
10
11 /**
12  * An extension of the JGroups MethodCall class. The reason for this subclass is a minor
13  * optimisation in the way method IDs are dealt with. The JGroups class of the same name uses
14  * a short as a method id, which is more efficient as far as network streaming is concerned.
15  * <p/>
16  * However, JBossCache uses this id for a lot of == and switch comparisons. Java, being an
17  * integer oriented virtual machine, goes through a lot of extra steps when performing such simple
18  * comparisons or arithmetic on non-integer numeric types.
19  * <p/>
20  * See <a HREF="http://www.liemur.com/Articles/FineTuningJavaCode-IntOrientedMachine.html">http://www.liemur.com/Articles/FineTuningJavaCode-IntOrientedMachine.html</a>
21  * <p/>
22  * Thanks to Elias Ross/genman for this info.
23  *
24  * @author <a HREF="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
25  */

26 public class MethodCall extends org.jgroups.blocks.MethodCall
27 {
28    /**
29     * It's unclear why this class would be serialized.
30     */

31    private static final long serialVersionUID = -5316198032742449998L;
32    
33    private int methodIdInteger = -1;
34
35    public MethodCall()
36    {
37       super();
38    }
39
40    public MethodCall(Method JavaDoc method, Object JavaDoc[] arguments)
41    {
42       super(method, arguments);
43    }
44
45    public MethodCall(Method JavaDoc method, Object JavaDoc[] arguments, int methodIdInteger)
46    {
47       super(method, arguments);
48       this.methodIdInteger = methodIdInteger;
49    }
50
51    public void setMethodId(int id)
52    {
53       methodIdInteger = id;
54    }
55
56    public int getMethodId()
57    {
58       return methodIdInteger;
59    }
60
61    public String JavaDoc toString()
62    {
63       StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
64       boolean first = true;
65       ret.append("MethodName: ");
66       ret.append(method_name);
67       ret.append("; MethodIdInteger: ");
68       ret.append(methodIdInteger);
69       ret.append("; Args: (");
70       if (args != null)
71       {
72          for (int i = 0; i < args.length; i++)
73          {
74             if (first)
75             {
76                first = false;
77             }
78             else
79             {
80                ret.append(", ");
81             }
82             ret.append(args[i]);
83          }
84       }
85       ret.append(')');
86       return ret.toString();
87
88    }
89 }
90
Popular Tags