2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.policy.pdp.rest.jmx;
23 import java.lang.management.ManagementFactory;
25 import javax.management.MBeanServer;
26 import javax.management.ObjectName;
27 import javax.servlet.ServletContextEvent;
28 import javax.servlet.ServletContextListener;
29 import javax.servlet.annotation.WebListener;
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33 import org.openecomp.policy.common.logging.flexlogger.*;
35 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
42 public class PdpRestMBeanListener implements ServletContextListener {
43 private static final String JMX_OBJECT_NAME = "PdpRest:type=PdpRestMonitor";
44 private static final Logger logger = FlexLogger.getLogger(PdpRestMBeanListener.class);
46 private ObjectName objectName;
49 public void contextInitialized(ServletContextEvent contextEvent) {
50 if (logger.isInfoEnabled())
51 logger.info("Registering.");
53 final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
55 objectName = new ObjectName(JMX_OBJECT_NAME);
56 server.registerMBean(PdpRestMonitor.singleton, objectName);
57 logger.info("MBean registered: " + objectName);
58 } catch (Exception e) {
60 logger.warn(e.getMessage(), e);
62 logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to Register " +e.getMessage(), e);
68 public void contextDestroyed(ServletContextEvent contextEvent) {
69 if (logger.isInfoEnabled())
70 logger.info("Unregistering");
71 final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
73 objectName = new ObjectName(JMX_OBJECT_NAME);
74 server.unregisterMBean(objectName);
75 if (logger.isInfoEnabled())
76 logger.info("MBean unregistered: " + objectName);
77 } catch (Exception e) {
79 logger.warn(e.getMessage(), e);
81 logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to Destroy Context" +e.getMessage(), e);