當前位置: 首頁>>代碼示例>>Java>>正文


Java ITopic類代碼示例

本文整理匯總了Java中com.hazelcast.core.ITopic的典型用法代碼示例。如果您正苦於以下問題:Java ITopic類的具體用法?Java ITopic怎麽用?Java ITopic使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ITopic類屬於com.hazelcast.core包,在下文中一共展示了ITopic類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testThreeArgConstructorRegistersTopicListener

import com.hazelcast.core.ITopic; //導入依賴的package包/類
@Test
public void testThreeArgConstructorRegistersTopicListener() {
    MapConfig mapConfig = mock(MapConfig.class);

    Config config = mock(Config.class);
    when(config.findMapConfig(eq(CACHE_NAME))).thenReturn(mapConfig);

    ITopic<Object> topic = mock(ITopic.class);
    when(topic.addMessageListener(isNotNull(MessageListener.class))).thenReturn("ignored");

    HazelcastInstance instance = mock(HazelcastInstance.class);
    when(instance.getConfig()).thenReturn(config);
    when(instance.getTopic(eq(CACHE_NAME))).thenReturn(topic);

    new LocalRegionCache(CACHE_NAME, instance, null);
    verify(config).findMapConfig(eq(CACHE_NAME));
    verify(instance).getConfig();
    verify(instance).getTopic(eq(CACHE_NAME));
    verify(topic).addMessageListener(isNotNull(MessageListener.class));
}
 
開發者ID:hazelcast,項目名稱:hazelcast-hibernate5,代碼行數:21,代碼來源:LocalRegionCacheTest.java

示例2: registerHazelcastEventPipe

import com.hazelcast.core.ITopic; //導入依賴的package包/類
private <T extends Serializable> void registerHazelcastEventPipe(final ITopic<DolphinEvent<T>> topic) {
    hazelcastEventPipeLock.lock();
    try {
        Assert.requireNonNull(topic, "hazelcastTopic");

        final String registrationId = topic.addMessageListener(new com.hazelcast.core.MessageListener<DolphinEvent<T>>() {
            @Override
            public void onMessage(com.hazelcast.core.Message<DolphinEvent<T>> message) {
                final DolphinEvent<T> event = message.getMessageObject();
                triggerEventHandling(event);
            }
        });
        Assert.requireNonBlank(registrationId, "registrationId");

        iTopicRegistrations.put(topic.getName(), registrationId);
        iTopicCount.put(topic.getName(), 1);
    } finally {
        hazelcastEventPipeLock.unlock();
    }
}
 
開發者ID:canoo,項目名稱:dolphin-platform,代碼行數:21,代碼來源:DistributedEventBus.java

示例3: unregisterHazelcastEventPipe

import com.hazelcast.core.ITopic; //導入依賴的package包/類
private <T extends Serializable> void unregisterHazelcastEventPipe(final ITopic<DolphinEvent<T>> topic) {
    hazelcastEventPipeLock.lock();
    try {
        Assert.requireNonNull(topic, "hazelcastTopic");

        final Integer count = iTopicCount.get(topic.getName());
        if (count == null || count != 1) {
            throw new IllegalStateException("Count for topic " + topic.getName() + " is wrong: " + count);
        }

        final String registrationId = iTopicRegistrations.get(topic.getName());
        Assert.requireNonBlank(registrationId, "registrationId");

        topic.removeMessageListener(registrationId);

        iTopicRegistrations.remove(topic.getName());
        iTopicCount.remove(topic.getName());
    } finally {
        hazelcastEventPipeLock.unlock();
    }
}
 
開發者ID:canoo,項目名稱:dolphin-platform,代碼行數:22,代碼來源:DistributedEventBus.java

示例4: addMessageListener

