com.hazelcast.core.ITopic Java Examples

The following examples show how to use com.hazelcast.core.ITopic. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DistributedEventBus.java    From dolphin-platform with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #2
Source File: DistributedEventBus.java    From dolphin-platform with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #3
Source File: HazelcastTest.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@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() );
    }
}
 
Example #4
Source File: QueueTopicProxyFactory.java    From hazelcastmq with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #5
Source File: ClusterDataFactory.java    From lannister with Apache License 2.0 5 votes vote down vote up
public <E> ITopic<E> createTopic(String name) {
	switch (Settings.INSTANCE.clusteringMode()) {
	case HAZELCAST:
		return Hazelcast.INSTANCE.getTopic(name);

	case IGNITE:
	case SINGLE:
		return new SingleTopic<E>(name);

	default:
		return null;
	}
}
 
Example #6
Source File: WebConfigurerTest.java    From flair-engine with Apache License 2.0 4 votes vote down vote up
@Override
public <E> ITopic<E> getTopic(String s) {
    return null;
}
 
Example #7
Source File: WebConfigurerTest.java    From flair-engine with Apache License 2.0 4 votes vote down vote up
@Override
public <E> ITopic<E> getReliableTopic(String s) {
    return null;
}
 
Example #8
Source File: Hazelcast.java    From lannister with Apache License 2.0 4 votes vote down vote up
protected <E> ITopic<E> getTopic(String name) {
	return substance.getTopic(name);
}
 
Example #9
Source File: Topics.java    From lannister with Apache License 2.0 4 votes vote down vote up
public ITopic<Notification> notifier() {
	return notifier;
}
 
Example #10
Source File: DistributedEventBus.java    From dolphin-platform with Apache License 2.0 4 votes vote down vote up
protected <T extends Serializable> void publishForOtherSessions(final DolphinEvent<T> event) {
    Assert.requireNonNull(event, "event");
    final ITopic<DolphinEvent<T>> topic = toHazelcastTopic(event.getMessageEventContext().getTopic());
    topic.publish(event);
}
 
Example #11
Source File: DistributedEventBus.java    From dolphin-platform with Apache License 2.0 4 votes vote down vote up
private <T extends Serializable> ITopic<DolphinEvent<T>> toHazelcastTopic(final Topic<T> topic) {
    return hazelcastClient.getTopic(topic.getName());
}
 
Example #12
Source File: ClusterConfig.java    From batchers with Apache License 2.0 4 votes vote down vote up
@Bean
public ITopic<JobProgressEvent> jobProgressEventsTopic() {
    return hazelcastInstance().getTopic("jobProgress");
}
 
Example #13
Source File: HzEventListener.java    From light with Apache License 2.0 4 votes vote down vote up
@PostConstruct
  public void register() {
ITopic<Map<String, Object>> eventBus = hInstance.getTopic("eventBus");
eventBus.addMessageListener(this);
  }