Search in sources :

Example 11 with ClientSession

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);
}
Also used : DolphinContext(com.canoo.dp.impl.server.context.DolphinContext) MessageEventContext(com.canoo.platform.remoting.server.event.MessageEventContext) HttpSession(javax.servlet.http.HttpSession) ClientSession(com.canoo.platform.server.client.ClientSession)

Example 12 with ClientSession

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;
}
Also used : ClientSession(com.canoo.platform.server.client.ClientSession)

Example 13 with ClientSession

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();
}
Also used : ClientSession(com.canoo.platform.server.client.ClientSession)

Example 14 with ClientSession

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();
    }
}
Also used : ClientSession(com.canoo.platform.server.client.ClientSession) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Example 15 with ClientSession

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");
}
Also used : HttpSessionMock(com.canoo.impl.server.util.HttpSessionMock) ClientSession(com.canoo.platform.server.client.ClientSession) HttpClientSessionImpl(com.canoo.dp.impl.server.client.HttpClientSessionImpl) Test(org.testng.annotations.Test)

Aggregations

ClientSession (com.canoo.platform.server.client.ClientSession)18 HttpClientSessionImpl (com.canoo.dp.impl.server.client.HttpClientSessionImpl)7 HttpSessionMock (com.canoo.impl.server.util.HttpSessionMock)7 Test (org.testng.annotations.Test)7 ClientSessionLifecycleHandlerImpl (com.canoo.dp.impl.server.client.ClientSessionLifecycleHandlerImpl)3 DolphinContextProvider (com.canoo.dp.impl.server.context.DolphinContextProvider)3 ClientSessionProvider (com.canoo.dp.impl.server.client.ClientSessionProvider)2 DolphinContext (com.canoo.dp.impl.server.context.DolphinContext)2 ClasspathScanner (com.canoo.platform.server.spi.components.ClasspathScanner)2 ManagedBeanFactory (com.canoo.platform.server.spi.components.ManagedBeanFactory)2 ServletContext (javax.servlet.ServletContext)2 HttpSession (javax.servlet.http.HttpSession)2 CreateContextCommand (com.canoo.dp.impl.remoting.commands.CreateContextCommand)1 Command (com.canoo.dp.impl.remoting.legacy.communication.Command)1 ClientSessionFilter (com.canoo.dp.impl.server.client.ClientSessionFilter)1 ClientSessionLifecycleHandler (com.canoo.dp.impl.server.client.ClientSessionLifecycleHandler)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