1 /*
2 * JCaptcha, the open source java framework for captcha definition and integration
3 * Copyright (c) 2007 jcaptcha.net. All Rights Reserved.
4 * See the LICENSE.txt file distributed with this package.
5 */
6
7 package com.octo.captcha.module.jmx;
8
9 import com.octo.captcha.service.CaptchaServiceException;
10 import com.octo.captcha.service.ManageableCaptchaService;
11
12
13 /***
14 * Helper that providdes methods to register and unregister a ManageableCaptchaService to a MBean Server.
15 *
16 * @author <a href="mailto:mag@jcaptcha.net">Marc-Antoine Garrigue</a>
17 * @version 1.0
18 */
19 public class JMXRegistrationHelper {
20 // /***
21 // * Register self to the first MBean server available in the JVM, if
22 // * any.
23 // *
24 // * @param name the name the service will be registered
25 // * to the MBean server.
26 // * @throws com.octo.captcha.service.CaptchaServiceException
27 // * in case of error. Possible
28 // * error details are :
29 // * <ul>
30 // * <li> CaptchaServiceException</li>
31 // * </ul>
32 // * @see com.octo.captcha.service.CaptchaServiceException
33 // */
34
35 public static void registerToMBeanServer(ManageableCaptchaService service, String name)
36 throws CaptchaServiceException {
37 // if (name == null) throw new CaptchaServiceException("Service registration name can't be null");
38 // ArrayList mbeanServers = MBeanServerFactory.findMBeanServer(null);
39 // if (mbeanServers.size() == 0) {
40 // throw new CaptchaServiceException("No current MBean Server, skiping the registering process");
41 // } else {
42 // MBeanServer mbeanServer = (MBeanServer) mbeanServers.get(0);
43 // try {
44 // ObjectName objectName = new ObjectName(name);
45 // mbeanServer.registerMBean(service, objectName);
46 // } catch (MalformedObjectNameException e) {
47 // throw new CaptchaServiceException(e);
48 // } catch (InstanceAlreadyExistsException e) {
49 // throw new CaptchaServiceException(e);
50 // } catch (MBeanRegistrationException e) {
51 // // this exception should never be raised (raised
52 // // only by an MBean that implements the MBeanRegistration
53 // // interface.
54 // throw new CaptchaServiceException("An unexpected exception has been raised : "
55 // + "CaptchaService needs maintenance !",
56 // e);
57 // } catch (NotCompliantMBeanException e) {
58 // // this should never happens
59 // throw new CaptchaServiceException("Exception trying to register the service to"
60 // + " the MBean server",
61 // e);
62 // }
63 // }
64 }
65 //
66 // /***
67 // * Unregister self from the first MBean server available in the JVM, if any
68 // */
69
70 public static void unregisterFromMBeanServer(String name) {
71
72 // if (name != null) {
73 // ArrayList mbeanServers = MBeanServerFactory.findMBeanServer(null);
74 // MBeanServer mbeanServer = (MBeanServer) mbeanServers.get(0);
75 // try {
76 // ObjectName objectName = new ObjectName(name);
77 // mbeanServer.unregisterMBean(objectName);
78 // } catch (MalformedObjectNameException e) {
79 // // this should never happens
80 // throw new CaptchaServiceException("Exception trying to create the object name under witch"
81 // + " the service is registered",
82 // e);
83 // } catch (InstanceNotFoundException e) {
84 // // this should never happens
85 // throw new CaptchaServiceException("Exception trying to unregister the ImageCaptchaFilter from"
86 // + " the MBean server",
87 // e);
88 // } catch (MBeanRegistrationException e) {
89 // // this remains silent for the client
90 // throw new CaptchaServiceException("Exception trying to unregister the ImageCaptchaFilter from"
91 // + "the MBean server",
92 // e);
93 // }
94 // } else {
95 // throw new CaptchaServiceException("Service registration name can't be null");
96 // }
97 }
98 //
99
100 }