Search in sources :

Example 1 with MonitoringStatistics

use of org.glassfish.jersey.server.monitoring.MonitoringStatistics in project jersey by jersey.

the class MonitoringFeature method configure.

@Override
public boolean configure(FeatureContext context) {
    final Boolean monitoringEnabledProperty = ServerProperties.getValue(context.getConfiguration().getProperties(), ServerProperties.MONITORING_ENABLED, null, Boolean.class);
    final Boolean statisticsEnabledProperty = ServerProperties.getValue(context.getConfiguration().getProperties(), ServerProperties.MONITORING_STATISTICS_ENABLED, null, Boolean.class);
    final Boolean mbeansEnabledProperty = ServerProperties.getValue(context.getConfiguration().getProperties(), ServerProperties.MONITORING_STATISTICS_MBEANS_ENABLED, null, Boolean.class);
    if (monitoringEnabledProperty != null) {
        monitoringEnabled = monitoringEnabledProperty;
        // monitoring statistics are enabled by default if monitoring is enabled
        statisticsEnabled = monitoringEnabled;
    }
    if (statisticsEnabledProperty != null) {
        monitoringEnabled = monitoringEnabled || statisticsEnabledProperty;
        statisticsEnabled = statisticsEnabledProperty;
    }
    if (mbeansEnabledProperty != null) {
        monitoringEnabled = monitoringEnabled || mbeansEnabledProperty;
        statisticsEnabled = statisticsEnabled || mbeansEnabledProperty;
        mBeansEnabled = mbeansEnabledProperty;
    }
    if (statisticsEnabledProperty != null && !statisticsEnabledProperty) {
        if (mbeansEnabledProperty != null && mBeansEnabled) {
            LOGGER.log(Level.WARNING, LocalizationMessages.WARNING_MONITORING_FEATURE_ENABLED(ServerProperties.MONITORING_STATISTICS_ENABLED));
        } else {
            LOGGER.log(Level.WARNING, LocalizationMessages.WARNING_MONITORING_FEATURE_DISABLED(ServerProperties.MONITORING_STATISTICS_ENABLED));
        }
    }
    if (monitoringEnabled) {
        context.register(ApplicationInfoListener.class);
        context.register(new AbstractBinder() {

            @Override
            protected void configure() {
                bindFactory(ReferencingFactory.<ApplicationInfo>referenceFactory()).to(new GenericType<Ref<ApplicationInfo>>() {
                }).in(Singleton.class);
                bindFactory(ApplicationInfoInjectionFactory.class).to(ApplicationInfo.class);
            }
        });
    }
    if (statisticsEnabled) {
        context.register(MonitoringEventListener.class);
        context.register(new AbstractBinder() {

            @Override
            protected void configure() {
                bindFactory(ReferencingFactory.<MonitoringStatistics>referenceFactory()).to(new GenericType<Ref<MonitoringStatistics>>() {
                }).in(Singleton.class);
                bindFactory(StatisticsInjectionFactory.class).to(MonitoringStatistics.class);
                bind(StatisticsListener.class).to(MonitoringStatisticsListener.class).in(Singleton.class);
            }
        });
    }
    if (mBeansEnabled) {
        // instance registration is needed here as MBeanExposer needs to be a singleton so that
        // one instance handles listening to events of MonitoringStatisticsListener and ContainerLifecycleListener
        context.register(new MBeanExposer());
    }
    return monitoringEnabled;
}
Also used : Ref(org.glassfish.jersey.internal.util.collection.Ref) Singleton(javax.inject.Singleton) MonitoringStatistics(org.glassfish.jersey.server.monitoring.MonitoringStatistics) MonitoringStatisticsListener(org.glassfish.jersey.server.monitoring.MonitoringStatisticsListener) AbstractBinder(org.glassfish.jersey.internal.inject.AbstractBinder) ApplicationInfo(org.glassfish.jersey.server.monitoring.ApplicationInfo) MBeanExposer(org.glassfish.jersey.server.internal.monitoring.jmx.MBeanExposer)

Aggregations

Singleton (javax.inject.Singleton)1 AbstractBinder (org.glassfish.jersey.internal.inject.AbstractBinder)1 Ref (org.glassfish.jersey.internal.util.collection.Ref)1 MBeanExposer (org.glassfish.jersey.server.internal.monitoring.jmx.MBeanExposer)1 ApplicationInfo (org.glassfish.jersey.server.monitoring.ApplicationInfo)1 MonitoringStatistics (org.glassfish.jersey.server.monitoring.MonitoringStatistics)1 MonitoringStatisticsListener (org.glassfish.jersey.server.monitoring.MonitoringStatisticsListener)1