1 22 package org.jboss.test.jmx.invokerproxy; 23 24 import java.util.Date ; 25 import java.util.Hashtable ; 26 import javax.management.ObjectName ; 27 import javax.management.MBeanServer ; 28 29 import org.jboss.invocation.jrmp.server.JRMPProxyFactory; 30 31 37 public class ProgramaticProxySetup 38 { 39 private String jndiName; 40 private MBeanServer server; 41 private ObjectName serviceName; 42 private ObjectName invokerName; 43 private JRMPProxyFactory proxyFactory; 44 45 public void setMBeanServer(MBeanServer server) 46 { 47 this.server = server; 48 } 49 50 public void setObjectName(ObjectName serviceName) 51 { 52 this.serviceName = serviceName; 53 } 54 55 public ObjectName getInvokerName() 56 { 57 return invokerName; 58 } 59 public void setInvokerName(ObjectName invokerName) 60 { 61 this.invokerName = invokerName; 62 } 63 64 public String getJndiName() 65 { 66 return jndiName; 67 } 68 public void setJndiName(String jndiName) 69 { 70 this.jndiName = jndiName; 71 } 72 73 public void start() throws Exception 74 { 75 proxyFactory = new JRMPProxyFactory(); 76 proxyFactory.setInvokerName(invokerName); 77 proxyFactory.setTargetName(serviceName); 78 proxyFactory.setJndiName(jndiName); 79 proxyFactory.setExportedInterface(IProxy.class); 80 proxyFactory.setInvokeTargetMethod(true); 81 Hashtable props = serviceName.getKeyPropertyList(); 82 props.put("proxyFactory", "JRMPProxyFactory"); 83 ObjectName proxyFactoryName = new ObjectName (serviceName.getDomain(), props); 84 server.registerMBean(proxyFactory, proxyFactoryName); 85 proxyFactory.start(); 86 Object proxy = proxyFactory.getProxy(); 87 System.out.println("Created IProxy: "+proxy); 88 } 89 90 public void stop() 91 { 92 proxyFactory.stop(); 93 try 94 { 95 Hashtable props = serviceName.getKeyPropertyList(); 96 props.put("proxyFactory", "JRMPProxyFactory"); 97 ObjectName proxyFactoryName = new ObjectName (serviceName.getDomain(), props); 98 server.unregisterMBean(proxyFactoryName); 99 } 100 catch(Exception e) 101 { 102 e.printStackTrace(); 103 } 104 } 105 106 public String echoDate(String prefix) 107 { 108 String date = prefix + " - " + new Date (); 109 return date; 110 } 111 } 112 | Popular Tags |