Example usage for com.liferay.portal.kernel.messaging SerialDestination SerialDestination

List of usage examples for com.liferay.portal.kernel.messaging SerialDestination SerialDestination

Introduction

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

Prototype

public SerialDestination() 

Source Link

Usage

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   ww w . j ava 2s. c o  m

            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.sync.servlet.SyncServletContextListener.java

License:Open Source License

protected void registerMessageListener(MessageListener messageListener, String destinationName) {

    SerialDestination serialDestination = new SerialDestination();

    serialDestination.setName(destinationName);

    serialDestination.afterPropertiesSet();

    MessageBusUtil.addDestination(serialDestination);

    MessageBusUtil.registerMessageListener(destinationName, messageListener);
}