Holger's Java API

## com.antelmann.db.remote
Class ChangeNotificationClient

    java.lang.Object
      com.antelmann.db.remote.ChangeNotificationClient

All Implemented Interfaces:
  Closeable

    public class ChangeNotificationClient

extends Object
implements Closeable

provides an easy mechanism to setup a client for change notification on a database.

Since:
  16.11.2008, 16:39:08
Author:
  holger Antelmann
See Also:
  `ChangeNotificationServer`, `RemoteDBChangeNotifier`, `RemoteDatabaseChangeHandler`

Constructor Summary
`ChangeNotificationClient(NetConnection con, Database<?> db, boolean deliverChanges)` starts a client daemon thread that listens to changes; if `deliverChanges` is true, this client also propagates changes from the database to the server using a notifier.
`ChangeNotificationClient(String databaseName, Database<?> db, String server, boolean deliverChanges)`
`ChangeNotificationClient(String databaseName, Database<?> db, String server, int port, boolean deliverChanges)` creates a SocketConnection to the server based on the given parameters and calls the constructor that takes a NetConnection

Method Summary
`void` `addListener(DatabaseChangeListener l)` convenience method; delegates to the monitor
`void` `close()` stops/closes both, notifier and handler; removes all listeners and sets all member variables to null
`protected void` `finalize()`
`MessageDelegator` `getDelegator()` returns the delegator that uses the RemoteDatabaseChangeHandler, which has been started in its own daemon thread at construction time
`Thread` `getDelegatorThread()` returns the thread that runs the delegator
`RemoteDatabaseChangeHandler` `getHandler()`
`RemoteDBChangeNotifier` `getNotifier()` this is non-null only if this instance was created with `deliverChanges` set to true
`boolean` `removeListener(DatabaseChangeListener l)` convenience method; delegates to the monitor
`void` `setNotificationFilter(RemoteDBChangeFilter filter)`

Methods inherited from class java.lang.Object
`clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ChangeNotificationClient

    public ChangeNotificationClient(String databaseName,
                                    Database<?> db,
                                    String server,
                                    boolean deliverChanges)
                             throws IOException

Throws:
  `IOException`

### ChangeNotificationClient

    public ChangeNotificationClient(String databaseName,
                                    Database<?> db,
                                    String server,
                                    int port,
                                    boolean deliverChanges)
                             throws IOException

  creates a SocketConnection to the server based on the given parameters and calls the constructor that takes a NetConnection

  Parameters:
    `databaseName` - the name of the database that must correspond to the database name used by the `ChangeNotificationServer`
    `db` - the database used to deliver the `RemoteDBUpdateEvent` instances
    `server` - the host that runs the `ChangeNotificationServer`
    `port` - the port on which the server runs
    `deliverChanges` - if set to true, a `DatabaseChangeMonitor` is deployed to propagate changes from the given database to the server for notification.
  Throws:
    `IOException`

### ChangeNotificationClient

    public ChangeNotificationClient(NetConnection con,
                                    Database<?> db,
                                    boolean deliverChanges)
                             throws IOException

  starts a client daemon thread that listens to changes; if `deliverChanges` is true, this client also propagates changes from the database to the server using a notifier. The handler is run by a `MessageDelegator` in a daemon thread. The notifier (a `RemoteDBChangeNotifier`) is enabled through a `DatabaseChangeMonitor` instance if applicable. Note that if this also client delivers changes, it will receive updates only if the server is set to send notifications to the same connection that delivered it.

  Parameters:
    `con` - the connection to the `ChangeNotificationServer`
    `db` - the database used to deliver the `RemoteDBUpdateEvent` instances
    `deliverChanges` - if set to true, a `DatabaseChangeMonitor` is deployed to propagate changes from the given database to the server for notification.
  Throws:
    `IOException`
  See Also:
    `ChangeNotificationServer.setDeliverToSelf(boolean)`, `DatabaseChangeMonitor`

Method Detail

### setNotificationFilter

    public void setNotificationFilter(RemoteDBChangeFilter filter)
                               throws IOException

  Throws:
    `IOException`

### getNotifier

    public RemoteDBChangeNotifier getNotifier()

  this is non-null only if this instance was created with `deliverChanges` set to true

### getDelegatorThread

    public Thread getDelegatorThread()

  returns the thread that runs the delegator

  See Also:
    `getDelegator()`

### getHandler

    public RemoteDatabaseChangeHandler getHandler()

### getDelegator

    public MessageDelegator getDelegator()

  returns the delegator that uses the RemoteDatabaseChangeHandler, which has been started in its own daemon thread at construction time

  See Also:
    `getDelegatorThread()`

### addListener

    public void addListener(DatabaseChangeListener l)

  convenience method; delegates to the monitor

### removeListener

    public boolean removeListener(DatabaseChangeListener l)

  convenience method; delegates to the monitor

### close

    public void close()

  stops/closes both, notifier and handler; removes all listeners and sets all member variables to null

  Specified by:
    `close` in interface `Closeable`

### finalize

    protected void finalize()
                     throws Throwable

  Overrides:
    `finalize` in class `Object`
  Throws:
    `Throwable`

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads