Class ResourceWatchHandle

java.lang.Object
cloud.opencode.base.classloader.resource.ResourceWatchHandle
All Implemented Interfaces:
AutoCloseable

public class ResourceWatchHandle extends Object implements AutoCloseable
Resource Watch Handle - Handle for a resource watch registration 资源监听句柄 - 资源监听注册的句柄

AutoCloseable handle that allows cancelling a resource watch registration. Closing the handle removes the associated watch callback.

可自动关闭的句柄,允许取消资源监听注册。关闭句柄会移除关联的监听回调。

Usage Examples | 使用示例:

try (ResourceWatchHandle handle = watcher.watch(path, event -> {
    System.out.println("File changed: " + event.type());
})) {
    // handle is auto-closed when leaving try block
}

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Null-safe: Yes - 空值安全: 是
Since:
JDK 25, opencode-base-classloader V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • ResourceWatchHandle

      public ResourceWatchHandle(Runnable cancelAction)
      Create a new ResourceWatchHandle 创建新的 ResourceWatchHandle
      Parameters:
      cancelAction - action to run on close | 关闭时执行的动作
      Throws:
      NullPointerException - if cancelAction is null | 如果 cancelAction 为 null 则抛出
  • Method Details

    • close

      public void close()
      Close the handle and cancel the watch registration. Idempotent: subsequent calls are no-ops. 关闭句柄并取消监听注册。幂等:后续调用无操作。
      Specified by:
      close in interface AutoCloseable
    • isClosed

      public boolean isClosed()
      Check if this handle has been closed 检查句柄是否已关闭
      Returns:
      true if closed | 已关闭返回 true