当前位置: 首页>>代码示例>>Java>>正文


Java HazelcastConstants类代码示例

本文整理汇总了Java中org.apache.camel.component.hazelcast.HazelcastConstants的典型用法代码示例。如果您正苦于以下问题:Java HazelcastConstants类的具体用法?Java HazelcastConstants怎么用?Java HazelcastConstants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HazelcastConstants类属于org.apache.camel.component.hazelcast包,在下文中一共展示了HazelcastConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendExchange

import org.apache.camel.component.hazelcast.HazelcastConstants; //导入依赖的package包/类
protected void sendExchange(String operation, Object key, Object value) {
    Exchange exchange = consumer.getEndpoint().createExchange();

    // set object to body
    exchange.getIn().setBody(value);

    // set headers
    if (key != null) {
        exchange.getIn().setHeader(HazelcastConstants.OBJECT_ID, key);
    }

    HazelcastComponentHelper.setListenerHeaders(exchange, HazelcastConstants.CACHE_LISTENER, operation, cacheName);

    try {
        consumer.getProcessor().process(exchange);
    } catch (Exception e) {
        exchange.setException(e);
    }

    if (exchange.getException() != null) {
        consumer.getExceptionHandler().handleException(String.format("Error processing exchange for hazelcast consumer on object '%s' in cache '%s'.", key, cacheName), exchange,
                exchange.getException());
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:CamelListener.java

示例2: sendExchange

import org.apache.camel.component.hazelcast.HazelcastConstants; //导入依赖的package包/类
private void sendExchange(MembershipEvent event, String action) {
    Exchange exchange = getEndpoint().createExchange();

    HazelcastComponentHelper.setListenerHeaders(exchange, HazelcastConstants.INSTANCE_LISTENER, action);

    // instance listener header values
    InetSocketAddress adr = event.getMember().getSocketAddress();
    if (adr != null) {
        exchange.getIn().setHeader(HazelcastConstants.INSTANCE_HOST, adr.getHostName());
        exchange.getIn().setHeader(HazelcastConstants.INSTANCE_PORT, adr.getPort());
    }

    try {
        getProcessor().process(exchange);
    } catch (Exception e) {
        exchange.setException(e);
    }

    if (exchange.getException() != null) {
        getExceptionHandler().handleException("Error processing exchange for Hazelcast consumer on your Hazelcast cluster.", exchange, exchange.getException());
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:HazelcastInstanceConsumer.java

示例3: process

import org.apache.camel.component.hazelcast.HazelcastConstants; //导入依赖的package包/类
public void process(Exchange exchange) throws Exception {
    final int operation = lookupOperationNumber(exchange);

    switch (operation) {
    case -1:
        // default operation to publish
    case HazelcastConstants.PUBLISH_OPERATION:
        this.publish(exchange);
        break;
    default:
        throw new IllegalArgumentException(String.format("The value '%s' is not allowed for parameter '%s' on the TOPIC cache.", operation, HazelcastConstants.OPERATION));
    }

    // finally copy headers
    HazelcastComponentHelper.copyHeaders(exchange);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:HazelcastTopicProducer.java

示例4: testAdd

import org.apache.camel.component.hazelcast.HazelcastConstants; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testAdd() throws Exception {
    CamelContext camelctx = createCamelContext();
    camelctx.start();
    try {
        MockEndpoint mock = camelctx.getEndpoint("mock:added", MockEndpoint.class);
        mock.expectedMessageCount(1);

        EntryEvent<Object, Object> event = new EntryEvent<Object, Object>("foo", null, EntryEventType.ADDED.getType(), "4711", "my-foo");
        argument.getValue().entryAdded(event);
        mock.assertIsSatisfied(3000);

        checkHeaders(mock.getExchanges().get(0).getIn().getHeaders(), HazelcastConstants.ADDED);
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:19,代码来源:HazelcastMapConsumerIntegrationTest.java

示例5: testUpdate

import org.apache.camel.component.hazelcast.HazelcastConstants; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testUpdate() throws Exception {
    CamelContext camelctx = createCamelContext();
    camelctx.start();
    try {
        MockEndpoint mock = camelctx.getEndpoint("mock:updated", MockEndpoint.class);
        mock.expectedMessageCount(1);

        EntryEvent<Object, Object> event = new EntryEvent<Object, Object>("foo", null, EntryEventType.UPDATED.getType(), "4711", "my-foo");
        argument.getValue().entryUpdated(event);

        mock.assertIsSatisfied(3000);

        checkHeaders(mock.getExchanges().get(0).getIn().getHeaders(), HazelcastConstants.UPDATED);
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:20,代码来源:HazelcastMapConsumerIntegrationTest.java

示例6: testRemove

import org.apache.camel.component.hazelcast.HazelcastConstants; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testRemove() throws Exception {
    CamelContext camelctx = createCamelContext();
    camelctx.start();
    try {
        MockEndpoint mock = camelctx.getEndpoint("mock:removed", MockEndpoint.class);
        mock.expectedMessageCount(1);

        EntryEvent<Object, Object> event = new EntryEvent<Object, Object>("foo", null, EntryEventType.REMOVED.getType(), "4711", "my-foo");
        argument.getValue().entryRemoved(event);

        mock.assertIsSatisfied(3000);
        checkHeaders(mock.getExchanges().get(0).getIn().getHeaders(), HazelcastConstants.REMOVED);
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:19,代码来源:HazelcastMapConsumerIntegrationTest.java

示例7: createRouteBuilder

import org.apache.camel.component.hazelcast.HazelcastConstants; //导入依赖的package包/类
private RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from(String.format("hazelcast-%sfoo", HazelcastConstants.MAP_PREFIX))
            .log("object...")
            .choice()
            .when(header(HazelcastConstants.LISTENER_ACTION)
                    .isEqualTo(HazelcastConstants.ADDED))
                    .log("...added").to("mock:added")
            .when(header(HazelcastConstants.LISTENER_ACTION)
                    .isEqualTo(HazelcastConstants.EVICTED))
                    .log("...evicted").to("mock:evicted")
            .when(header(HazelcastConstants.LISTENER_ACTION)
                    .isEqualTo(HazelcastConstants.UPDATED))
                    .log("...updated").to("mock:updated")
            .when(header(HazelcastConstants.LISTENER_ACTION)
                    .isEqualTo(HazelcastConstants.REMOVED))
                    .log("...removed").to("mock:removed")
            .otherwise().log("fail!");
        }
    };
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:24,代码来源:HazelcastMapConsumerIntegrationTest.java

示例8: testPutWithTTL

import org.apache.camel.component.hazelcast.HazelcastConstants; //导入依赖的package包/类
@Test
public void testPutWithTTL() throws Exception {
    CamelContext camelctx = createCamelContext();
    camelctx.start();
    try {
        Map<String, Object> headers = new HashMap<String, Object>();
        headers.put(HazelcastConstants.OBJECT_ID, "4711");
        headers.put(HazelcastConstants.TTL_VALUE, new Long(1));
        headers.put(HazelcastConstants.TTL_UNIT, TimeUnit.MINUTES);

        ProducerTemplate template = camelctx.createProducerTemplate();
        template.sendBodyAndHeaders("direct:put", "test", headers);
        Mockito.verify(map).put("4711", "test", 1, TimeUnit.MINUTES);
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:18,代码来源:HazelcastMapProducerIntegrationTest.java

示例9: testGet

import org.apache.camel.component.hazelcast.HazelcastConstants; //导入依赖的package包/类
@Test
public void testGet() throws Exception {
    CamelContext camelctx = createCamelContext();
    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();
        Mockito.when(map.get("4711")).thenReturn("my-foo");
        template.sendBodyAndHeader("direct:get", null, HazelcastConstants.OBJECT_ID, "4711");

        ConsumerTemplate consumer = camelctx.createConsumerTemplate();
        String body = consumer.receiveBody("seda:out", 5000, String.class);
        Mockito.verify(map).get("4711");
        Assert.assertEquals("my-foo", body);
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:18,代码来源:HazelcastMapProducerIntegrationTest.java

示例10: testGetAllEmptySet

import org.apache.camel.component.hazelcast.HazelcastConstants; //导入依赖的package包/类
@Test
public void testGetAllEmptySet() throws Exception {
    CamelContext camelctx = createCamelContext();
    camelctx.start();
    try {
        Set<Object> l = new HashSet<Object>();
        Map t = new HashMap();
        t.put("key1", "value1");
        t.put("key2", "value2");
        t.put("key3", "value3");
        Mockito.when(map.getAll(Mockito.anySet())).thenReturn(t);

        ProducerTemplate template = camelctx.createProducerTemplate();
        template.sendBodyAndHeader("direct:getAll", null, HazelcastConstants.OBJECT_ID, l);

        ConsumerTemplate consumer = camelctx.createConsumerTemplate();
        String body = consumer.receiveBody("seda:out", 5000, String.class);
        Mockito.verify(map).getAll(l);
        Assert.assertTrue(body.contains("key1=value1"));
        Assert.assertTrue(body.contains("key2=value2"));
        Assert.assertTrue(body.contains("key3=value3"));
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:26,代码来源:HazelcastMapProducerIntegrationTest.java

示例11: testGetAllOnlyOneKey

import org.apache.camel.component.hazelcast.HazelcastConstants; //导入依赖的package包/类
@Test
public void testGetAllOnlyOneKey() throws Exception {
    CamelContext camelctx = createCamelContext();
    camelctx.start();
    try {
        Set<Object> l = new HashSet<Object>();
        l.add("key1");
        Map t = new HashMap();
        t.put("key1", "value1");
        Mockito.when(map.getAll(l)).thenReturn(t);

        ProducerTemplate template = camelctx.createProducerTemplate();
        template.sendBodyAndHeader("direct:getAll", null, HazelcastConstants.OBJECT_ID, l);

        ConsumerTemplate consumer = camelctx.createConsumerTemplate();
        String body = consumer.receiveBody("seda:out", 5000, String.class);
        Mockito.verify(map).getAll(l);
        Assert.assertEquals("{key1=value1}", body);
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:23,代码来源:HazelcastMapProducerIntegrationTest.java

示例12: testQuery

import org.apache.camel.component.hazelcast.HazelcastConstants; //导入依赖的package包/类
@Test
public void testQuery() throws Exception {
    CamelContext camelctx = createCamelContext();
    camelctx.start();
    try {
        String sql = "bar > 1000";
        Mockito.when(map.values(Mockito.any(SqlPredicate.class))).thenReturn(Arrays.<Object>asList(new Dummy("beta", 2000), new Dummy("gamma", 3000)));

        ProducerTemplate template = camelctx.createProducerTemplate();
        template.sendBodyAndHeader("direct:queue", null, HazelcastConstants.QUERY, sql);
        Mockito.verify(map).values(Mockito.any(SqlPredicate.class));

        ConsumerTemplate consumer = camelctx.createConsumerTemplate();
        Collection<?> b1 = consumer.receiveBody("seda:out", 5000, Collection.class);

        Assert.assertNotNull(b1);
        Assert.assertEquals(2, b1.size());
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:22,代码来源:HazelcastMapProducerIntegrationTest.java

示例13: testUpdateOldValue

import org.apache.camel.component.hazelcast.HazelcastConstants; //导入依赖的package包/类
@Test
public void testUpdateOldValue() throws Exception {
    CamelContext camelctx = createCamelContext();
    camelctx.start();
    try {
        Map<String, Object> headers = new HashMap<String, Object>();
        headers.put(HazelcastConstants.OBJECT_ID, "4711");
        headers.put(HazelcastConstants.OBJECT_VALUE, "my-foo");

        ProducerTemplate template = camelctx.createProducerTemplate();
        template.sendBodyAndHeaders("direct:update", "replaced", headers);
        Mockito.verify(map).lock("4711");
        Mockito.verify(map).replace("4711", "my-foo", "replaced");
        Mockito.verify(map).unlock("4711");
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:19,代码来源:HazelcastMapProducerIntegrationTest.java

示例14: testPutIfAbsentWithTtl

import org.apache.camel.component.hazelcast.HazelcastConstants; //导入依赖的package包/类
@Test
public void testPutIfAbsentWithTtl() throws Exception {
    CamelContext camelctx = createCamelContext();
    camelctx.start();
    try {
        Map<String, Object> headers = new HashMap<String, Object>();
        headers.put(HazelcastConstants.OBJECT_ID, "4711");
        headers.put(HazelcastConstants.TTL_VALUE, new Long(1));
        headers.put(HazelcastConstants.TTL_UNIT, TimeUnit.MINUTES);

        ProducerTemplate template = camelctx.createProducerTemplate();
        template.sendBodyAndHeaders("direct:putIfAbsent", "replaced", headers);
        Mockito.verify(map).putIfAbsent("4711", "replaced", new Long(1), TimeUnit.MINUTES);
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:18,代码来源:HazelcastMapProducerIntegrationTest.java

示例15: testContainsKey

import org.apache.camel.component.hazelcast.HazelcastConstants; //导入依赖的package包/类
@Test
public void testContainsKey() throws Exception {
    CamelContext camelctx = createCamelContext();
    camelctx.start();
    try {
        Mockito.when(map.containsKey("testOk")).thenReturn(true);
        Mockito.when(map.containsKey("testKo")).thenReturn(false);

        ProducerTemplate template = camelctx.createProducerTemplate();
        template.sendBodyAndHeader("direct:containsKey", null, HazelcastConstants.OBJECT_ID, "testOk");

        ConsumerTemplate consumer = camelctx.createConsumerTemplate();
        Boolean body = consumer.receiveBody("seda:out", 5000, Boolean.class);
        Mockito.verify(map).containsKey("testOk");
        Assert.assertEquals(true, body);
        template.sendBodyAndHeader("direct:containsKey", null, HazelcastConstants.OBJECT_ID, "testKo");
        body = consumer.receiveBody("seda:out", 5000, Boolean.class);
        Mockito.verify(map).containsKey("testKo");
        Assert.assertEquals(false, body);
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:24,代码来源:HazelcastMapProducerIntegrationTest.java


注:本文中的org.apache.camel.component.hazelcast.HazelcastConstants类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。