Package com.google.android.gcm.server

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


    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) {
            // same device has more than on registration id: update it
            device.updateRegistrationId(canonicalRegId);
            pushResponse.addDeviceToUpdate(device);
            LOGGER.info("Updated registration id of device " + device);
          }
        } else {
          String error = result.getErrorCodeName();
          if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
            // Application has been removed from device - unregister it
            pushResponse.addDeviceToRemove(device);
            LOGGER.info("Unregistered device " + device);
          } else {
View Full Code Here


  }

  private void sendSingleMessage(String regId, HttpServletResponse resp) {
    logger.info("Sending message to device " + regId);
    Message message = createMessage();
    Result result;
    try {
      result = sender.sendNoRetry(message, regId);
    } catch (IOException e) {
      logger.log(Level.SEVERE, "Exception posting " + message, e);
      taskDone(resp);
      return;
    }
    if (result == null) {
      retryTask(resp);
      return;
    }
    if (result.getMessageId() != null) {
      logger.info("Succesfully sent message to device " + regId);
      String canonicalRegId = result.getCanonicalRegistrationId();
      if (canonicalRegId != null) {
        // same device has more than on registration id: update it
        logger.finest("canonicalRegId " + canonicalRegId);
        Datastore.updateRegistration(regId, canonicalRegId);
      }
    } else {
      String error = result.getErrorCodeName();
      if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
        // application has been removed from device - unregister it
        Datastore.unregister(regId);
      } else {
        logger.severe("Error sending message to device " + regId
View Full Code Here

                Sender sender = new Sender(myApiKey);
                Message.Builder message = new Message.Builder();
                for (Map.Entry<String, String> entry : data.entrySet()) {
                    message.addData(entry.getKey(), entry.getValue());
                }
                Result result = sender.send(message.build(), registrationId, 5);

                if (result.getMessageId() != null) {
                    String canonicalRegId = result.getCanonicalRegistrationId();
                    if (canonicalRegId != null) {
                        // same device has more than on registration ID: update database
                        user.setAndroidId(canonicalRegId);
                        database.saveUser(user);
                    }
                }
                else {
                    String error = result.getErrorCodeName();
                    if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
                        // application has been removed from device - unregister database
                        user.setAndroidId(null);
                        database.saveUser(user);
                       
View Full Code Here

        final Set<String> inactiveTokens = new HashSet<String>();

        // read the results:
        for (int i = 0; i < results.size(); i++) {
            // use the current index to access the individual results
            Result result = results.get(i);

            // is there an error code that indicates an invalid regID ?
            if (Constants.ERROR_INVALID_REGISTRATION.equals(result.getErrorCodeName())) {

                // Ok the result at INDEX 'i' was an 'InvalidRegistration'!

                // Now use the INDEX of the 'InvalidRegistration' result object, and look
                // for the matching registrationID inside of the List that contains
View Full Code Here

        final Set<String> inactiveTokens = new HashSet<String>();

        // read the results:
        for (int i = 0; i < results.size(); i++) {
            // use the current index to access the individual results
            Result result = results.get(i);

            // is there an error code that indicates an invalid regID ?
            if (Constants.ERROR_INVALID_REGISTRATION.equals(result.getErrorCodeName())) {

                // Ok the result at INDEX 'i' was an 'InvalidRegistration'!

                // Now use the INDEX of the 'InvalidRegistration' result object, and look
                // for the matching registrationID inside of the List that contains
View Full Code Here

        final Set<String> inactiveTokens = new HashSet<String>();

        // read the results:
        for (int i = 0; i < results.size(); i++) {
            // use the current index to access the individual results
            Result result = results.get(i);

            // is there an error code that indicates an invalid regID ?
            if (Constants.ERROR_INVALID_REGISTRATION.equals(result.getErrorCodeName())) {

                // Ok the result at INDEX 'i' was an 'InvalidRegistration'!

                // Now use the INDEX of the 'InvalidRegistration' result object, and look
                // for the matching registrationID inside of the List that contains
View Full Code Here

        final Set<String> inactiveTokens = new HashSet<String>();

        // read the results:
        for (int i = 0; i < results.size(); i++) {
            // use the current index to access the individual results
            Result result = results.get(i);

            // is there an error code that indicates an invalid regID ?
            if (Constants.ERROR_INVALID_REGISTRATION.equals(result.getErrorCodeName())) {

                // Ok the result at INDEX 'i' was an 'InvalidRegistration'!

                // Now use the INDEX of the 'InvalidRegistration' result object, and look
                // for the matching registrationID inside of the List that contains
View Full Code Here

    new Thread(new Runnable() {
      @Override
      public void run() {
        try {
          LOG.debug("Send GCM message to the device {}", registrationId);
          Result result = sender.send(tickleMessage, registrationId, bufferConfig.gcmSendRetries());
          if (result.getMessageId() == null) {
            LOG.error("Could not send the tickle messge. Reason: {}", result.getErrorCodeName());
            pendingRequest.failed("Cannot send message over GCM. Reason: " + result.getErrorCodeName());
          } else {
            LOG.debug("Successfully sent the message over GCM");
            if (result.getCanonicalRegistrationId() != null) {
              LOG.debug("Update the registration id {} to canonical name {}", registrationId,
                  result.getCanonicalRegistrationId());
              registrationId = result.getCanonicalRegistrationId();
            }
          }
        } catch (IOException e) {
          LOG.error("Cannot send tickle message to device {}", registrationId, e);
          pendingRequest.failed(e);
View Full Code Here

TOP

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

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.