List of usage examples for com.liferay.portal.kernel.messaging MessageListener MessageListener
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/*from w ww . j ava 2s . c om*/ 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/*from w w w . j a v a 2 s .c om*/ public void receive(Message message) { Object[] payload = (Object[]) message.getPayload(); if (eventType.isMatch(payload[0])) { count.incrementAndGet(); } } }); return count; }
From source file:com.liferay.exportimport.resources.importer.test.ResourcesImporterTest.java
License:Open Source License
@Before public void setUp() throws Exception { Bundle testBundle = FrameworkUtil.getBundle(ResourcesImporterTest.class); _bundleContext = testBundle.getBundleContext(); URL warURL = ResourcesImporterTest.class.getResource("dependencies/test.war"); warURL = new URL(warURL.toExternalForm() + "?Web-ContextPath=/test-resource-importer"); URL bundleURL = new URL("webbundle", null, warURL.toString()); _bundle = _bundleContext.installBundle(bundleURL.toString()); Dictionary<String, Object> properties = new Hashtable<>(); properties.put("destination.name", "liferay/resources_importer"); final CountDownLatch countDownLatch = new CountDownLatch(1); ServiceRegistration<MessageListener> serviceRegistration = _bundleContext .registerService(MessageListener.class, new MessageListener() { public void receive(Message message) throws MessageListenerException { countDownLatch.countDown(); }/*from www . j a v a 2s. c o m*/ }, properties); _bundle.start(); countDownLatch.await(1, TimeUnit.MINUTES); serviceRegistration.unregister(); }
From source file:com.liferay.server.admin.web.internal.portlet.action.EditServerMVCActionCommand.java
License:Open Source License
protected void reindex(final ActionRequest actionRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); Map<String, Serializable> taskContextMap = new HashMap<>(); String className = ParamUtil.getString(actionRequest, "className"); if (!ParamUtil.getBoolean(actionRequest, "blocking")) { _indexWriterHelper.reindex(themeDisplay.getUserId(), "reindex", _portalInstancesLocalService.getCompanyIds(), className, taskContextMap); return;/* w w w . j av a 2 s .c o m*/ } final String jobName = "reindex-".concat(_portalUUID.generate()); final CountDownLatch countDownLatch = new CountDownLatch(1); MessageListener messageListener = new MessageListener() { @Override public void receive(Message message) throws MessageListenerException { int status = message.getInteger("status"); if ((status != BackgroundTaskConstants.STATUS_CANCELLED) && (status != BackgroundTaskConstants.STATUS_FAILED) && (status != BackgroundTaskConstants.STATUS_SUCCESSFUL)) { return; } if (!jobName.equals(message.getString("name"))) { return; } PortletSession portletSession = actionRequest.getPortletSession(); long lastAccessedTime = portletSession.getLastAccessedTime(); int maxInactiveInterval = portletSession.getMaxInactiveInterval(); int extendedMaxInactiveIntervalTime = (int) (System.currentTimeMillis() - lastAccessedTime + maxInactiveInterval); portletSession.setMaxInactiveInterval(extendedMaxInactiveIntervalTime); countDownLatch.countDown(); } }; _messageBus.registerMessageListener(DestinationNames.BACKGROUND_TASK_STATUS, messageListener); try { _indexWriterHelper.reindex(themeDisplay.getUserId(), jobName, _portalInstancesLocalService.getCompanyIds(), className, taskContextMap); countDownLatch.await(ParamUtil.getLong(actionRequest, "timeout", Time.HOUR), TimeUnit.MILLISECONDS); } finally { _messageBus.unregisterMessageListener(DestinationNames.BACKGROUND_TASK_STATUS, messageListener); } }
From source file:se.vgregion.messagebus.MessageBusComponentTest.java
License:Open Source License
@DirtiesContext @Test/*from ww w . ja v a2s.c om*/ public void testProducer() throws Exception { messageBus.addDestination(new SerialDestination("destination")); messageBus.registerMessageListener("destination", new MessageListener() { public void receive(Message message) { result = message.getPayload().toString(); } }); String testString = "testing"; Message message = new Message(); message.setPayload(testString); template.sendBody("direct:testProducer", message); Thread.sleep(500); assertEquals(testString, result); }