@Override
 protected void registerBeans() {
   if (!exposedBeans.isEmpty()) {
     super.setBeans(exposedBeans);
     super.registerBeans();
   }
 }
  @Test
  public void testEndpointMBeanExporterWithProperties()
      throws IntrospectionException, InstanceNotFoundException, MalformedObjectNameException,
          ReflectionException {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("endpoints.jmx.domain", "test-domain");
    environment.setProperty("endpoints.jmx.unique_names", "true");
    environment.setProperty("endpoints.jmx.static_names", "key1=value1, key2=value2");
    this.context = new AnnotationConfigApplicationContext();
    this.context.setEnvironment(environment);
    this.context.register(
        JmxAutoConfiguration.class,
        EndpointAutoConfiguration.class,
        EndpointMBeanExportAutoConfiguration.class);
    this.context.refresh();
    this.context.getBean(EndpointMBeanExporter.class);

    MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);

    assertNotNull(
        mbeanExporter
            .getServer()
            .getMBeanInfo(
                ObjectNameManager.getInstance(
                    getObjectName("test-domain", "healthEndpoint", this.context).toString()
                        + ",key1=value1,key2=value2")));
  }
 @Override
 public final void onInit() throws Exception {
   Assert.isTrue(
       this.getBeanFactory() instanceof ListableBeanFactory, "A ListableBeanFactory is required.");
   Map<String, MBeanExporter> exporters =
       BeanFactoryUtils.beansOfTypeIncludingAncestors(
           (ListableBeanFactory) this.getBeanFactory(), MBeanExporter.class);
   Assert.isTrue(exporters.size() > 0, "No MBeanExporter is available in the current context.");
   MBeanExporter exporter = null;
   for (MBeanExporter exp : exporters.values()) {
     exporter = exp;
     if (exporter instanceof IntegrationMBeanExporter) {
       break;
     }
   }
   if (this.notificationMapper == null) {
     this.notificationMapper =
         new DefaultNotificationMapper(this.objectName, this.defaultNotificationType);
   }
   exporter.registerManagedResource(this.delegate, this.objectName);
   if (this.logger.isInfoEnabled()) {
     this.logger.info(
         "Registered JMX notification publisher as MBean with ObjectName: " + this.objectName);
   }
 }
 @Override
 protected void doRegister(Object mbean, ObjectName objectName) throws JMException {
   ObjectName newObjectName = replacePrefix(objectName);
   if (logger.isDebugEnabled()) {
     logger.debug(
         "doRegister with oldObjectName {} / newObjectName {}", objectName, newObjectName);
   }
   super.doRegister(mbean, newObjectName);
 }
 @Override
 public void destroy() {
   super.destroy();
   for (MessageChannelMetrics monitor : channels) {
     logger.info("Summary on shutdown: " + monitor);
   }
   for (MessageHandlerMetrics monitor : handlers) {
     logger.info("Summary on shutdown: " + monitor);
   }
 }
 @Override
 public void destroy() {
   super.destroy();
   this.channelsByName.clear();
   this.handlersByName.clear();
   this.sourcesByName.clear();
   for (MessageChannelMetrics monitor : this.channels) {
     logger.info("Summary on shutdown: " + monitor);
   }
   for (MessageHandlerMetrics monitor : this.handlers) {
     logger.info("Summary on shutdown: " + monitor);
   }
 }
  /** Marks this repository as complete and ready for use. */
  @Override
  public void start() {
    final Status status = _status.get();
    if (status == Status.STARTING) {
      return; // already starting
    }
    checkStatus(status, Status.CREATING);
    if (_status.compareAndSet(status, Status.STARTING) == false) {
      return; // another thread just beat this one
    }
    try {
      // Spring interfaces
      for (final Lifecycle obj : _lifecycles) {
        obj.start();
      }

      // JMX managed resources
      final MBeanServer jmxServer = findInstance(MBeanServer.class);
      if (jmxServer != null) {
        final MBeanExporter exporter = new MBeanExporter();
        exporter.setServer(jmxServer);
        for (final Map.Entry<ObjectName, Object> resourceEntry : _managedResources.entrySet()) {
          exporter.registerManagedResource(resourceEntry.getValue(), resourceEntry.getKey());
        }
      }

      _status.set(Status.RUNNING);

    } catch (final RuntimeException ex) {
      _status.set(Status.FAILED);
      throw ex;
    } finally {
      // reduce memory usage and avoid memory leaks
      _managedResources.clear();
      _initialized.clear();
    }
  }
 @Override
 public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
   super.setBeanFactory(beanFactory);
   Assert.isTrue(beanFactory instanceof ListableBeanFactory, "A ListableBeanFactory is required.");
   this.beanFactory = (ListableBeanFactory) beanFactory;
 }
 @Override
 public void setBeanClassLoader(ClassLoader classLoader) {
   this.beanClassLoader = classLoader;
   super.setBeanClassLoader(classLoader);
 }
