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

06601 6518 remove get events #6602

Merged
merged 31 commits into from May 16, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ea2f117
Flatten SwirldsPlatform.buildEventHandlers()
cody-littley May 9, 2023
c2114cb
Flatten SwirldsPlatform.buildEventHandlers()
cody-littley May 9, 2023
9bbc3b2
Started work refactoring PlatformMetrics
cody-littley May 9, 2023
6790f0d
Incremental improvements.
cody-littley May 9, 2023
2bb5dc5
More progress.
cody-littley May 9, 2023
584b13a
IT'S GONE!
cody-littley May 9, 2023
8f6737c
Cleanup.
cody-littley May 9, 2023
2279708
Made suggested changes.
cody-littley May 10, 2023
0b620af
Merge branch '06516-flatten-build-event-handlers' into 06518-6516-del…
cody-littley May 11, 2023
81bbbbc
Merge branch 'develop' into 06518-6516-delete-platform-metrics
cody-littley May 11, 2023
edc629f
Removed many getters from SwirldsPlatform
cody-littley May 11, 2023
40a1930
Removed getParameters()
cody-littley May 11, 2023
bf555f3
Remove sleep after sync methods.
cody-littley May 11, 2023
5e35177
Remove more methods.
cody-littley May 11, 2023
ad7315c
Removed more getters.
cody-littley May 11, 2023
e37b788
Removed getLastSignedStateTimestamp()
cody-littley May 11, 2023
91993d7
Removed even more methods.
cody-littley May 11, 2023
727e71d
cleanup
cody-littley May 11, 2023
4001a9d
Merge branch 'develop' into 6548-6518-remove-getters
cody-littley May 12, 2023
21e057f
Fixed smells.
cody-littley May 12, 2023
7efcaf1
Merge branch 'develop' into 6548-6518-remove-getters
cody-littley May 12, 2023
8487e88
Made suggested change.
cody-littley May 12, 2023
bba897c
Made suggested changes.
cody-littley May 15, 2023
ffb11ea
Made suggested change.
cody-littley May 15, 2023
21642b4
Make suggested changes.
cody-littley May 15, 2023
5c82c01
Made suggested changes.
cody-littley May 15, 2023
ac5ea3f
Move GUI code for getting all events out of the platform.
cody-littley May 15, 2023
5cc178d
Merge branch 'develop' into 06601-6518-remove-get-events
cody-littley May 15, 2023
5679323
Merge branch 'develop' into 06601-6518-remove-get-events
cody-littley May 15, 2023
9106887
Fixed comile issue.
cody-littley May 16, 2023
7b37ecc
Fixed broken test.
cody-littley May 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -32,7 +32,6 @@
import com.swirlds.common.system.BasicSoftwareVersion;
import com.swirlds.common.system.NodeId;
import com.swirlds.common.system.Platform;
import com.swirlds.common.system.PlatformWithDeprecatedMethods;
import com.swirlds.common.system.SwirldMain;
import com.swirlds.common.system.SwirldState;
import com.swirlds.common.system.address.Address;
Expand Down Expand Up @@ -477,7 +476,8 @@ public void init(final Platform platform, final NodeId id) {
public void run() {
while (true) {
if (window != null && !freezeCheckbox.getState()) {
eventsCache = ((PlatformWithDeprecatedMethods) platform).getAllEvents();
eventsCache = GuiPlatformAccessor.getInstance()
.getAllEvents(platform.getSelfId().id());
// after this getAllEvents call, the set of events to draw is frozen
// for the duration of this screen redraw. But their status (consensus or not) may change
// while it is being drawn. If an event is discarded while being drawn, then it forgets its
Expand Down

This file was deleted.

Expand Up @@ -56,12 +56,10 @@
import com.swirlds.common.system.NodeId;
import com.swirlds.common.system.Platform;
import com.swirlds.common.system.PlatformStatus;
import com.swirlds.common.system.PlatformWithDeprecatedMethods;
import com.swirlds.common.system.SoftwareVersion;
import com.swirlds.common.system.SwirldState;
import com.swirlds.common.system.address.Address;
import com.swirlds.common.system.address.AddressBook;
import com.swirlds.common.system.events.PlatformEvent;
import com.swirlds.common.system.transaction.internal.SwirldTransaction;
import com.swirlds.common.system.transaction.internal.SystemTransaction;
import com.swirlds.common.threading.SyncPermitProvider;
Expand Down Expand Up @@ -226,7 +224,6 @@
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
Expand All @@ -241,7 +238,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class SwirldsPlatform implements Platform, PlatformWithDeprecatedMethods, ConnectionTracker, Startable {
public class SwirldsPlatform implements Platform, ConnectionTracker, Startable {

public static final String PLATFORM_THREAD_POOL_NAME = "platform-core";
/** use this for all logging, as controlled by the optional data/log4j2.xml file */
Expand Down Expand Up @@ -1758,43 +1755,6 @@ public boolean createTransaction(@NonNull final byte[] transaction) {
return transactionSubmitter.submitTransaction(new SwirldTransaction(transaction));
}

/**
* {@inheritDoc}
*/
@Deprecated(forRemoval = true)
@Override
public PlatformEvent[] getAllEvents() {
// There is currently a race condition that can cause an exception if event order changes at
// just the right moment. Since this is just a testing utility method and not used in production
// environments, we can just retry until we succeed.
int maxRetries = 100;
while (maxRetries-- > 0) {
try {
final EventImpl[] allEvents = shadowGraph.getAllEvents();
Arrays.sort(allEvents, (o1, o2) -> {
if (o1.getConsensusOrder() != -1 && o2.getConsensusOrder() != -1) {
// both are consensus
return Long.compare(o1.getConsensusOrder(), o2.getConsensusOrder());
} else if (o1.getConsensusTimestamp() == null && o2.getConsensusTimestamp() == null) {
// neither are consensus
return o1.getTimeReceived().compareTo(o2.getTimeReceived());
} else {
// one is consensus, the other is not
if (o1.getConsensusTimestamp() == null) {
return 1;
} else {
return -1;
}
}
});
return allEvents;
} catch (final IllegalArgumentException e) {
logger.error(EXCEPTION.getMarker(), "Exception while sorting events", e);
}
}
throw new IllegalStateException("Unable to sort events after 100 retries");
}

/**
* {@inheritDoc}
*/
Expand Down
Expand Up @@ -16,15 +16,22 @@

package com.swirlds.platform.gui;

import static com.swirlds.logging.LogMarker.EXCEPTION;

import com.swirlds.common.system.events.PlatformEvent;
import com.swirlds.platform.Consensus;
import com.swirlds.platform.components.state.StateManagementComponent;
import com.swirlds.platform.gossip.shadowgraph.ShadowGraph;
import com.swirlds.platform.internal.EventImpl;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
* Provides a way to access private platform objects from the GUI. Suboptimal, but necessary to preserve the current UI
Expand All @@ -35,6 +42,8 @@
@Deprecated(forRemoval = true)
public final class GuiPlatformAccessor {

private static final Logger logger = LogManager.getLogger(GuiPlatformAccessor.class);

private final Map<Long, String> aboutStrings = new ConcurrentHashMap<>();
private final Map<Long, String> platformNames = new ConcurrentHashMap<>();
private final Map<Long, byte[]> swirldIds = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -165,6 +174,41 @@ public ShadowGraph getShadowGraph(final long nodeId) {
return shadowGraphs.getOrDefault(nodeId, null);
}

/**
* Get a sorted list of events.
*/
public PlatformEvent[] getAllEvents(final long nodeId) {
// There is currently a race condition that can cause an exception if event order changes at
// just the right moment. Since this is just a testing utility method and not used in production
// environments, we can just retry until we succeed.
int maxRetries = 100;
while (maxRetries-- > 0) {
try {
final EventImpl[] allEvents = getShadowGraph(nodeId).getAllEvents();
Arrays.sort(allEvents, (o1, o2) -> {
if (o1.getConsensusOrder() != -1 && o2.getConsensusOrder() != -1) {
// both are consensus
return Long.compare(o1.getConsensusOrder(), o2.getConsensusOrder());
} else if (o1.getConsensusTimestamp() == null && o2.getConsensusTimestamp() == null) {
// neither are consensus
return o1.getTimeReceived().compareTo(o2.getTimeReceived());
} else {
// one is consensus, the other is not
if (o1.getConsensusTimestamp() == null) {
return 1;
} else {
return -1;
}
}
});
return allEvents;
} catch (final IllegalArgumentException e) {
logger.error(EXCEPTION.getMarker(), "Exception while sorting events", e);
}
}
throw new IllegalStateException("Unable to sort events after 100 retries");
}

/**
* Set the state management component for a node.
*
Expand Down