Search in sources :

Example 21 with EventListener

use of java.util.EventListener in project hazelcast by hazelcast.

the class ListenerConfigHolder method asListenerConfig.

public <T extends ListenerConfig> T asListenerConfig(SerializationService serializationService) {
    validate();
    ListenerConfig listenerConfig = null;
    if (className != null) {
        switch(listenerType) {
            case GENERIC:
                listenerConfig = new ListenerConfig(className);
                break;
            case ITEM:
                listenerConfig = new ItemListenerConfig(className, includeValue);
                break;
            case ENTRY:
                listenerConfig = new EntryListenerConfig(className, local, includeValue);
                break;
            case SPLIT_BRAIN_PROTECTION:
                listenerConfig = new SplitBrainProtectionListenerConfig(className);
                break;
            case CACHE_PARTITION_LOST:
                listenerConfig = new CachePartitionLostListenerConfig(className);
                break;
            case MAP_PARTITION_LOST:
                listenerConfig = new MapPartitionLostListenerConfig(className);
                break;
            default:
        }
    } else {
        EventListener eventListener = serializationService.toObject(listenerImplementation);
        switch(listenerType) {
            case GENERIC:
                listenerConfig = new ListenerConfig(eventListener);
                break;
            case ITEM:
                listenerConfig = new ItemListenerConfig((ItemListener) eventListener, includeValue);
                break;
            case ENTRY:
                listenerConfig = new EntryListenerConfig((MapListener) eventListener, local, includeValue);
                break;
            case SPLIT_BRAIN_PROTECTION:
                listenerConfig = new SplitBrainProtectionListenerConfig((SplitBrainProtectionListener) eventListener);
                break;
            case CACHE_PARTITION_LOST:
                listenerConfig = new CachePartitionLostListenerConfig((CachePartitionLostListener) eventListener);
                break;
            case MAP_PARTITION_LOST:
                listenerConfig = new MapPartitionLostListenerConfig((MapPartitionLostListener) eventListener);
                break;
            default:
        }
    }
    return (T) listenerConfig;
}
Also used : SplitBrainProtectionListener(com.hazelcast.splitbrainprotection.SplitBrainProtectionListener) CachePartitionLostListener(com.hazelcast.cache.impl.event.CachePartitionLostListener) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) ListenerConfig(com.hazelcast.config.ListenerConfig) SplitBrainProtectionListenerConfig(com.hazelcast.config.SplitBrainProtectionListenerConfig) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) ItemListenerConfig(com.hazelcast.config.ItemListenerConfig) SplitBrainProtectionListenerConfig(com.hazelcast.config.SplitBrainProtectionListenerConfig) MapPartitionLostListener(com.hazelcast.map.listener.MapPartitionLostListener) MapListener(com.hazelcast.map.listener.MapListener) ItemListenerConfig(com.hazelcast.config.ItemListenerConfig) ItemListener(com.hazelcast.collection.ItemListener) EventListener(java.util.EventListener)

Example 22 with EventListener

use of java.util.EventListener in project undertow by undertow-io.

the class ServletContextImpl method addListener.

@Override
public <T extends EventListener> void addListener(final T t) {
    ensureNotInitialized();
    ensureNotProgramaticListener();
    if (ApplicationListeners.listenerState() != NO_LISTENER && ServletContextListener.class.isAssignableFrom(t.getClass())) {
        throw UndertowServletMessages.MESSAGES.cannotAddServletContextListener();
    }
    ListenerInfo listener = new ListenerInfo(t.getClass(), new ImmediateInstanceFactory<EventListener>(t));
    getDeploymentInfo().addListener(listener);
    deployment.getApplicationListeners().addListener(new ManagedListener(listener, true));
}
Also used : ListenerInfo(io.undertow.servlet.api.ListenerInfo) ServletContextListener(javax.servlet.ServletContextListener) ManagedListener(io.undertow.servlet.core.ManagedListener) EventListener(java.util.EventListener)

Example 23 with EventListener

use of java.util.EventListener in project meteo by pierre.

the class JettyServer method start.

public void start(final Injector injector) throws Exception {
    final long startTime = System.currentTimeMillis();
    server = new Server();
    // Setup JMX
    final MBeanContainer mbContainer = new MBeanContainer(mbeanServer);
    server.getContainer().addEventListener(mbContainer);
    server.addBean(mbContainer);
    mbContainer.addBean(Log.getLog());
    final Connector connector = new SelectChannelConnector();
    connector.setStatsOn(config.isJettyStatsOn());
    connector.setHost(config.getLocalIp());
    connector.setPort(config.getLocalPort());
    server.addConnector(connector);
    server.setStopAtShutdown(true);
    final ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    context.addEventListener(new GuiceServletContextListener() {

        @Override
        protected Injector getInjector() {
            return injector;
        }
    });
    // Jersey insists on using java.util.logging (JUL)
    final EventListener listener = new SetupJULBridge();
    context.addEventListener(listener);
    // Make sure Guice filter all requests
    final FilterHolder filterHolder = new FilterHolder(GuiceFilter.class);
    context.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
    // Backend servlet for Guice - never used
    final ServletHolder sh = new ServletHolder(DefaultServlet.class);
    context.addServlet(sh, "/*");
    server.start();
    final long secondsToStart = (System.currentTimeMillis() - startTime) / 1000;
    log.info(String.format("Jetty server started in %d:%02d", secondsToStart / 60, secondsToStart % 60));
}
Also used : Connector(org.eclipse.jetty.server.Connector) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) MBeanServer(javax.management.MBeanServer) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) Injector(com.google.inject.Injector) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) EventListener(java.util.EventListener) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) GuiceServletContextListener(com.google.inject.servlet.GuiceServletContextListener)

Example 24 with EventListener

use of java.util.EventListener in project spring-boot by spring-projects.

the class JettyServletWebServerFactoryTests method faultyListenerCausesStartFailure.

