Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor BinaryLogClient into an abstract base class to allow for more flexible use #16

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Forgot to delete the BroadcastLifecycleListener.
  • Loading branch information
ldcasillas-progreso committed Apr 18, 2014
commit 620d0dfe32a81a5470cc01d5bf351749313579f9
86 changes: 0 additions & 86 deletions src/main/java/com/github/shyiko/mysql/binlog/BinaryLogClient.java
Original file line number Diff line number Diff line change
@@ -284,7 +284,6 @@ public interface LifecycleListener {

/**
* Called once client has successfully logged in but before started to receive binlog events.
* @param client
*/
void onConnect(BinaryLogClient client);

@@ -302,7 +301,6 @@ public interface LifecycleListener {

/**
* Called upon disconnect (regardless of the reason).
* @param client
*/
void onDisconnect(BinaryLogClient client);
}
@@ -330,88 +328,4 @@ public void onDisconnect(BinaryLogClient client) {

}

/**
* A {@link LifecycleListener} that rebroadcasts events to a dynamic list of children.
*/
public static class BroadcastLifecycleListener implements LifecycleListener {
private final List<LifecycleListener> lifecycleListeners = new LinkedList<LifecycleListener>();

@Override
public void onConnect(BinaryLogClient client) {
synchronized (lifecycleListeners) {
for (LifecycleListener listener : lifecycleListeners) {
listener.onConnect(client);
}
}
}

@Override
public void onCommunicationFailure(BinaryLogClient client, Exception ex) {
synchronized (lifecycleListeners) {
for (LifecycleListener listener : lifecycleListeners) {
listener.onCommunicationFailure(client, ex);
}
}
}

@Override
public void onEventDeserializationFailure(BinaryLogClient client, Exception ex) {
synchronized (lifecycleListeners) {
for (LifecycleListener listener : lifecycleListeners) {
listener.onEventDeserializationFailure(client, ex);
}
}
}

@Override
public void onDisconnect(BinaryLogClient client) {
synchronized (lifecycleListeners) {
for (LifecycleListener listener : lifecycleListeners) {
listener.onDisconnect(client);
}
}
}

/**
* @return registered lifecycle listeners
*/
public List<LifecycleListener> getLifecycleListeners() {
return Collections.unmodifiableList(lifecycleListeners);
}

/**
* Register lifecycle listener. Note that multiple lifecycle listeners will be called in order they
* where registered.
*/
public void registerLifecycleListener(LifecycleListener listener) {
synchronized (lifecycleListeners) {
lifecycleListeners.add(listener);
}
}

/**
* Unregister all lifecycle listener of specific type.
*/
public synchronized void unregisterLifecycleListener(Class<? extends LifecycleListener> listenerClass) {
synchronized (lifecycleListeners) {
Iterator<LifecycleListener> iterator = lifecycleListeners.iterator();
while (iterator.hasNext()) {
LifecycleListener lifecycleListener = iterator.next();
if (listenerClass.isInstance(lifecycleListener)) {
iterator.remove();
}
}
}
}

/**
* Unregister single lifecycle listener.
*/
public synchronized void unregisterLifecycleListener(LifecycleListener listener) {
synchronized (lifecycleListeners) {
lifecycleListeners.remove(listener);
}
}
}

}