Uploaded image for project: 'Infinispan'
  1. Infinispan
  2. ISPN-5704 Enhancements for Functional Map API
  3. ISPN-5849

AutoCloseable return from adding listeners can be clunky to use

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

XMLWordPrintable

    • Icon: Sub-task Sub-task
    • Resolution: Obsolete
    • Icon: Major Major
    • None
    • None
    • None
    • None

      On one side, to use it as a try-with-resource, you need to declare it right in the try();

            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
            }
      

      So its 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.

              Unassigned Unassigned
              rh-ee-galder Galder ZamarreƱo
              Archiver:
              rhn-support-adongare Amol Dongare

                Created:
                Updated:
                Resolved:
                Archived: