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

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

Introduction

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

Prototype

public static void sendMessage(String destinationName, Object payload) 

Source Link

Usage

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

License:Open Source License

@Override
public void receive(Message message) {
    Object payload = message.getPayload();

    if (payload instanceof KnownDevicesCommand) {
        Message response = MessageBusUtil.createResponseMessage(message);
        Object knownDevices = deviceRecognitionProvider.getKnownDevices();
        response.setPayload(knownDevices);
        MessageBusUtil.sendMessage(message.getResponseDestinationName(), response);
        return;//from  w ww .ja  v  a 2 s.  c o m
    }

    if (payload instanceof DeviceFromRequestCommand) {
        DeviceFromRequestCommand deviceFromRequestCommand = (DeviceFromRequestCommand) payload;
        Message response = MessageBusUtil.createResponseMessage(message);
        Object device = deviceRecognitionProvider.getDeviceFromRequest(deviceFromRequestCommand.getRequest());
        response.setPayload(device);
        MessageBusUtil.sendMessage(message.getResponseDestinationName(), response);
        return;
    }
}

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

License:Open Source License

@Override
public void receive(Message message) {
    Object payload = message.getPayload();

    if (payload instanceof ActionForDeviceCommand) {
        ActionForDeviceCommand command = (ActionForDeviceCommand) payload;
        Message response = MessageBusUtil.createResponseMessage(message);
        Object action = deviceRulesProvider.getAction(command.getDevice(), command.getCompanyId(),
                command.getGroupId(), command.getLayoutId());
        response.setPayload(action);/*ww w  .ja va2s . c  o m*/
        MessageBusUtil.sendMessage(message.getResponseDestinationName(), response);
        return;
    }

    if (payload instanceof RulesListCommand) {
        RulesListCommand command = (RulesListCommand) payload;
        Message response = MessageBusUtil.createResponseMessage(message);
        Object rulesList = deviceRulesProvider.getRules(command.getCompanyId(), command.getGroupId(),
                command.getLayoutId());
        response.setPayload(rulesList);
        MessageBusUtil.sendMessage(message.getResponseDestinationName(), response);
        return;
    }

    if (payload instanceof PortletRequest) {
        PortletRequest request = (PortletRequest) payload;
        Message response = MessageBusUtil.createResponseMessage(message);
        Object errorCodes = deviceRulesProvider.handleRulesRequest(request);
        response.setPayload(errorCodes);
        MessageBusUtil.sendMessage(message.getResponseDestinationName(), response);
        return;
    }
}

From source file:com.inikah.slayer.service.impl.PhotoLocalServiceImpl.java

License:Open Source License

public Photo upload(long imageId, long profileId, File file, String description) {

    Photo photo = null;//  w  ww.j  a v a 2s . co m

    if (imageId == 0l) {
        try {
            imageId = counterLocalService.increment(Image.class.getName());
            photo = createPhoto(imageId);
            photo = addPhoto(photo);
        } catch (SystemException e) {
            e.printStackTrace();
        }
    } else {
        try {
            photo = fetchPhoto(imageId);
        } catch (SystemException e) {
            e.printStackTrace();
        }
    }

    try {
        Image image = imageLocalService.updateImage(imageId, file);
        photo.setContentType(image.getType());
    } catch (PortalException e) {
        e.printStackTrace();
    } catch (SystemException e) {
        e.printStackTrace();
    }

    photo.setUploadDate(new java.util.Date());
    photo.setClassName(Profile.class.getName());
    photo.setClassPK(profileId);
    photo.setDescription(description);
    photo.setImageType(IConstants.IMG_TYPE_PHOTO);

    try {
        photo = updatePhoto(photo);
    } catch (SystemException e) {
        e.printStackTrace();
    }

    //createThumbnail(imageId);
    Message message = new Message();
    message.put("messageName", "createThumbnail");
    message.put("imageId", String.valueOf(imageId));
    MessageBusUtil.sendMessage("inikah/destination", message);

    return photo;
}

From source file:com.inkwell.internet.slogan.service.impl.SloganLocalServiceImpl.java

