Package com.google.android.gcm.server

Examples of com.google.android.gcm.server.MulticastResult


      }
    }
    Message message = messageBuilder.build();
    PushResponse pushResponse = new PushResponse();
    try {
      MulticastResult multicastResult = sender.send(message, Lists.newArrayList(registrationIds), 10);
     
      // analyze the results
      for (int i = 0; i < registrationIds.size(); i++) {
        Result result = multicastResult.getResults().get(i);
        Device device = devices.get(i);
        if (result.getMessageId() != null) {
          LOGGER.info("Sent GCM message to " + device);
          String canonicalRegId = result.getCanonicalRegistrationId();
          if (canonicalRegId != null) {
View Full Code Here


  private void sendMulticastMessage(String multicastKey,
      HttpServletResponse resp) {
    // Recover registration ids from datastore
    List<String> regIds = Datastore.getMulticast(multicastKey);
    Message message = createMessage();
    MulticastResult multicastResult;
    try {
      multicastResult = sender.sendNoRetry(message, regIds);
    } catch (IOException e) {
      logger.log(Level.SEVERE, "Exception posting " + message, e);
      multicastDone(resp, multicastKey);
      return;
    }
    boolean allDone = true;
    // check if any registration id must be updated
    if (multicastResult.getCanonicalIds() != 0) {
      List<Result> results = multicastResult.getResults();
      for (int i = 0; i < results.size(); i++) {
        String canonicalRegId = results.get(i).getCanonicalRegistrationId();
        if (canonicalRegId != null) {
          String regId = regIds.get(i);
          Datastore.updateRegistration(regId, canonicalRegId);
        }
      }
    }
    if (multicastResult.getFailure() != 0) {
      // there were failures, check if any could be retried
      List<Result> results = multicastResult.getResults();
      List<String> retriableRegIds = new ArrayList<String>();
      for (int i = 0; i < results.size(); i++) {
        String error = results.get(i).getErrorCodeName();
        if (error != null) {
          String regId = regIds.get(i);
View Full Code Here

    List<String> devices = new ArrayList<String>();
    devices
        .add("APA91bHeYhgI7-zfNI-X47bqwHsRESL5iimgyDpirRPKGQ-MmuMD0wnvQo6ZKyTgmD2Fh0Qlvre0czu3ewJkhvvm99sW2TO3lXaxfCaXMnz9PEMNxc8egT69uHQGXXr0pdEdrCyJ1v9oqSWVv5gMdiJMijEy0VdZlg");

    MulticastResult result = sendMessageToDevice(CTCommon.API_KEY, devices, "test title", "test msg");
    log.severe("result = " + result.toString());
    return retObj;
  }
View Full Code Here

  }

  private MulticastResult sendMessageToDevice(String apiKey, List<String> devices, String title, String message) {
    Sender sender = new Sender(apiKey);
    Message gcmMessage = new Message.Builder().addData("title", title).addData("message", message).build();
    MulticastResult result = null;
    try {
      result = sender.send(gcmMessage, devices, 3);
    } catch (IOException e) {
      //e.printStackTrace();
      log.severe(e.getMessage());
View Full Code Here

    String rowdata = pnm.getRowdata();
    Map<String, String> extraMap = new HashMap<String, String>();
    extraMap.put("rowdata", rowdata);

    // Create a GCM sender
    MulticastResult result = sendMessageToDevice(CTCommon.API_KEY, devices, title, message, extraMap);
    retJson = (JSONObject) JSONObject.toJSON(result);
    return retJson;
  }
View Full Code Here

    String rowdata = pnm.getRowdata();
    Map<String, String> extraMap = new HashMap<String, String>();
    extraMap.put("rowdata", rowdata);

    // Create a GCM sender
    MulticastResult result = sendMessageToDevice(CTCommon.API_KEY, devices, title, message, extraMap);
    retJson = (JSONObject) JSONObject.toJSON(result);
    return retJson;
  }
View Full Code Here

      for (String key : extraMap.keySet()) {
        builder.addData(key, extraMap.get(key));
      }
    }
    Message gcmMessage = builder.build();
    MulticastResult result = null;
    try {
      result = sender.send(gcmMessage, devices, 3);
    } catch (IOException e) {
      // e.printStackTrace();
      log.severe(e.getMessage());
View Full Code Here

  private void sendMulticastMessage(String multicastKey, String serverStatusKey, HttpServletResponse resp) {
    // Recover registration ids from datastore
    List<String> regIds = Datastore.getMulticast(multicastKey);
    Message message = createMessage(serverStatusKey);
   
    MulticastResult multicastResult;
    try {
      multicastResult = sender.sendNoRetry(message, regIds);
    } catch (IOException e) {
      logger.log(Level.SEVERE, "Exception posting " + message, e);
      multicastDone(resp, multicastKey, serverStatusKey);
      return;
    }
    boolean allDone = true;
    // check if any registration id must be updated
    if (multicastResult.getCanonicalIds() != 0) {
      List<Result> results = multicastResult.getResults();
      for (int i = 0; i < results.size(); i++) {
        String canonicalRegId = results.get(i).getCanonicalRegistrationId();
        if (canonicalRegId != null) {
          String regId = regIds.get(i);
          Datastore.updateRegistration(regId, canonicalRegId);
        }
      }
    }
    if (multicastResult.getFailure() != 0) {
      // there were failures, check if any could be retried
      List<Result> results = multicastResult.getResults();
      List<String> retriableRegIds = new ArrayList<String>();
      for (int i = 0; i < results.size(); i++) {
        String error = results.get(i).getErrorCodeName();
        if (error != null) {
          String regId = regIds.get(i);
View Full Code Here

     */
    private void processGCM(AndroidVariant androidVariant, List<String> registrationIDs, Message gcmMessage, Sender sender) throws IOException {

        logger.log(Level.INFO, "Sending payload for [" + registrationIDs.size() + "] devices to GCM");

        MulticastResult multicastResult = sender.send(gcmMessage, registrationIDs, 0);

        // after sending, let's identify the inactive/invalid registrationIDs and trigger their deletion:
        cleanupInvalidRegistrationIDsForVariant(androidVariant.getVariantID(), multicastResult, registrationIDs);
    }
View Full Code Here

     */
    private void processGCM(AndroidVariant androidVariant, List<String> registrationIDs, Message gcmMessage, Sender sender) throws IOException {

        logger.info("Sending payload for [" + registrationIDs.size() + "] devices to GCM");

        MulticastResult multicastResult = sender.send(gcmMessage, registrationIDs, 0);

        // after sending, let's identify the inactive/invalid registrationIDs and trigger their deletion:
        cleanupInvalidRegistrationIDsForVariant(androidVariant.getVariantID(), multicastResult, registrationIDs);
    }
View Full Code Here

TOP

Related Classes of com.google.android.gcm.server.MulticastResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.