1 22 package org.jboss.test.aop.bean; 23 24 import org.jboss.aop.Dispatcher; 25 import org.jboss.aspects.remoting.ClusteredRemoting; 26 import org.jboss.aspects.remoting.NotRegisteredException; 27 import org.jboss.aspects.remoting.Remoting; 28 import org.jboss.ha.framework.interfaces.RoundRobin; 29 import org.jboss.logging.Logger; 30 import org.jboss.remoting.InvokerLocator; 31 import org.jboss.system.ServiceMBeanSupport; 32 33 import javax.management.MBeanRegistration ; 34 import javax.management.MBeanServer ; 35 import javax.management.ObjectName ; 36 37 42 public class RemotingTester 43 extends ServiceMBeanSupport 44 implements RemotingTesterMBean, MBeanRegistration 45 { 46 static Logger log = Logger.getLogger(RemotingTester.class); 49 MBeanServer m_mbeanServer; 50 51 53 public RemotingTester() 55 { 56 } 57 58 60 public ObjectName preRegister(MBeanServer server, ObjectName name) 62 throws Exception 63 { 64 m_mbeanServer = server; 65 return name; 66 } 67 68 public void postRegister(Boolean registrationDone) 69 { 70 } 71 72 public void preDeregister() throws Exception 73 { 74 } 75 76 public void postDeregister() 77 { 78 } 79 80 protected void startService() 81 throws Exception 82 { 83 } 84 85 protected void stopService() 86 { 87 } 88 89 public POJO testRemoting() 90 { 91 try 92 { 93 log.info("Testing REMOTING"); 94 POJO remote = new POJO("hello"); 95 Dispatcher.singleton.registerTarget("myobj", remote); 96 97 return (POJO) Remoting.createRemoteProxy("myobj", remote.getClass(), "socket://localhost:5150"); 98 } 99 catch (Throwable ex) 100 { 101 log.error("failed", ex); 102 throw new RuntimeException (ex.getMessage()); 103 } 104 } 105 106 public NonadvisedPOJO testNonadvisedRemoting() 107 { 108 try 109 { 110 log.info("Testing NONADVISED REMOTING"); 111 NonadvisedPOJO remote = new NonadvisedPOJO("hello"); 112 Dispatcher.singleton.registerTarget("myobj", remote); 113 114 return (NonadvisedPOJO) Remoting.createRemoteProxy("myobj", remote.getClass(), "socket://localhost:5150"); 115 } 116 catch (Throwable ex) 117 { 118 log.error("failed", ex); 119 throw new RuntimeException (ex.getMessage()); 120 } 121 } 122 123 public POJO testClusteredRemoting() 124 { 125 try 126 { 127 log.info("Testing CLUSTERED REMOTING"); 128 POJO remote = new POJO("hello"); 129 return (POJO) ClusteredRemoting.clusterObject("clusteredobj", remote, 130 "DefaultPartition", new RoundRobin(), 131 new InvokerLocator("socket://localhost:5150")); 132 } 133 catch (Throwable ex) 134 { 135 log.error("failed", ex); 136 throw new RuntimeException (ex.getMessage()); 137 } 138 } 139 140 public NonadvisedPOJO testClusteredNonadvisedRemoting() 141 { 142 try 143 { 144 log.info("Testing CLUSTERED NONADVISED REMOTING"); 145 NonadvisedPOJO remote = new NonadvisedPOJO("hello"); 146 return (NonadvisedPOJO) ClusteredRemoting.clusterObject("nonadvisedclusteredobj", remote, 147 "DefaultPartition", new RoundRobin(), 148 new InvokerLocator("socket://localhost:5150")); 149 } 150 catch (Throwable ex) 151 { 152 log.error("failed", ex); 153 throw new RuntimeException (ex.getMessage()); 154 } 155 } 156 157 158 public void unregisterNonClusteredObject(String oid) 159 { 160 Object obj = Dispatcher.singleton.getRegistered(oid); 161 if (obj == null) 162 { 163 throw new NotRegisteredException(oid.toString() + " is not registered"); 164 } 165 Dispatcher.singleton.unregisterTarget(oid); 166 } 167 168 public void unregisterTarget(Object object) 169 { 170 ClusteredRemoting.unregisterClusteredObject(object); 171 } 172 173 } 175 176 | Popular Tags |