Search in sources :

Example 1 with ClientNotificationMessage

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

the class ClientNotificationCoalescer method coalesce.

public List<ClientNotificationMessage> coalesce(List<ClientNotificationMessage> inNotifications) {
    LinkedHashSet<ClientNotificationMessage> notificationsNoDuplicates = new LinkedHashSet<ClientNotificationMessage>(inNotifications);
    // sort by distribute & address property
    Map<Boolean, Map<IClientNotificationAddress, List<ClientNotificationMessage>>> messagesPerDistributeAndAddress = new HashMap<>();
    messagesPerDistributeAndAddress.put(true, new HashMap<IClientNotificationAddress, List<ClientNotificationMessage>>());
    messagesPerDistributeAndAddress.put(false, new HashMap<IClientNotificationAddress, List<ClientNotificationMessage>>());
    for (ClientNotificationMessage message : notificationsNoDuplicates) {
        Map<IClientNotificationAddress, List<ClientNotificationMessage>> messagesPerAddress = messagesPerDistributeAndAddress.get(message.isDistributeOverCluster());
        List<ClientNotificationMessage> messages = messagesPerAddress.get(message.getAddress());
        if (messages == null) {
            messages = new ArrayList<ClientNotificationMessage>();
            messagesPerAddress.put(message.getAddress(), messages);
        }
        messages.add(message);
    }
    List<ClientNotificationMessage> result = new ArrayList<>();
    for (Entry<Boolean, Map<IClientNotificationAddress, List<ClientNotificationMessage>>> distributeEntry : messagesPerDistributeAndAddress.entrySet()) {
        boolean distribute = distributeEntry.getKey();
        for (Entry<IClientNotificationAddress, List<ClientNotificationMessage>> e : distributeEntry.getValue().entrySet()) {
            result.addAll(coalesce(distribute, e.getKey(), e.getValue()));
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ClientNotificationMessage(org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage) IClientNotificationAddress(org.eclipse.scout.rt.shared.clientnotification.IClientNotificationAddress) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with ClientNotificationMessage

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

the class ClientNotificationClusterNotificationTest method testClientNotificationsReceived.

/**
 * Tests that the client notifications are added to the queue when received
 */
@SuppressWarnings("unchecked")
@Test
public void testClientNotificationsReceived() {
    IMessage<IClusterNotificationMessage> momMsg = mock(IMessage.class);
    ClientNotificationAddress address = ClientNotificationAddress.createAllNodesAddress();
    ClientNotificationMessage message = new ClientNotificationMessage(address, "test", true, "cid");
    ArrayList<ClientNotificationMessage> messages = new ArrayList<ClientNotificationMessage>();
    messages.add(message);
    when(momMsg.getTransferObject()).thenReturn(new ClusterNotificationMessage(new ClientNotificationClusterNotification(messages), m_testProps));
    m_svc.onMessage(momMsg);
    IClientNotificationService c = BEANS.get(IClientNotificationService.class);
    List<ClientNotificationMessage> notifications = c.getNotifications(TEST_NODE);
    assertEquals(1, notifications.size());
}
Also used : ClientNotificationClusterNotification(org.eclipse.scout.rt.server.clientnotification.ClientNotificationClusterNotification) ClientNotificationAddress(org.eclipse.scout.rt.shared.clientnotification.ClientNotificationAddress) ArrayList(java.util.ArrayList) ClusterNotificationMessage(org.eclipse.scout.rt.server.services.common.clustersync.internal.ClusterNotificationMessage) IClientNotificationService(org.eclipse.scout.rt.shared.clientnotification.IClientNotificationService) ClientNotificationMessage(org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage) Test(org.junit.Test)

Example 3 with ClientNotificationMessage

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

the class TransactionalClientNotificationCollectorTest method testMessagesAddedIfActive.

@Test
public void testMessagesAddedIfActive() throws Exception {
    ClientNotificationMessage mockMessage = Mockito.mock(ClientNotificationMessage.class);
    boolean added = m_collector.addAll(CollectionUtility.arrayList(mockMessage));
    assertTrue(added);
    List<ClientNotificationMessage> res = m_collector.consume();
    assertEquals(1, res.size());
    assertEquals(mockMessage, res.get(0));
}
Also used : ClientNotificationMessage(org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage) Test(org.junit.Test)

Example 4 with ClientNotificationMessage

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

the class ClientNotificationNodeQueueTest method testBlockingWait.

@Test
public void testBlockingWait() {
    IFuture<List<ClientNotificationMessage>> res = Jobs.schedule(new Callable<List<ClientNotificationMessage>>() {

        @Override
        public List<ClientNotificationMessage> call() throws Exception {
            return m_queue.getNotifications(10, 100, TimeUnit.MILLISECONDS);
        }
    }, Jobs.newInput().withRunContext(RunContexts.copyCurrent()));
    ClientNotificationAddress allNodes = ClientNotificationAddress.createAllNodesAddress();
    m_queue.put(new ClientNotificationMessage(allNodes, "test", true, "cid"));
    m_queue.put(new ClientNotificationMessage(allNodes, "test2", true, "cid"));
    List<ClientNotificationMessage> notifications = res.awaitDoneAndGet();
    assertEquals(2, notifications.size());
    assertEquals("test", notifications.get(0).getNotification());
    assertEquals("test2", notifications.get(1).getNotification());
}
Also used : ClientNotificationAddress(org.eclipse.scout.rt.shared.clientnotification.ClientNotificationAddress) List(java.util.List) ClientNotificationMessage(org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage) Test(org.junit.Test)

Example 5 with ClientNotificationMessage

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

the class ClientNotificationRegistryTest method testNotificationsWithoutDistributingOverCluster.

/**
 * Empty collection of notifications must not trigger a cluster notification.
 */
@Test
public void testNotificationsWithoutDistributingOverCluster() {
    final IClusterSynchronizationService mockClusterSyncService = Mockito.mock(IClusterSynchronizationService.class);
    final IBean<?> bean = TestingUtility.registerBean(new BeanMetaData(IClusterSynchronizationService.class).withInitialInstance(mockClusterSyncService).withApplicationScoped(true));
    try {
        ClientNotificationRegistry reg = new ClientNotificationRegistry(TEST_QUEUE_EXPIRE_TIMEOUT);
        reg.registerSession("testNodeId", "testSessionId", TEST_USER);
        reg.registerSession("testNodeId2", "testSessionId", TEST_USER);
        reg.putForAllNodes(TEST_NOTIFICATION, false);
        List<ClientNotificationMessage> notificationsNode1 = consumeNoWait(reg, "testNodeId");
        List<ClientNotificationMessage> notificationsNode2 = consumeNoWait(reg, "testNodeId2");
        assertSingleTestNotification(notificationsNode1);
        assertSingleTestNotification(notificationsNode2);
        Mockito.verifyZeroInteractions(mockClusterSyncService);
    } finally {
        TestingUtility.unregisterBean(bean);
    }
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) IClusterSynchronizationService(org.eclipse.scout.rt.server.services.common.clustersync.IClusterSynchronizationService) ClientNotificationMessage(org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage) Test(org.junit.Test)

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