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;
}
Aggregations