Search in sources :

Example 1 with ClientSessionProvider

use of com.canoo.dp.impl.server.client.ClientSessionProvider in project dolphin-platform by canoo.

the class ClientScopeImpl method getClientSession.

protected ClientSession getClientSession() {
    final ClientSessionProvider clientSessionProvider = PlatformBootstrap.getServerCoreComponents().getInstance(ClientSessionProvider.class);
    Assert.requireNonNull(clientSessionProvider, "clientSessionProvider");
    return clientSessionProvider.getCurrentClientSession();
}
Also used : ClientSessionProvider(com.canoo.dp.impl.server.client.ClientSessionProvider)

Example 2 with ClientSessionProvider

use of com.canoo.dp.impl.server.client.ClientSessionProvider in project dolphin-platform by canoo.

the class ClientScopeContext method getDolphinSession.

private ClientSession getDolphinSession() {
    final ClientSessionProvider provider = PlatformBootstrap.getServerCoreComponents().getInstance(ClientSessionProvider.class);
    Assert.requireNonNull(provider, "provider");
    return provider.getCurrentClientSession();
}
Also used : ClientSessionProvider(com.canoo.dp.impl.server.client.ClientSessionProvider)

Example 3 with ClientSessionProvider

use of com.canoo.dp.impl.server.client.ClientSessionProvider in project dolphin-platform by canoo.

the class SpringBeanFactory method createClientSession.

@Bean(name = "clientSession")
@ClientScope
protected ClientSession createClientSession() {
    final ClientSessionProvider provider = PlatformBootstrap.getServerCoreComponents().getInstance(ClientSessionProvider.class);
    Assert.requireNonNull(provider, "provider");
    return provider.getCurrentClientSession();
}
Also used : ClientSessionProvider(com.canoo.dp.impl.server.client.ClientSessionProvider) ClientScope(com.canoo.platform.server.spring.ClientScope) Bean(org.springframework.context.annotation.Bean)

Example 4 with ClientSessionProvider

use of com.canoo.dp.impl.server.client.ClientSessionProvider in project dolphin-platform by canoo.

the class RemotingModule method initialize.

