01: package org.apache.mina.integration.jmx;
02:
03: import java.lang.management.ManagementFactory;
04: import java.net.InetSocketAddress;
05: import java.util.concurrent.TimeUnit;
06:
07: import javax.management.MBeanServer;
08: import javax.management.ObjectName;
09:
10: import org.apache.mina.common.IoAcceptor;
11: import org.apache.mina.common.IoHandlerAdapter;
12: import org.apache.mina.filter.executor.ExecutorFilter;
13: import org.apache.mina.filter.executor.IoEventQueueThrottle;
14: import org.apache.mina.filter.executor.OrderedThreadPoolExecutor;
15: import org.apache.mina.filter.logging.LoggingFilter;
16: import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
17:
18: public class Foo {
19: public static void main(String[] args) throws Exception {
20: final MBeanServer server = ManagementFactory
21: .getPlatformMBeanServer();
22:
23: IoAcceptor service = new NioSocketAcceptor();
24: service.setHandler(new IoHandlerAdapter());
25:
26: ExecutorFilter executorFilter = new ExecutorFilter(
27: new OrderedThreadPoolExecutor(0, 16, 30,
28: TimeUnit.SECONDS, new IoEventQueueThrottle(
29: 1048576)));
30:
31: service.getFilterChain().addLast("executor", executorFilter);
32: service.bind(new InetSocketAddress(8080));
33:
34: server.registerMBean(new IoServiceMBean(service),
35: new ObjectName(
36: "org.apache.mina:type=service,name=myService"));
37:
38: server.registerMBean(new IoFilterMBean(executorFilter),
39: new ObjectName(
40: "org.apache.mina:type=filter,name=executor"));
41:
42: server.registerMBean(new IoFilterMBean(new LoggingFilter()),
43: new ObjectName(
44: "org.apache.mina:type=filter,name=logger"));
45: }
46: }
|