License:Open Source License

private void sendMessage(Slogan slogan, ServiceContext serviceContext) {

    Message message = new Message();
    message.put("userId", serviceContext.getUserId());
    message.put("slogan", slogan.getSloganText());
    MessageBusUtil.sendMessage("inkwell/slogan", message);
}

From source file:com.library.slayer.service.impl.LMSBookLocalServiceImpl.java

License:Open Source License

public void sendMessage(LMSBook lmsBook, ServiceContext serviceContext) {
    /*/*  w w  w . j av a  2 s . co  m*/
     * Here we are setting the message that Message Bus will carry to the
     * Listener class. Here we are setting the id and name of the book that
     * the user has added into the databse
     */
    Message message = new Message();
    message.put("bookID", lmsBook.getBookId());
    message.put("bookName", lmsBook.getBookTitle());
    /*
     * Now we are sending the message to the listener class
     */
    MessageBusUtil.sendMessage("destinationBus", message);
}

From source file:com.liferay.analytics.internal.osgi.SpringOsgiBridge.java

License:Open Source License

@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {

    MessageBusUtil.sendMessage(AnalyticsServiceActivator.DESTINATION_NAME,
            contextRefreshedEvent.getApplicationContext());
}

From source file:com.liferay.analyticsprocessor.servlet.AnalyticsProcessorServlet.java

License:Open Source License

protected void processEvents(HttpServletRequest request, HttpServletResponse response) throws Exception {

    String themeDisplayDataJSON = ParamUtil.getString(request, "themeDisplayData");

    if (Validator.isNull(themeDisplayDataJSON)) {
        return;//from  w w w.  j a v a 2  s .  co  m
    }

    JSONObject themeDisplayDataJSONObject = JSONFactoryUtil.createJSONObject(themeDisplayDataJSON);

    String eventsJSON = ParamUtil.getString(request, "events", "[]");

    JSONArray eventsJSONArray = JSONFactoryUtil.createJSONArray(eventsJSON);

    if (eventsJSONArray.length() == 0) {
        return;
    }

    AnonymousUser anonymousUser = _anonymousUsersManager.getAnonymousUser(request, response);

    for (int i = 0; i < eventsJSONArray.length(); ++i) {
        Message message = new Message();

        message.put("clientIP", request.getRemoteAddr());
        message.put("userAgent", request.getHeader(HttpHeaders.USER_AGENT));

        copyJSONObjectData(message, themeDisplayDataJSONObject);

        message.put("anonymousUserId", anonymousUser.getAnonymousUserId());

        JSONObject eventJSONObject = eventsJSONArray.getJSONObject(i);

        message.put("event", eventJSONObject.getString("event", "view"));
        message.put("timestamp", eventJSONObject.getString("timestamp"));

        copyJSONObjectData(message, eventJSONObject.getJSONObject("properties"));

        MessageBusUtil.sendMessage("liferay/analytics", message);
    }
}

From source file:com.liferay.anonymoususers.internal.osgi.SpringOsgiBridge.java

License:Open Source License

@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {

    MessageBusUtil.sendMessage(AnonymousUserServiceActivator.DESTINATION_NAME,
            contextRefreshedEvent.getApplicationContext());
}

From source file:com.liferay.client.json.ruon.util.RUONUtil.java

License:Open Source License

public static void updateNetwork(String name, long ttl, Converter converter) throws PortalException {

    Message message = new Message();

    message.put("command", "updateNetwork");
    message.put("name", name);
    message.put("ttl", ttl);
    message.put("converter", converter);

    MessageBusUtil.sendMessage(DestinationNames.RUON, message);
}

From source file:com.liferay.client.json.ruon.util.RUONUtil.java

License:Open Source License

public static void updatePresence(long userId, String networkName, boolean online) throws PortalException {

    Message message = new Message();

    message.put("command", "updatePresence");
    message.put("userId", userId);
    message.put("networkName", networkName);
    message.put("online", online);

    MessageBusUtil.sendMessage(DestinationNames.RUON, message);
}