Class ConnectionPoolSegment.Initializer

java.lang.Object
org.attribyte.sql.pool.ConnectionPoolSegment.Initializer
Enclosing class:
ConnectionPoolSegment

public static class ConnectionPoolSegment.Initializer extends Object
Initializes and creates a connection pool segment.
  • Constructor Details

    • Initializer

      public Initializer()
      Creates an empty initializer.
    • Initializer

      public Initializer(ConnectionPoolSegment.Initializer other)
      Creates an initializer from another.

      Does not copy the name segment name.

      Parameters:
      other - The other initializer.
  • Method Details

    • setName

      Sets the name of the segment.
      Parameters:
      name - The segment name.
      Returns:
      A self-reference.
    • setLogger

      public ConnectionPoolSegment.Initializer setLogger(org.attribyte.api.Logger logger)
      Sets the logger for this segment.
      Parameters:
      logger - The logger.
      Returns:
      A self-reference.
    • setSize

      public ConnectionPoolSegment.Initializer setSize(int size)
      Sets the number of connections in the segment.
      Parameters:
      size - The segment size.
      Returns:
      A self-reference.
    • setAcquireTimeout

      public ConnectionPoolSegment.Initializer setAcquireTimeout(long timeout, TimeUnit timeoutUnit)
      Sets the maximum amount of time to wait for a connection if all are busy.
      Parameters:
      timeout - The timeout value.
      timeoutUnit - The timeout units.
      Returns:
      A self-reference.
    • setActiveTimeout

      public ConnectionPoolSegment.Initializer setActiveTimeout(long timeout, TimeUnit timeoutUnit)
      Sets the maximum amount of time a connection may be active before automatically closed.
      Parameters:
      timeout - The timeout value.
      timeoutUnit - The timeout units.
      Returns:
      A self-reference.
    • setActiveTimeoutMonitorFrequency

      public ConnectionPoolSegment.Initializer setActiveTimeoutMonitorFrequency(long timeout, TimeUnit timeoutUnit)
      Sets the frequency the active timeout monitor runs.
      Parameters:
      timeout - The frequency value.
      timeoutUnit - The frequency units.
      Returns:
      A self-reference.
    • setConnectionLifetime

      public ConnectionPoolSegment.Initializer setConnectionLifetime(long connectionLife, TimeUnit connectionLifeUnit)
      Sets the lifetime of (real) connections before automatic close/reopen.
      Parameters:
      connectionLife - The connection life.
      connectionLifeUnit - The connection life units.
      Returns:
      A self-reference.
    • setConnection

      public ConnectionPoolSegment.Initializer setConnection(JDBConnection jdbcConnection)
      Sets the database connection.
      Parameters:
      jdbcConnection - The connection.
      Returns:
      A self-reference.
    • hasConnection

      public boolean hasConnection()
      Does this initializer have a connection set?
      Returns:
      Is the connection set?
    • setCloseConcurrency

      public ConnectionPoolSegment.Initializer setCloseConcurrency(int closerConcurrency)
      Sets the number of threads handling connection close. Default is 0.

      If concurrency is 0 (logical) close operations will be performed (and block) in the calling thread. Higher concurrency allows close to return immediately after queuing the connection, with this number of threads monitoring the queue.

      Parameters:
      closerConcurrency - The number of threads.
      Returns:
      A self-reference.
    • setMaxConcurrentReconnects

      public ConnectionPoolSegment.Initializer setMaxConcurrentReconnects(int maxConcurrentReconnects)
      Sets the maximum number of simultaneous database reconnect attempts.
      Parameters:
      maxConcurrentReconnects - The maximum number of concurrent reconnects.
      Returns:
      A self-reference.
    • setMaxReconnectDelay

      public ConnectionPoolSegment.Initializer setMaxReconnectDelay(long time, TimeUnit timeUnit)
      Sets the maximum delay (after failure) between reconnect attempts.
      Parameters:
      time - The time.
      timeUnit - The time unit.
      Returns:
      A self-reference.
    • setTestOnLogicalOpen

      public ConnectionPoolSegment.Initializer setTestOnLogicalOpen(boolean testOnLogicalOpen)
      Sets thr option to test connections when they are logically opened.
      Parameters:
      testOnLogicalOpen - Should connections be tested on logical open?.
      Returns:
      A self-reference.
    • setTestOnLogicalClose

      public ConnectionPoolSegment.Initializer setTestOnLogicalClose(boolean testOnLogicalClose)
      Sets the option to test connections when they are logically closed.
      Parameters:
      testOnLogicalClose - Should connections be tested on logical close?.
      Returns:
      A self-reference.
    • setIdleTimeBeforeShutdown

      public ConnectionPoolSegment.Initializer setIdleTimeBeforeShutdown(long time, TimeUnit timeUnit)
      Sets the time this segment must be idle before it is shutdown.
      Parameters:
      time - The time.
      timeUnit - The time unit.
      Returns:
      A self-reference.
    • setMinActiveTime

      public ConnectionPoolSegment.Initializer setMinActiveTime(long time, TimeUnit timeUnit)
      Sets the minimum time this segment must be active before it is eligible for shutdown.
      Parameters:
      time - The time.
      timeUnit - The time unit.
      Returns:
      A self-reference.
    • setPasswordSource

      public ConnectionPoolSegment.Initializer setPasswordSource(PasswordSource passwordSource)
      Sets a password source for this segment.
      Parameters:
      passwordSource - The password source.
      Returns:
      A self-reference.
    • setIncompleteTransactionOnClosePolicy

      public ConnectionPoolSegment.Initializer setIncompleteTransactionOnClosePolicy(ConnectionPoolConnection.IncompleteTransactionPolicy incompleteTransactionPolicy)
      Sets the incomplete transaction (on close) policy.
      Parameters:
      incompleteTransactionPolicy - The policy.
      Returns:
      A self-reference.
    • setOpenStatementOnClosePolicy

      public ConnectionPoolSegment.Initializer setOpenStatementOnClosePolicy(ConnectionPoolConnection.OpenStatementPolicy openStatementPolicy)
      Sets the open statement (on close) policy.
      Parameters:
      openStatementPolicy - The policy.
      Returns:
      A self-reference.
    • setForceRealClosePolicy

      public ConnectionPoolSegment.Initializer setForceRealClosePolicy(ConnectionPoolConnection.ForceRealClosePolicy forceRealClosePolicy)
      Sets the policy followed by the pool when a "forced" close is trigger (for example, connection is in-use longer than the configured maximum lease time).
      Parameters:
      forceRealClosePolicy - The policy.
      Returns:
      A self-reference.
    • setCloseTimeLimitMillis

      public ConnectionPoolSegment.Initializer setCloseTimeLimitMillis(long closeTimeLimitMillis)
      Sets the maximum amount of time connection close will block.
      Parameters:
      closeTimeLimitMillis - The time.
      Returns:
      A self-reference.
    • setActivityTimeoutPolicy

      public ConnectionPoolSegment.Initializer setActivityTimeoutPolicy(ConnectionPoolConnection.ActivityTimeoutPolicy activityTimeoutPolicy)
      Sets the policy followed by the pool when a connection activity timeout is reached. This may happen due to developer error (connection never closed), or due to long-running transactions.
      Parameters:
      activityTimeoutPolicy - The policy.
      Returns:
      A self-reference.
    • createSegment

      public ConnectionPoolSegment createSegment() throws org.attribyte.api.InitializationException
      Creates a segment after configuration.
      Returns:
      The segment.
      Throws:
      org.attribyte.api.InitializationException - if configuration is invalid.
    • validate

      public void validate(boolean withDefaults) throws org.attribyte.api.InitializationException
      Verify that all required initialization variables are set.
      Parameters:
      withDefaults - If true defaults will be supplied if possible.
      Throws:
      org.attribyte.api.InitializationException - If initialization is invalid.