BewareMyPower commented on pull request #14346:
URL: https://github.com/apache/pulsar/pull/14346#issuecomment-1044260854


   For example, here is an example implementation for 
`registerFunctionInstanceWithArchive`:
   
   ```java
           final AtomicBoolean computed = new AtomicBoolean(false);
           final AtomicReference<Throwable> throwable = new AtomicReference<>();
           final FunctionCacheEntry entry = cacheFunctions.computeIfAbsent(fid, 
__ -> {
               try {
                   final FunctionCacheEntry cacheEntry =
                           new FunctionCacheEntry(narArchive, eid, 
rootClassLoader, narExtractionDirectory);
                   computed.set(true);
                   return cacheEntry;
               } catch (IOException e) { // I think it's better to catch 
`IOException`, instead of `Throwable`
                   throwable.set(e);
                   return null;
               }
           });
           if (throwable.get() != null) {
               Exceptions.rethrowIOException(throwable.get());
           }
           if (!computed.get() && entry != null) { // the key already exists
               entry.register(eid, Collections.singleton(narArchive), 
Collections.emptyList());
           }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to