Search in sources :

Example 46 with Map

use of java.util.Map in project camel by apache.

the class Main method getCamelContextMap.

protected Map<String, CamelContext> getCamelContextMap() {
    Map<String, CamelContext> answer = Maps.newHashMap();
    if (injector != null) {
        Set<Map.Entry<Key<?>, Binding<?>>> entries = injector.getBindings().entrySet();
        for (Map.Entry<Key<?>, Binding<?>> entry : entries) {
            Key<?> key = entry.getKey();
            Class<?> keyType = Injectors.getKeyType(key);
            if (keyType != null && CamelContext.class.isAssignableFrom(keyType)) {
                Binding<?> binding = entry.getValue();
                Object value = binding.getProvider().get();
                if (value != null) {
                    CamelContext castValue = CamelContext.class.cast(value);
                    answer.put(key.toString(), castValue);
                }
            }
        }
    }
    return answer;
}
Also used : CamelContext(org.apache.camel.CamelContext) Binding(com.google.inject.Binding) Map(java.util.Map) Key(com.google.inject.Key)

Example 47 with Map

use of java.util.Map in project camel by apache.

the class Injectors method tryCloseJitBindings.

private static void tryCloseJitBindings(Closer closer, Injector injector, Class<? extends Annotation> scopeAnnotationToClose, CloseErrors errors) {
    Class<? extends Injector> type = injector.getClass();
    Field field;
    try {
        field = type.getDeclaredField("jitBindings");
        field.setAccessible(true);
        Object bindings = field.get(injector);
        if (bindings != null) {
            if (bindings instanceof Map) {
                Map<Key<?>, BindingImpl<?>> map = (Map<Key<?>, BindingImpl<?>>) bindings;
                Set<Entry<Key<?>, BindingImpl<?>>> entries = map.entrySet();
                for (Entry<Key<?>, BindingImpl<?>> entry : entries) {
                    closeBinding(entry.getKey(), entry.getValue(), scopeAnnotationToClose, closer, errors);
                }
            }
        }
    } catch (NoSuchFieldException e) {
    // ignore - Guice has refactored so we can't access the jit bindings
    // System.out.println("No such field! " + e);
    } catch (IllegalAccessException e) {
    // ignore - Guice has refactored so we can't access the jit bindings
    // System.out.println("Failed to access field: " + field +
    // ". Reason: " + e);
    }
}
Also used : Field(java.lang.reflect.Field) BindingImpl(com.google.inject.internal.BindingImpl) Entry(java.util.Map.Entry) Map(java.util.Map) Key(com.google.inject.Key)

Example 48 with Map

use of java.util.Map in project camel by apache.

the class HazelcastMapProducerForSpringTest method testGetAllEmptySet.

@Test
public void testGetAllEmptySet() {
    Set<Object> l = new HashSet<Object>();
    Map t = new HashMap();
    t.put("key1", "value1");
    t.put("key2", "value2");
    t.put("key3", "value3");
    when(map.getAll(anySet())).thenReturn(t);
    template.sendBodyAndHeader("direct:getAll", null, HazelcastConstants.OBJECT_ID, l);
    String body = consumer.receiveBody("seda:out", 5000, String.class);
    verify(map).getAll(l);
    assertTrue(body.contains("key1=value1"));
    assertTrue(body.contains("key2=value2"));
    assertTrue(body.contains("key3=value3"));
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) IMap(com.hazelcast.core.IMap) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 49 with Map

use of java.util.Map in project camel by apache.

the class HazelcastMapProducerForSpringTest method testGetAllOnlyOneKey.

@Test
public void testGetAllOnlyOneKey() {
    Set<Object> l = new HashSet<Object>();
    l.add("key1");
    Map t = new HashMap();
    t.put("key1", "value1");
    when(map.getAll(l)).thenReturn(t);
    template.sendBodyAndHeader("direct:getAll", null, HazelcastConstants.OBJECT_ID, l);
    String body = consumer.receiveBody("seda:out", 5000, String.class);
    verify(map).getAll(l);
    assertEquals("{key1=value1}", body);
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) IMap(com.hazelcast.core.IMap) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 50 with Map

use of java.util.Map in project camel by apache.

the class InfinispanProducerTest method publishMapNormalAsync.

@Test
public void publishMapNormalAsync() throws Exception {
    template.send("direct:putallasync", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            Map<String, String> map = new HashMap<String, String>();
            map.put(KEY_ONE, VALUE_ONE);
            map.put(KEY_TWO, VALUE_TWO);
            exchange.getIn().setHeader(InfinispanConstants.MAP, map);
        }
    });
    Thread.sleep(100);
    assertEquals(2, currentCache().size());
    Object value = currentCache().get(KEY_ONE);
    assertEquals(VALUE_ONE, value.toString());
    value = currentCache().get(KEY_TWO);
    assertEquals(VALUE_TWO, value.toString());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Map (java.util.Map)15646 HashMap (java.util.HashMap)9529 ArrayList (java.util.ArrayList)3619 List (java.util.List)2988 Test (org.junit.Test)2558 Set (java.util.Set)1837 HashSet (java.util.HashSet)1646 IOException (java.io.IOException)1486 Iterator (java.util.Iterator)1307 LinkedHashMap (java.util.LinkedHashMap)1284 TreeMap (java.util.TreeMap)1022 ImmutableMap (com.google.common.collect.ImmutableMap)879 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)729 File (java.io.File)662 Collection (java.util.Collection)576 Collectors (java.util.stream.Collectors)436 ConcurrentMap (java.util.concurrent.ConcurrentMap)375 LinkedList (java.util.LinkedList)333 SSOException (com.iplanet.sso.SSOException)294 Collections (java.util.Collections)288