Search in sources :

Example 1 with ManagementProvider

use of org.exoplatform.management.spi.ManagementProvider in project kernel by exoplatform.

the class ManageableComponentAdapterMT method register.

protected void register(Container co, Object instance) {
    if (registered.compareAndSet(false, true)) {
        do {
            if (co instanceof ManageableContainer) {
                break;
            }
        } while ((co = co.getSuccessor()) != null);
        if (co instanceof ManageableContainer) {
            ManageableContainer container = (ManageableContainer) co;
            if (container.managementContext != null) {
                // Register the instance against the management context
                if (LOG.isDebugEnabled())
                    LOG.debug("==> add " + instance + " to a mbean server");
                container.managementContext.register(instance);
                // Register if it is a management provider
                if (instance instanceof ManagementProvider) {
                    ManagementProvider provider = (ManagementProvider) instance;
                    container.addProvider(provider);
                }
            }
        }
    }
}
Also used : ManagementProvider(org.exoplatform.management.spi.ManagementProvider)

Example 2 with ManagementProvider

use of org.exoplatform.management.spi.ManagementProvider in project kernel by exoplatform.

the class ManageableComponentAdapter method register.

protected void register(Container co, Object instance) {
    if (registered.compareAndSet(false, true)) {
        do {
            if (co instanceof ManageableContainer) {
                break;
            }
        } while ((co = co.getSuccessor()) != null);
        if (co instanceof ManageableContainer) {
            ManageableContainer container = (ManageableContainer) co;
            if (container.managementContext != null) {
                // Register the instance against the management context
                if (LOG.isDebugEnabled())
                    LOG.debug("==> add " + instance + " to a mbean server");
                container.managementContext.register(instance);
                // Register if it is a management provider
                if (instance instanceof ManagementProvider) {
                    ManagementProvider provider = (ManagementProvider) instance;
                    container.addProvider(provider);
                }
            }
        }
    }
}
Also used : ManagementProvider(org.exoplatform.management.spi.ManagementProvider)

Example 3 with ManagementProvider

use of org.exoplatform.management.spi.ManagementProvider in project kernel by exoplatform.

the class ManageableContainer method registerComponentInstance.

/**
 * {@inheritDoc}
 */
public <T> ComponentAdapter<T> registerComponentInstance(Object componentKey, T componentInstance) throws ContainerException {
    ComponentAdapter<T> adapter = super.registerComponentInstance(componentKey, componentInstance);
    if (managementContext != null) {
        managementContext.register(componentInstance);
        // Register if it is a management provider
        if (componentInstance instanceof ManagementProvider) {
            ManagementProvider provider = (ManagementProvider) componentInstance;
            addProvider(provider);
        }
    }
    return adapter;
}
Also used : ManagementProvider(org.exoplatform.management.spi.ManagementProvider) JMXManagementProvider(org.exoplatform.management.jmx.impl.JMXManagementProvider)

Example 4 with ManagementProvider

use of org.exoplatform.management.spi.ManagementProvider in project kernel by exoplatform.

the class ManagementContextImpl method register.

public void register(Object o) {
    Object resource = null;
    // Apply managed by annotation
    ManagedBy managedBy = o.getClass().getAnnotation(ManagedBy.class);
    if (managedBy != null) {
        try {
            Class<?> managedByClass = managedBy.value();
            Constructor<?> blah = managedByClass.getConstructor(o.getClass());
            resource = blah.newInstance(o);
        } catch (NoSuchMethodException e) {
            LOG.error(e.getLocalizedMessage(), e);
        } catch (InstantiationException e) {
            LOG.error(e.getLocalizedMessage(), e);
        } catch (IllegalAccessException e) {
            LOG.error(e.getLocalizedMessage(), e);
        } catch (InvocationTargetException e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
    } else {
        resource = o;
    }
    // 
    if (resource != null) {
        MetaDataBuilder builder = new MetaDataBuilder(resource.getClass());
        if (builder.isBuildable()) {
            ManagedTypeMetaData metaData = builder.build();
            // 
            ManagementContextImpl managementContext;
            if (resource instanceof Container) {
                managementContext = (ManagementContextImpl) ((Container) resource).getManagementContext();
            } else {
                managementContext = new ManagementContextImpl(this, resource, metaData);
            }
            // 
            if (registrations.containsKey(resource)) {
                LOG.debug("The component " + resource + " has already been registered");
                return;
            } else {
                registrations.put(resource, managementContext);
            }
            // 
            ManageableContainer container = findContainer();
            // Install for all the providers related
            for (ManagementProvider provider : container.getProviders()) {
                Object name = provider.manage(managementContext);
                if (name != null) {
                    managementContext.managedSet.put(provider, name);
                }
            }
            // Allow for more resource management
            if (resource instanceof ManagementAware) {
                ((ManagementAware) resource).setContext(managementContext);
            }
        }
    }
}
Also used : ManagedBy(org.exoplatform.management.annotations.ManagedBy) InvocationTargetException(java.lang.reflect.InvocationTargetException) RootContainer(org.exoplatform.container.RootContainer) ExoContainer(org.exoplatform.container.ExoContainer) Container(org.exoplatform.container.spi.Container) ManagedTypeMetaData(org.exoplatform.management.spi.ManagedTypeMetaData) ManagementAware(org.exoplatform.management.ManagementAware) ManagementProvider(org.exoplatform.management.spi.ManagementProvider)

Aggregations

ManagementProvider (org.exoplatform.management.spi.ManagementProvider)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ExoContainer (org.exoplatform.container.ExoContainer)1 RootContainer (org.exoplatform.container.RootContainer)1 Container (org.exoplatform.container.spi.Container)1 ManagementAware (org.exoplatform.management.ManagementAware)1 ManagedBy (org.exoplatform.management.annotations.ManagedBy)1 JMXManagementProvider (org.exoplatform.management.jmx.impl.JMXManagementProvider)1 ManagedTypeMetaData (org.exoplatform.management.spi.ManagedTypeMetaData)1