public PushManager get(Product product) { if (StringUtils.isBlank(product.getDevCertPath()) || StringUtils.isBlank(product.getDevCertPass()) || StringUtils.isBlank(product.getCertPath()) || StringUtils.isBlank(product.getCertPass())) { logger.error("Product iOS Push Service Miss Cert Path and Password. {}", product); return null; } PushManager service = mapping.get(product.getId()); if (service == null) { ApnsEnvironment apnsEnvironment = null; SSLContext sslContext = null; try { if (sandBox) { apnsEnvironment = ApnsEnvironment.getSandboxEnvironment(); sslContext = SSLContextUtil.createDefaultSSLContext( product.getDevCertPath(), product.getDevCertPass()); } else { apnsEnvironment = ApnsEnvironment.getProductionEnvironment(); sslContext = SSLContextUtil.createDefaultSSLContext(product.getCertPath(), product.getCertPass()); } } catch (KeyStoreException e) { logger.error(e.getMessage(), e); } catch (NoSuchAlgorithmException e) { logger.error(e.getMessage(), e); } catch (CertificateException e) { logger.error(e.getMessage(), e); } catch (UnrecoverableKeyException e) { logger.error(e.getMessage(), e); } catch (KeyManagementException e) { logger.error(e.getMessage(), e); } catch (IOException e) { logger.error(e.getMessage(), e); } PushManagerConfiguration configuration = new PushManagerConfiguration(); configuration.setConcurrentConnectionCount(1); final PushManager<SimpleApnsPushNotification> pushManager = new PushManager<SimpleApnsPushNotification>( apnsEnvironment, sslContext, null, // Optional: custom event loop group null, // Optional: custom ExecutorService for calling listeners null, // Optional: custom BlockingQueue implementation configuration, "ApnsPushManager-" + product.getId()); pushManager.registerRejectedNotificationListener(new PushRejectedNotificationListener()); pushManager.registerFailedConnectionListener(new PushFailedConnectionListener()); pushManager.start(); // ApnsServiceBuilder builder = APNS.newService(); // if (sandBox){ // builder.withCert(product.getDevCertPath(), product.getDevCertPass()); // builder.withSandboxDestination(); // }else{ // builder.withCert(product.getCertPath(), product.getCertPass()); // builder.withProductionDestination(); // } // service = // builder.asPool(10).withCacheLength(Integer.MAX_VALUE).withDelegate(delegateAdapter).asQueued().build(); mapping.put(product.getId(), pushManager); service = pushManager; } return service; }