use of org.glassfish.jersey.server.monitoring.ApplicationInfo 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;
}
use of org.glassfish.jersey.server.monitoring.ApplicationInfo in project jersey by jersey.
the class MBeanExposer method onStatistics.
@Override
public void onStatistics(MonitoringStatistics statistics) {
if (domain == null) {
final String globalSubType = ",subType=" + PROPERTY_SUBTYPE_GLOBAL;
final ApplicationInfo appStats = applicationInfoProvider.get();
String appName = appStats.getResourceConfig().getApplicationName();
if (appName == null) {
appName = "App_" + Integer.toHexString(appStats.getResourceConfig().hashCode());
}
domain = "org.glassfish.jersey:type=" + appName;
unregisterJerseyMBeans(false);
uriStatsGroup = new ResourcesMBeanGroup(statistics.getUriStatistics(), true, this, ",subType=Uris");
Map<String, ResourceStatistics> newMap = transformToStringKeys(statistics.getResourceClassStatistics());
resourceClassStatsGroup = new ResourcesMBeanGroup(newMap, false, this, ",subType=Resources");
responseMXBean = new ResponseMXBeanImpl();
registerMBean(responseMXBean, globalSubType + ",global=Responses");
requestMBean = new ExecutionStatisticsDynamicBean(statistics.getRequestStatistics(), this, globalSubType, "AllRequestTimes");
exceptionMapperMXBean = new ExceptionMapperMXBeanImpl(statistics.getExceptionMapperStatistics(), this, globalSubType);
new ApplicationMXBeanImpl(appStats, this, globalSubType);
}
requestMBean.updateExecutionStatistics(statistics.getRequestStatistics());
uriStatsGroup.updateResourcesStatistics(statistics.getUriStatistics());
responseMXBean.updateResponseStatistics(statistics.getResponseStatistics());
exceptionMapperMXBean.updateExceptionMapperStatistics(statistics.getExceptionMapperStatistics());
this.resourceClassStatsGroup.updateResourcesStatistics(transformToStringKeys(statistics.getResourceClassStatistics()));
}
use of org.glassfish.jersey.server.monitoring.ApplicationInfo in project jersey by jersey.
the class ApplicationInfoListener method processApplicationStatistics.
private void processApplicationStatistics(ApplicationEvent event) {
final long now = System.currentTimeMillis();
final ApplicationInfo applicationInfo = new ApplicationInfoImpl(event.getResourceConfig(), new Date(now), event.getRegisteredClasses(), event.getRegisteredInstances(), event.getProviders());
applicationInfoRefProvider.get().set(applicationInfo);
}
Aggregations