Merge pull request #2999 from christophsturm/christoph/rename-clock

rename Clock to ClockWatcher
This commit is contained in:
sqrrm 2019-07-29 14:39:22 +02:00 committed by GitHub
commit 2570e9b728
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 115 additions and 112 deletions

View File

@ -24,9 +24,9 @@ import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
// Helps configure listener objects that are run by the `UserThread` each second
// and can do per second, per minute and delayed second actions.
// and can do per second, per minute and delayed second actions. Also detects when we were in standby, and logs it.
@Slf4j
public class Clock {
public class ClockWatcher {
public static final int IDLE_TOLERANCE_MS = 20000;
public interface Listener {
@ -46,7 +46,7 @@ public class Clock {
private long counter = 0;
private long lastSecondTick;
public Clock() {
public ClockWatcher() {
}
public void start() {
@ -66,7 +66,7 @@ public class Clock {
long missedMs = diff - 1000;
listeners.forEach(listener -> listener.onMissedSecondTick(missedMs));
if (missedMs > Clock.IDLE_TOLERANCE_MS) {
if (missedMs > ClockWatcher.IDLE_TOLERANCE_MS) {
log.info("We have been in standby mode for {} sec", missedMs / 1000);
listeners.forEach(listener -> listener.onAwakeFromStandby(missedMs));
}

View File

@ -53,7 +53,7 @@ import bisq.network.p2p.P2PModule;
import bisq.network.p2p.network.BridgeAddressProvider;
import bisq.network.p2p.seed.SeedNodeRepository;
import bisq.common.Clock;
import bisq.common.ClockWatcher;
import bisq.common.CommonOptionKeys;
import bisq.common.app.AppModule;
import bisq.common.crypto.KeyRing;
@ -92,7 +92,7 @@ public class CoreModule extends AppModule {
bind(KeyStorage.class).in(Singleton.class);
bind(KeyRing.class).in(Singleton.class);
bind(User.class).in(Singleton.class);
bind(Clock.class).in(Singleton.class);
bind(ClockWatcher.class).in(Singleton.class);
bind(Preferences.class).in(Singleton.class);
bind(BridgeAddressProvider.class).to(Preferences.class).in(Singleton.class);
bind(CorruptedDatabaseFilesHandler.class).in(Singleton.class);

View File

@ -58,7 +58,7 @@ import bisq.network.crypto.EncryptionService;
import bisq.network.p2p.P2PService;
import bisq.network.p2p.peers.keepalive.messages.Ping;
import bisq.common.Clock;
import bisq.common.ClockWatcher;
import bisq.common.Timer;
import bisq.common.UserThread;
import bisq.common.app.DevEnv;
@ -134,7 +134,7 @@ public class BisqSetup {
private final PrivateNotificationManager privateNotificationManager;
private final FilterManager filterManager;
private final TradeStatisticsManager tradeStatisticsManager;
private final Clock clock;
private final ClockWatcher clockWatcher;
private final FeeService feeService;
private final DaoSetup daoSetup;
private final EncryptionService encryptionService;
@ -212,7 +212,7 @@ public class BisqSetup {
PrivateNotificationManager privateNotificationManager,
FilterManager filterManager,
TradeStatisticsManager tradeStatisticsManager,
Clock clock,
ClockWatcher clockWatcher,
FeeService feeService,
DaoSetup daoSetup,
EncryptionService encryptionService,
@ -252,7 +252,7 @@ public class BisqSetup {
this.privateNotificationManager = privateNotificationManager;
this.filterManager = filterManager;
this.tradeStatisticsManager = tradeStatisticsManager;
this.clock = clock;
this.clockWatcher = clockWatcher;
this.feeService = feeService;
this.daoSetup = daoSetup;
this.encryptionService = encryptionService;
@ -599,7 +599,7 @@ public class BisqSetup {
private void initDomainServices() {
log.info("initDomainServices");
clock.start();
clockWatcher.start();
tradeLimits.onAllServicesInitialized();

View File

@ -38,7 +38,7 @@ import bisq.network.p2p.P2PModule;
import bisq.network.p2p.network.BridgeAddressProvider;
import bisq.network.p2p.seed.SeedNodeRepository;
import bisq.common.Clock;
import bisq.common.ClockWatcher;
import bisq.common.CommonOptionKeys;
import bisq.common.app.AppModule;
import bisq.common.crypto.KeyRing;
@ -69,7 +69,7 @@ public class ModuleForAppWithP2p extends AppModule {
bind(KeyStorage.class).in(Singleton.class);
bind(KeyRing.class).in(Singleton.class);
bind(User.class).in(Singleton.class);
bind(Clock.class).in(Singleton.class);
bind(ClockWatcher.class).in(Singleton.class);
bind(NetworkProtoResolver.class).to(CoreNetworkProtoResolver.class).in(Singleton.class);
bind(PersistenceProtoResolver.class).to(CorePersistenceProtoResolver.class).in(Singleton.class);
bind(Preferences.class).in(Singleton.class);

View File

@ -47,7 +47,7 @@ import bisq.network.p2p.BootstrapListener;
import bisq.network.p2p.NodeAddress;
import bisq.network.p2p.P2PService;
import bisq.common.Clock;
import bisq.common.ClockWatcher;
import bisq.common.UserThread;
import bisq.common.crypto.KeyRing;
import bisq.common.handlers.ErrorMessageHandler;
@ -117,7 +117,7 @@ public class TradeManager implements PersistedDataHost {
private final ReferralIdService referralIdService;
private final AccountAgeWitnessService accountAgeWitnessService;
private final ArbitratorManager arbitratorManager;
private final Clock clock;
private final ClockWatcher clockWatcher;
private final Storage<TradableList<Trade>> tradableListStorage;
private TradableList<Trade> tradableList;
@ -151,7 +151,7 @@ public class TradeManager implements PersistedDataHost {
PersistenceProtoResolver persistenceProtoResolver,
AccountAgeWitnessService accountAgeWitnessService,
ArbitratorManager arbitratorManager,
Clock clock,
ClockWatcher clockWatcher,
@Named(Storage.STORAGE_DIR) File storageDir) {
this.user = user;
this.keyRing = keyRing;
@ -168,7 +168,7 @@ public class TradeManager implements PersistedDataHost {
this.referralIdService = referralIdService;
this.accountAgeWitnessService = accountAgeWitnessService;
this.arbitratorManager = arbitratorManager;
this.clock = clock;
this.clockWatcher = clockWatcher;
tradableListStorage = new Storage<>(storageDir, persistenceProtoResolver);
@ -623,7 +623,7 @@ public class TradeManager implements PersistedDataHost {
public void applyTradePeriodState() {
updateTradePeriodState();
clock.addListener(new Clock.Listener() {
clockWatcher.addListener(new ClockWatcher.Listener() {
@Override
public void onSecondTick() {
}

View File

@ -35,7 +35,7 @@ import bisq.core.util.validation.BtcAddressValidator;
import bisq.network.p2p.P2PService;
import bisq.common.Clock;
import bisq.common.ClockWatcher;
import bisq.common.app.DevEnv;
import org.bitcoinj.core.Coin;
@ -89,7 +89,7 @@ public class PendingTradesViewModel extends ActivatableWithDataModel<PendingTrad
final AccountAgeWitnessService accountAgeWitnessService;
public final P2PService p2PService;
private final ClosedTradableManager closedTradableManager;
public final Clock clock;
public final ClockWatcher clockWatcher;
@Getter
private final User user;
@ -113,7 +113,7 @@ public class PendingTradesViewModel extends ActivatableWithDataModel<PendingTrad
P2PService p2PService,
ClosedTradableManager closedTradableManager,
AccountAgeWitnessService accountAgeWitnessService,
Clock clock,
ClockWatcher clockWatcher,
User user) {
super(dataModel);
@ -123,7 +123,7 @@ public class PendingTradesViewModel extends ActivatableWithDataModel<PendingTrad
this.p2PService = p2PService;
this.closedTradableManager = closedTradableManager;
this.accountAgeWitnessService = accountAgeWitnessService;
this.clock = clock;
this.clockWatcher = clockWatcher;
this.user = user;
}

View File

@ -30,7 +30,7 @@ import bisq.core.locale.Res;
import bisq.core.trade.Trade;
import bisq.core.user.Preferences;
import bisq.common.Clock;
import bisq.common.ClockWatcher;
import bisq.common.util.Tuple3;
import de.jensd.fx.fontawesome.AwesomeDude;
@ -85,7 +85,7 @@ public abstract class TradeStepView extends AnchorPane {
private TxIdTextField txIdTextField;
protected TradeSubView.NotificationGroup notificationGroup;
private Subscription txIdSubscription;
private Clock.Listener clockListener;
private ClockWatcher.Listener clockListener;
private final ChangeListener<String> errorMessageListener;
protected Label infoLabel;
@ -139,7 +139,7 @@ public abstract class TradeStepView extends AnchorPane {
showSupportFields();
};
clockListener = new Clock.Listener() {
clockListener = new ClockWatcher.Listener() {
@Override
public void onSecondTick() {
}
@ -175,7 +175,7 @@ public abstract class TradeStepView extends AnchorPane {
updateTradePeriodState(newValue);
});
model.clock.addListener(clockListener);
model.clockWatcher.addListener(clockListener);
if (infoLabel != null)
infoLabel.setText(getInfoText());
@ -198,7 +198,7 @@ public abstract class TradeStepView extends AnchorPane {
tradePeriodStateSubscription.unsubscribe();
if (clockListener != null)
model.clock.removeListener(clockListener);
model.clockWatcher.removeListener(clockListener);
if (notificationGroup != null)
notificationGroup.button.setOnAction(null);

View File

@ -41,7 +41,7 @@ import bisq.core.util.BSFormatter;
import bisq.network.p2p.P2PService;
import bisq.network.p2p.network.Statistic;
import bisq.common.Clock;
import bisq.common.ClockWatcher;
import bisq.common.UserThread;
import org.bitcoinj.core.Peer;
@ -111,7 +111,7 @@ public class NetworkSettingsView extends ActivatableViewAndModel<GridPane, Activ
private final FilterManager filterManager;
private final BisqEnvironment bisqEnvironment;
private final TorNetworkSettingsWindow torNetworkSettingsWindow;
private final Clock clock;
private final ClockWatcher clockWatcher;
private final BSFormatter formatter;
private final WalletsSetup walletsSetup;
private final P2PService p2PService;
@ -137,7 +137,7 @@ public class NetworkSettingsView extends ActivatableViewAndModel<GridPane, Activ
FilterManager filterManager,
BisqEnvironment bisqEnvironment,
TorNetworkSettingsWindow torNetworkSettingsWindow,
Clock clock,
ClockWatcher clockWatcher,
BSFormatter formatter) {
super();
this.walletsSetup = walletsSetup;
@ -147,7 +147,7 @@ public class NetworkSettingsView extends ActivatableViewAndModel<GridPane, Activ
this.filterManager = filterManager;
this.bisqEnvironment = bisqEnvironment;
this.torNetworkSettingsWindow = torNetworkSettingsWindow;
this.clock = clock;
this.clockWatcher = clockWatcher;
this.formatter = formatter;
}
@ -425,7 +425,7 @@ public class NetworkSettingsView extends ActivatableViewAndModel<GridPane, Activ
tableView.getItems().forEach(P2pNetworkListItem::cleanup);
networkListItems.clear();
networkListItems.setAll(p2PService.getNetworkNode().getAllConnections().stream()
.map(connection -> new P2pNetworkListItem(connection, clock, formatter))
.map(connection -> new P2pNetworkListItem(connection, clockWatcher, formatter))
.collect(Collectors.toList()));
}

View File

@ -24,7 +24,7 @@ import bisq.network.p2p.network.Connection;
import bisq.network.p2p.network.OutboundConnection;
import bisq.network.p2p.network.Statistic;
import bisq.common.Clock;
import bisq.common.ClockWatcher;
import org.apache.commons.lang3.time.DurationFormatUtils;
@ -43,7 +43,7 @@ public class P2pNetworkListItem {
private final Statistic statistic;
private final Connection connection;
private final Subscription sentBytesSubscription, receivedBytesSubscription, onionAddressSubscription, roundTripTimeSubscription;
private final Clock clock;
private final ClockWatcher clockWatcher;
private final BSFormatter formatter;
private final StringProperty lastActivity = new SimpleStringProperty();
@ -53,11 +53,11 @@ public class P2pNetworkListItem {
private final StringProperty connectionType = new SimpleStringProperty();
private final StringProperty roundTripTime = new SimpleStringProperty();
private final StringProperty onionAddress = new SimpleStringProperty();
private final Clock.Listener listener;
private final ClockWatcher.Listener listener;
public P2pNetworkListItem(Connection connection, Clock clock, BSFormatter formatter) {
public P2pNetworkListItem(Connection connection, ClockWatcher clockWatcher, BSFormatter formatter) {
this.connection = connection;
this.clock = clock;
this.clockWatcher = clockWatcher;
this.formatter = formatter;
this.statistic = connection.getStatistic();
@ -70,7 +70,7 @@ public class P2pNetworkListItem {
roundTripTimeSubscription = EasyBind.subscribe(statistic.roundTripTimeProperty(),
roundTripTime -> this.roundTripTime.set((int) roundTripTime == 0 ? "-" : roundTripTime + " ms"));
listener = new Clock.Listener() {
listener = new ClockWatcher.Listener() {
@Override
public void onSecondTick() {
onLastActivityChanged(statistic.getLastActivityTimestamp());
@ -82,7 +82,7 @@ public class P2pNetworkListItem {
public void onMinuteTick() {
}
};
clock.addListener(listener);
clockWatcher.addListener(listener);
onLastActivityChanged(statistic.getLastActivityTimestamp());
updatePeerType();
updateConnectionType();
@ -100,7 +100,7 @@ public class P2pNetworkListItem {
receivedBytesSubscription.unsubscribe();
onionAddressSubscription.unsubscribe();
roundTripTimeSubscription.unsubscribe();
clock.removeListener(listener);
clockWatcher.removeListener(listener);
}
public void updateConnectionType() {

View File

@ -17,36 +17,19 @@
package bisq.monitor.metric;
import java.io.File;
import bisq.monitor.AvailableTor;
import bisq.monitor.Metric;
import bisq.monitor.Monitor;
import bisq.monitor.Reporter;
import bisq.monitor.ThreadGate;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.core.env.PropertySource;
import bisq.common.Clock;
import bisq.common.app.Capabilities;
import bisq.common.app.Capability;
import bisq.common.proto.network.NetworkEnvelope;
import bisq.common.proto.network.NetworkProtoResolver;
import bisq.core.app.BisqEnvironment;
import bisq.core.btc.BaseCurrencyNetwork;
import bisq.core.btc.BtcOptionKeys;
import bisq.core.network.p2p.seed.DefaultSeedNodeRepository;
import bisq.core.proto.network.CoreNetworkProtoResolver;
import bisq.core.proto.persistable.CorePersistenceProtoResolver;
import bisq.monitor.AvailableTor;
import bisq.monitor.Metric;
import bisq.monitor.Monitor;
import bisq.monitor.Reporter;
import bisq.monitor.ThreadGate;
import bisq.network.p2p.network.Connection;
import bisq.network.p2p.network.MessageListener;
import bisq.network.p2p.network.NetworkNode;
@ -56,6 +39,26 @@ import bisq.network.p2p.peers.PeerManager;
import bisq.network.p2p.peers.keepalive.KeepAliveManager;
import bisq.network.p2p.peers.peerexchange.PeerExchangeManager;
import bisq.network.p2p.storage.messages.BroadcastMessage;
import bisq.common.ClockWatcher;
import bisq.common.app.Capabilities;
import bisq.common.app.Capability;
import bisq.common.proto.network.NetworkEnvelope;
import bisq.common.proto.network.NetworkProtoResolver;
import org.springframework.core.env.PropertySource;
import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import lombok.extern.slf4j.Slf4j;
/**
@ -63,7 +66,7 @@ import lombok.extern.slf4j.Slf4j;
* answers are then compiled into buckets of message types. Based on these
* buckets, the Metric reports (for each host) the message types observed and
* their number along with a relative comparison between all hosts.
*
*
* @author Florian Reimair
*
*/
@ -104,43 +107,6 @@ public class P2PNetworkLoad extends Metric implements MessageListener, SetupList
}
}
/**
* Efficient way to count message occurrences.
*/
private class Counter {
private int value = 1;
/**
* atomic get and reset
*
* @return the current value
*/
synchronized int getAndReset() {
try {
return value;
} finally {
value = 0;
}
}
synchronized void increment() {
value++;
}
}
public P2PNetworkLoad(Reporter reporter) {
super(reporter);
}
@Override
public void configure(Properties properties) {
super.configure(properties);
history = Collections.synchronizedMap(new FixedSizeHistoryTracker(Integer.parseInt(configuration.getProperty(HISTORY_SIZE, "200"))));
Capabilities.app.addAll(Capability.DAO_FULL_NODE);
}
@Override
protected void execute() {
@ -175,7 +141,7 @@ public class P2PNetworkLoad extends Metric implements MessageListener, SetupList
CorePersistenceProtoResolver persistenceProtoResolver = new CorePersistenceProtoResolver(null,
networkProtoResolver, storageDir);
DefaultSeedNodeRepository seedNodeRepository = new DefaultSeedNodeRepository(environment, null);
PeerManager peerManager = new PeerManager(networkNode, seedNodeRepository, new Clock(),
PeerManager peerManager = new PeerManager(networkNode, seedNodeRepository, new ClockWatcher(),
persistenceProtoResolver, maxConnections, storageDir);
// init file storage
@ -223,6 +189,43 @@ public class P2PNetworkLoad extends Metric implements MessageListener, SetupList
lastRun = System.currentTimeMillis();
}
public P2PNetworkLoad(Reporter reporter) {
super(reporter);
}
@Override
public void configure(Properties properties) {
super.configure(properties);
history = Collections.synchronizedMap(new FixedSizeHistoryTracker(Integer.parseInt(configuration.getProperty(HISTORY_SIZE, "200"))));
Capabilities.app.addAll(Capability.DAO_FULL_NODE);
}
/**
* Efficient way to count message occurrences.
*/
private class Counter {
private int value = 1;
/**
* atomic get and reset
*
* @return the current value
*/
synchronized int getAndReset() {
try {
return value;
} finally {
value = 0;
}
}
synchronized void increment() {
value++;
}
}
@Override
public void onMessage(NetworkEnvelope networkEnvelope, Connection connection) {
if (networkEnvelope instanceof BroadcastMessage) {

View File

@ -29,7 +29,7 @@ import bisq.network.p2p.peers.peerexchange.Peer;
import bisq.network.p2p.peers.peerexchange.PeerList;
import bisq.network.p2p.seed.SeedNodeRepository;
import bisq.common.Clock;
import bisq.common.ClockWatcher;
import bisq.common.Timer;
import bisq.common.UserThread;
import bisq.common.app.Capabilities;
@ -103,7 +103,7 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
///////////////////////////////////////////////////////////////////////////////////////////
private final NetworkNode networkNode;
private final Clock clock;
private final ClockWatcher clockWatcher;
private int maxConnections;
private final Set<NodeAddress> seedNodeAddresses;
@ -111,7 +111,7 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
private final Storage<PeerList> storage;
private final HashSet<Peer> persistedPeers = new HashSet<>();
private final Set<Peer> reportedPeers = new HashSet<>();
private final Clock.Listener listener;
private final ClockWatcher.Listener listener;
private final List<Listener> listeners = new CopyOnWriteArrayList<>();
private Timer checkMaxConnectionsTimer;
private boolean stopped;
@ -132,13 +132,13 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
@Inject
public PeerManager(NetworkNode networkNode,
SeedNodeRepository seedNodeRepository,
Clock clock,
ClockWatcher clockWatcher,
PersistenceProtoResolver persistenceProtoResolver,
@Named(NetworkOptionKeys.MAX_CONNECTIONS) int maxConnections,
@Named(Storage.STORAGE_DIR) File storageDir) {
this.networkNode = networkNode;
this.seedNodeAddresses = new HashSet<>(seedNodeRepository.getSeedNodeAddresses());
this.clock = clock;
this.clockWatcher = clockWatcher;
storage = new Storage<>(storageDir, persistenceProtoResolver);
this.networkNode.addConnectionListener(this);
@ -146,7 +146,7 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
setConnectionLimits(maxConnections);
// we check if app was idle for more then 5 sec.
listener = new Clock.Listener() {
listener = new ClockWatcher.Listener() {
@Override
public void onSecondTick() {
}
@ -162,12 +162,12 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
listeners.forEach(Listener::onAwakeFromStandby);
}
};
clock.addListener(listener);
clockWatcher.addListener(listener);
}
public void shutDown() {
networkNode.removeConnectionListener(this);
clock.removeListener(listener);
clockWatcher.removeListener(listener);
stopCheckMaxConnectionsTimer();
}

View File

@ -203,7 +203,7 @@ public class DummySeedNode {
// seedNodesRepository.setNodeAddressToExclude(mySeedNodeAddress);
/* seedNodeP2PService = new P2PService(seedNodesRepository, mySeedNodeAddress.getPort(), maxConnections,
torDir, useLocalhostForP2P, networkId, storageDir, null, null, null, new Clock(), null, null,
torDir, useLocalhostForP2P, networkId, storageDir, null, null, null, new ClockWatcher(), null, null,
null, TestUtils.getNetworkProtoResolver(), TestUtils.getPersistenceProtoResolver());
seedNodeP2PService.start(listener);*/
}

View File

@ -123,7 +123,7 @@ public class TestUtils {
P2PService p2PService = new P2PService(seedNodesRepository, port, new File("seed_node_" + port), useLocalhostForP2P,
2, P2PService.MAX_CONNECTIONS_DEFAULT, new File("dummy"), null, null, null,
new Clock(), null, encryptionService, keyRing, getNetworkProtoResolver(), getPersistenceProtoResolver());
new ClockWatcher(), null, encryptionService, keyRing, getNetworkProtoResolver(), getPersistenceProtoResolver());
p2PService.start(new P2PServiceListener() {
@Override
public void onRequestingDataCompleted() {