use of com.canoo.dp.impl.server.client.ClientSessionLifecycleHandlerImpl 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;
}
use of com.canoo.dp.impl.server.client.ClientSessionLifecycleHandlerImpl 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;
}
use of com.canoo.dp.impl.server.client.ClientSessionLifecycleHandlerImpl 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));
}
Aggregations