KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > bean > RemotingTester


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

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 JavaDoc;
34 import javax.management.MBeanServer JavaDoc;
35 import javax.management.ObjectName JavaDoc;
36
37 /**
38  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
39  * @version $Revision: 43771 $
40  * @see Monitorable
41  */

42 public class RemotingTester
43 extends ServiceMBeanSupport
44 implements RemotingTesterMBean, MBeanRegistration JavaDoc
45 {
46    // Constants ----------------------------------------------------
47
// Attributes ---------------------------------------------------
48
static Logger log = Logger.getLogger(RemotingTester.class);
49    MBeanServer JavaDoc m_mbeanServer;
50
51    // Static -------------------------------------------------------
52

53    // Constructors -------------------------------------------------
54
public RemotingTester()
55    {
56    }
57
58    // Public -------------------------------------------------------
59

60    // MBeanRegistration implementation -----------------------------------
61
public ObjectName JavaDoc preRegister(MBeanServer JavaDoc server, ObjectName JavaDoc name)
62    throws Exception JavaDoc
63    {
64       m_mbeanServer = server;
65       return name;
66    }
67
68    public void postRegister(Boolean JavaDoc registrationDone)
69    {
70    }
71
72    public void preDeregister() throws Exception JavaDoc
73    {
74    }
75
76    public void postDeregister()
77    {
78    }
79
80    protected void startService()
81    throws Exception JavaDoc
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 JavaDoc ex)
100       {
101          log.error("failed", ex);
102          throw new RuntimeException JavaDoc(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 JavaDoc ex)
117       {
118          log.error("failed", ex);
119          throw new RuntimeException JavaDoc(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 JavaDoc ex)
134       {
135          log.error("failed", ex);
136          throw new RuntimeException JavaDoc(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 JavaDoc ex)
151       {
152          log.error("failed", ex);
153          throw new RuntimeException JavaDoc(ex.getMessage());
154       }
155    }
156
157
158    public void unregisterNonClusteredObject(String JavaDoc oid)
159    {
160       Object JavaDoc 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 JavaDoc object)
169    {
170       ClusteredRemoting.unregisterClusteredObject(object);
171    }
172
173    // Inner classes -------------------------------------------------
174
}
175
176
Popular Tags