Search in sources :

Example 6 with ClientNotificationMessage

use of org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage in project scout.rt by eclipse.

the class BridgeToServerBeanDecorator method ensureRunInServerContext.

protected Object ensureRunInServerContext(final IBeanInvocationContext<T> context) {
    if (PropertyMap.isSet(PropertyMap.PROP_SERVER_SCOPE)) {
        // already in a server scope
        return continueCall(context);
    }
    // bridge to server scope
    ClientNotificationCollector collector = new ClientNotificationCollector();
    ServerRunContext bridgeRunContext = ServerRunContexts.copyCurrent().withClientNotificationCollector(collector).withClientNodeId(INode.ID);
    ISession currentSession = ISession.CURRENT.get();
    IServerSession bridgeSession = null;
    if (currentSession != null) {
        bridgeSession = BEANS.get(ServerSessionProviderWithCache.class).provide(currentSession.getId(), bridgeRunContext);
    }
    Object result = bridgeRunContext.withSession(bridgeSession).call(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                return continueCall(context);
            } catch (Exception e) {
                ITransaction.CURRENT.get().addFailure(e);
                throw e;
            }
        }
    });
    ClientNotificationDispatcher clientNotificationDispatcher = BEANS.get(ClientNotificationDispatcher.class);
    List<ClientNotificationMessage> values = collector.consume();
    if (!values.isEmpty()) {
        clientNotificationDispatcher.dispatchNotifications(values);
    }
    return result;
}
Also used : ISession(org.eclipse.scout.rt.shared.ISession) ServerRunContext(org.eclipse.scout.rt.server.context.ServerRunContext) IServerSession(org.eclipse.scout.rt.server.IServerSession) ClientNotificationCollector(org.eclipse.scout.rt.server.clientnotification.ClientNotificationCollector) ClientNotificationMessage(org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage) ClientNotificationDispatcher(org.eclipse.scout.rt.client.clientnotification.ClientNotificationDispatcher)

Example 7 with ClientNotificationMessage

use of org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage in project scout.rt by eclipse.

the class ClientNotificationNodeQueue method putDroppingOld.

/**
 * Put notifications into queue and drop oldest ones, if capacity is reached.
 */
private void putDroppingOld(Collection<? extends ClientNotificationMessage> notifications) {
    int dropCount = 0;
    for (ClientNotificationMessage message : notifications) {
        boolean inserted = m_notifications.offer(message);
        while (!inserted) {
            ClientNotificationMessage removed = m_notifications.poll();
            if (removed != null) {
                dropCount++;
            }
            inserted = m_notifications.offer(message);
        }
    }
    if (dropCount > 0) {
        LOG.warn("Notification queue capacity reached. Remove oldest {} notification messages.", dropCount);
    }
}
Also used : ClientNotificationMessage(org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage)

Example 8 with ClientNotificationMessage

use of org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage in project scout.rt by eclipse.

the class ClientNotificationNodeQueue method getNotifications.

protected List<ClientNotificationMessage> getNotifications(int maxAmount, long maxWaitTime, TimeUnit unit) {
    List<ClientNotificationMessage> collected = new LinkedList<>();
    try {
        // blocking wait to get first message
        ClientNotificationMessage next = m_notifications.poll(maxWaitTime, unit);
        if (next != null) {
            collected.add(next);
        }
        // add more available notifications
        // with short wait timeout to not go back with one notification when some are about to pop up.
        // 0 for no reschedule
        int timeout = 234;
        while (next != null && collected.size() < maxAmount) {
            next = m_notifications.poll(timeout, TimeUnit.MILLISECONDS);
            if (next != null) {
                collected.add(next);
            }
        }
    } catch (InterruptedException e) {
        LOG.info("Interrupted while waiting for client notification messages", e);
    }
    return collected;
}
Also used : ClientNotificationMessage(org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage) LinkedList(java.util.LinkedList)

Example 9 with ClientNotificationMessage

use of org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage in project scout.rt by eclipse.

the class ClientNotificationRegistry method publishClusterInternal.

/**
 * Publish messages to other cluster nodes. Message not foreseen for cluster distributions are filtered.
 */
private void publishClusterInternal(Collection<? extends ClientNotificationMessage> messages) {
    Collection<ClientNotificationMessage> filteredMessages = new LinkedList<ClientNotificationMessage>();
    for (ClientNotificationMessage message : messages) {
        if (message.isDistributeOverCluster()) {
            filteredMessages.add(message);
        }
    }
    // do not publish empty messages
    if (filteredMessages.isEmpty()) {
        return;
    }
    try {
        IClusterSynchronizationService service = BEANS.get(IClusterSynchronizationService.class);
        service.publish(new ClientNotificationClusterNotification(filteredMessages));
    } catch (RuntimeException e) {
        LOG.error("Failed to publish client notification", e);
    }
}
Also used : IClusterSynchronizationService(org.eclipse.scout.rt.server.services.common.clustersync.IClusterSynchronizationService) ClientNotificationMessage(org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage) LinkedList(java.util.LinkedList)

Aggregations

ClientNotificationMessage (org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage)9 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 IClusterSynchronizationService (org.eclipse.scout.rt.server.services.common.clustersync.IClusterSynchronizationService)2 ClientNotificationAddress (org.eclipse.scout.rt.shared.clientnotification.ClientNotificationAddress)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 ClientNotificationDispatcher (org.eclipse.scout.rt.client.clientnotification.ClientNotificationDispatcher)1 BeanMetaData (org.eclipse.scout.rt.platform.BeanMetaData)1 IServerSession (org.eclipse.scout.rt.server.IServerSession)1 ClientNotificationClusterNotification (org.eclipse.scout.rt.server.clientnotification.ClientNotificationClusterNotification)1 ClientNotificationCollector (org.eclipse.scout.rt.server.clientnotification.ClientNotificationCollector)1 ServerRunContext (org.eclipse.scout.rt.server.context.ServerRunContext)1 ClusterNotificationMessage (org.eclipse.scout.rt.server.services.common.clustersync.internal.ClusterNotificationMessage)1 ISession (org.eclipse.scout.rt.shared.ISession)1 IClientNotificationAddress (org.eclipse.scout.rt.shared.clientnotification.IClientNotificationAddress)1