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

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

Introduction

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

Prototype

public static Object sendSynchronousMessage(String destinationName, Object payload,
            String responseDestinationName) throws MessageBusException 

Source Link

Usage

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

License:Open Source License

@Override
public KnownDevices getKnownDevices() {
    try {/*from w ww  .ja  v a  2s  .  com*/
        Object result = MessageBusUtil.sendSynchronousMessage(
                MultideviceConstants.DESTINATION_DEVICE_RECOGNITION_PROVIDER, new KnownDevicesCommand(),
                MultideviceConstants.DESTINATION_DEVICE_RECOGNITION_PROVIDER_RESPONSE);
        if (!(result instanceof KnownDevices)) {
            _log.error("Unexpected response! Expected " + KnownDevices.class.getName() + " but got "
                    + result.getClass().getName());
            return null;
        }
        return (KnownDevices) result;
    } catch (MessageBusException e) {
        _log.error("Failed to get known devices!", e);
    }
    return null;
}

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

License:Open Source License

@Override
public Device getDeviceFromRequest(HttpServletRequest request) {
    try {/* w  w w  . ja  v a  2s  .com*/
        Object result = MessageBusUtil.sendSynchronousMessage(
                MultideviceConstants.DESTINATION_DEVICE_RECOGNITION_PROVIDER,
                new DeviceFromRequestCommand(request),
                MultideviceConstants.DESTINATION_DEVICE_RECOGNITION_PROVIDER_RESPONSE);
        if (!(result instanceof Device)) {
            _log.error("Unexpected response! Expected " + Device.class.getName() + " but got "
                    + result.getClass().getName());
            return null;
        }
        return (Device) result;
    } catch (MessageBusException e) {
        _log.error("Failed to get device from request!", e);
    }
    return null;
}

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

License:Open Source License

/**
 * @see//from  w  ww  . j a v a2  s. c  o m
 * com.commsen.liferay.multidevice.rules.DeviceRulesProvider#getThemeAndColorScheme
 * (com.commsen.liferay.multidevice.Device)
 */
@Override
public DeviceAction getAction(Device device, long companyId, long groupId, long pageId) {
    try {
        ActionForDeviceCommand actionForDeviceCommand = new ActionForDeviceCommand(device, companyId, groupId,
                pageId);
        Object result = MessageBusUtil.sendSynchronousMessage(
                MultideviceConstants.DESTINATION_DEVICE_RULES_PROVIDER, actionForDeviceCommand,
                MultideviceConstants.DESTINATION_DEVICE_RULES_PROVIDER_RESPONSE);
        if (!(result instanceof DeviceAction)) {
            _log.error("Unexpected response! Expected " + DeviceAction.class.getName() + " but got "
                    + result.getClass().getName());
            return null;
        }
        return (DeviceAction) result;
    } catch (MessageBusException e) {
        _log.error("Failed to get action for device " + device, e);
    }
    return null;
}

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

License:Open Source License

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override//from   ww w  .j a va 2  s.com
public List<RuleInfo> getRules(long companyId, long groupId, long pageId) {
    try {
        RulesListCommand themeRulesListCommand = new RulesListCommand(companyId, groupId, pageId);
        Object result = MessageBusUtil.sendSynchronousMessage(
                MultideviceConstants.DESTINATION_DEVICE_RULES_PROVIDER, themeRulesListCommand,
                MultideviceConstants.DESTINATION_DEVICE_RULES_PROVIDER_RESPONSE);
        if (!(result instanceof List)) {
            _log.error("Unexpected response! Expected " + List.class.getName() + " but got "
                    + result.getClass().getName());
            return null;
        }
        return (List) result;
    } catch (MessageBusException e) {
        _log.error("Failed to get list of device rules!", e);
    }
    return null;
}

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

License:Open Source License

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override// w ww  .  j a  va2 s  .c o  m
public List<String> handleRulesRequest(PortletRequest request) {
    try {
        Object result = MessageBusUtil.sendSynchronousMessage(
                MultideviceConstants.DESTINATION_DEVICE_RULES_PROVIDER, request,
                MultideviceConstants.DESTINATION_DEVICE_RULES_PROVIDER_RESPONSE);
        if (!(result instanceof List)) {
            _log.error("Unexpected response! Expected " + List.class.getName() + " but got "
                    + result.getClass().getName());
            return null;
        }
        return (List) result;
    } catch (MessageBusException e) {
        _log.error("Failed to handle device rules request!", e);
    }
    return null;
}

From source file:com.liferay.deploylistener.hook.deploy.DeployListenerDeployManagerImpl.java

License:Open Source License

protected boolean sendMesssage(String context, String command) {
    String destinationName = "liferay/deploy_listener/" + context;

    if (!MessageBusUtil.hasMessageListener(destinationName)) {
        return true;
    }/*from  ww  w .  ja v  a  2s  . co m*/

    for (int i = 0; i < PortletPropsValues.MESSAGE_MAX_ATTEMPTS; i++) {
        Message message = new Message();

        message.put(MESSAGE_KEY_COMMAND, command);
        message.put(MESSAGE_KEY_CONTEXT, context);

        try {
            if (_log.isDebugEnabled()) {
                _log.debug("Send message " + i + " for context " + context + " with command " + command);
            }

            Object response = MessageBusUtil.sendSynchronousMessage(destinationName, message,
                    PortletPropsValues.MESSAGE_TIMEOUT);

            if (_log.isDebugEnabled()) {
                _log.debug("Message " + i + " for context " + context + " with command " + command
                        + " received response " + response);
            }

            if (response.equals(MESSAGE_RESPONSE_SKIP)) {
                return false;
            } else if (response.equals(MESSAGE_RESPONSE_SUCCESS)) {
                return true;
            } else if (response.equals(MESSAGE_RESPONSE_WAIT)) {
                continue;
            } else {
                return true;
            }
        } catch (MessageBusException mbe) {
            if (_log.isWarnEnabled()) {
                _log.warn(mbe.getMessage());
            }
        }

        try {
            Thread.sleep(PortletPropsValues.MESSAGE_TIMEOUT);
        } catch (InterruptedException ie) {
            _log.error(ie, ie);

            return true;
        }
    }

    return true;
}