001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.aop.bean;
023:
024: import org.jboss.aop.Dispatcher;
025: import org.jboss.aop.Advised;
026: import org.jboss.aspects.remoting.ClusteredRemoting;
027: import org.jboss.aspects.remoting.Remoting;
028: import org.jboss.ha.framework.interfaces.RoundRobin;
029: import org.jboss.logging.Logger;
030: import org.jboss.remoting.InvokerLocator;
031: import org.jboss.system.ServiceMBeanSupport;
032:
033: import javax.management.MBeanRegistration;
034: import javax.management.MBeanServer;
035: import javax.management.ObjectName;
036:
037: /**
038: *
039: * @see Monitorable
040: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
041: * @version $Revision: 57211 $
042: */
043: public class RemotingTester extends ServiceMBeanSupport implements
044: RemotingTesterMBean, MBeanRegistration {
045: // Constants ----------------------------------------------------
046: // Attributes ---------------------------------------------------
047: static Logger log = Logger.getLogger(RemotingTester.class);
048: MBeanServer m_mbeanServer;
049:
050: // Static -------------------------------------------------------
051:
052: // Constructors -------------------------------------------------
053: public RemotingTester() {
054: }
055:
056: // Public -------------------------------------------------------
057:
058: // MBeanRegistration implementation -----------------------------------
059: public ObjectName preRegister(MBeanServer server, ObjectName name)
060: throws Exception {
061: m_mbeanServer = server;
062: return name;
063: }
064:
065: public void postRegister(Boolean registrationDone) {
066: }
067:
068: public void preDeregister() throws Exception {
069: }
070:
071: public void postDeregister() {
072: }
073:
074: protected void startService() throws Exception {
075: }
076:
077: protected void stopService() {
078: }
079:
080: public POJO testRemoting() {
081: try {
082: log.info("Testing REMOTING");
083: POJO remote = new POJO("hello");
084: Dispatcher.singleton.registerTarget("myobj", remote);
085:
086: return (POJO) Remoting.createRemoteProxy("myobj", remote
087: .getClass(), "socket://"
088: + System.getProperty("jbosstest.server.host",
089: "localhost") + ":5150");
090: } catch (Throwable ex) {
091: log.error("failed", ex);
092: throw new RuntimeException(ex.getMessage());
093: }
094: }
095:
096: public NonadvisedPOJO testNonadvisedRemoting() {
097: try {
098: log.info("Testing NONADVISED REMOTING");
099: NonadvisedPOJO remote = new NonadvisedPOJO("hello");
100: Dispatcher.singleton.registerTarget("myobj", remote);
101:
102: return (NonadvisedPOJO) Remoting.createRemoteProxy("myobj",
103: remote.getClass(), "socket://"
104: + System.getProperty(
105: "jbosstest.server.host",
106: "localhost") + ":5150");
107: } catch (Throwable ex) {
108: log.error("failed", ex);
109: throw new RuntimeException(ex.getMessage());
110: }
111: }
112:
113: public POJO testClusteredRemoting() {
114: try {
115: log.info("Testing CLUSTERED REMOTING");
116: POJO remote = new POJO("hello");
117: return (POJO) ClusteredRemoting.clusterObject(
118: "clusteredobj", remote, "DefaultPartition",
119: new RoundRobin(), new InvokerLocator("socket://"
120: + System.getProperty(
121: "jbosstest.server.host",
122: "localhost") + ":5150"));
123: } catch (Throwable ex) {
124: log.error("failed", ex);
125: throw new RuntimeException(ex.getMessage());
126: }
127: }
128:
129: public NonadvisedPOJO testClusteredNonadvisedRemoting() {
130: try {
131: log.info("Testing CLUSTERED NONADVISED REMOTING");
132: NonadvisedPOJO remote = new NonadvisedPOJO("hello");
133: return (NonadvisedPOJO) ClusteredRemoting.clusterObject(
134: "nonadvisedclusteredobj", remote,
135: "DefaultPartition", new RoundRobin(),
136: new InvokerLocator("socket://"
137: + System.getProperty(
138: "jbosstest.server.host",
139: "localhost") + ":5150"));
140: } catch (Throwable ex) {
141: log.error("failed", ex);
142: throw new RuntimeException(ex.getMessage());
143: }
144: }
145:
146: public void unregisterTarget(Object object) {
147: ClusteredRemoting.unregisterClusteredObject(object);
148: }
149:
150: // Inner classes -------------------------------------------------
151: }
|