public class ApnsServiceBuilder extends Object
ApnsService
.
Note that this class is not synchronized. If multiple threads access a
ApnsServiceBuilder
instance concurrently, and at least on of the
threads modifies one of the attributes structurally, it must be
synchronized externally.
Starting a new ApnsService
is easy:
ApnsService = APNS.newService() .withCert("/path/to/certificate.p12", "MyCertPassword") .withSandboxDestination() .build()
Constructor and Description |
---|
ApnsServiceBuilder()
Constructs a new instance of
ApnsServiceBuilder |
Modifier and Type | Method and Description |
---|---|
ApnsServiceBuilder |
asBatched()
Construct service which will process notification requests in batch.
|
ApnsServiceBuilder |
asBatched(int waitTimeInSec,
int maxWaitTimeInSec)
Construct service which will process notification requests in batch.
|
ApnsServiceBuilder |
asBatched(int waitTimeInSec,
int maxWaitTimeInSec,
ScheduledExecutorService batchThreadPoolExecutor)
Construct service which will process notification requests in batch.
|
ApnsServiceBuilder |
asBatched(int waitTimeInSec,
int maxWaitTimeInSec,
ThreadFactory threadFactory)
Construct service which will process notification requests in batch.
|
ApnsServiceBuilder |
asPool(ExecutorService executor,
int maxConnections)
Constructs a pool of connections to the notification servers.
|
ApnsServiceBuilder |
asPool(int maxConnections)
Constructs a pool of connections to the notification servers.
|
ApnsServiceBuilder |
asQueued()
Constructs a new thread with a processing queue to process
notification requests.
|
ApnsServiceBuilder |
asQueued(ThreadFactory threadFactory)
Constructs a new thread with a processing queue to process
notification requests.
|
ApnsService |
build()
Returns a fully initialized instance of
ApnsService ,
according to the requested settings. |
ApnsServiceBuilder |
withAppleDestination(boolean isProduction)
Specify to use Apple servers as iPhone gateway and feedback servers.
|
ApnsServiceBuilder |
withAuthProxy(Proxy proxy,
String proxyUsername,
String proxyPassword)
Specify the proxy and the authentication parameters to be used
to establish the connections to Apple Servers.
|
ApnsServiceBuilder |
withAutoAdjustCacheLength(boolean autoAdjustCacheLength)
Specify if the notification cache should auto adjust.
|
ApnsServiceBuilder |
withCacheLength(int cacheLength)
Specify the number of notifications to cache for error purposes.
|
ApnsServiceBuilder |
withCert(InputStream stream,
String password)
Specify the certificate used to connect to Apple APNS
servers.
|
ApnsServiceBuilder |
withCert(InputStream stream,
String password,
String alias)
Specify the certificate store used to connect to Apple APNS
servers.
|
ApnsServiceBuilder |
withCert(KeyStore keyStore,
String password)
Specify the certificate used to connect to Apple APNS
servers.
|
ApnsServiceBuilder |
withCert(KeyStore keyStore,
String password,
String alias)
Specify the certificate store used to connect to Apple APNS
servers.
|
ApnsServiceBuilder |
withCert(String fileName,
String password)
Specify the certificate used to connect to Apple APNS
servers.
|
ApnsServiceBuilder |
withConnectTimeout(int connectTimeout)
Specify the timeout value to use for connectionTimeout in created
sockets, for both feedback and push connections, in milliseconds.
|
ApnsServiceBuilder |
withDelegate(ApnsDelegate delegate)
Sets the delegate of the service, that gets notified of the
status of message delivery.
|
ApnsServiceBuilder |
withErrorDetectionThreadFactory(ThreadFactory threadFactory)
Provide a custom source for threads used for monitoring connections.
|
ApnsServiceBuilder |
withFeedbackDestination(String host,
int port)
Specify the Feedback for getting failed devices from
Apple iPhone Push servers.
|
ApnsServiceBuilder |
withGatewayDestination(String host,
int port)
Specify the gateway server for sending Apple iPhone
notifications.
|
ApnsServiceBuilder |
withNoErrorDetection()
Disables the enhanced error detection, enabled by the
enhanced push notification interface.
|
ApnsServiceBuilder |
withProductionDestination()
Specify to use the Apple Production servers as iPhone gateway
and feedback servers.
|
ApnsServiceBuilder |
withProxy(Proxy proxy)
Specify the proxy to be used to establish the connections
to Apple Servers
|
ApnsServiceBuilder |
withProxySocket(Socket proxySocket)
Deprecated.
use
withProxy(Proxy) instead |
ApnsServiceBuilder |
withReadTimeout(int readTimeout)
Specify the timeout value to be set in new setSoTimeout in created
sockets, for both feedback and push connections, in milliseconds.
|
ApnsServiceBuilder |
withReconnectPolicy(ReconnectPolicy.Provided rp)
Specify the reconnection policy for the socket connection.
|
ApnsServiceBuilder |
withReconnectPolicy(ReconnectPolicy rp)
Specify the reconnection policy for the socket connection.
|
ApnsServiceBuilder |
withSandboxDestination()
Specify to use the Apple sandbox servers as iPhone gateway
and feedback servers.
|
ApnsServiceBuilder |
withSocksProxy(String host,
int port)
Specify the address of the SOCKS proxy the connection should
use.
|
ApnsServiceBuilder |
withSSLContext(SSLContext sslContext)
Specify the SSLContext that should be used to initiate the
connection to Apple Server.
|
public ApnsServiceBuilder()
ApnsServiceBuilder
public ApnsServiceBuilder withCert(String fileName, String password) throws RuntimeIOException, InvalidSSLConfig
fileName
- the path to the certificatepassword
- the password of the keystoreRuntimeIOException
- if it fileName
cannot be
found or readInvalidSSLConfig
- if fileName is invalid Keystore
or the password is invalidpublic ApnsServiceBuilder withCert(InputStream stream, String password) throws InvalidSSLConfig
stream
- the keystore represented as input streampassword
- the password of the keystoreInvalidSSLConfig
- if stream is invalid Keystore
or the password is invalidpublic ApnsServiceBuilder withCert(KeyStore keyStore, String password) throws InvalidSSLConfig
keyStore
- the keystorepassword
- the password of the keystoreInvalidSSLConfig
- if stream is invalid Keystore
or the password is invalidpublic ApnsServiceBuilder withCert(InputStream stream, String password, String alias) throws InvalidSSLConfig
stream
- the keystore represented as input streampassword
- the password of the keystorealias
- the alias identifing the key to be usedInvalidSSLConfig
- if stream is an invalid Keystore,
the password is invalid or the alias is not foundpublic ApnsServiceBuilder withCert(KeyStore keyStore, String password, String alias) throws InvalidSSLConfig
keyStore
- the keystorepassword
- the password of the keystorealias
- the alias identifing the key to be usedInvalidSSLConfig
- if stream is an invalid Keystore,
the password is invalid or the alias is not foundpublic ApnsServiceBuilder withSSLContext(SSLContext sslContext)
withCert(InputStream, String)
or withCert(String, String)
instead. But some
clients may need to represent the Keystore in a different
format than supported.sslContext
- Context to be used to create secure connectionspublic ApnsServiceBuilder withReadTimeout(int readTimeout)
readTimeout
- timeout value to be set in new setSoTimeoutpublic ApnsServiceBuilder withConnectTimeout(int connectTimeout)
connectTimeout
- timeout value to use for connectionTimeoutpublic ApnsServiceBuilder withGatewayDestination(String host, int port)
withSandboxDestination()
or withProductionDestination()
. Clients may use
this method to connect to mocking tests and such.host
- hostname the notification gateway of Appleport
- port of the notification gateway of Applepublic ApnsServiceBuilder withFeedbackDestination(String host, int port)
withSandboxDestination()
or withProductionDestination()
. Clients may use
this method to connect to mocking tests and such.host
- hostname of the feedback server of Appleport
- port of the feedback server of Applepublic ApnsServiceBuilder withAppleDestination(boolean isProduction)
isProduction
is true, then it connects to the
production servers, otherwise, it connects to the sandbox serversisProduction
- determines which Apple servers should be used:
production or sandboxpublic ApnsServiceBuilder withSandboxDestination()
public ApnsServiceBuilder withProductionDestination()
public ApnsServiceBuilder withReconnectPolicy(ReconnectPolicy rp)
public ApnsServiceBuilder withAutoAdjustCacheLength(boolean autoAdjustCacheLength)
autoAdjustCacheLength
- the notification cache should auto adjust.public ApnsServiceBuilder withReconnectPolicy(ReconnectPolicy.Provided rp)
public ApnsServiceBuilder withSocksProxy(String host, int port)
Read the Java Networking and Proxies guide to understand the proxies complexity.
Be aware that this method only handles SOCKS proxies, not
HTTPS proxies. Use withProxy(Proxy)
instead.
host
- the hostname of the SOCKS proxyport
- the port of the SOCKS proxy serverpublic ApnsServiceBuilder withAuthProxy(Proxy proxy, String proxyUsername, String proxyPassword)
Read the Java Networking and Proxies guide to understand the proxies complexity.
proxy
- the proxy object to be used to create connectionsproxyUsername
- a String object representing the username of the proxy serverproxyPassword
- a String object representing the password of the proxy serverpublic ApnsServiceBuilder withProxy(Proxy proxy)
Read the Java Networking and Proxies guide to understand the proxies complexity.
proxy
- the proxy object to be used to create connectionspublic ApnsServiceBuilder withCacheLength(int cacheLength)
cacheLength
- Number of notifications to cache for error purposes@Deprecated public ApnsServiceBuilder withProxySocket(Socket proxySocket)
withProxy(Proxy)
insteadproxySocket
- the underlying socket for connectionspublic ApnsServiceBuilder asPool(int maxConnections)
public ApnsServiceBuilder asPool(ExecutorService executor, int maxConnections)
public ApnsServiceBuilder asQueued()
public ApnsServiceBuilder asQueued(ThreadFactory threadFactory)
threadFactory
- thread factory to use for queue processingpublic ApnsServiceBuilder asBatched()
waitTimeInSec (set as 5sec)
for more request to come
before executing but not more than maxWaitTimeInSec (set as 10sec)
Note: It is not recommended to use pooled connectionpublic ApnsServiceBuilder asBatched(int waitTimeInSec, int maxWaitTimeInSec)
waitTimeInSec
for more request to come
before executing but not more than maxWaitTimeInSec
Note: It is not recommended to use pooled connectionwaitTimeInSec
- time to wait for more notification request before executing
batchmaxWaitTimeInSec
- maximum wait time for batch before executingpublic ApnsServiceBuilder asBatched(int waitTimeInSec, int maxWaitTimeInSec, ThreadFactory threadFactory)
waitTimeInSec
for more request to come
before executing but not more than maxWaitTimeInSec
Each batch creates new connection and close it after finished.
In case reconnect policy is specified it will be applied by batch processing.
E.g.: ReconnectPolicy.Provided.EVERY_HALF_HOUR
will reconnect the connection in case batch is running for more than half an hour
Note: It is not recommended to use pooled connectionwaitTimeInSec
- time to wait for more notification request before executing
batchmaxWaitTimeInSec
- maximum wait time for batch before executingthreadFactory
- thread factory to use for batch processingpublic ApnsServiceBuilder asBatched(int waitTimeInSec, int maxWaitTimeInSec, ScheduledExecutorService batchThreadPoolExecutor)
waitTimeInSec
for more request to come
before executing but not more than maxWaitTimeInSec
Each batch creates new connection and close it after finished.
In case reconnect policy is specified it will be applied by batch processing.
E.g.: ReconnectPolicy.Provided.EVERY_HALF_HOUR
will reconnect the connection in case batch is running for more than half an hour
Note: It is not recommended to use pooled connectionwaitTimeInSec
- time to wait for more notification request before executing
batchmaxWaitTimeInSec
- maximum wait time for batch before executingbatchThreadPoolExecutor
- executor for batched processing (may be null)public ApnsServiceBuilder withDelegate(ApnsDelegate delegate)
public ApnsServiceBuilder withNoErrorDetection()
public ApnsServiceBuilder withErrorDetectionThreadFactory(ThreadFactory threadFactory)
threadFactory
- thread factory to use for error detectionpublic ApnsService build()
ApnsService
,
according to the requested settings.Copyright © 2015. All rights reserved.