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;
}
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());
}
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));
}
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());
}
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);
}
}
Aggregations