Search in sources :

Example 1 with ManagementAware

use of org.exoplatform.management.ManagementAware 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

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 ManagedTypeMetaData (org.exoplatform.management.spi.ManagedTypeMetaData)1 ManagementProvider (org.exoplatform.management.spi.ManagementProvider)1