import com.hazelcast.core.ITopic; //導入依賴的package包/類
@Test
public void addMessageListener() throws InterruptedException {
    HazelcastClient hClient = getHazelcastClient();
    ITopic<String> topic = hClient.getTopic("addMessageListener");
    final CountDownLatch latch = new CountDownLatch(1);
    final String message = "Hazelcast Rocks!";
    topic.addMessageListener(new MessageListener<String>() {
        public void onMessage(Message<String> msg) {
            if (msg.getMessageObject().equals(message)) {
                latch.countDown();
            }
        }
    });
    topic.publish(message);
    assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
}
 
開發者ID:mdogan,項目名稱:hazelcast-archive,代碼行數:17,代碼來源:HazelcastClientTopicTest.java

示例5: removeMessageListener

import com.hazelcast.core.ITopic; //導入依賴的package包/類
@Test
    public void removeMessageListener() throws InterruptedException {
        HazelcastClient hClient = getHazelcastClient();
        ITopic<String> topic = hClient.getTopic("removeMessageListener");
        final CountDownLatch latch = new CountDownLatch(2);
        final CountDownLatch cp = new CountDownLatch(1);
//        final String message = "Hazelcast Rocks!";
        MessageListener<String> messageListener = new MessageListener<String>() {
            public void onMessage(Message<String> msg) {
//                if (msg.startsWith(message)) {
                System.out.println("Received " + msg + " at " + this);
                latch.countDown();
                cp.countDown();
//                }
            }
        };
        final String message = "message_" + messageListener.hashCode() + "_";
        topic.addMessageListener(messageListener);
        topic.publish(message + "1");
        cp.await();
        topic.removeMessageListener(messageListener);
        topic.publish(message + "2");
        Thread.sleep(50);
        assertEquals(1, latch.getCount());
    }
 
開發者ID:mdogan,項目名稱:hazelcast-archive,代碼行數:26,代碼來源:HazelcastClientTopicTest.java

示例6: testPerformance

import com.hazelcast.core.ITopic; //導入依賴的package包/類
@Test
public void testPerformance() throws InterruptedException {
    HazelcastClient hClient = getHazelcastClient();
    long begin = System.currentTimeMillis();
    int count = 10000;
    final ITopic topic = hClient.getTopic("perf");
    ExecutorService ex = Executors.newFixedThreadPool(10);
    final CountDownLatch l = new CountDownLatch(count);
    for (int i = 0; i < count; i++) {
        ex.submit(new Runnable() {
            public void run() {
                topic.publish("my object");
                l.countDown();
            }
        });
    }
    assertTrue(l.await(20, TimeUnit.SECONDS));
    long time = System.currentTimeMillis() - begin;
    System.out.println("per second: " + count * 1000 / time);
}
 
開發者ID:mdogan,項目名稱:hazelcast-archive,代碼行數:21,代碼來源:HazelcastClientTopicTest.java

示例7: testSimpleUsage

import com.hazelcast.core.ITopic; //導入依賴的package包/類
@Test
public void testSimpleUsage() {
    withHazelcast(3, hazelcastInstance -> {
        ITopic<String> topic = hazelcastInstance.getReliableTopic("default");

        List<String> receivedMessage = new ArrayList<>();
        topic.addMessageListener(message -> receivedMessage.add(message.getMessageObject()));

        topic.publish("Hello World");
        topic.publish("Hello Hazelcast!");

        assertThat(receivedMessage)
                .isEqualTo(Arrays.asList("Hello World", "Hello Hazelcast!"));

        assertThat(topic.getLocalTopicStats().getPublishOperationCount())
                .isEqualTo(2L);
        assertThat(topic.getLocalTopicStats().getReceiveOperationCount())
                .isEqualTo(2L);
    });
}
 
開發者ID:kazuhira-r,項目名稱:hazelcast-examples,代碼行數:21,代碼來源:HazelcastReliableTopicTest.java

示例8: testWithRingbufferTtl

import com.hazelcast.core.ITopic; //導入依賴的package包/類
@Test
public void testWithRingbufferTtl() {
    withHazelcast(3, hazelcastInstance -> {
        ITopic<String> topic = hazelcastInstance.getReliableTopic("with-ttl");

        long start = System.currentTimeMillis();

        IntStream
                .rangeClosed(1, 10005)
                .forEach(i -> topic.publish("message-" + i));

        long elapsed = System.currentTimeMillis() - start;

        assertThat(topic.getLocalTopicStats().getPublishOperationCount())
                .isEqualTo(10005L);
        assertThat(topic.getLocalTopicStats().getReceiveOperationCount())
                .isEqualTo(0L);

        assertThat(elapsed)
                .isGreaterThanOrEqualTo(30 * 1000L);
    });
}
 
開發者ID:kazuhira-r,項目名稱:hazelcast-examples,代碼行數:23,代碼來源:HazelcastReliableTopicTest.java

示例9: setup

import com.hazelcast.core.ITopic; //導入依賴的package包/類
@Setup
@SuppressWarnings("unchecked")
public void setup() {
    totalMessagesSend = targetInstance.getAtomicLong(name + ":TotalExpectedCounter");
    topics = new ITopic[topicCount];
    listeners = new LinkedList<MessageListenerImpl>();

    String[] names = generateStringKeys(name, topicCount, keyLocality, targetInstance);

    int listenerIdCounter = 0;
    for (int i = 0; i < topics.length; i++) {
        ITopic<MessageEntity> topic = targetInstance.getReliableTopic(names[i]);
        topics[i] = topic;
        for (int l = 0; l < listenersPerTopic; l++) {
            MessageListenerImpl topicListener = new MessageListenerImpl(listenerIdCounter);
            listenerIdCounter++;
            topic.addMessageListener(topicListener);
            listeners.add(topicListener);
        }
    }
}
 
開發者ID:hazelcast,項目名稱:hazelcast-simulator,代碼行數:22,代碼來源:ReliableTopicTest.java

示例10: setup

import com.hazelcast.core.ITopic; //導入依賴的package包/類
@Setup
public void setup() {
    totalExpectedCounter = targetInstance.getAtomicLong(name + ":TotalExpectedCounter");
    totalFoundCounter = targetInstance.getAtomicLong(name + ":TotalFoundCounter");

    topics = new ITopic[topicCount];
    listeners = new LinkedList<TopicListener>();
    for (int topicIndex = 0; topicIndex < topics.length; topicIndex++) {
        ITopic<Long> topic = targetInstance.getTopic(name + topicIndex);
        topics[topicIndex] = topic;

        for (int listenerIndex = 0; listenerIndex < listenersPerTopic; listenerIndex++) {
            TopicListener topicListener = new TopicListener();
            topic.addMessageListener(topicListener);
            listeners.add(topicListener);
        }
    }
}
 
開發者ID:hazelcast,項目名稱:hazelcast-simulator,代碼行數:19,代碼來源:ITopicTest.java

示例11: doTest

import com.hazelcast.core.ITopic; //導入依賴的package包/類
@Test
public void doTest() {
    logger.info( "do test" );
    Hazelcast.addInstanceListener( this );

    ITopic<Object> topic = Hazelcast.getTopic( "default" );
    topic.addMessageListener( this );
    topic.publish( "my-message-object" );

    Collection<Instance> instances = Hazelcast.getInstances();
    for ( Instance instance : instances ) {
        logger.info( "ID: [" + instance.getId() + "] Type: [" + instance.getInstanceType() + "]" );
    }

    Set<Member> setMembers = Hazelcast.getCluster().getMembers();
    for ( Member member : setMembers ) {
        logger.info( "isLocalMember " + member.localMember() );
        logger.info( "member.inetsocketaddress " + member.getInetSocketAddress() );
    }
}
 
開發者ID:apache,項目名稱:usergrid,代碼行數:21,代碼來源:HazelcastTest.java

示例12: listener

