~ubuntu-branches/ubuntu/raring/libjboss-remoting-java/raring

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/detection/jndi/Server.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.remoting.detection.jndi;
 
23
 
 
24
import org.apache.log4j.Level;
 
25
import org.apache.log4j.Logger;
 
26
import org.jboss.jrunit.extensions.ServerTestCase;
 
27
import org.jboss.remoting.InvocationRequest;
 
28
import org.jboss.remoting.InvokerLocator;
 
29
import org.jboss.remoting.ServerInvocationHandler;
 
30
import org.jboss.remoting.ServerInvoker;
 
31
import org.jboss.remoting.callback.InvokerCallbackHandler;
 
32
import org.jboss.remoting.detection.jndi.JNDIDetector;
 
33
import org.jboss.remoting.transport.Connector;
 
34
 
 
35
import javax.management.MBeanServer;
 
36
import javax.management.MBeanServerFactory;
 
37
import javax.management.ObjectName;
 
38
import java.net.InetAddress;
 
39
import java.net.UnknownHostException;
 
40
 
 
41
/**
 
42
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
 
43
 * @author Michael Voss
 
44
 */
 
45
public class Server extends ServerTestCase
 
46
{
 
47
   private static Connector connector = null;
 
48
   private MBeanServer server;
 
49
   private JNDIDetector detector;
 
50
   private Logger logger;
 
51
 
 
52
   private String jndiAddress = null;
 
53
   private int jndiPort = 2410;
 
54
   private String port = "3001";
 
55
 
 
56
 
 
57
   private void init()
 
58
   {
 
59
      String localHost = "";
 
60
      try
 
61
      {
 
62
         jndiAddress = localHost = InetAddress.getLocalHost().getHostAddress();
 
63
      }
 
64
      catch (UnknownHostException uhe)
 
65
      {
 
66
         uhe.printStackTrace();
 
67
         System.exit(1);
 
68
      }
 
69
 
 
70
      try
 
71
      {
 
72
 
 
73
 
 
74
         connector = new Connector();
 
75
         InvokerLocator locator = new InvokerLocator("multiplex://" + localHost + ":" + port);
 
76
         connector.setInvokerLocator(locator.getLocatorURI());
 
77
         connector.create();
 
78
         try
 
79
         {
 
80
            connector.addInvocationHandler("sample", new SampleInvocationHandler());
 
81
         }
 
82
         catch (Exception e)
 
83
         {
 
84
            e.printStackTrace();
 
85
            System.exit(1);
 
86
         }
 
87
         connector.start();
 
88
 
 
89
         server.registerMBean(connector, new ObjectName("jboss.remoting:type=Connector"));
 
90
 
 
91
 
 
92
      }
 
93
      catch (Exception e)
 
94
      {
 
95
         e.printStackTrace();
 
96
      }
 
97
 
 
98
 
 
99
   }
 
100
 
 
101
 
 
102
   private void registerJNDI()
 
103
   {
 
104
 
 
105
      detector = new JNDIDetector();
 
106
 
 
107
      try
 
108
      {
 
109
         server.registerMBean(detector, new ObjectName("remoting:type=JNDIDetector"));
 
110
      }
 
111
      catch (Exception ignored)
 
112
      {
 
113
      }
 
114
 
 
115
      detector.setPort(jndiPort);
 
116
      detector.setHost(jndiAddress);
 
117
      try
 
118
      {
 
119
         detector.start();
 
120
      }
 
121
      catch (Exception e)
 
122
      {
 
123
         e.printStackTrace();
 
124
      }
 
125
 
 
126
   }
 
127
 
 
128
 
 
129
   public void setUp()
 
130
   {
 
131
      logger = Logger.getLogger(getClass());
 
132
      logger.setLevel((Level) Level.DEBUG);
 
133
 
 
134
      server = MBeanServerFactory.createMBeanServer();
 
135
      init();
 
136
      registerJNDI();
 
137
 
 
138
 
 
139
   }
 
140
 
 
141
 
 
142
   public void tearDown()
 
143
   {
 
144
      try
 
145
      {
 
146
 
 
147
         server.unregisterMBean(new ObjectName("remoting:type=JNDIDetector"));
 
148
         if (detector != null)
 
149
         {
 
150
            try
 
151
            {
 
152
               detector.stop();
 
153
            }
 
154
            catch (Exception ignored)
 
155
            {
 
156
            }
 
157
         }
 
158
         if (connector != null)
 
159
         {
 
160
            try
 
161
            {
 
162
               connector.stop();
 
163
            }
 
164
            catch (Exception ignored)
 
165
            {
 
166
            }
 
167
 
 
168
            connector = null;
 
169
            server.unregisterMBean(new ObjectName("jboss.remoting:type=Connector"));
 
170
            Thread.sleep(1000);
 
171
 
 
172
         }
 
173
      }
 
174
      catch (Exception e)
 
175
      {
 
176
      }
 
177
 
 
178
   }
 
179
 
 
180
 
 
181
   public static void main(String[] args)
 
182
   {
 
183
 
 
184
      Server server = new Server();
 
185
      try
 
186
      {
 
187
         server.setUp();
 
188
 
 
189
         while (true)
 
190
         {
 
191
            Thread.sleep(1000);
 
192
         }
 
193
      }
 
194
      catch (Exception e)
 
195
      {
 
196
         e.printStackTrace();
 
197
      }
 
198
   }
 
199
 
 
200
 
 
201
   public static class SampleInvocationHandler implements ServerInvocationHandler
 
202
   {
 
203
 
 
204
      public Object invoke(InvocationRequest invocation) throws Throwable
 
205
      {
 
206
         return null;
 
207
      }
 
208
 
 
209
 
 
210
      public void addListener(InvokerCallbackHandler callbackHandler)
 
211
      {
 
212
 
 
213
      }
 
214
 
 
215
 
 
216
      public void removeListener(InvokerCallbackHandler callbackHandler)
 
217
      {
 
218
 
 
219
      }
 
220
 
 
221
 
 
222
      public void setMBeanServer(MBeanServer server)
 
223
      {
 
224
 
 
225
      }
 
226
 
 
227
      public void setInvoker(ServerInvoker invoker)
 
228
      {
 
229
 
 
230
      }
 
231
 
 
232
   }
 
233
}
 
 
b'\\ No newline at end of file'