Search in sources :

Example 21 with ObjectInstance

use of javax.management.ObjectInstance in project Activiti by Activiti.

the class DefaultManagementAgent method registerMBeanWithServer.

private void registerMBeanWithServer(Object obj, ObjectName name, boolean forceRegistration) throws JMException {
    boolean exists = isRegistered(name);
    if (exists) {
        if (forceRegistration) {
            LOG.info("ForceRegistration enabled, unregistering existing MBean with ObjectName: {}", name);
            server.unregisterMBean(name);
        } else {
            // okay ignore we do not want to force it and it could be a shared
            // instance
            LOG.debug("MBean already registered with ObjectName: {}", name);
        }
    }
    // register bean if by force or not exists
    ObjectInstance instance = null;
    if (forceRegistration || !exists) {
        LOG.trace("Registering MBean with ObjectName: {}", name);
        instance = server.registerMBean(obj, name);
    }
    // modify the name
    if (instance != null) {
        ObjectName registeredName = instance.getObjectName();
        LOG.debug("Registered MBean with ObjectName: {}", registeredName);
        mbeansRegistered.put(name, registeredName);
    }
}
Also used : ObjectInstance(javax.management.ObjectInstance) ObjectName(javax.management.ObjectName)

Example 22 with ObjectInstance

use of javax.management.ObjectInstance in project aries by apache.

the class MBeanHolder method register.

void register(final MBeanServer server) {
    ObjectInstance instance;
    try {
        instance = server.registerMBean(mbean, requestedObjectName);
        registrations.put(server, instance.getObjectName());
    } catch (InstanceAlreadyExistsException e) {
        log.error("register: Failure registering MBean " + mbean, e);
    } catch (MBeanRegistrationException e) {
        log.error("register: Failure registering MBean " + mbean, e);
    } catch (NotCompliantMBeanException e) {
        log.error("register: Failure registering MBean " + mbean, e);
    }
}
Also used : NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ObjectInstance(javax.management.ObjectInstance) MBeanRegistrationException(javax.management.MBeanRegistrationException)

Example 23 with ObjectInstance

use of javax.management.ObjectInstance in project geode by apache.

the class ManagementAdapter method handleManagerStart.

/**
   * Handles all the distributed mbean creation part when a Manager is started
   */
public void handleManagerStart() throws ManagementException {
    if (!isServiceInitialised("handleManagerStart")) {
        return;
    }
    MBeanJMXAdapter jmxAdapter = service.getJMXAdapter();
    Map<ObjectName, Object> registeredMBeans = jmxAdapter.getLocalGemFireMBean();
    DistributedSystemBridge dsBridge = new DistributedSystemBridge(service);
    this.aggregator = new MBeanAggregator(dsBridge);
    // register the aggregator for Federation framework to use
    service.addProxyListener(aggregator);
    /*
     * get the local member mbean as it need to be provided to aggregator first
     */
    MemberMXBean localMember = service.getMemberMXBean();
    ObjectName memberObjectName = MBeanJMXAdapter.getMemberMBeanName(InternalDistributedSystem.getConnectedInstance().getDistributedMember());
    FederationComponent addedComp = service.getLocalManager().getFedComponents().get(memberObjectName);
    service.afterCreateProxy(memberObjectName, MemberMXBean.class, localMember, addedComp);
    for (ObjectName objectName : registeredMBeans.keySet()) {
        if (objectName.equals(memberObjectName)) {
            continue;
        }
        Object object = registeredMBeans.get(objectName);
        ObjectInstance instance;
        try {
            instance = mbeanServer.getObjectInstance(objectName);
            String className = instance.getClassName();
            Class cls = ClassLoadUtil.classFromName(className);
            Type[] intfTyps = cls.getGenericInterfaces();
            FederationComponent newObj = service.getLocalManager().getFedComponents().get(objectName);
            for (Type intfTyp1 : intfTyps) {
                Class intfTyp = (Class) intfTyp1;
                service.afterCreateProxy(objectName, intfTyp, object, newObj);
            }
        } catch (InstanceNotFoundException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed in Registering distributed mbean ");
            }
            throw new ManagementException(e);
        } catch (ClassNotFoundException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed in Registering distributed mbean");
            }
            throw new ManagementException(e);
        }
    }
}
Also used : InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectInstance(javax.management.ObjectInstance) ObjectName(javax.management.ObjectName) MemberMXBean(org.apache.geode.management.MemberMXBean) Type(java.lang.reflect.Type) JMXNotificationType(org.apache.geode.management.JMXNotificationType) ManagementException(org.apache.geode.management.ManagementException) MBeanJMXAdapter(org.apache.geode.management.internal.MBeanJMXAdapter) FederationComponent(org.apache.geode.management.internal.FederationComponent)

