Class PostgresWatcher


  • public class PostgresWatcher
    extends java.lang.Object
    The core class of Postgres Watcher, responsible for database connection, listening, and notification.
    • Constructor Summary

      Constructors 
      Constructor Description
      PostgresWatcher​(java.lang.String url, java.lang.String user, java.lang.String password)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Close the connection and the listening thread.
      void connect()
      Connecting to the database
      void listen​(java.lang.String channel, java.util.function.Consumer<java.lang.String> callback)
      Listen to the specified channel and invoke a callback when a message is received.
      void notify​(java.lang.String channel, java.lang.String message)
      sent NOTIFY
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PostgresWatcher

        public PostgresWatcher​(java.lang.String url,
                               java.lang.String user,
                               java.lang.String password)
    • Method Detail

      • connect

        public void connect()
                     throws java.sql.SQLException
        Connecting to the database
        Throws:
        java.sql.SQLException
      • listen

        public void listen​(java.lang.String channel,
                           java.util.function.Consumer<java.lang.String> callback)
        Listen to the specified channel and invoke a callback when a message is received.
      • notify

        public void notify​(java.lang.String channel,
                           java.lang.String message)
                    throws java.sql.SQLException
        sent NOTIFY
        Throws:
        java.sql.SQLException
      • close

        public void close()
        Close the connection and the listening thread.