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

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

Introduction

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

Prototype

public static void registerMessageListener(String destinationName, MessageListener messageListener) 

Source Link

Usage

From source file:com.commsen.liferay.multidevice.DeviceRecognitionDestinationEventListener.java

License:Open Source License

@Override
public void messageListenerUnregistered(String destinationName, MessageListener messageListener) {
    if (!isProceed(destinationName, messageListener)) {
        return;/*from   w w w .  ja  v a  2 s .co  m*/
    }
    MessageBusUtil.registerMessageListener(MultideviceConstants.DESTINATION_DEVICE_RECOGNITION_PROVIDER,
            deviceRecognitionMessageListener);
}

From source file:com.commsen.liferay.multidevice.rules.DeviceRulesDestinationEventListener.java

License:Open Source License

@Override
public void messageListenerUnregistered(String destinationName, MessageListener messageListener) {
    if (!isProceed(destinationName, messageListener)) {
        return;// www.  ja  va2 s. c  o  m
    }
    MessageBusUtil.registerMessageListener(MultideviceConstants.DESTINATION_DEVICE_RULES_PROVIDER,
            deviceRulesMessageListener);
}

From source file:com.liferay.adaptive.media.image.internal.configuration.test.BaseAMImageConfigurationTestCase.java

License:Open Source License

protected List<Message> collectConfigurationMessages(CheckedRunnable runnable) throws Exception {

    List<Message> messages = new ArrayList<>();

    MessageListener messageListener = messages::add;

    MessageBusUtil.registerMessageListener(AMImageDestinationNames.ADAPTIVE_MEDIA_IMAGE_CONFIGURATION,
            messageListener);/*  w  w w  .  j a  v  a  2  s.  c  o  m*/

    try {
        runnable.run();
    } finally {
        MessageBusUtil.unregisterMessageListener(AMImageDestinationNames.ADAPTIVE_MEDIA_IMAGE_CONFIGURATION,
                messageListener);
    }

    return messages;
}

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

License:Open Source License

protected List<Message> collectConfigurationMessages(CheckedRunnable runnable) throws Exception {

    String destinationName = AdaptiveMediaImageDestinationNames.ADAPTIVE_MEDIA_IMAGE_CONFIGURATION;

    try (DestinationReplacer destinationReplacer = new DestinationReplacer(destinationName)) {

        List<Message> messages = new ArrayList<>();

        MessageListener messageListener = messages::add;

        MessageBusUtil.registerMessageListener(destinationName, messageListener);

        try {//from  w w w .j av  a 2  s.c om
            runnable.run();
        } finally {
            MessageBusUtil.unregisterMessageListener(destinationName, messageListener);
        }

        return messages;
    }
}

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;
            }// w  w w  . ja v a  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.calendar.servlet.CalendarServletContextListener.java

License:Open Source License

@Override
protected void doPortalInit() throws Exception {
    _messageListener = new HotDeployMessageListener(ClpSerializer.getServletContextName()) {

        @Override// ww w . j  a v  a  2  s .  c o m
        protected void onDeploy(Message message) throws Exception {
            if (!PortletPropsValues.CALENDAR_SYNC_CALEVENTS_ON_STARTUP) {
                return;
            }

            StopWatch stopWatch = null;

            if (_log.isInfoEnabled()) {
                stopWatch = new StopWatch();

                stopWatch.start();
            }

            CalendarImporterLocalServiceUtil.importCalEvents();

            if (_log.isInfoEnabled()) {
                StringBundler sb = new StringBundler(6);

                sb.append("Calendar events synchronization takes ");
                sb.append(stopWatch.getTime());
                sb.append(" ms. Set the property ");
                sb.append("\"calendar.sync.calevents.on.startup\" ");
                sb.append("to \"false\" to disable calendar events ");
                sb.append("synchronization.");

                _log.info(sb.toString());
            }
        }

    };

    MessageBusUtil.registerMessageListener(DestinationNames.HOT_DEPLOY, _messageListener);
}

From source file:com.liferay.chat.servlet.ChatServletContextListener.java

License:Open Source License

@Override
protected void doPortalInit() {
    _messageListener = new HotDeployMessageListener(ClpSerializer.getServletContextName(), "contacts-portlet") {

        @Override/* w  ww.  j  a v a  2 s  .com*/
        protected void onUndeploy(Message message) throws Exception {
            ChatExtensionsUtil.unregister(message.getString("servletContextName"));
        }

    };

    MessageBusUtil.registerMessageListener(DestinationNames.HOT_DEPLOY, _messageListener);
}

From source file:com.liferay.contacts.servlet.ContactsServletContextListener.java

License:Open Source License

@Override
protected void doPortalInit() {
    _messageListener = new HotDeployMessageListener(ClpSerializer.getServletContextName(), "chat-portlet") {

        @Override// w w w .  j  av a2  s.  c om
        protected void onDeploy(Message message) throws Exception {
            registerChatExtension();
        }

        @Override
        protected void onUndeploy(Message message) throws Exception {
            ContactsExtensionsUtil.unregister(message.getString("servletContextName"));
        }

    };

    MessageBusUtil.registerMessageListener(DestinationNames.HOT_DEPLOY, _messageListener);
}

From source file:com.liferay.document.library.service.test.DLAppServiceTest.java

License:Open Source License

protected static AtomicInteger registerDLSyncEventProcessorMessageListener(final String targetEvent) {

    final AtomicInteger counter = new AtomicInteger();

    MessageBusUtil.registerMessageListener(DestinationNames.DOCUMENT_LIBRARY_SYNC_EVENT_PROCESSOR,
            new MessageListener() {

                @Override/*w  w  w .  j a  va 2 s .  c  o  m*/
                public void receive(Message message) {
                    Object event = message.get("event");

                    if (targetEvent.equals(event)) {
                        counter.incrementAndGet();
                    }
                }

            });

    return counter;
}

From source file:com.liferay.document.library.service.test.PDFProcessorTest.java

License:Open Source License

protected static AtomicInteger registerPDFProcessorMessageListener(final EventType eventType) {

    final AtomicInteger count = new AtomicInteger();

    MessageBusUtil.registerMessageListener(DestinationNames.DOCUMENT_LIBRARY_PDF_PROCESSOR,
            new MessageListener() {

                @Override/*w  w  w.j  a v  a2s .c o  m*/
                public void receive(Message message) {
                    Object[] payload = (Object[]) message.getPayload();

                    if (eventType.isMatch(payload[0])) {
                        count.incrementAndGet();
                    }
                }

            });

    return count;
}