Example 24 with ObjectInstance

use of javax.management.ObjectInstance in project geode by apache.

the class MBeanJMXAdapter method hasNotificationSupport.

/**
   * Checks whether an MBean implements notification support classes or not
   * 
   * @param objectName
   * @return if this MBean can be a notification broadcaster
   */
public boolean hasNotificationSupport(ObjectName objectName) {
    try {
        if (!isRegistered(objectName)) {
            return false;
        }
        ObjectInstance instance = mbeanServer.getObjectInstance(objectName);
        String className = instance.getClassName();
        Class cls = ClassLoadUtil.classFromName(className);
        Type[] intfTyps = cls.getGenericInterfaces();
        for (int i = 0; i < intfTyps.length; i++) {
            Class intfTyp = (Class) intfTyps[i];
            if (intfTyp.equals(NotificationEmitter.class)) {
                return true;
            }
        }
        Class supreClassTyp = (Class) cls.getGenericSuperclass();
        if (supreClassTyp != null && supreClassTyp.equals(NotificationBroadcasterSupport.class)) {
            return true;
        }
    } catch (InstanceNotFoundException e) {
        throw new ManagementException(e);
    } catch (ClassNotFoundException e) {
        throw new ManagementException(e);
    }
    return false;
}
Also used : Type(java.lang.reflect.Type) ManagementException(org.apache.geode.management.ManagementException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectInstance(javax.management.ObjectInstance) NotificationBroadcasterSupport(javax.management.NotificationBroadcasterSupport)

Example 25 with ObjectInstance

use of javax.management.ObjectInstance in project geode by apache.

the class LocalProcessControllerJUnitTest method setUp.

@Before
public void setUp() throws Exception {
    pid = ProcessUtils.identifyPid();
    final Process process = new Process(pid, true);
    this.objectName = ObjectName.getInstance(getClass().getSimpleName() + ":testName=" + testName.getMethodName());
    this.server = ManagementFactory.getPlatformMBeanServer();
    final ObjectInstance instance = this.server.registerMBean(process, objectName);
    assertNotNull(instance);
}
Also used : ObjectInstance(javax.management.ObjectInstance) Process(org.apache.geode.internal.process.mbean.Process) Before(org.junit.Before)

Aggregations

ObjectInstance (javax.management.ObjectInstance)75 ObjectName (javax.management.ObjectName)36 Test (org.junit.Test)27 InstanceNotFoundException (javax.management.InstanceNotFoundException)15 MBeanServer (javax.management.MBeanServer)12 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)10 JmxResultProcessor (com.googlecode.jmxtrans.model.JmxResultProcessor)9 Result (com.googlecode.jmxtrans.model.Result)9 HashSet (java.util.HashSet)7 Attribute (javax.management.Attribute)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)5 AttributeNotFoundException (javax.management.AttributeNotFoundException)5 MBeanRegistrationException (javax.management.MBeanRegistrationException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 HashMap (java.util.HashMap)4 AttributeList (javax.management.AttributeList)4 MBeanException (javax.management.MBeanException)4 MBeanServerConnection (javax.management.MBeanServerConnection)4 ReflectionException (javax.management.ReflectionException)4