コード例 #1
0
ファイル: JMXVisitor.java プロジェクト: wanguan/picocontainer
 /**
  * Register the component as MBean. The implementation uses the known DynamicMBeanProvider
  * instances to get the MBean from the component.
  *
  * @see com.picocontainer.PicoVisitor#visitComponentAdapter(com.picocontainer.ComponentAdapter)
  */
 @Override
 public void visitComponentAdapter(final ComponentAdapter componentAdapter) {
   super.visitComponentAdapter(componentAdapter);
   if (picoContainer == null) {
     throw new JMXRegistrationException(
         "Cannot start JMXVisitor traversal with a ComponentAdapter");
   }
   if (!visited.contains(componentAdapter.getComponentKey())) {
     visited.add(componentAdapter.getComponentKey());
     for (final DynamicMBeanProvider provider : mBeanProviders) {
       final JMXRegistrationInfo info = provider.provide(picoContainer, componentAdapter);
       if (info != null) {
         registeredInfo.add(register(info.getMBean(), info.getObjectName()));
         break;
       }
     }
   }
 }
コード例 #2
0
 /**
  * Retrieve the component instance. The implementation will automatically register it in the
  * {@link MBeanServer}, if a provider can return a {@link javax.management.DynamicMBean} for it.
  *
  * <p>Note, that you will have to wrap this {@link ComponentAdapter} with a {@link
  * CachingComponentAdapter} to avoid the registration of the same component again.
  *
  * @throws PicoInitializationException Thrown by the delegate or if the registering of the {@link
  *     javax.management.DynamicMBean} in the {@link MBeanServer } fails.
  * @see
  *     org.picocontainer.defaults.DecoratingComponentAdapter#getComponentInstance(org.picocontainer.PicoContainer)
  */
 public Object getComponentInstance(final PicoContainer container)
     throws PicoInitializationException, PicoIntrospectionException {
   final ComponentAdapter componentAdapter = new CachingComponentAdapter(getDelegate());
   final Object componentInstance = componentAdapter.getComponentInstance(container);
   for (int i = 0; i < providers.length; ++i) {
     final JMXRegistrationInfo info = providers[i].provide(container, componentAdapter);
     if (info != null) {
       Exception exception = null;
       try {
         mBeanServer.registerMBean(info.getMBean(), info.getObjectName());
       } catch (final InstanceAlreadyExistsException e) {
         exception = e;
       } catch (final MBeanRegistrationException e) {
         exception = e;
       } catch (final NotCompliantMBeanException e) {
         exception = e;
       }
       if (exception != null) {
         throw new PicoInitializationException("Registering MBean failed", exception);
       }
     }
   }
   return componentInstance;
 }