[infinispan-issues] [JBoss JIRA] (ISPN-5849) AutoCloseable return from adding listeners can be clunky to use
Tristan Tarrant (JIRA)
issues at jboss.org
Tue May 17 08:22:09 EDT 2016
[ https://issues.jboss.org/browse/ISPN-5849?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Tristan Tarrant updated ISPN-5849:
----------------------------------
Fix Version/s: 9.0.0.Alpha3
(was: 9.0.0.Alpha2)
> AutoCloseable return from adding listeners can be clunky to use
> ---------------------------------------------------------------
>
> Key: ISPN-5849
> URL: https://issues.jboss.org/browse/ISPN-5849
> Project: Infinispan
> Issue Type: Sub-task
> Reporter: Galder ZamarreƱo
> Assignee: Galder ZamarreƱo
> Fix For: 9.0.0.Alpha3
>
>
> On one side, to use it as a try-with-resource, you need to declare it right in the {{try()}};
> {code}
> 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
> }
> {code}
> So it's usability is mostly designed for unit tests since listeners tend to be set and removed at a later stage. IOW, listeners are not generally a short-lived object.
> The other aspect that is clunky to use is the fact that AutoCloseable's close() throws Exception, which again makes it ackward to use for example if lambdas.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
More information about the infinispan-issues
mailing list