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

Listener close might get ahead of last event

    XMLWordPrintable

Details

    • Sub-task
    • Status: Resolved (View Workflow)
    • Major
    • Resolution: Won't Do
    • None
    • None
    • None
    • None

    Description

      In this example:

            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
      

      The output is:

      Written (via onWrite): value1
      Written (via onWrite): value2
      Written (via add): new-value1
      

      Even though the listener is closed after the 2nd new value has been modified, it seems like the close might get ahead somehow.

      Attachments

        Issue Links

          Activity

            People

              gzamarre Galder ZamarreƱo
              gzamarre Galder ZamarreƱo
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: