Example usage for com.liferay.portal.kernel.messaging MessageBusUtil getMessageBus

List of usage examples for com.liferay.portal.kernel.messaging MessageBusUtil getMessageBus

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.messaging MessageBusUtil getMessageBus.

Prototype

public static MessageBus getMessageBus() 

Source Link

Usage

From source file:com.liferay.adaptive.media.document.library.thumbnails.internal.test.util.DestinationReplacer.java

License:Open Source License

public DestinationReplacer(String... destinationNames) {
    MessageBus messageBus = MessageBusUtil.getMessageBus();

    _destinations = Stream.of(destinationNames).map(messageBus::getDestination).collect(Collectors.toList());

    for (String destinationName : destinationNames) {
        SynchronousDestination synchronousDestination = new SynchronousDestination();

        synchronousDestination.setName(destinationName);

        messageBus.replace(synchronousDestination);
    }//from  w ww. j a v a 2s . com
}

From source file:com.liferay.adaptive.media.document.library.thumbnails.internal.test.util.DestinationReplacer.java

License:Open Source License

@Override
public void close() throws Exception {
    MessageBus messageBus = MessageBusUtil.getMessageBus();

    _destinations.forEach(messageBus::replace);
}

From source file:com.liferay.adaptive.media.image.internal.test.util.DestinationReplacer.java

License:Open Source License

public DestinationReplacer(String destinationName) {
    MessageBus messageBus = MessageBusUtil.getMessageBus();

    _destination = messageBus.getDestination(destinationName);

    SynchronousDestination synchronousDestination = new SynchronousDestination();

    synchronousDestination.setName(destinationName);

    messageBus.replace(synchronousDestination);
}

From source file:com.liferay.adaptive.media.image.internal.test.util.DestinationReplacer.java

License:Open Source License

@Override
public void close() throws Exception {
    MessageBus messageBus = MessageBusUtil.getMessageBus();

    messageBus.replace(_destination);
}

From source file:com.liferay.alloy.mvc.BaseAlloyControllerImpl.java

License:Open Source License

protected void initMessageListener(String destinationName, MessageListener messageListener,
        boolean enableScheduler) {

    MessageBus messageBus = MessageBusUtil.getMessageBus();

    Destination destination = messageBus.getDestination(destinationName);

    if (destination != null) {
        Set<MessageListener> messageListeners = destination.getMessageListeners();

        for (MessageListener curMessageListener : messageListeners) {
            if (!(curMessageListener instanceof InvokerMessageListener)) {
                continue;
            }//from w  ww  .  j ava2 s  .c om

            InvokerMessageListener invokerMessageListener = (InvokerMessageListener) curMessageListener;

            curMessageListener = invokerMessageListener.getMessageListener();

            if (messageListener == curMessageListener) {
                return;
            }

            Class<?> messageListenerClass = messageListener.getClass();

            String messageListenerClassName = messageListenerClass.getName();

            Class<?> curMessageListenerClass = curMessageListener.getClass();

            if (!messageListenerClassName.equals(curMessageListenerClass.getName())) {

                continue;
            }

            try {
                if (enableScheduler) {
                    SchedulerEngineHelperUtil.unschedule(getSchedulerJobName(), getMessageListenerGroupName(),
                            StorageType.MEMORY_CLUSTERED);
                }

                MessageBusUtil.unregisterMessageListener(destinationName, curMessageListener);
            } catch (Exception e) {
                log.error(e, e);
            }

            break;
        }
    } else {
        SerialDestination serialDestination = new SerialDestination();

        serialDestination.setName(destinationName);

        serialDestination.open();

        MessageBusUtil.addDestination(serialDestination);
    }

    try {
        MessageBusUtil.registerMessageListener(destinationName, messageListener);

        if (enableScheduler) {
            SchedulerEngineHelperUtil.schedule(getSchedulerTrigger(), StorageType.MEMORY_CLUSTERED, null,
                    destinationName, null, 0);
        }
    } catch (Exception e) {
        log.error(e, e);
    }
}

From source file:com.liferay.analytics.messaging.AnalyticsHotDeployMessageListener.java

License:Open Source License

@Override
protected void onDeploy(Message message) throws Exception {
    MessageBus messageBus = MessageBusUtil.getMessageBus();

    try {//www . j a v  a2  s. c  o m
        messageBus.registerMessageListener(_analyticsMessageDestination, _analyticsMessageListener);

        if (_log.isInfoEnabled()) {
            _log.info("Registering message listener for " + _analyticsMessageDestination);
        }
    } catch (Exception e) {
        _log.error("Cannot register message listener for" + _analyticsMessageDestination);
    }
}

From source file:com.liferay.content.targeting.analytics.messaging.AnalyticsHotDeployMessageListener.java

License:Open Source License

@Override
protected void onDeploy(Message message) throws Exception {
    MessageBus messageBus = MessageBusUtil.getMessageBus();

    try {/*from   w  w w . j  a  v  a  2 s.  c  o  m*/
        messageBus.registerMessageListener(_analyticsMessageDestination, _analyticsMessageListener);

        if (_log.isInfoEnabled()) {
            _log.info("Registering message listener for " + _analyticsMessageDestination);
        }
    } catch (Exception e) {
        _log.error("Cannot register message listener for" + _analyticsMessageDestination, e);
    }
}

From source file:org.vaadin.tori.util.LiferayToriActivityMessaging.java

License:Apache License

@Override
public void register() {
    if (!MessageBusUtil.getMessageBus().hasDestination(TORI_DESTINATION)) {
        log.info("Adding a message bus destination: " + TORI_DESTINATION);
        @SuppressWarnings("deprecation")
        Destination destination = new ParallelDestination(TORI_DESTINATION);
        destination.open();/*ww w  .  j a va  2  s  .  c  om*/
        MessageBusUtil.addDestination(destination);
    }

    MessageBusUtil.registerMessageListener(TORI_DESTINATION, this);
}