Search in sources :

Example 1 with PlatformConfiguration

use of com.canoo.platform.core.PlatformConfiguration in project dolphin-platform by canoo.

the class MetricsModule method initialize.

@Override
public void initialize(final ServerCoreComponents coreComponents) {
    final PlatformConfiguration configuration = coreComponents.getConfiguration();
    final ServletContext servletContext = coreComponents.getInstance(ServletContext.class);
    if (!configuration.getBooleanProperty(METRICS_NOOP_PROPERTY, true)) {
        final PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
        final List<Tag> tagList = TagUtil.convertTags(ContextManagerImpl.getInstance().getGlobalContexts());
        new ClassLoaderMetrics(tagList).bindTo(prometheusRegistry);
        new JvmMemoryMetrics(tagList).bindTo(prometheusRegistry);
        new JvmGcMetrics(tagList).bindTo(prometheusRegistry);
        new ProcessorMetrics(tagList).bindTo(prometheusRegistry);
        new JvmThreadMetrics(tagList).bindTo(prometheusRegistry);
        servletContext.addFilter(METRICS_SERVLET_FILTER_NAME, new RequestMetricsFilter()).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, ALL_URL_MAPPING);
        servletContext.addListener(new MetricsHttpSessionListener());
        servletContext.addServlet(METRICS_SERVLET_NAME, new MetricsServlet(prometheusRegistry)).addMapping(configuration.getProperty(METRICS_ENDPOINT_PROPERTY));
        MetricsImpl.getInstance().init(prometheusRegistry);
    }
}
Also used : PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) PlatformConfiguration(com.canoo.platform.core.PlatformConfiguration) ProcessorMetrics(io.micrometer.core.instrument.binder.system.ProcessorMetrics) RequestMetricsFilter(com.canoo.dp.impl.platform.server.metrics.servlet.RequestMetricsFilter) JvmMemoryMetrics(io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics) JvmGcMetrics(io.micrometer.core.instrument.binder.jvm.JvmGcMetrics) ClassLoaderMetrics(io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics) JvmThreadMetrics(io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics) MetricsHttpSessionListener(com.canoo.dp.impl.platform.server.metrics.servlet.MetricsHttpSessionListener) MetricsServlet(com.canoo.dp.impl.platform.server.metrics.servlet.MetricsServlet) ServletContext(javax.servlet.ServletContext) Tag(io.micrometer.core.instrument.Tag) DispatcherType(javax.servlet.DispatcherType)

Example 2 with PlatformConfiguration

use of com.canoo.platform.core.PlatformConfiguration in project dolphin-platform by canoo.

the class CorsModule method initialize.

@Override
public void initialize(final ServerCoreComponents coreComponents) throws ModuleInitializationException {
    Assert.requireNonNull(coreComponents, "coreComponents");
    final ServletContext servletContext = coreComponents.getInstance(ServletContext.class);
    final PlatformConfiguration configuration = coreComponents.getConfiguration();
    final List<String> endpointList = configuration.getListProperty(CORS_ENDPOINTS_URL_MAPPINGS, CORS_ENDPOINTS_URL_MAPPINGS_DEFAULT_VALUE);
    final String[] endpoints = endpointList.toArray(new String[endpointList.size()]);
    final CrossSiteOriginFilter filter = new CrossSiteOriginFilter(configuration);
    final FilterRegistration.Dynamic createdFilter = servletContext.addFilter(CORS_FILTER, filter);
    createdFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, endpoints);
}
Also used : CrossSiteOriginFilter(com.canoo.dp.impl.server.servlet.CrossSiteOriginFilter) PlatformConfiguration(com.canoo.platform.core.PlatformConfiguration) ServletContext(javax.servlet.ServletContext) DispatcherType(javax.servlet.DispatcherType) FilterRegistration(javax.servlet.FilterRegistration)

Example 3 with PlatformConfiguration

use of com.canoo.platform.core.PlatformConfiguration in project dolphin-platform by canoo.

