Package com.notnoop.apns

Examples of com.notnoop.apns.ApnsNotification


  class SendMessagesBatch implements Runnable {
    public void run() {
      ApnsConnection newConnection = prototype.copy();
      try {
        ApnsNotification msg;
        while ((msg = batch.poll()) != null) {
          try {
            newConnection.sendMessage(msg);
          } catch (NetworkIOException e) {
                        logger.warn("Network exception sending message msg "+ msg.getIdentifier(), e);
                    }
        }
      } finally {
        Utilities.close(newConnection);
      }
View Full Code Here


        shouldContinue = true;
        thread = threadFactory.newThread(new Runnable() {
            public void run() {
                while (shouldContinue) {
                    try {
                        ApnsNotification msg = queue.take();
                        service.push(msg);
                    } catch (InterruptedException e) {
                      // ignore
                    } catch (NetworkIOException e) {
                      // ignore: failed connect...
View Full Code Here

                        logger.debug("Closed connection cause={}; id={}", e, id);
                        delegate.connectionClosed(e, id);

                        Queue<ApnsNotification> tempCache = new LinkedList<ApnsNotification>();
                        ApnsNotification notification = null;
                        boolean foundNotification = false;

                        while (!cachedNotifications.isEmpty()) {
                            notification = cachedNotifications.poll();
                            logger.debug("Candidate for removal, message id {}", notification.getIdentifier());

                            if (notification.getIdentifier() == id) {
                                logger.debug("Bad message found {}", notification.getIdentifier());
                                foundNotification = true;
                                break;
                            }
                            tempCache.add(notification);
                        }

                        if (foundNotification) {
                            logger.debug("delegate.messageSendFailed, message id {}", notification.getIdentifier());
                            delegate.messageSendFailed(notification, new ApnsDeliveryErrorException(e));
                        } else {
                            cachedNotifications.addAll(tempCache);
                            int resendSize = tempCache.size();
                            logger.warn("Received error for message that wasn't in the cache...");
                            if (autoAdjustCacheLength) {
                                cacheLength = cacheLength + (resendSize / 2);
                                delegate.cacheLengthExceeded(cacheLength);
                            }
                            logger.debug("delegate.messageSendFailed, unknown id");
                            delegate.messageSendFailed(null, new ApnsDeliveryErrorException(e));
                        }

                        int resendSize = 0;

                        while (!cachedNotifications.isEmpty()) {

                            resendSize++;
                            final ApnsNotification resendNotification = cachedNotifications.poll();
                            logger.debug("Queuing for resend {}", resendNotification.getIdentifier());
                            notificationsBuffer.add(resendNotification);
                        }
                        logger.debug("resending {} notifications", resendSize);
                        delegate.notificationsResent(resendSize);
View Full Code Here

    public void testConnection() throws NetworkIOException {
        ApnsConnectionImpl testConnection = null;
        try {
            testConnection =
                    new ApnsConnectionImpl(factory, host, port, proxy, proxyUsername, proxyPassword, reconnectPolicy.copy(), delegate);
            final ApnsNotification notification = new EnhancedApnsNotification(0, 0, new byte[]{0}, new byte[]{0});
            testConnection.sendMessage(notification);
        } finally {
            if (testConnection != null) {
                testConnection.close();
            }
View Full Code Here

  }

  @Test
  public void simpleBatchWait_one() throws IOException, InterruptedException {
    // send message
    ApnsNotification message = service.push("1234", "{}");

    // make sure no message was send yet
    verify(prototype, times(0)).copy();
    verify(prototype, times(0)).sendMessage(message);
    verify(prototype, times(0)).close();
View Full Code Here

  }

  @Test
  public void simpleBatchWait_multiple() throws IOException, InterruptedException {
    // send message
    ApnsNotification message1 = service.push("1234", "{}");
    Thread.sleep(delayTimeInSec1_2_millis);
    ApnsNotification message2 = service.push("4321", "{}");

    // make sure no message was send yet
    verify(prototype, times(0)).copy();
    verify(prototype, times(0)).sendMessage(message1);
    verify(prototype, times(0)).sendMessage(message2);
View Full Code Here

  }

  @Test
  public void simpleBatchWait_maxDelay() throws IOException, InterruptedException {
    // send message
    ApnsNotification message1 = service.push("1234", "{}");
    Thread.sleep(delayTimeInSec1_4_millis * 3);
    ApnsNotification message2 = service.push("4321", "{}");
    Thread.sleep(delayTimeInSec1_4_millis * 3);
    ApnsNotification message3 = service.push("4321", "{}");
    Thread.sleep(delayTimeInSec1_4_millis * 3);
    ApnsNotification message4 = service.push("4321", "{}");

    // make sure no message was send yet
    verify(prototype, times(0)).copy();
    verify(prototype, times(0)).sendMessage(message1);
    verify(prototype, times(0)).sendMessage(message2);
View Full Code Here

        shouldContinue = true;
        thread = new Thread() {
            public void run() {
                while (shouldContinue) {
                    try {
                        ApnsNotification msg = queue.take();
                        service.push(msg);
                    } catch (InterruptedException e) {
                    }
                }
            }
View Full Code Here

TOP

Related Classes of com.notnoop.apns.ApnsNotification

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.