01 /*
02 *
03 * Licensed to the Apache Software Foundation (ASF) under one
04 * or more contributor license agreements. See the NOTICE file
05 * distributed with this work for additional information
06 * regarding copyright ownership. The ASF licenses this file
07 * to you under the Apache License, Version 2.0 (the
08 * "License"); you may not use this file except in compliance
09 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21 package org.apache.qpid.management.wsdm;
22
23 import java.lang.management.ManagementFactory;
24
25 import javax.servlet.ServletException;
26 import javax.servlet.http.HttpServlet;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29
30 import org.apache.qpid.management.Messages;
31 import org.apache.qpid.management.Names;
32 import org.apache.qpid.transport.util.Logger;
33
34 /**
35 * QPid Emulator Initializer.
36 * This component is basically responsible to create and initialize
37 * an emulator module used for simulate object instances creation.
38 *
39 * @author Andrea Gazzarini
40 */
41 public class QEmuInitializer extends HttpServlet
42 {
43 private static final long serialVersionUID = 6149614872902682208L;
44 private final static Logger LOGGER = Logger.get(QEmuInitializer.class);
45
46 /**
47 * QEmu initialization method.
48 *
49 * @throws ServletException when the module cannot be initialized.
50 */
51 public void init() throws ServletException
52 {
53 try
54 {
55 ManagementFactory.getPlatformMBeanServer().registerMBean(
56 new QEmu(),
57 Names.QPID_EMULATOR_OBJECT_NAME);
58 } catch(Exception exception)
59 {
60 LOGGER.warn(exception,Messages.QMAN_300005_QEMU_INITIALIZATION_FAILURE);
61 throw new ServletException(exception);
62 }
63 }
64
65 /**
66 * This is a startup module only so an override of the
67 * default servlet behaviour must be done in order to
68 * prevent incoming http requests processing.
69 *
70 * @param request the http request.
71 * @param response the http response.
72 * @throws ServletException each time this method is called.
73 */
74 @Override
75 public void service(HttpServletRequest request,HttpServletResponse response) throws ServletException
76 {
77 throw new ServletException();
78 }
79
80 /**
81 * Unregister QPid emulator.
82 */
83 public void destroy()
84 {
85 try
86 {
87 ManagementFactory.getPlatformMBeanServer()
88 .unregisterMBean(Names.QPID_EMULATOR_OBJECT_NAME);
89 } catch (Exception exception)
90 {
91 }
92 }
93 }
|