Class BinaryLogClient

    • Field Detail

      • gtidSet

        protected GtidSet gtidSet
      • gtidSetAccessLock

        protected final Object gtidSetAccessLock
    • Constructor Detail

      • BinaryLogClient

        public BinaryLogClient​(String hostname,
                               int port,
                               String username,
                               String password)
        Alias for BinaryLogClient(hostname, port, <no schema> = null, username, password).
        Parameters:
        hostname - mysql server hostname
        port - mysql server port
        username - login name
        password - password
        See Also:
        BinaryLogClient(String, int, String, String, String)
      • BinaryLogClient

        public BinaryLogClient​(String hostname,
                               int port,
                               String schema,
                               String username,
                               String password)
        Parameters:
        hostname - mysql server hostname
        port - mysql server port
        schema - database name, nullable. Note that this parameter has nothing to do with event filtering. It's used only during the authentication.
        username - login name
        password - password
    • Method Detail

      • isBlocking

        public boolean isBlocking()
      • setBlocking

        public void setBlocking​(boolean blocking)
        Parameters:
        blocking - blocking mode. If set to false - BinaryLogClient will disconnect after the last event.
      • getSSLMode

        public SSLMode getSSLMode()
      • setSSLMode

        public void setSSLMode​(SSLMode sslMode)
      • setUseNonGracefulDisconnect

        public void setUseNonGracefulDisconnect​(boolean useNonGracefulDisconnect)
      • getMasterServerId

        public long getMasterServerId()
      • getServerId

        public long getServerId()
        Returns:
        server id (65535 by default)
        See Also:
        setServerId(long)
      • setServerId

        public void setServerId​(long serverId)
        Parameters:
        serverId - server id (in the range from 1 to 2^32 - 1). This value MUST be unique across whole replication group (that is, different from any other server id being used by any master or slave). Keep in mind that each binary log client (mysql-binlog-connector-java/BinaryLogClient, mysqlbinlog, etc) should be treated as a simplified slave and thus MUST also use a different server id.
        See Also:
        getServerId()
      • setBinlogFilename

        public void setBinlogFilename​(String binlogFilename)
        Specified by:
        setBinlogFilename in interface BinaryLogClientMXBean
        Parameters:
        binlogFilename - binary log filename. Special values are:
        • null, which turns on automatic resolution (resulting in the last known binlog and position). This is what happens by default when you don't specify binary log filename explicitly.
        • "" (empty string), which instructs server to stream events starting from the oldest known binlog.
        See Also:
        getBinlogFilename()
      • getBinlogPosition

        public long getBinlogPosition()
        Specified by:
        getBinlogPosition in interface BinaryLogClientMXBean
        Returns:
        binary log position of the next event, 4 by default (which is a position of first event). Note that this value changes with each incoming event.
        See Also:
        setBinlogPosition(long)
      • setBinlogPosition

        public void setBinlogPosition​(long binlogPosition)
        Specified by:
        setBinlogPosition in interface BinaryLogClientMXBean
        Parameters:
        binlogPosition - binary log position. Any value less than 4 gets automatically adjusted to 4 on connect.
        See Also:
        getBinlogPosition()
      • getConnectionId

        public long getConnectionId()
        Returns:
        thread id
      • getGtidSet

        public String getGtidSet()
        Returns:
        GTID set. Note that this value changes with each received GTID event (provided client is in GTID mode).
        See Also:
        setGtidSet(String)
      • setGtidSet

        public void setGtidSet​(String gtidStr)
        Parameters:
        gtidStr - GTID set string (can be an empty string).

        NOTE #1: Any value but null will switch BinaryLogClient into a GTID mode (this will also set binlogFilename to "" (provided it's null) forcing MySQL to send events starting from the oldest known binlog (keep in mind that connection will fail if gtid_purged is anything but empty (unless setGtidSetFallbackToPurged(boolean) is set to true))).

        NOTE #2: GTID set is automatically updated with each incoming GTID event (provided GTID mode is on).

        See Also:
        getGtidSet(), setGtidSetFallbackToPurged(boolean)
      • setGtidSetFallbackToPurged

        public void setGtidSetFallbackToPurged​(boolean gtidSetFallbackToPurged)
        Parameters:
        gtidSetFallbackToPurged - true if gtid_purged should be used as a fallback when gtidSet is set to "" and MySQL server has purged some of the binary logs, false otherwise (default).
      • setUseBinlogFilenamePositionInGtidMode

        public void setUseBinlogFilenamePositionInGtidMode​(boolean useBinlogFilenamePositionInGtidMode)
        Parameters:
        useBinlogFilenamePositionInGtidMode - true if MySQL server should start streaming events from a given getBinlogFilename() and getBinlogPosition() instead of "the oldest known binlog" when getGtidSet() is set, false otherwise (default).
      • isKeepAlive

        public boolean isKeepAlive()
        Returns:
        true if "keep alive" thread should be automatically started (default), false otherwise.
        See Also:
        setKeepAlive(boolean)
      • setKeepAlive

        public void setKeepAlive​(boolean keepAlive)
        Parameters:
        keepAlive - true if "keep alive" thread should be automatically started (recommended and true by default), false otherwise.
        See Also:
        isKeepAlive(), setKeepAliveInterval(long)
      • getKeepAliveInterval

        public long getKeepAliveInterval()
        Returns:
        "keep alive" interval in milliseconds, 1 minute by default.
        See Also:
        setKeepAliveInterval(long)
      • setKeepAliveConnectTimeout

        public void setKeepAliveConnectTimeout​(long connectTimeout)
        Deprecated.
        Parameters:
        connectTimeout - "keep alive" connect timeout in milliseconds.
        See Also:
        getKeepAliveConnectTimeout()
      • getHeartbeatInterval

        public long getHeartbeatInterval()
        Returns:
        heartbeat period in milliseconds (0 if not set (default)).
        See Also:
        setHeartbeatInterval(long)
      • setHeartbeatInterval

        public void setHeartbeatInterval​(long heartbeatInterval)
        Parameters:
        heartbeatInterval - heartbeat period in milliseconds.

        If set (recommended)

        • HEARTBEAT event will be emitted every "heartbeatInterval".
        • if setKeepAlive(boolean) is on then keepAlive thread will attempt to reconnect if no HEARTBEAT events were received within setKeepAliveInterval(long) (instead of trying to send PING every setKeepAliveInterval(long), which is fundamentally flawed - https://github.com/shyiko/mysql-binlog-connector-java/issues/118).
        Note that when used together with keepAlive heartbeatInterval MUST be set less than keepAliveInterval.
        See Also:
        getHeartbeatInterval()
      • getConnectTimeout

        public long getConnectTimeout()
        Returns:
        connect timeout in milliseconds, 3 seconds by default.
        See Also:
        setConnectTimeout(long)
      • setConnectTimeout

        public void setConnectTimeout​(long connectTimeout)
        Parameters:
        connectTimeout - connect timeout in milliseconds.
        See Also:
        getConnectTimeout()
      • setEventDeserializer

        public void setEventDeserializer​(EventDeserializer eventDeserializer)
        Parameters:
        eventDeserializer - custom event deserializer
      • setSocketFactory

        public void setSocketFactory​(SocketFactory socketFactory)
        Parameters:
        socketFactory - custom socket factory. If not provided, socket will be created with "new Socket()".
      • setSslSocketFactory

        public void setSslSocketFactory​(SSLSocketFactory sslSocketFactory)
        Parameters:
        sslSocketFactory - custom ssl socket factory
      • setThreadFactory

        public void setThreadFactory​(ThreadFactory threadFactory)
        Parameters:
        threadFactory - custom thread factory. If not provided, threads will be created using simple "new Thread()".
      • getMariaDB

        public Boolean getMariaDB()
        Returns:
        true/false depending on whether we've connected to MariaDB. NULL if not connected.
      • isUseSendAnnotateRowsEvent

        public boolean isUseSendAnnotateRowsEvent()
      • setUseSendAnnotateRowsEvent

        public void setUseSendAnnotateRowsEvent​(boolean useSendAnnotateRowsEvent)
      • getMariaDbSlaveCapability

        public int getMariaDbSlaveCapability()
        Returns:
        the configured MariaDB slave compatibility level, defaults to 4.
      • setMariaDbSlaveCapability

        public void setMariaDbSlaveCapability​(int mariaDbSlaveCapability)
        Set the client's MariaDB slave compatibility level. This only applies when connecting to MariaDB.
        Parameters:
        mariaDbSlaveCapability - the expected compatibility level
      • setupConnection

        protected void setupConnection()
                                throws IOException
        Apply additional options for connection before requesting binlog stream.
        Throws:
        IOException
      • requestBinaryLogStreamMaria

        protected void requestBinaryLogStreamMaria​(long serverId)
                                            throws IOException
        Throws:
        IOException
      • ensureGtidEventDataDeserializer

        protected void ensureGtidEventDataDeserializer()
      • isConnected

        public boolean isConnected()
        Specified by:
        isConnected in interface BinaryLogClientMXBean
        Returns:
        true if client is connected, false otherwise
      • updateGtidSet

        protected void updateGtidSet​(Event event)
      • commitGtid

        protected void commitGtid​(String sql)
      • registerEventListener

        public void registerEventListener​(BinaryLogClient.EventListener eventListener)
        Register event listener. Note that multiple event listeners will be called in order they where registered.
        Parameters:
        eventListener - event listener
      • unregisterEventListener

        public void unregisterEventListener​(Class<? extends BinaryLogClient.EventListener> listenerClass)
        Unregister all event listener of specific type.
        Parameters:
        listenerClass - event listener class to unregister
      • unregisterEventListener

        public void unregisterEventListener​(BinaryLogClient.EventListener eventListener)
        Unregister single event listener.
        Parameters:
        eventListener - event listener to unregister
      • registerLifecycleListener

        public void registerLifecycleListener​(BinaryLogClient.LifecycleListener lifecycleListener)
        Register lifecycle listener. Note that multiple lifecycle listeners will be called in order they where registered.
        Parameters:
        lifecycleListener - lifecycle listener to register
      • unregisterLifecycleListener

        public void unregisterLifecycleListener​(Class<? extends BinaryLogClient.LifecycleListener> listenerClass)
        Unregister all lifecycle listener of specific type.
        Parameters:
        listenerClass - lifecycle listener class to unregister
      • unregisterLifecycleListener

        public void unregisterLifecycleListener​(BinaryLogClient.LifecycleListener eventListener)
        Unregister single lifecycle listener.
        Parameters:
        eventListener - lifecycle listener to unregister
      • disconnect

        public void disconnect()
                        throws IOException
        Disconnect from the replication stream. Note that this does not cause binlogFilename/binlogPosition to be cleared out. As the result following connect() resumes client from where it left off.
        Specified by:
        disconnect in interface BinaryLogClientMXBean
        Throws:
        IOException