Search in sources :

Example 1 with ApplicationInfo

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

Example 2 with ApplicationInfo

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()));
}
Also used : ApplicationInfo(org.glassfish.jersey.server.monitoring.ApplicationInfo) ResourceStatistics(org.glassfish.jersey.server.monitoring.ResourceStatistics)

Example 3 with ApplicationInfo

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);
}
Also used : ApplicationInfo(org.glassfish.jersey.server.monitoring.ApplicationInfo) Date(java.util.Date)

Aggregations

ApplicationInfo (org.glassfish.jersey.server.monitoring.ApplicationInfo)3 Date (java.util.Date)1 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 MonitoringStatistics (org.glassfish.jersey.server.monitoring.MonitoringStatistics)1 MonitoringStatisticsListener (org.glassfish.jersey.server.monitoring.MonitoringStatisticsListener)1 ResourceStatistics (org.glassfish.jersey.server.monitoring.ResourceStatistics)1