View Javadoc

1   package net.sf.crispy.impl;
2   
3   import java.lang.reflect.Method;
4   import java.util.Map;
5   import java.util.Vector;
6   
7   import net.sf.crispy.Executor;
8   import net.sf.crispy.InvocationException;
9   import net.sf.crispy.InvocationStrategy;
10  import net.sf.crispy.strategy.ClassMethodMapInvocationStrategy;
11  import net.sf.crispy.util.Util;
12  
13  import org.jboss.remoting.Client;
14  import org.jboss.remoting.InvokerLocator;
15  
16  /**
17   * Remote-Call for JBoss remoting.
18   * 
19   * @author Linke
20   *
21   */
22  public class JBossRemotingExecutor extends Executor {
23  	
24  	public final static String DEFAULT_URL_AND_PORT = "socket://localhost:5411";
25  	
26  	private Client client = null;
27  
28  	public String getDefaultUrlAndPort() { return DEFAULT_URL_AND_PORT;	}
29      public InvocationStrategy getDefaultInvocationStrategy() { return new ClassMethodMapInvocationStrategy(); }
30  
31  	public Object execute(Class pvProxyClass, Object pvProxy, Method pvMethod, Object[] pvArgs) throws Exception {
32  		if (client == null) {
33  			InvokerLocator locator = new InvokerLocator(getUrlAndPort());
34  			client = new org.jboss.remoting.Client(locator);
35  		}
36  		
37  	    Vector params = new Vector();
38  		if (pvArgs != null) {
39  			for (int i = 0; i < pvArgs.length; i++) {
40  				params.add(pvArgs[i]);
41  			}
42  		}
43  
44  	    
45  	    Object lvInvocationStrategy = getInvocationStrategy();
46  	    if (log.isDebugEnabled()) { log.debug("InvocationStrategy from JBossRemoting client: " + lvInvocationStrategy); }
47  	    
48  	    Object lvResult = null;
49  	    try {
50  	    	lvResult = client.invoke(params, (Map) lvInvocationStrategy);			
51  		} catch (Throwable e) {
52  			lvResult = new InvocationException("Problem by invoke JBossRemoting client: " + lvInvocationStrategy,  e);
53  		}
54  		
55  		if (lvResult instanceof Exception) {
56  			Throwable lvThrowable = Util.findDeepestThrowable((Exception) lvResult);
57  			if (lvThrowable instanceof Exception) {
58  				throw (Exception) lvThrowable;
59  			} else {
60  				throw new InvocationException("Exception in " + this.getClass().getName() + ": ", lvThrowable);
61  			}
62  		}
63  
64  		return lvResult;
65  	}
66  
67  }