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

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

Introduction

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

Prototype

@Override
    public void open() 

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 w ww  .j a v  a  2 s. 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);
    }
}