org.picocontainer.gems.jmx
Class JMXExposed<T>

java.lang.Object
  extended by org.picocontainer.behaviors.AbstractBehavior<T>
      extended by org.picocontainer.gems.jmx.JMXExposed<T>
All Implemented Interfaces:
Serializable, Behavior<T>, ComponentAdapter<T>, ComponentMonitorStrategy, LifecycleStrategy

public class JMXExposed<T>
extends AbstractBehavior<T>

ComponentAdapter that is exposing a component as MBean in a MBeanServer.

Author:
Jörg Schaible
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.picocontainer.ComponentAdapter
ComponentAdapter.NOTHING
 
Field Summary
 
Fields inherited from class org.picocontainer.behaviors.AbstractBehavior
delegate
 
Constructor Summary
JMXExposed(ComponentAdapter<T> delegate, MBeanServer mBeanServer)
          Construct a JMXExposed behaviour.
JMXExposed(ComponentAdapter<T> delegate, MBeanServer mBeanServer, DynamicMBeanProvider[] providers)
          Construct a JMXExposed behaviour
 
Method Summary
 void dispose(Object component)
          Invokes delegate dispose method if the delegate is a LifecycleStrategy Invoke the "dispose" method on the component instance if this is disposable.
 T getComponentInstance(PicoContainer container, Type into)
          Retrieve the component instance.
 String getDescriptor()
          Get a string key descriptor of the component adapter.
 boolean hasLifecycle(Class<?> type)
          Invokes delegate hasLifecycle(Class) method if the delegate is a LifecycleStrategy Test if a component instance has a lifecycle.
 
Methods inherited from class org.picocontainer.behaviors.AbstractBehavior
accept, changeMonitor, componentHasLifecycle, currentMonitor, dispose, findAdapterOfType, getComponentImplementation, getComponentInstance, getComponentKey, getDelegate, start, start, stop, stop, toString, verify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JMXExposed

public JMXExposed(ComponentAdapter<T> delegate,
                  MBeanServer mBeanServer,
                  DynamicMBeanProvider[] providers)
           throws NullPointerException
Construct a JMXExposed behaviour

Parameters:
delegate - The delegated ComponentAdapter.
mBeanServer - The MBeanServer used for registering the MBean.
providers - An array with providers for converting the component instance into a DynamicMBean.
Throws:
NullPointerException - Thrown if the MBeanServer or the array with the DynamicMBeanProvider instances is null.

JMXExposed

public JMXExposed(ComponentAdapter<T> delegate,
                  MBeanServer mBeanServer)
           throws NullPointerException
Construct a JMXExposed behaviour. This instance uses a DynamicMBeanComponentProvider as default to register any component instance in the MBeanServer, that is already a DynamicMBean.

Parameters:
delegate - The delegated ComponentAdapter.
mBeanServer - The MBeanServer used for registering the MBean.
Throws:
NullPointerException - Thrown if the MBeanServer or the array with the DynamicMBeanProvider instances is null.
Method Detail

getComponentInstance

public T getComponentInstance(PicoContainer container,
                              Type into)
                       throws PicoCompositionException
Retrieve the component instance. The implementation will automatically register it in the MBeanServer, if a provider can return a DynamicMBean for it.

Note, that you will have to wrap this ComponentAdapter with a Cached to avoid the registration of the same component again.

Specified by:
getComponentInstance in interface ComponentAdapter<T>
Overrides:
getComponentInstance in class AbstractBehavior<T>
Parameters:
container - the PicoContainer, that is used to resolve any possible dependencies of the instance.
into - the class that is about to be injected into. Use ComponentAdapter.NOTHING.class if this is not important to you.
Returns:
the component instance.
Throws:
PicoCompositionException - Thrown by the delegate or if the registering of the DynamicMBean in the MBeanServer fails.
See Also:
AbstractBehavior#getComponentInstance(org.picocontainer.PicoContainer, java.lang.Class)

getDescriptor

public String getDescriptor()
Description copied from interface: ComponentAdapter
Get a string key descriptor of the component adapter.

Returns:

dispose

public void dispose(Object component)
Description copied from class: AbstractBehavior
Invokes delegate dispose method if the delegate is a LifecycleStrategy Invoke the "dispose" method on the component instance if this is disposable. It is up to the implementation of the strategy what "dispose" and "disposable" means.

Specified by:
dispose in interface LifecycleStrategy
Overrides:
dispose in class AbstractBehavior<T>
Parameters:
component - the instance of the component to dispose

hasLifecycle

public boolean hasLifecycle(Class<?> type)
Description copied from class: AbstractBehavior
Invokes delegate hasLifecycle(Class) method if the delegate is a LifecycleStrategy Test if a component instance has a lifecycle.

Specified by:
hasLifecycle in interface LifecycleStrategy
Overrides:
hasLifecycle in class AbstractBehavior<T>
Parameters:
type - the component's type
Returns:
true if the component has a lifecycle


Copyright © 2003-2010 Codehaus. All Rights Reserved.