Search in sources :

Example 6 with InvalidateCacheNotification

use of org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification in project scout.rt by eclipse.

the class CodeServiceTest method testInvlidateCodeType.

/**
 * Tests that a client notification is created when invalidating a code type
 * {@link CodeService#invalidateCodeType(Class)}
 */
@Test
public void testInvlidateCodeType() {
    ICodeService codeService = BEANS.get(ICodeService.class);
    codeService.getCodeType(SomeCodeType.class);
    // verify that execLoadCodes has been invoked and reset flag, so that next execLoadCodes can be detected
    assertTrue(SomeCodeType.EXEC_LOAD_CODES_INVOKED.getAndSet(false));
    codeService.invalidateCodeType(SomeCodeType.class);
    assertFalse(SomeCodeType.EXEC_LOAD_CODES_INVOKED.get());
    // check notification
    ArgumentCaptor<InvalidateCacheNotification> notification = ArgumentCaptor.forClass(InvalidateCacheNotification.class);
    verify(m_clientNotificationReg).putTransactionalForAllNodes(notification.capture(), anyBoolean());
    Set<Class<? extends ICodeType<?, ?>>> codeTypeClasses = ((CodeTypeCacheEntryFilter) notification.getValue().getFilter()).getCodeTypeClasses();
    assertEquals("CodeType list in the notification size", 1, codeTypeClasses.size());
    assertEquals("CodeType list(0) class", SomeCodeType.class, codeTypeClasses.iterator().next());
    // get codetype manually
    codeService.getCodeType(SomeCodeType.class);
    assertTrue(SomeCodeType.EXEC_LOAD_CODES_INVOKED.get());
}
Also used : ICodeType(org.eclipse.scout.rt.shared.services.common.code.ICodeType) CodeTypeCacheEntryFilter(org.eclipse.scout.rt.shared.services.common.code.CodeTypeCacheEntryFilter) ICodeService(org.eclipse.scout.rt.shared.services.common.code.ICodeService) InvalidateCacheNotification(org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification) Test(org.junit.Test)

Example 7 with InvalidateCacheNotification

use of org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification in project scout.rt by eclipse.

the class ClientNotificationServerCacheWrapper method invalidate.

@Override
public void invalidate(ICacheEntryFilter<K, V> filter, boolean propagate) {
    super.invalidate(filter, propagate);
    // always send invalidate operations from a server to clients and do not check on the propagate property
    InvalidateCacheNotification notification = new InvalidateCacheNotification(getCacheId(), filter);
    BEANS.get(ClientNotificationRegistry.class).putTransactionalForAllNodes(notification, false);
}
Also used : InvalidateCacheNotification(org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification) ClientNotificationRegistry(org.eclipse.scout.rt.server.clientnotification.ClientNotificationRegistry)

Example 8 with InvalidateCacheNotification

use of org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification in project scout.rt by eclipse.

the class InvalidateCacheNotificationCoalescer method coalesce.

@Override
public List<InvalidateCacheNotification> coalesce(List<InvalidateCacheNotification> notifications) {
    List<InvalidateCacheNotification> result = new ArrayList<>();
    if (notifications.isEmpty()) {
        return result;
    }
    Map<String, List<ICacheEntryFilter<?, ?>>> filterMap = new HashMap<>();
    for (InvalidateCacheNotification notification : notifications) {
        List<ICacheEntryFilter<?, ?>> list = filterMap.get(notification.getCacheId());
        if (list == null) {
            list = new ArrayList<>();
            list.add(notification.getFilter());
        } else {
            coalesceFilters(list, notification.getFilter());
        }
        filterMap.put(notification.getCacheId(), list);
    }
    for (Entry<String, List<ICacheEntryFilter<?, ?>>> entry : filterMap.entrySet()) {
        for (ICacheEntryFilter<?, ?> filter : entry.getValue()) {
            result.add(new InvalidateCacheNotification(entry.getKey(), filter));
        }
    }
    return result;
}
Also used : ICacheEntryFilter(org.eclipse.scout.rt.shared.cache.ICacheEntryFilter) HashMap(java.util.HashMap) InvalidateCacheNotification(org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

InvalidateCacheNotification (org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification)8 Test (org.junit.Test)6 CodeTypeCacheEntryFilter (org.eclipse.scout.rt.shared.services.common.code.CodeTypeCacheEntryFilter)4 ICodeService (org.eclipse.scout.rt.shared.services.common.code.ICodeService)4 ICodeType (org.eclipse.scout.rt.shared.services.common.code.ICodeType)4 ArrayList (java.util.ArrayList)3 AllCacheEntryFilter (org.eclipse.scout.rt.shared.cache.AllCacheEntryFilter)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Set (java.util.Set)1 PublishInput (org.eclipse.scout.rt.mom.api.PublishInput)1 ClientNotificationRegistry (org.eclipse.scout.rt.server.clientnotification.ClientNotificationRegistry)1 ClusterNotificationMessage (org.eclipse.scout.rt.server.services.common.clustersync.internal.ClusterNotificationMessage)1 ICacheEntryFilter (org.eclipse.scout.rt.shared.cache.ICacheEntryFilter)1 KeyCacheEntryFilter (org.eclipse.scout.rt.shared.cache.KeyCacheEntryFilter)1 BookmarkChangedClientNotification (org.eclipse.scout.rt.shared.services.common.bookmark.BookmarkChangedClientNotification)1