the class ClientSessionModule method initialize.

@Override
public void initialize(final ServerCoreComponents coreComponents) throws ModuleInitializationException {
    Assert.requireNonNull(coreComponents, "coreComponents");
    final ServletContext servletContext = coreComponents.getInstance(ServletContext.class);
    final PlatformConfiguration configuration = coreComponents.getConfiguration();
    final ClasspathScanner classpathScanner = coreComponents.getInstance(ClasspathScanner.class);
    final ManagedBeanFactory beanFactory = coreComponents.getInstance(ManagedBeanFactory.class);
    final ClientSessionLifecycleHandlerImpl lifecycleHandler = new ClientSessionLifecycleHandlerImpl();
    coreComponents.provideInstance(ClientSessionLifecycleHandler.class, lifecycleHandler);
    coreComponents.provideInstance(ClientSessionProvider.class, new ClientSessionProvider() {

        @Override
        public ClientSession getCurrentClientSession() {
            return lifecycleHandler.getCurrentDolphinSession();
        }
    });
    final ClientSessionManager clientSessionManager = new ClientSessionManager(configuration, lifecycleHandler);
    final List<String> endpointList = configuration.getListProperty(ID_FILTER_URL_MAPPINGS, ID_FILTER_URL_MAPPINGS_DEFAULT_VALUE);
    final String[] endpoints = endpointList.toArray(new String[endpointList.size()]);
    final ClientSessionFilter filter = new ClientSessionFilter(clientSessionManager);
    final FilterRegistration.Dynamic createdFilter = servletContext.addFilter(DOLPHIN_CLIENT_ID_FILTER_NAME, filter);
    createdFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, endpoints);
    final HttpSessionCleanerListener sessionCleaner = new HttpSessionCleanerListener(clientSessionManager);
    servletContext.addListener(sessionCleaner);
    final Set<Class<?>> listeners = classpathScanner.getTypesAnnotatedWith(ServerListener.class);
    for (final Class<?> listenerClass : listeners) {
        if (ClientSessionListener.class.isAssignableFrom(listenerClass)) {
            final ClientSessionListener listener = (ClientSessionListener) beanFactory.createDependentInstance(listenerClass);
            lifecycleHandler.addSessionDestroyedListener(s -> listener.sessionDestroyed(s));
            lifecycleHandler.addSessionCreatedListener(s -> listener.sessionCreated(s));
        }
    }
    final ClientSessionMutextHolder mutextHolder = new ClientSessionMutextHolder();
    lifecycleHandler.addSessionDestroyedListener(s -> mutextHolder.sessionDestroyed(s));
    lifecycleHandler.addSessionCreatedListener(s -> mutextHolder.sessionCreated(s));
}
Also used : ClientSessionManager(com.canoo.dp.impl.server.client.ClientSessionManager) PlatformConfiguration(com.canoo.platform.core.PlatformConfiguration) ClientSessionLifecycleHandlerImpl(com.canoo.dp.impl.server.client.ClientSessionLifecycleHandlerImpl) HttpSessionCleanerListener(com.canoo.dp.impl.server.client.HttpSessionCleanerListener) ClasspathScanner(com.canoo.platform.server.spi.components.ClasspathScanner) ClientSessionProvider(com.canoo.dp.impl.server.client.ClientSessionProvider) ClientSession(com.canoo.platform.server.client.ClientSession) ManagedBeanFactory(com.canoo.platform.server.spi.components.ManagedBeanFactory) ServletContext(javax.servlet.ServletContext) ClientSessionListener(com.canoo.platform.server.client.ClientSessionListener) DispatcherType(javax.servlet.DispatcherType) ClientSessionFilter(com.canoo.dp.impl.server.client.ClientSessionFilter) FilterRegistration(javax.servlet.FilterRegistration) ClientSessionMutextHolder(com.canoo.dp.impl.server.client.ClientSessionMutextHolder)

Example 4 with PlatformConfiguration

