Skip to content

Commit

Permalink
Merge pull request #299 from gama-platform/fixes-flush-all-buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
lesquoyb committed Aug 27, 2024
2 parents 97d4aaa + b5d8e9e commit 65dcf0e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions gama.core/src/gama/core/runtime/GAMA.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ public static void flushWritePerAgent(final AbstractAgent owner) {
bufferingController.flushWriteOfOwner(owner);
}

public static void flushAllBufferings() {
bufferingController.flushAllBufferings();
public static void flushAllBuffers() {
bufferingController.flushAllBuffers();
}

/**
Expand Down
24 changes: 13 additions & 11 deletions gama.core/src/gama/core/runtime/concurrent/BufferingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.NotImplementedException;
Expand Down Expand Up @@ -374,10 +374,10 @@ public synchronized void flushWriteOfOwner(AbstractAgent owner) {
}

/**
* Flushes all bufferings that are waiting.
* Flushes write and save bufferings, whether registered per cycle or per agent
* Flushes all buffers that are waiting.
* Flushes write and save buffers, whether registered per cycle or per agent
*/
public synchronized void flushAllBufferings() {
public synchronized void flushAllBuffers() {
// flushes the console per cycle first
for (var agent : consoleBufferListPerAgentForCycles.keySet()) {
flushWriteInCycle(agent);
Expand All @@ -387,19 +387,21 @@ public synchronized void flushAllBufferings() {
flushWriteOfOwner(agent);
}
// flushes the files registered for the cycle
var agents = fileBufferPerAgentForCycles.entrySet().stream().map(s -> s.getValue().keySet())
.collect(Collectors.toSet())
.toArray(new AbstractAgent[0]);
var agents = fileBufferPerAgentForCycles.entrySet().stream()
.map( s -> s.getValue().keySet())
.flatMap(Collection::stream)
.toArray(length -> new AbstractAgent[length]);
for (AbstractAgent agent : agents) {
flushSaveFilesInCycle(agent);
}
// finally flushes the files registered per agent
agents = fileBufferPerAgent.entrySet().stream().map(s -> s.getValue().keySet())
.collect(Collectors.toSet())
.toArray(new AbstractAgent[0]);
agents = fileBufferPerAgent.entrySet().stream()
.map( s -> s.getValue().keySet())
.flatMap(Collection::stream)
.toArray(length -> new AbstractAgent[length]);
for (AbstractAgent agent : agents) {
flushSaveFilesOfOwner(agent);
}
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions gama.ui.application/src/gama/ui/application/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public Object start(final IApplicationContext context) throws Exception {
if (display != null) { display.dispose(); }
final Location instanceLoc = Platform.getInstanceLocation();
if (instanceLoc != null) { instanceLoc.release(); }
GAMA.flushAllBufferings();
GAMA.flushAllBuffers();
}
}
return EXIT_OK;
Expand Down Expand Up @@ -270,7 +270,7 @@ public static Object checkWorkspace() throws IOException {

@Override
public void stop() {
GAMA.flushAllBufferings();
GAMA.flushAllBuffers();
final IWorkbench workbench = getWorkbench();
if (workbench == null) return;
final Display display = workbench.getDisplay();
Expand Down

0 comments on commit 65dcf0e

Please sign in to comment.