[infinispan-issues] [JBoss JIRA] (ISPN-5850) Listener close might get ahead of last event
Galder Zamarreño (JIRA)
issues at jboss.org
Mon Oct 12 03:48:00 EDT 2015
Galder Zamarreño created ISPN-5850:
--------------------------------------
Summary: Listener close might get ahead of last event
Key: ISPN-5850
URL: https://issues.jboss.org/browse/ISPN-5850
Project: Infinispan
Issue Type: Sub-task
Reporter: Galder Zamarreño
Assignee: Galder Zamarreño
Fix For: 8.1.0.Final
In this example:
{code}
FunctionalMap.ReadOnlyMap<String, String> readOnlyMap = CreateFunctionalMaps.ro();
FunctionalMap.WriteOnlyMap<String, String> writeOnlyMap = CreateFunctionalMaps.wo();
FunctionalMap.ReadWriteMap<String, String> readWriteMap = CreateFunctionalMaps.rw();
// `written` is a ReadEntryView of the written entry
try(AutoCloseable handler = writeOnlyMap.listeners().onWrite(written ->
System.out.printf("Written (via onWrite): %s%n", written.get()))) {
Map<String, String> entries = new HashMap<>();
entries.put("key1", "value1");
entries.put("key2", "value2");
writeOnlyMap.evalMany(entries, (v, writeView) -> writeView.set(v))
.get(); // Wait for completable future
}
AutoCloseable writeCloseHandler = writeOnlyMap.listeners().add(new WriteListener<String, String>() {
@Override
public void onWrite(ReadEntryView<String, String> written) {
System.out.printf("Written (via add): %s%n", written.get());
}
});
CompletableFuture<Void> f0 = writeOnlyMap.eval("key1", view -> view.set("new-value1"));
CompletableFuture<Void> f1 = f0.thenAccept(ignore ->
writeOnlyMap.eval("key2", view -> view.set("new-value2")));
CompletableFuture<Void> f2 = f1.thenAccept(ignore -> {
try {
writeCloseHandler.close();
} catch (Exception e) {
e.printStackTrace(); // TODO: Customise this generated block
}
});
f2.get(); // Wait for completable future
{code}
The output is:
{code}
Written (via onWrite): value1
Written (via onWrite): value2
Written (via add): new-value1
{code}
Even though the listener is closed after the 2nd new value has been modified, it seems like the close might get ahead somehow.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
More information about the infinispan-issues
mailing list