com.relayrides.pushy.apns
Class PushManagerFactory<T extends ApnsPushNotification>

java.lang.Object
  extended by com.relayrides.pushy.apns.PushManagerFactory<T>

public class PushManagerFactory<T extends ApnsPushNotification>
extends Object

A PushManagerFactory is used to configure and construct a new PushManager.

Author:
Jon Chambers

Constructor Summary
PushManagerFactory(ApnsEnvironment environment, SSLContext sslContext)
          Constructs a new factory that will construct PushManagers that operate in the given environment with the given credentials.
 
Method Summary
 PushManager<T> buildPushManager()
          Constructs a new PushManager with the settings provided to this factory.
static SSLContext createDefaultSSLContext(KeyStore keyStore, char[] keyStorePassword)
          Creates a new SSL context using the JVM default trust managers and the certificates in the given keystore.
static SSLContext createDefaultSSLContext(String pathToPKCS12File, String keystorePassword)
          Creates a new SSL context using the JVM default trust managers and the certificates in the given PKCS12 file.
 PushManagerFactory<T> setConcurrentConnectionCount(int concurrentConnectionCount)
          Sets the number of concurrent connections constructed PushManagers should maintain to the APNs gateway.
 PushManagerFactory<T> setEventLoopGroup(NioEventLoopGroup eventLoopGroup)
          Sets a custom event loop group to be used by constructed PushMangers.
 PushManagerFactory<T> setListenerExecutorService(ExecutorService listenerExecutorService)
          Sets a custom executor service to be used by constructed PushManagers to dispatch notifications to registered listeners.
 PushManagerFactory<T> setQueue(BlockingQueue<T> queue)
          Sets the queue to be used to pass new notifications to constructed PushManagers.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PushManagerFactory

public PushManagerFactory(ApnsEnvironment environment,
                          SSLContext sslContext)
Constructs a new factory that will construct PushManagers that operate in the given environment with the given credentials.

Parameters:
environment - the environment in which constructed PushManagers will operate
sslContext - the SSL context in which connections controlled by the constructed PushManager will operate
Method Detail

setConcurrentConnectionCount

public PushManagerFactory<T> setConcurrentConnectionCount(int concurrentConnectionCount)

Sets the number of concurrent connections constructed PushManagers should maintain to the APNs gateway. By default, constructed PushManagers will maintain a single connection to the gateway.

Parameters:
concurrentConnectionCount - the number of parallel connections to maintain
Returns:
a reference to this factory for ease of chaining configuration calls

setEventLoopGroup

public PushManagerFactory<T> setEventLoopGroup(NioEventLoopGroup eventLoopGroup)

Sets a custom event loop group to be used by constructed PushMangers. If null, constructed PushManagers will be create and maintain their own event loop groups. If a non-null event loop group is provided, callers must shut down the event loop group after shutting down all PushManager instances that use that event loop group.

By default, constructed PushManagers will construct and maintain their own event loop groups.

Parameters:
eventLoopGroup - the event loop group constructed PushManagers should use for their connections to the APNs gateway and feedback service; if not null, the caller must shut down the event loop group after shutting down all push managers that use the group
Returns:
a reference to this factory for ease of chaining configuration calls

setListenerExecutorService

public PushManagerFactory<T> setListenerExecutorService(ExecutorService listenerExecutorService)

Sets a custom executor service to be used by constructed PushManagers to dispatch notifications to registered listeners. If null, constructed PushManager instances will create and maintain their own executor services. If a non-null executor service is provided, callers must shut down the executor service after shutting down all PushManager instances that use that executor service.

By default, constructed PushManagers will construct and maintain their own executor services.

Parameters:
listenerExecutorService - the executor service to be used by constructed PushManager instances to dispatch notifications to registered listeners; if not null, the caller must shut down the executor service after shutting down all push managers that use the executor service
Returns:
a reference to this factory for ease of chaining configuration calls

setQueue

public PushManagerFactory<T> setQueue(BlockingQueue<T> queue)

Sets the queue to be used to pass new notifications to constructed PushManagers. If null (the default), constructed push managers will construct their own queues.

Parameters:
queue - the queue to be used to pass new notifications to constructed push managers
Returns:
a reference to this factory for ease of chaining configuration calls

buildPushManager

public PushManager<T> buildPushManager()

Constructs a new PushManager with the settings provided to this factory. The returned push manager will not be started automatically.

Returns:
a new, configured PushManager

createDefaultSSLContext

public static SSLContext createDefaultSSLContext(String pathToPKCS12File,
                                                 String keystorePassword)
                                          throws KeyStoreException,
                                                 NoSuchAlgorithmException,
                                                 CertificateException,
                                                 UnrecoverableKeyException,
                                                 KeyManagementException,
                                                 IOException
Creates a new SSL context using the JVM default trust managers and the certificates in the given PKCS12 file.

Parameters:
pathToPKCS12File - the path to a PKCS12 file that contains the client certificate
keystorePassword - the password to read the PKCS12 file; may be null
Returns:
an SSL context configured with the given client certificate and the JVM default trust managers
Throws:
KeyStoreException
NoSuchAlgorithmException
CertificateException
UnrecoverableKeyException
KeyManagementException
IOException

createDefaultSSLContext

public static SSLContext createDefaultSSLContext(KeyStore keyStore,
                                                 char[] keyStorePassword)
                                          throws KeyStoreException,
                                                 NoSuchAlgorithmException,
                                                 UnrecoverableKeyException,
                                                 KeyManagementException
Creates a new SSL context using the JVM default trust managers and the certificates in the given keystore.

Parameters:
keyStore - A KeyStore containing the client certificates to present during a TLS handshake; may be null if the environment does not require TLS. The KeyStore should be loaded before being used here.
keyStorePassword - a password to unlock the given KeyStore; may be null
Returns:
an SSL context configured with the certificates in the given keystore and the JVM default trust managers
Throws:
KeyStoreException
NoSuchAlgorithmException
UnrecoverableKeyException
KeyManagementException


Copyright © 2013–2014 RelayRides. All rights reserved.