use of com.canoo.platform.server.client.ClientSession in project dolphin-platform by canoo.
the class AbstractEventBus method publish.
@Override
public <T extends Serializable> void publish(final Topic<T> topic, final T data) {
checkInitialization();
final DolphinEvent event = new DolphinEvent(topic, System.currentTimeMillis(), data);
event.addMetadata(EventConstants.TYPE_PARAM, EventConstants.TYPE_PLATFORM);
final DolphinContext currentContext = getCurrentContext();
if (currentContext != null) {
final ClientSession clientSession = currentContext.getClientSession();
if (clientSession != null) {
event.addMetadata(EventConstants.CLIENT_SESSION_PARAM, clientSession.getId());
final HttpSession httpSession = clientSession.getHttpSession();
if (httpSession != null) {
event.addMetadata(EventConstants.HTTP_SESSION_PARAM, httpSession.getId());
}
}
}
// Handle listener in same session
if (currentContext != null) {
final List<ListenerWithFilter<T>> listenersInCurrentSession = getListenersForSessionAndTopic(currentContext.getId(), topic);
for (ListenerWithFilter<T> listenerAndFilter : listenersInCurrentSession) {
final Predicate<MessageEventContext<T>> filter = listenerAndFilter.getFilter();
final MessageListener<T> listener = listenerAndFilter.getListener();
if (filter == null || filter.test(event.getMessageEventContext())) {
listener.onMessage(event);
}
}
}
publishForOtherSessions(event);
}
use of com.canoo.platform.server.client.ClientSession in project dolphin-platform by canoo.
the class DolphinSessionInfo method getSession.
private ClientSession getSession() {
ClientSession session = dolphinSessionRef.get();
Assert.requireNonNull(session, "session");
return session;
}
use of com.canoo.platform.server.client.ClientSession in project dolphin-platform by canoo.
the class ClientSessionManager method createClientSession.
public String createClientSession(final HttpSession httpSession) throws MaxSessionCountReachedException {
Assert.requireNonNull(httpSession, "httpSession");
if (!canAddInSession(httpSession)) {
throw new MaxSessionCountReachedException();
}
final ClientSession clientSession = new HttpClientSessionImpl(httpSession);
add(httpSession, clientSession);
lifecycleHandler.onSessionCreated(clientSession);
LOG.trace("Created new DolphinContext {} in http session {}", clientSession.getId(), httpSession.getId());
return clientSession.getId();
}
use of com.canoo.platform.server.client.ClientSession in project dolphin-platform by canoo.
the class ClientSessionManager method removeAllClientSessionsInHttpSession.
public void removeAllClientSessionsInHttpSession(final HttpSession httpSession) {
final Lock lock = getOrCreateClientSessionLockForHttpSession(httpSession);
Assert.requireNonNull(lock, "lock");
lock.lock();
try {
Map<String, ClientSession> map = getOrCreateClientSessionMapInHttpSession(httpSession);
for (ClientSession session : map.values()) {
lifecycleHandler.onSessionDestroyed(session);
}
map.clear();
} finally {
lock.unlock();
}
}
use of com.canoo.platform.server.client.ClientSession in project dolphin-platform by canoo.
the class ClientSessionImplTest method testImmutableAttributeSet2.
@Test(expectedExceptions = UnsupportedOperationException.class)
public void testImmutableAttributeSet2() {
// given:
ClientSession dolphinSession = new HttpClientSessionImpl(new HttpSessionMock());
// when:
dolphinSession.setAttribute("test-attribute", "Hello Dolphin Session");
// then:
dolphinSession.getAttributeNames().remove("test-attribute");
}
Aggregations