use of com.canoo.platform.core.PlatformConfiguration in project dolphin-platform by canoo.

the class HttpTimeoutModule method initialize.

@Override
public void initialize(final ServerCoreComponents coreComponents) throws ModuleInitializationException {
    Assert.requireNonNull(coreComponents, "coreComponents");
    final ServletContext servletContext = coreComponents.getInstance(ServletContext.class);
    final PlatformConfiguration configuration = coreComponents.getConfiguration();
    HttpSessionTimeoutListener sessionCleaner = new HttpSessionTimeoutListener(configuration);
    servletContext.addListener(sessionCleaner);
}
Also used : PlatformConfiguration(com.canoo.platform.core.PlatformConfiguration) HttpSessionTimeoutListener(com.canoo.dp.impl.server.servlet.HttpSessionTimeoutListener) ServletContext(javax.servlet.ServletContext)

Example 5 with PlatformConfiguration

use of com.canoo.platform.core.PlatformConfiguration in project dolphin-platform by canoo.

the class ServerTimingModule method initialize.

@Override
public void initialize(final ServerCoreComponents coreComponents) throws ModuleInitializationException {
    Assert.requireNonNull(coreComponents, "coreComponents");
    final ServletContext servletContext = coreComponents.getInstance(ServletContext.class);
    final PlatformConfiguration configuration = coreComponents.getConfiguration();
    final Filter filter = new ServerTimingFilter(true);
    final FilterRegistration.Dynamic createdFilter = servletContext.addFilter(FILTER_NAME, filter);
    createdFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
}
Also used : PlatformConfiguration(com.canoo.platform.core.PlatformConfiguration) ServerTimingFilter(com.canoo.dp.impl.server.servlet.ServerTimingFilter) ServerTimingFilter(com.canoo.dp.impl.server.servlet.ServerTimingFilter) Filter(javax.servlet.Filter) ServletContext(javax.servlet.ServletContext) DispatcherType(javax.servlet.DispatcherType) FilterRegistration(javax.servlet.FilterRegistration)

Aggregations

PlatformConfiguration (com.canoo.platform.core.PlatformConfiguration)5 ServletContext (javax.servlet.ServletContext)5 DispatcherType (javax.servlet.DispatcherType)4 FilterRegistration (javax.servlet.FilterRegistration)3 MetricsHttpSessionListener (com.canoo.dp.impl.platform.server.metrics.servlet.MetricsHttpSessionListener)1 MetricsServlet (com.canoo.dp.impl.platform.server.metrics.servlet.MetricsServlet)1 RequestMetricsFilter (com.canoo.dp.impl.platform.server.metrics.servlet.RequestMetricsFilter)1 ClientSessionFilter (com.canoo.dp.impl.server.client.ClientSessionFilter)1 ClientSessionLifecycleHandlerImpl (com.canoo.dp.impl.server.client.ClientSessionLifecycleHandlerImpl)1 ClientSessionManager (com.canoo.dp.impl.server.client.ClientSessionManager)1 ClientSessionMutextHolder (com.canoo.dp.impl.server.client.ClientSessionMutextHolder)1 ClientSessionProvider (com.canoo.dp.impl.server.client.ClientSessionProvider)1 HttpSessionCleanerListener (com.canoo.dp.impl.server.client.HttpSessionCleanerListener)1 CrossSiteOriginFilter (com.canoo.dp.impl.server.servlet.CrossSiteOriginFilter)1 HttpSessionTimeoutListener (com.canoo.dp.impl.server.servlet.HttpSessionTimeoutListener)1 ServerTimingFilter (com.canoo.dp.impl.server.servlet.ServerTimingFilter)1 ClientSession (com.canoo.platform.server.client.ClientSession)1 ClientSessionListener (com.canoo.platform.server.client.ClientSessionListener)1 ClasspathScanner (com.canoo.platform.server.spi.components.ClasspathScanner)1 ManagedBeanFactory (com.canoo.platform.server.spi.components.ManagedBeanFactory)1