Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/org/openlcb/cdi/cmd/RestoreConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static void parseConfigFromReader(@NonNull BufferedReader reader, @NonNul
try {
while ((line = reader.readLine()) != null) {
if (line.charAt(0) == '#') continue;
if (line.isEmpty()) continue;
int pos = line.indexOf('=');
if (pos < 0) {
logger.log(Level.WARNING, "Failed to parse line: {0}", line);
Expand Down
14 changes: 11 additions & 3 deletions src/org/openlcb/cdi/impl/ConfigRepresentation.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class ConfigRepresentation extends DefaultPropertyListenerSupport {
private final Map<String, CdiEntry> variables = new HashMap<>();
// Last time the progressbar was updated from the load.
private long lastProgress;

private int cacheMemoryRead;

public EventNameStore eventNameStore;

Expand Down Expand Up @@ -98,10 +100,10 @@ private void triggerFetchCdi() {
public void progressNotify(long bytesRead, long totalBytes) {
lastProgress = new Date().getTime();
if (totalBytes > 0) {
setState(String.format("Loading: %.2f%% complete", bytesRead * 100.0 /
setState(String.format("Loading display format: %.2f%% complete", bytesRead * 100.0 /
totalBytes));
} else {
setState(String.format("Loading: %d bytes complete", bytesRead));
setState(String.format("Loading display format: %d bytes complete", bytesRead));
}
}

Expand Down Expand Up @@ -139,12 +141,18 @@ public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
.UPDATE_LOADING_COMPLETE)) {
synchronized (this) {
if (--pendingCacheFills == 0) {
firePropertyChange(UPDATE_CACHE_COMPLETE, null, null);
firePropertyChange(UPDATE_CACHE_COMPLETE, null, 1);
for (MemorySpaceCache sp : spaces.values()) {
sp.removePropertyChangeListener(prefillListener);
}
}
}
} else if (propertyChangeEvent.getPropertyName().equals(MemorySpaceCache
.LOADING_RANGE)) {
cacheMemoryRead += (Integer)propertyChangeEvent.getNewValue();
setState(String.format("Loading configuration data: %d bytes complete", cacheMemoryRead));
firePropertyChange(UPDATE_STATE, null, cacheMemoryRead);

}
}
};
Expand Down
3 changes: 3 additions & 0 deletions src/org/openlcb/cdi/impl/MemorySpaceCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
public class MemorySpaceCache {
// This event will be fired when the cache is completely pre-filled.
public static final String UPDATE_LOADING_COMPLETE = "UPDATE_LOADING_COMPLETE";
// This event will be fired as each range is read
public static final String LOADING_RANGE = "LOADING_RANGE";
// This event will be fired on the registered data listeners.
public static final String UPDATE_DATA = "UPDATE_DATA";
private static final Logger logger = Logger.getLogger(MemorySpaceCache.class.getName());
Expand Down Expand Up @@ -224,6 +226,7 @@ private void loadRange() {
if (count > 64) {
count = 64;
}
firePropertyChange(LOADING_RANGE, null, count);
final int fcount = count;
access.doRead(currentRangeNextOffset, space, count,
new MemoryConfigurationService.McsReadHandler() {
Expand Down
3 changes: 2 additions & 1 deletion src/org/openlcb/cdi/swing/CdiPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
import util.CollapsiblePanel;
import util.WrapLayout;

import static org.openlcb.cdi.impl.ConfigRepresentation.UPDATE_CACHE_COMPLETE;
import static org.openlcb.cdi.impl.ConfigRepresentation.UPDATE_ENTRY_DATA;
import static org.openlcb.cdi.impl.ConfigRepresentation.UPDATE_REP;
import static org.openlcb.cdi.impl.ConfigRepresentation.UPDATE_STATE;
Expand Down Expand Up @@ -670,7 +671,7 @@ private void addLoadingListener() {
loadingListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
if (event.getPropertyName().equals(UPDATE_REP)) {
if (event.getPropertyName().equals(UPDATE_CACHE_COMPLETE)) {
displayCdi();
} else if (event.getPropertyName().equals(UPDATE_STATE)) {
loadingText.setText(rep.getStatus());
Expand Down
2 changes: 1 addition & 1 deletion test/org/openlcb/cdi/impl/ConfigRepresentationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void testComplexCdiLoad() throws Exception {
ConfigRepresentation rep = new ConfigRepresentation(iface, remoteNode);
// Since all of our memory configuration commands execute inline, the representation will
// be ready by the time it returns.
Assert.assertEquals("Representation complete.", rep.getStatus());
Assert.assertEquals("Loading configuration data: 73 bytes complete", rep.getStatus());
Assert.assertNotNull(rep.getRoot());

ConfigRepresentation.CdiContainer cont = rep.getRoot();
Expand Down