Class BenchmarkApnsServerBuilder

java.lang.Object
com.eatthepath.pushy.apns.server.BenchmarkApnsServerBuilder

public class BenchmarkApnsServerBuilder extends Object

A BenchmarkApnsServerBuilder constructs new BenchmarkApnsServer instances. Callers must supply server credentials via one of the setServerCredentials methods prior to constructing a new server with the build() method; all other settings are optional.

Server builders may be reused to generate multiple servers, and their settings may be changed from one server to the next.

Since:
0.13.0
Author:
Jon Chambers
  • Field Details

    • DEFAULT_MAX_CONCURRENT_STREAMS

      public static final int DEFAULT_MAX_CONCURRENT_STREAMS
      The default maximum number of concurrent streams for an APNs server, which matches the default limit set by the real APNs server at the time of this writing.
      See Also:
  • Constructor Details

    • BenchmarkApnsServerBuilder

      public BenchmarkApnsServerBuilder()
  • Method Details

    • setServerCredentials

      public BenchmarkApnsServerBuilder setServerCredentials(File certificatePemFile, File privateKeyPkcs8File, String privateKeyPassword)

      Sets the credentials for the server under construction using the certificates in the given PEM file and the private key in the given PKCS#8 file.

      Parameters:
      certificatePemFile - a PEM file containing the certificate chain for the server under construction
      privateKeyPkcs8File - a PKCS#8 file containing the private key for the server under construction
      privateKeyPassword - the password for the given private key, or null if the key is not password-protected
      Returns:
      a reference to this builder
    • setServerCredentials

      public BenchmarkApnsServerBuilder setServerCredentials(InputStream certificatePemInputStream, InputStream privateKeyPkcs8InputStream, String privateKeyPassword)

      Sets the credentials for the server under construction using the certificates in the given PEM input stream and the private key in the given PKCS#8 input stream.

      Parameters:
      certificatePemInputStream - a PEM input stream containing the certificate chain for the server under construction
      privateKeyPkcs8InputStream - a PKCS#8 input stream containing the private key for the server under construction
      privateKeyPassword - the password for the given private key, or null if the key is not password-protected
      Returns:
      a reference to this builder
    • setServerCredentials

      public BenchmarkApnsServerBuilder setServerCredentials(X509Certificate[] certificates, PrivateKey privateKey, String privateKeyPassword)

      Sets the credentials for the server under construction.

      Parameters:
      certificates - a certificate chain including the server's own certificate
      privateKey - the private key for the server's certificate
      privateKeyPassword - the password for the given private key, or null if the key is not password-protected
      Returns:
      a reference to this builder
    • setTrustedClientCertificateChain

      public BenchmarkApnsServerBuilder setTrustedClientCertificateChain(File certificatePemFile)

      Sets the trusted certificate chain for the server under construction using the contents of the given PEM file. If not set (or null), the server will use the JVM's default trust manager.

      In development environments, callers will almost always need to provide a trusted certificate chain for clients (since clients in development environments will generally not present credentials recognized by the JVM's default trust manager).

      Parameters:
      certificatePemFile - a PEM file containing one or more trusted certificates
      Returns:
      a reference to this builder
    • setTrustedClientCertificateChain

      public BenchmarkApnsServerBuilder setTrustedClientCertificateChain(InputStream certificateInputStream)

      Sets the trusted certificate chain for the server under construction using the contents of the given PEM input stream. If not set (or null), the server will use the JVM's default trust manager.

      In development environments, callers will almost always need to provide a trusted certificate chain for clients (since clients in development environments will generally not present credentials recognized by the JVM's default trust manager).

      Parameters:
      certificateInputStream - an input stream to PEM-formatted data containing one or more trusted certificates
      Returns:
      a reference to this builder
    • setTrustedServerCertificateChain

      public BenchmarkApnsServerBuilder setTrustedServerCertificateChain(X509Certificate... certificates)

      Sets the trusted certificate chain for the server under construction. If not set (or null), the server will use the JVM's default trust manager.

      In development environments, callers will almost always need to provide a trusted certificate chain for clients (since clients in development environments will generally not present credentials recognized by the JVM's default trust manager).

      Parameters:
      certificates - one or more trusted certificates
      Returns:
      a reference to this builder
    • setEventLoopGroup

      public BenchmarkApnsServerBuilder setEventLoopGroup(EventLoopGroup eventLoopGroup)

      Sets the event loop group to be used by the server under construction. If not set (or if null), the server will create and manage its own event loop group.

      Parameters:
      eventLoopGroup - the event loop group to use for this server, or null to let the server manage its own event loop group
      Returns:
      a reference to this builder
    • setMaxConcurrentStreams

      public BenchmarkApnsServerBuilder setMaxConcurrentStreams(int maxConcurrentStreams)
      Sets the maximum number of concurrent HTTP/2 streams allowed by the server under construction. By default, mock servers will have a concurrent stream limit of 1500<T extends com.eatthepath.pushy.apns.server.BaseHttp2Server>.
      Parameters:
      maxConcurrentStreams - the maximum number of concurrent HTTP/2 streams allowed by the server under construction; must be positive
      Returns:
      a reference to this builder
    • setUseAlpn

      public BenchmarkApnsServerBuilder setUseAlpn(boolean useAlpn)

      Sets whether the server under construction should use ALPN. By default, mock servers do not use ALPN and instead require clients to use direct negotiation.

      Note that Pushy itself does not require (or even use) ALPN and always uses direct protocol negotiation. ALPN is only useful in cases where Pushy's mock server is being used with a non-Pushy APNs client.

      Note also that turning on ALPN support may introduce new system requirements for the mock server. Prior to version 9, Java does not include support for ALPN, and so it will need to be provided by thid-party software such as the Jetty ALPN agent or Netty's netty-tcnative package.

      Parameters:
      useAlpn - true to enable ALPN support, or false to require direct protocol negotiation
      Returns:
      a reference to this builder
      See Also:
    • build

      public BenchmarkApnsServer build() throws SSLException
      Constructs a new server with the previously-set configuration.
      Returns:
      a new server instance with the previously-set configuration
      Throws:
      SSLException - if an SSL context could not be created for the new server for any reason