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.drools.core.jmx;
23 import java.lang.management.ManagementFactory;
25 import javax.management.InstanceAlreadyExistsException;
26 import javax.management.InstanceNotFoundException;
27 import javax.management.MBeanRegistrationException;
28 import javax.management.MBeanServer;
29 import javax.management.MalformedObjectNameException;
30 import javax.management.NotCompliantMBeanException;
31 import javax.management.ObjectName;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class PdpJmxListener {
38 public static final Logger logger = LoggerFactory.getLogger(PdpJmxListener.class);
40 public static void stop() {
41 final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
43 server.unregisterMBean(new ObjectName("PolicyEngine:type=PdpJmx"));
44 } catch (MBeanRegistrationException | InstanceNotFoundException
45 | MalformedObjectNameException e) {
46 logger.error("PdpJmxListener.stop(): " +
47 "Could not unregister PolicyEngine:type=PdpJmx MBean " +
48 "with the MBean server", e);
54 public static void start() {
55 final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
57 server.registerMBean(PdpJmx.getInstance(), new ObjectName("PolicyEngine:type=PdpJmx"));
58 } catch (InstanceAlreadyExistsException | MBeanRegistrationException
59 | NotCompliantMBeanException | MalformedObjectNameException e) {
60 logger.error("PdpJmxListener.start(): " +
61 "Could not unregister PolicyEngine:type=PdpJmx MBean " +
62 "with the MBean server", e);