Exemplo n.º 10
0
 @Override
 public void setServer(MBeanServer server) {
   threadServer.set(server);
   super.setServer(server);
 }
  @Override
  public void afterSingletonsInstantiated() {
    Map<String, MessageHandlerMetrics> messageHandlers =
        this.applicationContext.getBeansOfType(MessageHandlerMetrics.class);
    for (Entry<String, MessageHandlerMetrics> entry : messageHandlers.entrySet()) {
      String beanName = entry.getKey();
      MessageHandlerMetrics bean = entry.getValue();
      if (this.handlerInAnonymousWrapper(bean) != null) {
        if (logger.isDebugEnabled()) {
          logger.debug("Skipping " + beanName + " because it wraps another handler");
        }
        continue;
      }
      // If the handler is proxied, we have to extract the target to expose as an MBean.
      // The MetadataMBeanInfoAssembler does not support JDK dynamic proxies.
      MessageHandlerMetrics monitor = (MessageHandlerMetrics) extractTarget(bean);
      this.handlers.add(monitor);
    }

    Map<String, MessageSourceMetrics> messageSources =
        this.applicationContext.getBeansOfType(MessageSourceMetrics.class);
    for (Entry<String, MessageSourceMetrics> entry : messageSources.entrySet()) {
      // If the source is proxied, we have to extract the target to expose as an MBean.
      // The MetadataMBeanInfoAssembler does not support JDK dynamic proxies.
      MessageSourceMetrics monitor = (MessageSourceMetrics) extractTarget(entry.getValue());
      this.sources.add(monitor);
    }

    Map<String, MessageChannelMetrics> messageChannels =
        this.applicationContext.getBeansOfType(MessageChannelMetrics.class);
    for (Entry<String, MessageChannelMetrics> entry : messageChannels.entrySet()) {
      // If the channel is proxied, we have to extract the target to expose as an MBean.
      // The MetadataMBeanInfoAssembler does not support JDK dynamic proxies.
      MessageChannelMetrics monitor = (MessageChannelMetrics) extractTarget(entry.getValue());
      this.channels.add(monitor);
    }
    Map<String, MessageProducer> messageProducers =
        this.applicationContext.getBeansOfType(MessageProducer.class);
    for (Entry<String, MessageProducer> entry : messageProducers.entrySet()) {
      MessageProducer messageProducer = entry.getValue();
      if (messageProducer instanceof Lifecycle) {
        Lifecycle target = (Lifecycle) extractTarget(messageProducer);
        if (!(target instanceof AbstractMessageProducingHandler)) {
          this.inboundLifecycleMessageProducers.add(target);
        }
      }
    }
    super.afterSingletonsInstantiated();
    try {
      registerChannels();
      registerHandlers();
      registerSources();
      registerEndpoints();

      if (this.applicationContext.containsBean(
          IntegrationContextUtils.INTEGRATION_MESSAGE_HISTORY_CONFIGURER_BEAN_NAME)) {
        Object messageHistoryConfigurer =
            this.applicationContext.getBean(
                IntegrationContextUtils.INTEGRATION_MESSAGE_HISTORY_CONFIGURER_BEAN_NAME);
        if (messageHistoryConfigurer instanceof MessageHistoryConfigurer) {
          registerBeanInstance(
              messageHistoryConfigurer,
              IntegrationContextUtils.INTEGRATION_MESSAGE_HISTORY_CONFIGURER_BEAN_NAME);
        }
      }
      if (!this.applicationContext.containsBean(
          IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME)) {
        IntegrationManagementConfigurer config = new IntegrationManagementConfigurer();
        config.setDefaultCountsEnabled(true);
        config.setDefaultStatsEnabled(true);
        config.setApplicationContext(this.applicationContext);
        config.setBeanName(IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME);
        config.afterSingletonsInstantiated();
      }
    } catch (RuntimeException e) {
      unregisterBeans();
      throw e;
    }
  }
 @Override
 protected void doUnregister(ObjectName objectName) {
   ObjectName newObjectName = replacePrefix(objectName);
   logger.debug("doRegister with oldObjectName {} / newObjectName {}", objectName, newObjectName);
   super.doUnregister(newObjectName);
 }