ApnsService service = null; service = APNS.newService() .withCert(certificatePath, certificatePassword) .withProductionDestination() .asPool(threadCount) .build(); service.start();
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(); }
/** * 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; }