congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ApnsService
Code IndexAdd Tabnine to your IDE (free)

How to use
ApnsService
in
com.notnoop.apns

Best Java code snippets using com.notnoop.apns.ApnsService (Showing top 15 results out of 315)

origin: stackoverflow.com

 ApnsService service =
   APNS.newService()
   .withCert("/etc/Certificates.p12", "password")
   .withSandboxDestination() // or .withProductionDestination()
   .build();

String payload =
  APNS.newPayload()
  .alertBody("My alert message")
  .badge(45)
  .sound("default")
  .build();

String deviceToken = "f4201f5d8278fe39545349d0868a24a3b60ed732";

log.warn("Sending push notification...");
service.push(deviceToken, payload);
origin: com.notnoop.apns/apns

@Override
public Map<String, Date> getInactiveDevices() throws NetworkIOException {
  return service.getInactiveDevices();
}
origin: stackoverflow.com

ApnsService service = null;
   service = APNS.newService()
       .withCert(certificatePath, certificatePassword)
       .withProductionDestination()
       .asPool(threadCount)
       .build();
   service.start();
origin: stackoverflow.com

 final InputStream certificate = Thread.currentThread().getContextClassLoader()
    .getResourceAsStream("aps_dev_credentials.p12");
final char[] passwd = {'1','2','3','4'};
final ApnsService apnsService = com.notnoop.apns.APNS.newService()
    .withCert(certificate, new String(passwd))
    .withSandboxDestination().build();
apnsService.testConnection();
origin: signalapp/PushServer

@Override
public void stop() throws Exception {
 pushApnService.stop();
 voipApnService.stop();
}
origin: org.apache.camel/camel-apns

private List<InactiveDevice> getInactiveDevices() {
  ApnsEndpoint ae = getEndpoint();
  Map<String, Date> inactiveDeviceMap = ae.getApnsService().getInactiveDevices();
  List<InactiveDevice> inactiveDeviceList = new ArrayList<>();
  for (Entry<String, Date> inactiveDeviceEntry : inactiveDeviceMap.entrySet()) {
    String deviceToken = inactiveDeviceEntry.getKey();
    Date date = inactiveDeviceEntry.getValue();
    InactiveDevice inactiveDevice = new InactiveDevice(deviceToken, date);
    inactiveDeviceList.add(inactiveDevice);
  }
  return inactiveDeviceList;
}
origin: com.notnoop.apns/apns

public void start() {
  if (started.getAndSet(true)) {
    // I prefer if we throw a runtime IllegalStateException here,
    // but I want to maintain semantic backward compatibility.
    // So it is returning immediately here
    return;
  }
  service.start();
  shouldContinue = true;
  thread = new Thread() {
    public void run() {
      while (shouldContinue) {
        try {
          ApnsNotification msg = queue.take();
          service.push(msg);
        } catch (InterruptedException e) {
          // ignore
        } catch (NetworkIOException e) {
          // ignore: failed connect...
        } catch (Exception e) {
          // weird if we reached here - something wrong is happening, but we shouldn't stop the service anyway!
          logger.warn("Unexpected message caught... Shouldn't be here", e);
        }
      }
    }
  };
  thread.start();
}
origin: com.notnoop.apns/apns

public void testConnection() throws NetworkIOException {
  service.testConnection();
}
origin: com.notnoop.apns/apns

public void stop() {
  started.set(false);
  shouldContinue = false;
  thread.interrupt();
  service.stop();
}
origin: com.notnoop.apns/apns

  public void run() {
    while (shouldContinue) {
      try {
        ApnsNotification msg = queue.take();
        service.push(msg);
      } catch (InterruptedException e) {
        // ignore
      } catch (NetworkIOException e) {
        // ignore: failed connect...
      } catch (Exception e) {
        // weird if we reached here - something wrong is happening, but we shouldn't stop the service anyway!
        logger.warn("Unexpected message caught... Shouldn't be here", e);
      }
    }
  }
};
origin: signalapp/PushServer

 @Override
 public void run() {
  Map<String, Date> inactiveDevices = pushApnService.getInactiveDevices();
  inactiveDevices.putAll(voipApnService.getInactiveDevices());
  for (String registrationId : inactiveDevices.keySet()) {
   Optional<String> device = redisGet(registrationId);
   if (device.isPresent()) {
    logger.warn("Got APN unregistered notice!");
    String[] parts    = device.get().split(".", 2);
    if (parts.length == 2) {
     String number    = parts[0];
     int    deviceId  = Integer.parseInt(parts[1]);
     long   timestamp = inactiveDevices.get(registrationId).getTime();
     unregisteredQueue.put(new UnregisteredEvent(registrationId, null, number, deviceId, timestamp));
    } else {
     logger.warn("APN unregister event for device with no parts: " + device.get());
    }
   } else {
    logger.warn("APN unregister event received for uncached ID: " + registrationId);
   }
  }
 }
}
origin: com.notnoop.apns/apns

/**
 * Returns a fully initialized instance of {@link ApnsService},
 * according to the requested settings.
 *
 * @return  a new instance of ApnsService
 */
public ApnsService build() {
  checkInitialization();
  ApnsService service;
  SSLSocketFactory sslFactory = sslContext.getSocketFactory();
  ApnsFeedbackConnection feedback = new ApnsFeedbackConnection(sslFactory, feedbackHost, feedbackPort, proxy);
  ApnsConnection conn = new ApnsConnectionImpl(sslFactory, gatewayHost, 
      gatewaPort, proxy, reconnectPolicy, 
      delegate, errorDetection, cacheLength, autoAdjustCacheLength);
  if (pooledMax != 1) {
    conn = new ApnsPooledConnection(conn, pooledMax, executor);
  }
  service = new ApnsServiceImpl(conn, feedback);
  if (isQueued) {
    service = new QueuedApnsService(service);
  }
  
  if (isBatched) {
    service = new BatchApnsService(conn, feedback, batchWaitTimeInSec, batchMaxWaitTimeInSec, batchThreadFactory);
  }
  service.start();
  return service;
}
origin: org.apache.camel/camel-apns

private void notify(Exchange exchange) throws ApnsException {
  MessageType messageType = getHeaderMessageType(exchange, MessageType.STRING);
  if (messageType == MessageType.APNS_NOTIFICATION) {
    ApnsNotification apnsNotification = exchange.getIn().getBody(ApnsNotification.class);
    getEndpoint().getApnsService().push(apnsNotification);
  } else {
    constructNotificationAndNotify(exchange, messageType);
  }
}
origin: org.apache.camel/camel-apns

private void constructNotificationAndNotify(Exchange exchange, MessageType messageType) {
  String payload;
  Collection<String> tokens;
  if (isTokensConfiguredUsingUri()) {
    if (hasTokensHeader(exchange)) {
      throw new IllegalArgumentException("Tokens already configured on endpoint " + ApnsConstants.HEADER_TOKENS);
    }
    tokens = new ArrayList<>(tokenList);
  } else {
    String tokensHeader = getHeaderTokens(exchange);
    tokens = extractTokensFromString(tokensHeader);
  }
  if (messageType == MessageType.STRING) {
    String message = exchange.getIn().getBody(String.class);
    payload = APNS.newPayload().alertBody(message).build();
  } else {
    String message = exchange.getIn().getBody(String.class);
    payload = message;
  }
  Date expiry = exchange.getIn().getHeader(ApnsConstants.HEADER_EXPIRY, Date.class);
  if (expiry != null) {
    getEndpoint().getApnsService().push(tokens, payload, expiry);
  } else {
    getEndpoint().getApnsService().push(tokens, payload);
  }
}
origin: signalapp/PushServer

public void sendMessage(ApnMessage message)
  throws TransientPushFailureException
{
 try {
  redisSet(message.getApnId(), message.getNumber(), message.getDeviceId());
  if (message.isVoip()) {
   voipApnService.push(message.getApnId(), message.getMessage(), new Date(message.getExpirationTime()));
   voipMeter.mark();
  } else {
   pushApnService.push(message.getApnId(), message.getMessage(), new Date(message.getExpirationTime()));
   pushMeter.mark();
  }
 } catch (NetworkIOException nioe) {
  logger.warn("Network Error", nioe);
  failureMeter.mark();
  throw new TransientPushFailureException(nioe);
 }
}
com.notnoop.apnsApnsService

Javadoc

Represents the connection and interface to the Apple APNS servers. The service is created by ApnsServiceBuilder like:
 
ApnsService = APNS.newService() 
.withCert("/path/to/certificate.p12", "MyCertPassword") 
.withSandboxDestination() 
.build() 

Most used methods

  • push
  • getInactiveDevices
    Returns the list of devices that reported failed-delivery attempts to the Apple Feedback services. T
  • start
    Starts the service. The underlying implementation may prepare its connections or datastructures to b
  • stop
    Stops the service and frees any allocated resources it created for this service. The underlying impl
  • testConnection
    Test that the service is setup properly and the Apple servers are reachable.

Popular in Java

  • Reading from database using SQL prepared statement
  • getSupportFragmentManager (FragmentActivity)
  • requestLocationUpdates (LocationManager)
  • getSystemService (Context)
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • InputStreamReader (java.io)
    A class for turning a byte stream into a character stream. Data read from the source input stream is
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now