Search in sources :

Example 1 with DolphinContextProvider

use of com.canoo.dp.impl.server.context.DolphinContextProvider in project dolphin-platform by canoo.

the class DefaultDolphinEventBusTest method create.

private DefaultDolphinEventBus create(final DolphinContext context) {
    DefaultDolphinEventBus eventBus = new DefaultDolphinEventBus();
    eventBus.init(new DolphinContextProvider() {

        @Override
        public DolphinContext getContext(ClientSession clientSession) {
            return getContextById(clientSession.getId());
        }

        @Override
        public DolphinContext getContextById(String clientSessionId) {
            if (context != null && context.getId().equals(clientSessionId)) {
                return context;
            }
            return null;
        }

        @Override
        public DolphinContext getCurrentDolphinContext() {
            return context;
        }
    }, new ClientSessionLifecycleHandlerImpl());
    return eventBus;
}
Also used : DolphinContext(com.canoo.dp.impl.server.context.DolphinContext) ClientSessionLifecycleHandlerImpl(com.canoo.dp.impl.server.client.ClientSessionLifecycleHandlerImpl) DolphinContextProvider(com.canoo.dp.impl.server.context.DolphinContextProvider) ClientSession(com.canoo.platform.server.client.ClientSession)

Example 2 with DolphinContextProvider

use of com.canoo.dp.impl.server.context.DolphinContextProvider 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 3 with DolphinContextProvider

use of com.canoo.dp.impl.server.context.DolphinContextProvider in project dolphin-platform by canoo.

the class DolphinPlatformSpringTestBootstrap method createEventBus.

/**
 * Method to create a spring managed {@link RemotingEventBus} instance in singleton scope.
 *
 * @return the instance
 */
@Bean(name = "dolphinEventBus")
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
protected RemotingEventBus createEventBus(final TestConfiguration testConfiguration) {
    Assert.requireNonNull(testConfiguration, "testConfiguration");
    final DolphinContextProvider contextProvider = new DolphinContextProvider() {

        @Override
        public DolphinContext getContext(ClientSession clientSession) {
            return getCurrentDolphinContext();
        }

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

        @Override
        public DolphinContext getCurrentDolphinContext() {
            return testConfiguration.getDolphinTestContext();
        }
    };
    final DefaultDolphinEventBus eventBus = new DefaultDolphinEventBus();
    eventBus.init(contextProvider, new ClientSessionLifecycleHandlerImpl());
    return eventBus;
}
Also used : ClientSessionLifecycleHandlerImpl(com.canoo.dp.impl.server.client.ClientSessionLifecycleHandlerImpl) DolphinContextProvider(com.canoo.dp.impl.server.context.DolphinContextProvider) DefaultDolphinEventBus(com.canoo.dp.impl.server.event.DefaultDolphinEventBus) ClientSession(com.canoo.platform.server.client.ClientSession) Scope(org.springframework.context.annotation.Scope) Bean(org.springframework.context.annotation.Bean)

Example 4 with DolphinContextProvider

use of com.canoo.dp.impl.server.context.DolphinContextProvider in project dolphin-platform by canoo.

the class RemotingCdiBeanFactory method createRemotingContext.

@Produces
@ClientScoped
public RemotingContext createRemotingContext(RemotingEventBus eventBus) {
    Assert.requireNonNull(eventBus, "eventBus");
    final DolphinContextProvider contextProvider = PlatformBootstrap.getServerCoreComponents().getInstance(DolphinContextProvider.class);
    Assert.requireNonNull(contextProvider, "contextProvider");
    final DolphinContext context = contextProvider.getCurrentDolphinContext();
    Assert.requireNonNull(context, "context");
    return new RemotingContextImpl(context, eventBus);
}
Also used : DolphinContext(com.canoo.dp.impl.server.context.DolphinContext) DolphinContextProvider(com.canoo.dp.impl.server.context.DolphinContextProvider) RemotingContextImpl(com.canoo.dp.impl.server.context.RemotingContextImpl) Produces(javax.enterprise.inject.Produces) ClientScoped(com.canoo.platform.server.javaee.ClientScoped)

Example 5 with DolphinContextProvider

use of com.canoo.dp.impl.server.context.DolphinContextProvider in project dolphin-platform by canoo.

the class RemotingSpringBeanFactory method createRemotingContext.

@Bean(name = "remotingContext")
@ClientScope
protected RemotingContext createRemotingContext(RemotingEventBus eventBus) {
    Assert.requireNonNull(eventBus, "eventBus");
    final DolphinContextProvider contextProvider = PlatformBootstrap.getServerCoreComponents().getInstance(DolphinContextProvider.class);
    Assert.requireNonNull(contextProvider, "contextProvider");
    final DolphinContext context = contextProvider.getCurrentDolphinContext();
    Assert.requireNonNull(context, "context");
    return new RemotingContextImpl(context, eventBus);
}
Also used : DolphinContext(com.canoo.dp.impl.server.context.DolphinContext) DolphinContextProvider(com.canoo.dp.impl.server.context.DolphinContextProvider) RemotingContextImpl(com.canoo.dp.impl.server.context.RemotingContextImpl) ClientScope(com.canoo.platform.server.spring.ClientScope) Bean(org.springframework.context.annotation.Bean)

Aggregations

DolphinContextProvider (com.canoo.dp.impl.server.context.DolphinContextProvider)5 DolphinContext (com.canoo.dp.impl.server.context.DolphinContext)3 ClientSession (com.canoo.platform.server.client.ClientSession)3 ClientSessionLifecycleHandlerImpl (com.canoo.dp.impl.server.client.ClientSessionLifecycleHandlerImpl)2 RemotingContextImpl (com.canoo.dp.impl.server.context.RemotingContextImpl)2 Bean (org.springframework.context.annotation.Bean)2 ClientSessionLifecycleHandler (com.canoo.dp.impl.server.client.ClientSessionLifecycleHandler)1 ClientSessionProvider (com.canoo.dp.impl.server.client.ClientSessionProvider)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 ControllerValidationException (com.canoo.dp.impl.server.controller.ControllerValidationException)1 AbstractEventBus (com.canoo.dp.impl.server.event.AbstractEventBus)1 DefaultDolphinEventBus (com.canoo.dp.impl.server.event.DefaultDolphinEventBus)1 DolphinPlatformServlet (com.canoo.dp.impl.server.servlet.DolphinPlatformServlet)1 InterruptServlet (com.canoo.dp.impl.server.servlet.InterruptServlet)1 RemotingEventBus (com.canoo.platform.remoting.server.event.RemotingEventBus)1 EventBusProvider (com.canoo.platform.remoting.server.event.spi.EventBusProvider)1 ClientScoped (com.canoo.platform.server.javaee.ClientScoped)1