Search in sources :

Example 1 with IClusterSynchronizationService

use of org.eclipse.scout.rt.server.services.common.clustersync.IClusterSynchronizationService 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)

Example 2 with IClusterSynchronizationService

use of org.eclipse.scout.rt.server.services.common.clustersync.IClusterSynchronizationService in project scout.rt by eclipse.

the class ClientNotificationRegistryTest method testEmptyNotificationsAreNotDistributedOverCluster.

/**
 * Empty collection of notifications must not trigger a cluster notification.
 */
@Test
public void testEmptyNotificationsAreNotDistributedOverCluster() {
    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.publish(Collections.<ClientNotificationMessage>emptySet());
        assertEquals(Collections.emptyList(), consumeNoWait(reg, "testNodeId"));
        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) Test(org.junit.Test)

Example 3 with IClusterSynchronizationService

use of org.eclipse.scout.rt.server.services.common.clustersync.IClusterSynchronizationService 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

IClusterSynchronizationService (org.eclipse.scout.rt.server.services.common.clustersync.IClusterSynchronizationService)3 BeanMetaData (org.eclipse.scout.rt.platform.BeanMetaData)2 ClientNotificationMessage (org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage)2 Test (org.junit.Test)2 LinkedList (java.util.LinkedList)1