import com.hazelcast.core.ITopic; //導入依賴的package包/類
/**
 * Subscribe for Mule events under the specified topic name
 * <p/>
 * {@sample.xml ../../../doc/pubsub-module.xml.sample pubsub:listener}
 *
 * @param topic    Name of the topic
 * @param callback flow to process
 */
@Source(exchangePattern = MessageExchangePattern.ONE_WAY)
public void listener(String topic, final SourceCallback callback) {
    ITopic hazelcastTopic = HazelcastManager.getInstance().getHazelcastInstance().getTopic(topic);
    hazelcastTopic.addMessageListener(new MessageListener() {
        @Override
        public void onMessage(Message message) {
            Thread.currentThread().setContextClassLoader(muleContext.getExecutionClassLoader());

            MuleEvent newEvent = createMuleEvent(message);

            // process it
            try {
                callback.processEvent(newEvent);
            } catch (MuleException e) {
                LOGGER.error(e.getMessage(), e);
            }
        }
    });
}
 
開發者ID:mulesoft,項目名稱:mule-module-publish-subscribe,代碼行數:28,代碼來源:PubSubModule.java

示例13: createTopicProxy

import com.hazelcast.core.ITopic; //導入依賴的package包/類
/**
 * Creates an {@link ITopic} proxy on the combination of a
 * {@link TransactionalQueue} and an actual {@link ITopic} instance. The proxy
 * will offer items to the transactional queue when they are published on the
 * topic. All other topic methods are simply passed through to the underlying
 * topic. By offering items to the queue on publish, a transactional topic can
 * be simulated via the ITopic interface.
 *
 * @param <E> the type of items in the topic
 * @param queue the transactional queue to offer all published objects
 * @param topic the underlying topic to handle all other operations
 *
 * @return the proxy around the queue and topic
 */
@SuppressWarnings("unchecked")
public static <E> ITopic<E> createTopicProxy(
    final TransactionalQueue<E> queue, final ITopic<E> topic) {
  InvocationHandler handler = new InvocationHandler() {
    @Override
    public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {

      if (method.getName().equals("publish")) {
        return queue.offer((E) args[0]);
      }
      else {
        return method.invoke(topic, args);
      }
    }
  };

  return (ITopic<E>) Proxy.newProxyInstance(
      ITopic.class.getClassLoader(), new Class[]{ITopic.class},
      handler);
}
 
開發者ID:mpilone,項目名稱:hazelcastmq,代碼行數:36,代碼來源:QueueTopicProxyFactory.java

示例14: testPerformance

import com.hazelcast.core.ITopic; //導入依賴的package包/類
@Test
public void testPerformance() throws InterruptedException {
    HazelcastClient hClient = getHazelcastClient();
    long begin = Clock.currentTimeMillis();
    int count = 10000;
    final ITopic topic = hClient.getTopic("perf");
    ExecutorService ex = Executors.newFixedThreadPool(10);
    final CountDownLatch l = new CountDownLatch(count);
    for (int i = 0; i < count; i++) {
        ex.submit(new Runnable() {
            public void run() {
                topic.publish("my object");
                l.countDown();
            }
        });
    }
    assertTrue(l.await(20, TimeUnit.SECONDS));
    long time = Clock.currentTimeMillis() - begin;
    System.out.println("per second: " + count * 1000 / time);
}
 
開發者ID:health-and-care-developer-network,項目名稱:health-and-care-developer-network,代碼行數:21,代碼來源:HazelcastClientTopicTest.java

示例15: main

import com.hazelcast.core.ITopic; //導入依賴的package包/類
public static void main(String[] args) {
        HazelcastInstance hz = Hazelcast.newHazelcastInstance();
        ITopic<String> topic = hz.getTopic("foo");
//        topic.addMessageListener(System.out::println);
        while(true){
            topic.publish("Hi from Anatole at " + new Date());
        }
    }
 
開發者ID:apache,項目名稱:incubator-tamaya-sandbox,代碼行數:9,代碼來源:Test.java


注:本文中的com.hazelcast.core.ITopic類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。