public class BinaryLogClient extends Object implements BinaryLogClientMXBean
Modifier and Type | Class and Description |
---|---|
static class |
BinaryLogClient.AbstractLifecycleListener
Default (no-op) implementation of
BinaryLogClient.LifecycleListener . |
static interface |
BinaryLogClient.EventListener
BinaryLogClient 's event listener. |
static interface |
BinaryLogClient.LifecycleListener
BinaryLogClient 's lifecycle listener. |
Constructor and Description |
---|
BinaryLogClient(String hostname,
int port,
String username,
String password)
Alias for BinaryLogClient(hostname, port, <no schema> = null, username, password).
|
BinaryLogClient(String hostname,
int port,
String schema,
String username,
String password) |
BinaryLogClient(String username,
String password)
Alias for BinaryLogClient("localhost", 3306, <no schema> = null, username, password).
|
BinaryLogClient(String schema,
String username,
String password)
Alias for BinaryLogClient("localhost", 3306, schema, username, password).
|
Modifier and Type | Method and Description |
---|---|
void |
connect()
Connect to the replication stream.
|
void |
connect(long timeout)
Connect to the replication stream in a separate thread.
|
void |
disconnect()
Disconnect from the replication stream.
|
String |
getBinlogFilename() |
long |
getBinlogPosition() |
long |
getConnectionId() |
long |
getConnectTimeout() |
List<BinaryLogClient.EventListener> |
getEventListeners() |
String |
getGtidSet() |
long |
getHeartbeatInterval() |
long |
getKeepAliveConnectTimeout()
Deprecated.
in favour of
getConnectTimeout() |
long |
getKeepAliveInterval() |
List<BinaryLogClient.LifecycleListener> |
getLifecycleListeners() |
long |
getServerId() |
SSLMode |
getSSLMode() |
boolean |
isBlocking() |
boolean |
isConnected() |
boolean |
isGtidSetFallbackToPurged() |
boolean |
isKeepAlive() |
void |
registerEventListener(BinaryLogClient.EventListener eventListener)
Register event listener.
|
void |
registerLifecycleListener(BinaryLogClient.LifecycleListener lifecycleListener)
Register lifecycle listener.
|
void |
setBinlogFilename(String binlogFilename) |
void |
setBinlogPosition(long binlogPosition) |
void |
setBlocking(boolean blocking) |
void |
setConnectTimeout(long connectTimeout) |
void |
setEventDeserializer(EventDeserializer eventDeserializer) |
void |
setGtidSet(String gtidSet) |
void |
setGtidSetFallbackToPurged(boolean gtidSetFallbackToPurged) |
void |
setHeartbeatInterval(long heartbeatInterval) |
void |
setKeepAlive(boolean keepAlive) |
void |
setKeepAliveConnectTimeout(long connectTimeout)
Deprecated.
in favour of
setConnectTimeout(long) |
void |
setKeepAliveInterval(long keepAliveInterval) |
void |
setServerId(long serverId) |
void |
setSocketFactory(SocketFactory socketFactory) |
void |
setSSLMode(SSLMode sslMode) |
void |
setSslSocketFactory(SSLSocketFactory sslSocketFactory) |
void |
setThreadFactory(ThreadFactory threadFactory) |
void |
unregisterEventListener(BinaryLogClient.EventListener eventListener)
Unregister single event listener.
|
void |
unregisterEventListener(Class<? extends BinaryLogClient.EventListener> listenerClass)
Unregister all event listener of specific type.
|
void |
unregisterLifecycleListener(BinaryLogClient.LifecycleListener eventListener)
Unregister single lifecycle listener.
|
void |
unregisterLifecycleListener(Class<? extends BinaryLogClient.LifecycleListener> listenerClass)
Unregister all lifecycle listener of specific type.
|
public BinaryLogClient(String username, String password)
public BinaryLogClient(String schema, String username, String password)
public BinaryLogClient(String hostname, int port, String username, String password)
public BinaryLogClient(String hostname, int port, String schema, String username, String password)
hostname
- mysql server hostnameport
- mysql server portschema
- database name, nullable. Note that this parameter has nothing to do with event filtering. It's
used only during the authentication.username
- login namepassword
- passwordpublic boolean isBlocking()
public void setBlocking(boolean blocking)
blocking
- blocking mode. If set to false - BinaryLogClient will disconnect after the last event.public SSLMode getSSLMode()
public void setSSLMode(SSLMode sslMode)
public long getServerId()
setServerId(long)
public void setServerId(long serverId)
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.getServerId()
public String getBinlogFilename()
getBinlogFilename
in interface BinaryLogClientMXBean
EventType.ROTATE
, for example).setBinlogFilename(String)
public void setBinlogFilename(String binlogFilename)
setBinlogFilename
in interface BinaryLogClientMXBean
binlogFilename
- binary log filename.
Special values are:
getBinlogFilename()
public long getBinlogPosition()
getBinlogPosition
in interface BinaryLogClientMXBean
setBinlogPosition(long)
public void setBinlogPosition(long binlogPosition)
setBinlogPosition
in interface BinaryLogClientMXBean
binlogPosition
- binary log position. Any value less than 4 gets automatically adjusted to 4 on connect.getBinlogPosition()
public long getConnectionId()
public String getGtidSet()
setGtidSet(String)
public void setGtidSet(String gtidSet)
gtidSet
- GTID set (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: setBinlogFilename(String)
and setBinlogPosition(long)
can be used to specify the
exact position from which MySQL server should start streaming events (taking into account GTID set).
NOTE #3: GTID set is automatically updated with each incoming GTID event (provided GTID mode is on).
getGtidSet()
,
setGtidSetFallbackToPurged(boolean)
public boolean isGtidSetFallbackToPurged()
setGtidSetFallbackToPurged(boolean)
public void setGtidSetFallbackToPurged(boolean gtidSetFallbackToPurged)
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).public boolean isKeepAlive()
setKeepAlive(boolean)
public void setKeepAlive(boolean keepAlive)
keepAlive
- true if "keep alive" thread should be automatically started (recommended and true by default),
false otherwise.isKeepAlive()
,
setKeepAliveInterval(long)
public long getKeepAliveInterval()
setKeepAliveInterval(long)
public void setKeepAliveInterval(long keepAliveInterval)
keepAliveInterval
- "keep alive" interval in milliseconds.getKeepAliveInterval()
,
setHeartbeatInterval(long)
public long getKeepAliveConnectTimeout()
getConnectTimeout()
setKeepAliveConnectTimeout(long)
public void setKeepAliveConnectTimeout(long connectTimeout)
setConnectTimeout(long)
connectTimeout
- "keep alive" connect timeout in milliseconds.getKeepAliveConnectTimeout()
public long getHeartbeatInterval()
setHeartbeatInterval(long)
public void setHeartbeatInterval(long heartbeatInterval)
heartbeatInterval
- heartbeat period in milliseconds.
If set (recommended)
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).
getHeartbeatInterval()
public long getConnectTimeout()
setConnectTimeout(long)
public void setConnectTimeout(long connectTimeout)
connectTimeout
- connect timeout in milliseconds.getConnectTimeout()
public void setEventDeserializer(EventDeserializer eventDeserializer)
eventDeserializer
- custom event deserializerpublic void setSocketFactory(SocketFactory socketFactory)
socketFactory
- custom socket factory. If not provided, socket will be created with "new Socket()".public void setSslSocketFactory(SSLSocketFactory sslSocketFactory)
sslSocketFactory
- custom ssl socket factorypublic void setThreadFactory(ThreadFactory threadFactory)
threadFactory
- custom thread factory. If not provided, threads will be created using simple "new Thread()".public void connect() throws IOException
AuthenticationException
- if authentication failsServerException
- if MySQL server responds with an errorIOException
- if anything goes wrong while trying to connectpublic void connect(long timeout) throws IOException, TimeoutException
connect
in interface BinaryLogClientMXBean
timeout
- timeout in millisecondsAuthenticationException
- if authentication failsServerException
- if MySQL server responds with an errorIOException
- if anything goes wrong while trying to connectTimeoutException
- if client was unable to connect within given time limitpublic boolean isConnected()
isConnected
in interface BinaryLogClientMXBean
public List<BinaryLogClient.EventListener> getEventListeners()
public void registerEventListener(BinaryLogClient.EventListener eventListener)
public void unregisterEventListener(Class<? extends BinaryLogClient.EventListener> listenerClass)
public void unregisterEventListener(BinaryLogClient.EventListener eventListener)
public List<BinaryLogClient.LifecycleListener> getLifecycleListeners()
public void registerLifecycleListener(BinaryLogClient.LifecycleListener lifecycleListener)
public void unregisterLifecycleListener(Class<? extends BinaryLogClient.LifecycleListener> listenerClass)
public void unregisterLifecycleListener(BinaryLogClient.LifecycleListener eventListener)
public void disconnect() throws IOException
connect()
resumes client from where it left off.disconnect
in interface BinaryLogClientMXBean
IOException
Copyright © 2017. All rights reserved.