@Test
void faultyListenerCausesStartFailure() {
    JettyServletWebServerFactory factory = getFactory();
    factory.addServerCustomizers((JettyServerCustomizer) (server) -> {
        Collection<WebAppContext> contexts = server.getBeans(WebAppContext.class);
        EventListener eventListener = new ServletContextListener() {

            @Override
            public void contextInitialized(ServletContextEvent event) {
                throw new RuntimeException();
            }

            @Override
            public void contextDestroyed(ServletContextEvent event) {
            }
        };
        WebAppContext context = contexts.iterator().next();
        try {
            context.addEventListener(eventListener);
        } catch (NoSuchMethodError ex) {
            Method addEventListener = ReflectionUtils.findMethod(context.getClass(), "addEventListener", EventListener.class);
            ReflectionUtils.invokeMethod(addEventListener, context, eventListener);
        }
    });
    assertThatExceptionOfType(WebServerException.class).isThrownBy(() -> {
        JettyWebServer jettyWebServer = (JettyWebServer) factory.getWebServer();
        try {
            jettyWebServer.start();
        } finally {
            QueuedThreadPool threadPool = (QueuedThreadPool) jettyWebServer.getServer().getThreadPool();
            assertThat(threadPool.isRunning()).isFalse();
        }
    });
}
Also used : SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Arrays(java.util.Arrays) ClassMatcher(org.eclipse.jetty.webapp.ClassMatcher) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Disabled(org.junit.jupiter.api.Disabled) Header(org.apache.http.Header) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) InetAddress(java.net.InetAddress) Future(java.util.concurrent.Future) AbstractConfiguration(org.eclipse.jetty.webapp.AbstractConfiguration) Configuration(org.eclipse.jetty.webapp.Configuration) BDDMockito.given(org.mockito.BDDMockito.given) Locale(java.util.Locale) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) Duration(java.time.Duration) Map(java.util.Map) PortInUseException(org.springframework.boot.web.server.PortInUseException) Method(java.lang.reflect.Method) Server(org.eclipse.jetty.server.Server) JspServlet(org.apache.jasper.servlet.JspServlet) Collection(java.util.Collection) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) AbstractServletWebServerFactoryTests(org.springframework.boot.web.servlet.server.AbstractServletWebServerFactoryTests) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) Test(org.junit.jupiter.api.Test) EventListener(java.util.EventListener) Mockito.inOrder(org.mockito.Mockito.inOrder) ServletContextEvent(jakarta.servlet.ServletContextEvent) Awaitility(org.awaitility.Awaitility) HttpClients(org.apache.http.impl.client.HttpClients) ServletContextListener(jakarta.servlet.ServletContextListener) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Handler(org.eclipse.jetty.server.Handler) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) WebServerException(org.springframework.boot.web.server.WebServerException) Dynamic(jakarta.servlet.ServletRegistration.Dynamic) AtomicReference(java.util.concurrent.atomic.AtomicReference) Charset(java.nio.charset.Charset) Compression(org.springframework.boot.web.server.Compression) Shutdown(org.springframework.boot.web.server.Shutdown) HttpClient(org.apache.http.client.HttpClient) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) ErrorPageErrorHandler(org.eclipse.jetty.servlet.ErrorPageErrorHandler) InOrder(org.mockito.InOrder) HandlerWrapper(org.eclipse.jetty.server.handler.HandlerWrapper) GracefulShutdownResult(org.springframework.boot.web.server.GracefulShutdownResult) Ssl(org.springframework.boot.web.server.Ssl) ExecutionException(java.util.concurrent.ExecutionException) ServerConnector(org.eclipse.jetty.server.ServerConnector) ReflectionUtils(org.springframework.util.ReflectionUtils) AbstractServletWebServerFactory(org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory) HttpResponse(org.apache.http.HttpResponse) Connector(org.eclipse.jetty.server.Connector) Collections(java.util.Collections) CapturedOutput(org.springframework.boot.testsupport.system.CapturedOutput) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) ServletContextListener(jakarta.servlet.ServletContextListener) WebServerException(org.springframework.boot.web.server.WebServerException) Method(java.lang.reflect.Method) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) Collection(java.util.Collection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) EventListener(java.util.EventListener) ServletContextEvent(jakarta.servlet.ServletContextEvent) Test(org.junit.jupiter.api.Test)

Example 25 with EventListener

use of java.util.EventListener in project wildfly by wildfly.

the class UndertowDeploymentInfoService method addListener.

private static void addListener(final ClassLoader classLoader, final ComponentRegistry components, final DeploymentInfo d, final ListenerMetaData listener, boolean programatic) throws ClassNotFoundException {
    ListenerInfo l;
    final Class<? extends EventListener> listenerClass = (Class<? extends EventListener>) classLoader.loadClass(listener.getListenerClass());
    ManagedReferenceFactory creator = components.createInstanceFactory(listenerClass);
    if (creator != null) {
        InstanceFactory<EventListener> factory = createInstanceFactory(creator);
        l = new ListenerInfo(listenerClass, factory, programatic);
    } else {
        l = new ListenerInfo(listenerClass, programatic);
    }
    d.addListener(l);
}
Also used : ListenerInfo(io.undertow.servlet.api.ListenerInfo) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) EventListener(java.util.EventListener)

Aggregations

EventListener (java.util.EventListener)71 Test (org.junit.Test)11 ListenerInfo (io.undertow.servlet.api.ListenerInfo)5 ServletRequestListener (javax.servlet.ServletRequestListener)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ServletContextListener (javax.servlet.ServletContextListener)3 HttpSessionListener (javax.servlet.http.HttpSessionListener)3 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)3 EventListenerList (org.eclipse.scout.rt.platform.util.EventListenerList)3 Bundle (org.osgi.framework.Bundle)3 BundleContext (org.osgi.framework.BundleContext)3 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 EventObject (java.util.EventObject)2 List (java.util.List)2 NamingException (javax.naming.NamingException)2 ServletRequestEvent (javax.servlet.ServletRequestEvent)2 HttpSessionIdListener (javax.servlet.http.HttpSessionIdListener)2