mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Refactor: Extract method from duplicated code
This commit is contained in:
parent
1e6744ddc0
commit
e57c26ecb0
@ -70,6 +70,7 @@ import java.util.Optional;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -316,34 +317,12 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdatedDataReceived() {
|
public void onUpdatedDataReceived() {
|
||||||
if (!isBootstrapped) {
|
applyIsBootstrapped(P2PServiceListener::onUpdatedDataReceived);
|
||||||
isBootstrapped = true;
|
|
||||||
|
|
||||||
p2PDataStorage.onBootstrapped();
|
|
||||||
|
|
||||||
// We don't use a listener at mailboxMessageService as we require the correct
|
|
||||||
// order of execution. The p2pServiceListeners must be called after
|
|
||||||
// mailboxMessageService.onUpdatedDataReceived.
|
|
||||||
mailboxMessageService.onBootstrapped();
|
|
||||||
|
|
||||||
p2pServiceListeners.forEach(P2PServiceListener::onUpdatedDataReceived);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNoSeedNodeAvailable() {
|
public void onNoSeedNodeAvailable() {
|
||||||
if (!isBootstrapped) {
|
applyIsBootstrapped(P2PServiceListener::onNoSeedNodeAvailable);
|
||||||
isBootstrapped = true;
|
|
||||||
|
|
||||||
p2PDataStorage.onBootstrapped();
|
|
||||||
|
|
||||||
// We don't use a listener at mailboxMessageService as we require the correct
|
|
||||||
// order of execution. The p2pServiceListeners must be called after
|
|
||||||
// mailboxMessageService.onUpdatedDataReceived.
|
|
||||||
mailboxMessageService.onBootstrapped();
|
|
||||||
|
|
||||||
p2pServiceListeners.forEach(P2PServiceListener::onNoSeedNodeAvailable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -356,6 +335,22 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
|||||||
p2pServiceListeners.forEach(P2PServiceListener::onDataReceived);
|
p2pServiceListeners.forEach(P2PServiceListener::onDataReceived);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void applyIsBootstrapped(Consumer<P2PServiceListener> listenerHandler) {
|
||||||
|
if (!isBootstrapped) {
|
||||||
|
isBootstrapped = true;
|
||||||
|
|
||||||
|
p2PDataStorage.onBootstrapped();
|
||||||
|
|
||||||
|
// We don't use a listener at mailboxMessageService as we require the correct
|
||||||
|
// order of execution. The p2pServiceListeners must be called after
|
||||||
|
// mailboxMessageService.onUpdatedDataReceived.
|
||||||
|
mailboxMessageService.onBootstrapped();
|
||||||
|
|
||||||
|
// Once we have applied the state in the P2P domain we notify our listeners
|
||||||
|
p2pServiceListeners.forEach(listenerHandler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// ConnectionListener implementation
|
// ConnectionListener implementation
|
||||||
|
Loading…
Reference in New Issue
Block a user