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.jmx.invokerproxy;
023:
024: import java.util.Date;
025: import java.util.Hashtable;
026: import javax.management.ObjectName;
027: import javax.management.MBeanServer;
028:
029: import org.jboss.invocation.jrmp.server.JRMPProxyFactory;
030:
031: /** A POJO XMBean service that uses the JRMPProxyFactory programatically to
032: * expose an IProxy interface to this services echoDate method.
033: *
034: * @author Scott.Stark@jboss.org
035: * @version $Revision: 57211 $
036: */
037: public class ProgramaticProxySetup {
038: private String jndiName;
039: private MBeanServer server;
040: private ObjectName serviceName;
041: private ObjectName invokerName;
042: private JRMPProxyFactory proxyFactory;
043:
044: public void setMBeanServer(MBeanServer server) {
045: this .server = server;
046: }
047:
048: public void setObjectName(ObjectName serviceName) {
049: this .serviceName = serviceName;
050: }
051:
052: public ObjectName getInvokerName() {
053: return invokerName;
054: }
055:
056: public void setInvokerName(ObjectName invokerName) {
057: this .invokerName = invokerName;
058: }
059:
060: public String getJndiName() {
061: return jndiName;
062: }
063:
064: public void setJndiName(String jndiName) {
065: this .jndiName = jndiName;
066: }
067:
068: public void start() throws Exception {
069: proxyFactory = new JRMPProxyFactory();
070: proxyFactory.setInvokerName(invokerName);
071: proxyFactory.setTargetName(serviceName);
072: proxyFactory.setJndiName(jndiName);
073: proxyFactory.setExportedInterface(IProxy.class);
074: proxyFactory.setInvokeTargetMethod(true);
075: Hashtable props = serviceName.getKeyPropertyList();
076: props.put("proxyFactory", "JRMPProxyFactory");
077: ObjectName proxyFactoryName = new ObjectName(serviceName
078: .getDomain(), props);
079: server.registerMBean(proxyFactory, proxyFactoryName);
080: proxyFactory.start();
081: Object proxy = proxyFactory.getProxy();
082: System.out.println("Created IProxy: " + proxy);
083: }
084:
085: public void stop() {
086: proxyFactory.stop();
087: try {
088: Hashtable props = serviceName.getKeyPropertyList();
089: props.put("proxyFactory", "JRMPProxyFactory");
090: ObjectName proxyFactoryName = new ObjectName(serviceName
091: .getDomain(), props);
092: server.unregisterMBean(proxyFactoryName);
093: } catch (Exception e) {
094: e.printStackTrace();
095: }
096: }
097:
098: public String echoDate(String prefix) {
099: String date = prefix + " - " + new Date();
100: return date;
101: }
102: }
|