(Client) Add Connection Listener to BufferingFlipperPlugin
Summary: - Add a new listener to be called when the plugin is initialized Note: - This is a part of this PR: https://github.com/facebook/flipper/pull/488 Reviewed By: jknoxville Differential Revision: D20474259 fbshipit-source-id: ef1673ffa7fbc087761a753fbae813346bd481c3
This commit is contained in:
committed by
Facebook GitHub Bot
parent
37096ba800
commit
4eccacbac8
@@ -10,6 +10,7 @@ package com.facebook.flipper.plugins.common;
|
||||
import com.facebook.flipper.core.FlipperConnection;
|
||||
import com.facebook.flipper.core.FlipperObject;
|
||||
import com.facebook.flipper.core.FlipperPlugin;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
@@ -24,17 +25,35 @@ public abstract class BufferingFlipperPlugin implements FlipperPlugin {
|
||||
|
||||
private @Nullable RingBuffer<CachedFlipperEvent> mEventQueue;
|
||||
private @Nullable FlipperConnection mConnection;
|
||||
private @Nullable MockResponseConnectionListener
|
||||
mMockResponseConnectionListenerConnectionListener;
|
||||
|
||||
public synchronized void setConnectionListener(@Nonnull MockResponseConnectionListener listener) {
|
||||
this.mMockResponseConnectionListenerConnectionListener = listener;
|
||||
}
|
||||
|
||||
public synchronized void removeConnectionListener() {
|
||||
this.mMockResponseConnectionListenerConnectionListener = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onConnect(FlipperConnection connection) {
|
||||
mConnection = connection;
|
||||
|
||||
sendBufferedEvents();
|
||||
|
||||
if (this.mMockResponseConnectionListenerConnectionListener != null) {
|
||||
this.mMockResponseConnectionListenerConnectionListener.onConnect(connection);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onDisconnect() {
|
||||
mConnection = null;
|
||||
|
||||
if (this.mMockResponseConnectionListenerConnectionListener != null) {
|
||||
this.mMockResponseConnectionListenerConnectionListener.onDisconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,4 +98,10 @@ public abstract class BufferingFlipperPlugin implements FlipperPlugin {
|
||||
this.flipperObject = flipperObject;
|
||||
}
|
||||
}
|
||||
|
||||
public interface MockResponseConnectionListener {
|
||||
void onConnect(FlipperConnection connection);
|
||||
|
||||
void onDisconnect();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user