org.firebirdsql.event

## Class FBEventManager

- java.lang.Object
- - org.firebirdsql.event.FBEventManager

- All Implemented Interfaces:
    java.lang.AutoCloseable, EventManager

      public class FBEventManager
      extends java.lang.Object
      implements EventManager

  An `EventManager` implementation to listen for database events.
  Author:
    Gabriel Reid, Mark Rotteveel, Vasiliy Yashkov

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `FBEventManager()`
    `FBEventManager(GDSType gdsType)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addEventListener(java.lang.String eventName, EventListener listener)` Register an EventListener that will be called when an event occurs.
    `void` | `close()` If connected, disconnects, otherwise does nothing.
    `void` | `connect()` Make a connection with a database to listen for events.
    `static EventManager` | `createFor(java.sql.Connection connection)` Creates an `EventManager` for a connection.
    `void` | `disconnect()` Close the connection to the database.
    `java.lang.String` | `getDatabase()`
    `java.lang.String` | `getDbCryptConfig()` Get the database encryption plugin configuration.
    `java.lang.String` | `getHost()`
    `java.lang.String` | `getPassword()`
    `int` | `getPort()`
    `java.lang.String` | `getUser()`
    `long` | `getWaitTimeout()` Get the poll timeout in milliseconds of the async thread to check whether it was stopped or not.
    `WireCrypt` | `getWireCrypt()` Get the wire encryption level.
    `boolean` | `isConnected()`
    `void` | `removeEventListener(java.lang.String eventName, EventListener listener)` Remove an EventListener for a given event.
    `void` | `setDatabase(java.lang.String database)` Sets the database path for the connection to the database.
    `void` | `setDbCryptConfig(java.lang.String dbCryptConfig)` Sets the database encryption plugin configuration.
    `void` | `setHost(java.lang.String host)` Sets the host for the connection to the database.
    `void` | `setPassword(java.lang.String password)` Sets the password for the connection to the database.
    `void` | `setPort(int port)` Sets the port for the connection to the database.
    `void` | `setUser(java.lang.String user)` Sets the username for the connection to the database .
    `void` | `setWaitTimeout(long waitTimeout)` Set the poll timeout in milliseconds of the async thread to check whether it was stopped or not.
    `void` | `setWireCrypt(WireCrypt wireCrypt)` Set the wire encryption level.
    `int` | `waitForEvent(java.lang.String eventName)` Wait for the one-time occurrence of an event.
    `int` | `waitForEvent(java.lang.String eventName, int timeout)` Wait for the one-time occurrence of an event.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### FBEventManager

          public FBEventManager()

    - #### FBEventManager

          public FBEventManager(GDSType gdsType)

  - ### Method Detail

    - #### createFor

          public static EventManager createFor(java.sql.Connection connection)
                                        throws java.sql.SQLException

      Creates an `EventManager` for a connection.

      The created event manager does not allow setting the properties and will instead throw `UnsupportedOperationException` for the setters.

      The returned instance is not necessarily an implementation of `FBEventManager`.

      Parameters:
        `connection` - A connection that unwraps to `FirebirdConnection`
      Returns:
        An event manager
      Throws:
        `java.sql.SQLException` - When `connection` does not unwrap to `FirebirdConnection`
      Since:
        3.0.7

    - #### connect

          public void connect()
                       throws java.sql.SQLException

      Description copied from interface: `EventManager`
      Make a connection with a database to listen for events.
      Specified by:
        `connect` in interface `EventManager`
      Throws:
        `java.sql.SQLException` - If a database communication error occurs

    - #### close

          public void close()
                     throws java.sql.SQLException

      Description copied from interface: `EventManager`
      If connected, disconnects, otherwise does nothing.

      Contrary to `EventManager.disconnect()`, this method does not throw `IllegalStateException` when not connected.

      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Specified by:
        `close` in interface `EventManager`
      Throws:
        `java.sql.SQLException` - For errors during disconnect

    - #### disconnect

          public void disconnect()
                          throws java.sql.SQLException

      Description copied from interface: `EventManager`
      Close the connection to the database.
      Specified by:
        `disconnect` in interface `EventManager`
      Throws:
        `java.sql.SQLException` - If a database communication error occurs
      See Also:
        `EventManager.close()`

    - #### isConnected

          public boolean isConnected()

      Specified by:
        `isConnected` in interface `EventManager`
      Returns:
        `true` when connected and able to listen for events
      See Also:
        `EventManager.connect()`, `EventManager.disconnect()`

    - #### setUser

          public void setUser(java.lang.String user)

      Description copied from interface: `EventManager`
      Sets the username for the connection to the database .
      Specified by:
        `setUser` in interface `EventManager`
      Parameters:
        `user` - for the connection to the database.

    - #### getUser

          public java.lang.String getUser()

      Specified by:
        `getUser` in interface `EventManager`
      Returns:
        the username for the connection to the database.

    - #### setPassword

          public void setPassword(java.lang.String password)

      Description copied from interface: `EventManager`
      Sets the password for the connection to the database.
      Specified by:
        `setPassword` in interface `EventManager`
      Parameters:
        `password` - for the connection to the database.

    - #### getPassword

          public java.lang.String getPassword()

      Specified by:
        `getPassword` in interface `EventManager`
      Returns:
        the password for the connection to the database.

    - #### setDatabase

          public void setDatabase(java.lang.String database)

      Description copied from interface: `EventManager`
      Sets the database path for the connection to the database.
      Specified by:
        `setDatabase` in interface `EventManager`
      Parameters:
        `database` - path for the connection to the database.

    - #### getDatabase

          public java.lang.String getDatabase()

      Specified by:
        `getDatabase` in interface `EventManager`
      Returns:
        the database path for the connection to the database.

    - #### getHost

          public java.lang.String getHost()

      Specified by:
        `getHost` in interface `EventManager`
      Returns:
        the host for the connection to the database.

    - #### setHost

          public void setHost(java.lang.String host)

      Description copied from interface: `EventManager`
      Sets the host for the connection to the database.
      Specified by:
        `setHost` in interface `EventManager`
      Parameters:
        `host` - for the connection to the database.

    - #### getPort

          public int getPort()

      Specified by:
        `getPort` in interface `EventManager`
      Returns:
        the port for the connection to the database.

    - #### setPort

          public void setPort(int port)

      Description copied from interface: `EventManager`
      Sets the port for the connection to the database.
      Specified by:
        `setPort` in interface `EventManager`
      Parameters:
        `port` - for the connection to the database.

    - #### getWireCrypt

          public WireCrypt getWireCrypt()

      Description copied from interface: `EventManager`
      Get the wire encryption level.
      Specified by:
        `getWireCrypt` in interface `EventManager`
      Returns:
        Wire encryption level

    - #### setWireCrypt

          public void setWireCrypt(WireCrypt wireCrypt)

      Description copied from interface: `EventManager`
      Set the wire encryption level.
      Specified by:
        `setWireCrypt` in interface `EventManager`
      Parameters:
        `wireCrypt` - Wire encryption level (`null` not allowed)

    - #### getDbCryptConfig

          public java.lang.String getDbCryptConfig()

      Description copied from interface: `EventManager`
      Get the database encryption plugin configuration.
      Specified by:
        `getDbCryptConfig` in interface `EventManager`
      Returns:
        Database encryption plugin configuration, meaning plugin specific

    - #### setDbCryptConfig

          public void setDbCryptConfig(java.lang.String dbCryptConfig)

      Description copied from interface: `EventManager`
      Sets the database encryption plugin configuration.
      Specified by:
        `setDbCryptConfig` in interface `EventManager`
      Parameters:
        `dbCryptConfig` - Database encryption plugin configuration, meaning plugin specific

    - #### getWaitTimeout

          public long getWaitTimeout()

      Description copied from interface: `EventManager`
      Get the poll timeout in milliseconds of the async thread to check whether it was stopped or not.

      Default value is 1000 (1 second).

      Specified by:
        `getWaitTimeout` in interface `EventManager`
      Returns:
        wait timeout in milliseconds

    - #### setWaitTimeout

          public void setWaitTimeout(long waitTimeout)

      Description copied from interface: `EventManager`
      Set the poll timeout in milliseconds of the async thread to check whether it was stopped or not.

      Default value is 1000 (1 second).

      Specified by:
        `setWaitTimeout` in interface `EventManager`
      Parameters:
        `waitTimeout` - wait timeout in milliseconds

    - #### addEventListener

          public void addEventListener(java.lang.String eventName,
                                       EventListener listener)
                                throws java.sql.SQLException

      Description copied from interface: `EventManager`
      Register an EventListener that will be called when an event occurs.
      Specified by:
        `addEventListener` in interface `EventManager`
      Parameters:
        `eventName` - The name of the event for which the listener will be notified
        `listener` - The EventListener that will be called when the given event occurs
      Throws:
        `java.sql.SQLException` - If a database access error occurs

    - #### removeEventListener

          public void removeEventListener(java.lang.String eventName,
                                          EventListener listener)
                                   throws java.sql.SQLException

      Description copied from interface: `EventManager`
      Remove an EventListener for a given event.
      Specified by:
        `removeEventListener` in interface `EventManager`
      Parameters:
        `eventName` - The name of the event for which the listener will be unregistered.
        `listener` - The EventListener that is to be unregistered
      Throws:
        `java.sql.SQLException` - If a database access error occurs

    - #### waitForEvent

          public int waitForEvent(java.lang.String eventName)
                           throws java.lang.InterruptedException,
                                  java.sql.SQLException

      Description copied from interface: `EventManager`
      Wait for the one-time occurrence of an event.

      This method blocks indefinitely until the event identified by the value of `eventName` occurs. The return value is the number of occurrences of the requested event.

      Specified by:
        `waitForEvent` in interface `EventManager`
      Parameters:
        `eventName` - The name of the event to wait for
      Returns:
        The number of occurences of the requested event
      Throws:
        `java.lang.InterruptedException` - If interrupted while waiting
        `java.sql.SQLException` - If a database access error occurs

    - #### waitForEvent

          public int waitForEvent(java.lang.String eventName,
                                  int timeout)
                           throws java.lang.InterruptedException,
                                  java.sql.SQLException

      Description copied from interface: `EventManager`
      Wait for the one-time occurrence of an event.

      This method blocks for a maximum of `timeout` milliseconds, waiting for the event identified by `eventName` to occur. A timeout value of `0` means wait indefinitely.

      The return value is the number of occurences of the event in question, or `-1` if the call timed out.

      Specified by:
        `waitForEvent` in interface `EventManager`
      Parameters:
        `eventName` - The name of the event to wait for
        `timeout` - The maximum number of milliseconds to wait
      Returns:
        The number of occurrences of the requested event, or `1` if the call timed out
      Throws:
        `java.lang.InterruptedException` - If interrupted while waiting
        `java.sql.SQLException` - If a database access error occurs

Copyright © 2001-2021 Jaybird (Firebird JDBC/JCA) team. All rights reserved.