Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright (c) 2010-2011. Axon Framework
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.axonframework.monitoring.jmx;
Utility class that allows Axon-related components to be configured with an MBeanServer. By default all MBeans are registered with the platform MBean Server using a standard ObjectName.

Author(s):
Jettro Coenradie
Allard Buijze
Since:
0.6
public final class JmxConfiguration {
    private static final Logger logger = LoggerFactory.getLogger(JmxConfiguration.class);
    private static final JmxConfiguration INSTANCE = new JmxConfiguration();
    private MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    private boolean enabled = true;
    private JmxConfiguration() {
    }

    
Returns the singleton instance of JmxConfiguration.

Returns:
the JmxConfiguration instance
    public static JmxConfiguration getInstance() {
        return ;
    }

    
Attempts to register the given mBean as an MBean with the default MBeanServer. If registration fails, no exceptions are thrown. Instead, failure is logged and silently accepted.

Parameters:
mBean The instance to register as MBean. Note that this instance needs to be MBean compliant. Otherwise, registration fails silently.
monitoredType The type of object that the MBean represents. This type is used to construct the ObjectName of the MBean.
    public void registerMBean(Object mBeanClass<?> monitoredType) {
        if () {
            try {
                .registerMBean(new StandardMBean(mBeannulltrue), objectNameFor(monitoredType));
            } catch (InstanceAlreadyExistsException e) {
                .warn("Object {} has already been registered as an MBean"mBean);
            } catch (MBeanRegistrationException e) {
                .error("An error occurred registering an MBean"e);
            } catch (NotCompliantMBeanException e) {
                .error("Non-compliant MBean registered."e);
            }
        }
    }
    private ObjectName objectNameFor(Class<?> clazz) {
        try {
            return new ObjectName("org.axonframework""type"clazz.getSimpleName());
        } catch (MalformedObjectNameException e) {
            throw new IllegalStateException("This JVM doesn't seem to accept perfectly normal ObjectNames");
        }
    }

    
Disables monitoring. Any calls to registerMBean(java.lang.Object,java.lang.Class) will be ignored.
    public void disableMonitoring() {
        this. = false;
    }
New to GrepCode? Check out our FAQ X