Search in sources :

Example 11 with MetadataCacheValueTranslator

use of com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator in project interlok by adaptris.

the class CheckCacheServiceTest method createServiceForTests.

private CheckCacheService createServiceForTests() {
    CheckCacheService service = createService();
    CacheEntryEvaluator eval = new CacheEntryEvaluator();
    eval.setKeyTranslator(new MetadataCacheValueTranslator(LOOKUP_VALUE));
    service.addCacheEntryEvaluator(eval);
    return service;
}
Also used : MetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator)

Example 12 with MetadataCacheValueTranslator

use of com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator in project interlok by adaptris.

the class BasicCacheExampleGenerator method configureRetrieveService.

private static <T extends RetrieveFromCacheService> T configureRetrieveService(T service) {
    CacheEntryEvaluator eval1 = new CacheEntryEvaluator();
    CacheEntryEvaluator eval2 = new CacheEntryEvaluator();
    CacheEntryEvaluator eval3 = new CacheEntryEvaluator();
    eval1.setKeyTranslator(new MetadataCacheValueTranslator("A_MetadataKey_Whose_Value_Is_The_Cache_key"));
    eval1.setValueTranslator(new MetadataCacheValueTranslator("A_MetadataKey_Which_Will_Contain_What_We_Find_in_The_Cache"));
    eval2.setKeyTranslator(new MetadataCacheValueTranslator("MetadataKey_Whose_Value_Is_The_Cache_Key_And_This_Key_Contains_A_Payload"));
    eval2.setValueTranslator(new StringPayloadCacheTranslator());
    eval3.setKeyTranslator(new MetadataCacheValueTranslator("JMSCorrelationID"));
    eval3.setValueTranslator(new JmsReplyToCacheValueTranslator());
    service.setCacheEntryEvaluators(new ArrayList(Arrays.asList(new CacheEntryEvaluator[] { eval1, eval2, eval3 })));
    return service;
}
Also used : ObjectMetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.ObjectMetadataCacheValueTranslator) MetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator) JmsReplyToCacheValueTranslator(com.adaptris.core.services.cache.translators.JmsReplyToCacheValueTranslator) ArrayList(java.util.ArrayList) CacheEntryEvaluator(com.adaptris.core.services.cache.CacheEntryEvaluator) StringPayloadCacheTranslator(com.adaptris.core.services.cache.translators.StringPayloadCacheTranslator)

Example 13 with MetadataCacheValueTranslator

use of com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator in project interlok by adaptris.

the class BasicCacheExampleGenerator method configureCheckCache.

private static <T extends CheckCacheService> T configureCheckCache(T cacheService) {
    CacheEntryEvaluator eval1 = new CacheEntryEvaluator();
    CacheEntryEvaluator eval2 = new CacheEntryEvaluator();
    eval1.setKeyTranslator(new MetadataCacheValueTranslator("A_MetadataKey_Whose_Value_Makes_The_Cache_Key"));
    eval2.setKeyTranslator(new MetadataCacheValueTranslator("Another_MetadataKey_Whose_Value_Makes_The_Cache_Key"));
    cacheService.setCacheEntryEvaluators(new ArrayList(Arrays.asList(new CacheEntryEvaluator[] { eval1, eval2 })));
    cacheService.setKeysFoundServiceId("AllKeysFoundInCache");
    cacheService.setKeysNotFoundServiceId("Not_All_Keys_In_Cache");
    cacheService.setUniqueId("checkCache");
    return cacheService;
}
Also used : ObjectMetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.ObjectMetadataCacheValueTranslator) MetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator) ArrayList(java.util.ArrayList) CacheEntryEvaluator(com.adaptris.core.services.cache.CacheEntryEvaluator)

Example 14 with MetadataCacheValueTranslator

use of com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator in project interlok by adaptris.

the class AddToCacheServiceTest method testDoService_EnforceSerializable_Serializable.

@Test
public void testDoService_EnforceSerializable_Serializable() throws Exception {
    AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(JmsConstants.JMS_CORRELATION_ID, CORRELATION_ID), new MetadataElement(SRC_KEY, SRC_VALUE) }));
    Cache cache = createCacheInstanceForTests();
    AddToCacheService service = createServiceForTests();
    CacheEntryEvaluator eval = service.getCacheEntryEvaluators().get(0);
    eval.setValueTranslator(new MetadataCacheValueTranslator(SRC_KEY));
    try {
        service.setConnection(new CacheConnection(cache));
        service.setEnforceSerializable(true);
        start(service);
        service.doService(msg);
        Object value = cache.get(CORRELATION_ID);
        assertEquals(SRC_VALUE, value.toString());
    } finally {
        stop(service);
    }
}
Also used : MetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Cache(com.adaptris.core.cache.Cache) Test(org.junit.Test)

Example 15 with MetadataCacheValueTranslator

use of com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator in project interlok by adaptris.

the class AddToCacheServiceTest method testDoService_NoErrorOnEmpty_NeitherKeyOrValue.

@Test
public void testDoService_NoErrorOnEmpty_NeitherKeyOrValue() throws Exception {
    AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(JmsConstants.JMS_CORRELATION_ID, CORRELATION_ID) }));
    Cache cache = createCacheInstanceForTests();
    AddToCacheService service = createServiceForTests();
    CacheEntryEvaluator eval = service.getCacheEntryEvaluators().get(0);
    eval.setErrorOnEmptyKey(false);
    eval.setErrorOnEmptyValue(false);
    eval.setValueTranslator(new MetadataCacheValueTranslator(SRC_KEY));
    eval.setKeyTranslator(new MetadataCacheValueTranslator(SRC_KEY));
    try {
        service.setConnection(new CacheConnection(cache));
        start(service);
        service.doService(msg);
        assertNull(cache.get(SRC_VALUE));
    } finally {
        stop(service);
    }
}
Also used : MetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Cache(com.adaptris.core.cache.Cache) Test(org.junit.Test)

Aggregations

MetadataCacheValueTranslator (com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator)20 Test (org.junit.Test)13 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)11 MetadataElement (com.adaptris.core.MetadataElement)11 Cache (com.adaptris.core.cache.Cache)5 ServiceException (com.adaptris.core.ServiceException)3 CacheEntryEvaluator (com.adaptris.core.services.cache.CacheEntryEvaluator)3 NullCacheValueTranslator (com.adaptris.core.services.cache.CacheEntryEvaluator.NullCacheValueTranslator)3 JmsReplyToCacheValueTranslator (com.adaptris.core.services.cache.translators.JmsReplyToCacheValueTranslator)3 ObjectMetadataCacheValueTranslator (com.adaptris.core.services.cache.translators.ObjectMetadataCacheValueTranslator)3 StaticCacheValueTranslator (com.adaptris.core.services.cache.translators.StaticCacheValueTranslator)3 ArrayList (java.util.ArrayList)3 StringPayloadCacheTranslator (com.adaptris.core.services.cache.translators.StringPayloadCacheTranslator)2 AddToCacheService (com.adaptris.core.services.cache.AddToCacheService)1 XpathCacheValueTranslator (com.adaptris.core.services.cache.translators.XpathCacheValueTranslator)1