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.remoting.interceptor;
023:
024: import javax.management.MBeanServer;
025: import javax.management.MBeanServerFactory;
026: import javax.management.ObjectName;
027: import org.apache.log4j.Level;
028: import org.jboss.remoting.InvokerLocator;
029: import org.jboss.remoting.ident.Identity;
030: import org.jboss.remoting.marshal.serializable.SerializableUnMarshaller;
031: import org.jboss.remoting.network.NetworkRegistry;
032: import org.jboss.remoting.transport.Connector;
033:
034: /**
035: * @author <a href="mailto:tom@jboss.org">Tom Elrod</a>
036: */
037: public class ServerInterceptorTest {
038: private InvokerLocator locator;
039:
040: public void setLocator(InvokerLocator locator) {
041: this .locator = locator;
042: }
043:
044: protected void setup() {
045: try {
046: System.setProperty("jboss.identity", Identity
047: .createUniqueID());
048: MBeanServer server = MBeanServerFactory.createMBeanServer();
049:
050: System.out.println("my identity is: "
051: + Identity.get(server));
052:
053: NetworkRegistry registry = NetworkRegistry.getInstance();
054: server.registerMBean(registry, new ObjectName(
055: "remoting:type=NetworkRegistry"));
056:
057: //int port = PortUtil.findFreePort();
058:
059: Connector connector = new Connector();
060: connector.setInvokerLocator(locator.getLocatorURI());
061: ObjectName obj = new ObjectName(
062: "jboss.remoting:type=Connector,transport="
063: + locator.getProtocol());
064: server.registerMBean(connector, obj);
065:
066: connector.start();
067:
068: connector.addInvocationHandler("test",
069: new TestInvocationHandler());
070:
071: // MulticastDetector detector = new MulticastDetector();
072: // server.registerMBean(detector, new ObjectName("remoting:type=Detector,transport=multicast"));
073: // detector.start();
074:
075: // TODO: -TME Not needed unless want to make jmx invocation within handler
076: // TestTarget target = new TestTarget();
077: // ObjectName objName = new ObjectName("test:type=UnifiedInvoker");
078: // server.registerMBean(target, objName);
079: // Registry.bind("test:type=UnifiedInvoker", objName);
080:
081: } catch (Throwable e) {
082: e.printStackTrace();
083: }
084:
085: }
086:
087: public static void main(String[] args) {
088: try {
089: //org.apache.log4j.BasicConfigurator.configure();
090: org.apache.log4j.Category.getRoot().setLevel(Level.DEBUG);
091:
092: int port = 8081;
093: String transport = "socket";
094: // InvokerLocator locator = new InvokerLocator(transport + "://localhost:" + port + "/?" +
095: // InvokerLocator.DATATYPE + "=" + SerializableUnMarshaller.DATATYPE);
096: InvokerLocator locator = new InvokerLocator(transport
097: + "://localhost:" + port + "/?"
098: + InvokerLocator.DATATYPE + "="
099: + SerializableUnMarshaller.DATATYPE);
100:
101: ServerInterceptorTest server = new ServerInterceptorTest();
102: server.setLocator(locator);
103: server.setup();
104:
105: while (true) {
106: Thread.sleep(1000);
107: }
108: } catch (Exception e) {
109: e.printStackTrace();
110: }
111: }
112:
113: /**
114: * When an object implementing interface <code>Runnable</code> is used
115: * to create a thread, starting the thread causes the object's
116: * <code>run</code> method to be called in that separately executing
117: * thread.
118: * <p/>
119: * The general contract of the method <code>run</code> is that it may
120: * take any action whatsoever.
121: *
122: * @see Thread#run()
123: */
124: public void run() {
125: setup();
126: }
127: }
|