@Override
public void initialize(ServerCoreComponents coreComponents) throws ModuleInitializationException {
    LOG.info("Starting Dolphin Platform");
    try {
        final ServletContext servletContext = coreComponents.getInstance(ServletContext.class);
        final ClasspathScanner classpathScanner = coreComponents.getInstance(ClasspathScanner.class);
        final ManagedBeanFactory beanFactory = coreComponents.getInstance(ManagedBeanFactory.class);
        final RemotingConfiguration configuration = new RemotingConfiguration(coreComponents.getConfiguration());
        final ClientSessionProvider sessionProvider = coreComponents.getInstance(ClientSessionProvider.class);
        final DolphinContextFactory dolphinContextFactory = new DefaultDolphinContextFactory(configuration, sessionProvider, beanFactory, classpathScanner);
        final DolphinContextCommunicationHandler communicationHandler = new DolphinContextCommunicationHandler(sessionProvider, dolphinContextFactory);
        final DolphinContextProvider contextProvider = new DolphinContextProvider() {

            @Override
            public DolphinContext getContext(final ClientSession clientSession) {
                return communicationHandler.getContext(clientSession);
            }

            @Override
            public DolphinContext getContextById(String clientSessionId) {
                return communicationHandler.getContextById(clientSessionId);
            }

            @Override
            public DolphinContext getCurrentDolphinContext() {
                return communicationHandler.getCurrentDolphinContext();
            }
        };
        coreComponents.provideInstance(DolphinContextProvider.class, contextProvider);
        final ClientSessionLifecycleHandler lifecycleHandler = coreComponents.getInstance(ClientSessionLifecycleHandler.class);
        servletContext.addServlet(DOLPHIN_SERVLET_NAME, new DolphinPlatformServlet(communicationHandler)).addMapping(configuration.getDolphinPlatformServletMapping());
        servletContext.addServlet(INTERRUPT_SERVLET_NAME, new InterruptServlet(contextProvider)).addMapping(configuration.getDolphinPlatformInterruptServletMapping());
        LOG.debug("Dolphin Platform initialized under context \"" + servletContext.getContextPath() + "\"");
        LOG.debug("Dolphin Platform endpoint defined as " + configuration.getDolphinPlatformServletMapping());
        Iterator<EventBusProvider> iterator = ServiceLoader.load(EventBusProvider.class).iterator();
        boolean providerFound = false;
        boolean flag = false;
        while (iterator.hasNext()) {
            EventBusProvider provider = iterator.next();
            if (configuration.getEventbusType().equals(provider.getType())) {
                if (providerFound) {
                    throw new IllegalStateException("More than 1 event bus provider found");
                }
                LOG.debug("Using event bus of type {} with provider class {}", provider.getType(), provider.getClass());
                providerFound = true;
                RemotingEventBus eventBus = provider.create(configuration);
                if (eventBus instanceof AbstractEventBus) {
                    ((AbstractEventBus) eventBus).init(contextProvider, lifecycleHandler);
                }
                coreComponents.provideInstance(RemotingEventBus.class, eventBus);
                flag = true;
            }
        }
        if (!flag) {
            throw new ModuleInitializationException("Configured event bus is not on the classpath.");
        }
    } catch (ControllerValidationException cve) {
        throw new ModuleInitializationException("Can not start Remote Presentation Model support based on bad controller definition", cve);
    }
}
Also used : DolphinContextCommunicationHandler(com.canoo.dp.impl.server.context.DolphinContextCommunicationHandler) InterruptServlet(com.canoo.dp.impl.server.servlet.InterruptServlet) AbstractEventBus(com.canoo.dp.impl.server.event.AbstractEventBus) ModuleInitializationException(com.canoo.platform.server.spi.ModuleInitializationException) DolphinPlatformServlet(com.canoo.dp.impl.server.servlet.DolphinPlatformServlet) ClasspathScanner(com.canoo.platform.server.spi.components.ClasspathScanner) RemotingEventBus(com.canoo.platform.remoting.server.event.RemotingEventBus) ClientSessionProvider(com.canoo.dp.impl.server.client.ClientSessionProvider) DolphinContextFactory(com.canoo.dp.impl.server.context.DolphinContextFactory) DefaultDolphinContextFactory(com.canoo.dp.impl.server.context.DefaultDolphinContextFactory) DefaultDolphinContextFactory(com.canoo.dp.impl.server.context.DefaultDolphinContextFactory) DolphinContextProvider(com.canoo.dp.impl.server.context.DolphinContextProvider) RemotingConfiguration(com.canoo.dp.impl.server.config.RemotingConfiguration) EventBusProvider(com.canoo.platform.remoting.server.event.spi.EventBusProvider) ClientSession(com.canoo.platform.server.client.ClientSession) ManagedBeanFactory(com.canoo.platform.server.spi.components.ManagedBeanFactory) ServletContext(javax.servlet.ServletContext) ControllerValidationException(com.canoo.dp.impl.server.controller.ControllerValidationException) ClientSessionLifecycleHandler(com.canoo.dp.impl.server.client.ClientSessionLifecycleHandler)

Example 5 with ClientSessionProvider

use of com.canoo.dp.impl.server.client.ClientSessionProvider 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)

Aggregations

ClientSessionProvider (com.canoo.dp.impl.server.client.ClientSessionProvider)6 ClientSession (com.canoo.platform.server.client.ClientSession)2 ClasspathScanner (com.canoo.platform.server.spi.components.ClasspathScanner)2 ManagedBeanFactory (com.canoo.platform.server.spi.components.ManagedBeanFactory)2 ServletContext (javax.servlet.ServletContext)2 ClientSessionFilter (com.canoo.dp.impl.server.client.ClientSessionFilter)1 ClientSessionLifecycleHandler (com.canoo.dp.impl.server.client.ClientSessionLifecycleHandler)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 HttpSessionCleanerListener (com.canoo.dp.impl.server.client.HttpSessionCleanerListener)1 RemotingConfiguration (com.canoo.dp.impl.server.config.RemotingConfiguration)1 DefaultDolphinContextFactory (com.canoo.dp.impl.server.context.DefaultDolphinContextFactory)1 DolphinContextCommunicationHandler (com.canoo.dp.impl.server.context.DolphinContextCommunicationHandler)1 DolphinContextFactory (com.canoo.dp.impl.server.context.DolphinContextFactory)1 DolphinContextProvider (com.canoo.dp.impl.server.context.DolphinContextProvider)1 ControllerValidationException (com.canoo.dp.impl.server.controller.ControllerValidationException)1 AbstractEventBus (com.canoo.dp.impl.server.event.AbstractEventBus)1 DolphinPlatformServlet (com.canoo.dp.impl.server.servlet.DolphinPlatformServlet)1 InterruptServlet (com.canoo.dp.impl.server.servlet.InterruptServlet)1