View Javadoc

1   package net.sf.crispy.impl;
2   
3   import java.util.Properties;
4   
5   import net.sf.crispy.InvocationException;
6   import net.sf.crispy.InvocationStrategy;
7   import net.sf.crispy.proxy.StaticProxy;
8   import net.sf.crispy.strategy.NameInvocationStrategy;
9   
10  import com.caucho.burlap.client.BurlapProxyFactory;
11  
12  /**
13   * Remote-Call with Burlap Remote Invocation (Caucho).
14   * 
15   * @author Linke
16   *
17   */
18  public class StaticBurlapProxy extends StaticProxy {
19  
20  	public final static String DEFAULT_URL_AND_PORT = "http://localhost:8091/crispy/burlap";
21  	
22  	private BurlapProxyFactory factory = new BurlapProxyFactory();
23  	
24  	public StaticBurlapProxy() {
25  		factory.setOverloadEnabled(true);		
26  	}
27  	
28      /**
29       * Get default url and port. If no url and port is in properties.
30       *  
31       * @return Default url and port.
32       */
33      public String getDefaultUrlAndPort() {
34      	return DEFAULT_URL_AND_PORT;
35      }
36      
37      public InvocationStrategy getDefaultInvocationStrategy(Properties pvProperties) {
38      	String lvInterfaceName = (String) pvProperties.get(PROPERTY_CURRENT_INTERFACE_CLASS);
39      	return new NameInvocationStrategy(lvInterfaceName);
40      }
41      
42  	/**
43  	 * @see net.sf.crispy.proxy.Proxy#newInstance(java.lang.Class)
44  	 */
45  	public Object newInstance(Class pvProxyClass) {
46  		String lvUrlAndPort = getUrlAndPort() + "/" + getInvocationStrategy();
47  		if (log.isDebugEnabled()) { log.debug("Burlap Url and Port: " + lvUrlAndPort); }
48  		
49  		try {
50  			Object lvProxyObject = null;
51  			synchronized (factory) {
52  				lvProxyObject = factory.create(pvProxyClass, lvUrlAndPort);
53  			}
54  			
55  			setProxyObject(lvProxyObject);
56  			setProxyClass(pvProxyClass);
57  		} catch (Exception e) {
58  			throw new InvocationException("Error in newInstance in StaticBurlapProxy: " + e, e);
59  		}
60  		if (log.isDebugEnabled()) { log.debug("Burlap Object created: " + getProxyObject()); }
61  		return getProxyObject();
62  	}
63  }