/** * @param client the client * @param path path to reap children from * @param executor executor to use for background tasks * @param reapingThresholdMs threshold in milliseconds that determines that a path can be deleted * @param mode reaping mode * @param leaderPath if not null, uses a leader selection so that only 1 reaper is active in the cluster */ public ChildReaper(CuratorFramework client, String path, Reaper.Mode mode, ScheduledExecutorService executor, int reapingThresholdMs, String leaderPath) { this.client = client; this.mode = mode; this.executor = new CloseableScheduledExecutorService(executor); this.reapingThresholdMs = reapingThresholdMs; this.reaper = new Reaper(client, executor, reapingThresholdMs, leaderPath); addPath(path); }
/** * The reaper must be started * * @throws Exception errors */ public void start() throws Exception { Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Cannot be started more than once"); task = executor.scheduleWithFixedDelay ( new Runnable() { @Override public void run() { doWork(); } }, reapingThresholdMs, reapingThresholdMs, TimeUnit.MILLISECONDS ); reaper.start(); }
@VisibleForTesting protected Future<?> schedule(PathHolder pathHolder, int reapingThresholdMs) { if ( reapingIsActive.get() ) { return executor.schedule(pathHolder, reapingThresholdMs, TimeUnit.MILLISECONDS); } return null; }
@Override public void close() throws IOException { if ( state.compareAndSet(State.STARTED, State.CLOSED) ) { executor.close(); if ( leaderLatch != null && ownsLeaderLatch ) { leaderLatch.close(); } } }
/** * @param client client * @param executor thread pool * @param reapingThresholdMs threshold in milliseconds that determines that a path can be deleted * @param leaderLatch a pre-created leader latch to ensure only 1 reaper is active in the cluster * @param ownsLeaderLatch indicates whether or not the reaper owns the leader latch (if it exists) and thus should start/stop it * */ private Reaper(CuratorFramework client, ScheduledExecutorService executor, int reapingThresholdMs, LeaderLatch leaderLatch, boolean ownsLeaderLatch) { this.client = client; this.executor = new CloseableScheduledExecutorService(executor); this.reapingThresholdMs = reapingThresholdMs / EMPTY_COUNT_THRESHOLD; this.leaderLatch = leaderLatch; if (leaderLatch != null) { addListenerToLeaderLatch(leaderLatch); } this.ownsLeaderLatch = ownsLeaderLatch; }
/** * The reaper must be started * * @throws Exception errors */ public void start() throws Exception { Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Cannot be started more than once"); task = executor.scheduleWithFixedDelay ( new Runnable() { @Override public void run() { doWork(); } }, reapingThresholdMs, reapingThresholdMs, TimeUnit.MILLISECONDS ); reaper.start(); }
/** * @param client the client * @param path path to reap children from * @param executor executor to use for background tasks * @param reapingThresholdMs threshold in milliseconds that determines that a path can be deleted * @param mode reaping mode * @param leaderPath if not null, uses a leader selection so that only 1 reaper is active in the cluster */ public ChildReaper(CuratorFramework client, String path, Reaper.Mode mode, ScheduledExecutorService executor, int reapingThresholdMs, String leaderPath) { this.client = client; this.mode = mode; this.executor = new CloseableScheduledExecutorService(executor); this.reapingThresholdMs = reapingThresholdMs; this.reaper = new Reaper(client, executor, reapingThresholdMs, leaderPath); addPath(path); }
/** * The reaper must be started * * @throws Exception errors */ public void start() throws Exception { Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Cannot be started more than once"); task = executor.scheduleWithFixedDelay ( new Runnable() { @Override public void run() { doWork(); } }, reapingThresholdMs, reapingThresholdMs, TimeUnit.MILLISECONDS ); reaper.start(); }
/** * @param client the client * @param path path to reap children from * @param executor executor to use for background tasks * @param reapingThresholdMs threshold in milliseconds that determines that a path can be deleted * @param mode reaping mode * @param leaderPath if not null, uses a leader selection so that only 1 reaper is active in the cluster */ public ChildReaper(CuratorFramework client, String path, Reaper.Mode mode, ScheduledExecutorService executor, int reapingThresholdMs, String leaderPath) { this.client = client; this.mode = mode; this.executor = new CloseableScheduledExecutorService(executor); this.reapingThresholdMs = reapingThresholdMs; this.reaper = new Reaper(client, executor, reapingThresholdMs, leaderPath); addPath(path); }
/** * The reaper must be started * * @throws Exception errors */ public void start() throws Exception { Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Cannot be started more than once"); task = executor.scheduleWithFixedDelay ( new Runnable() { @Override public void run() { doWork(); } }, reapingThresholdMs, reapingThresholdMs, TimeUnit.MILLISECONDS ); reaper.start(); }
/** * @param client the client * @param path path to reap children from * @param executor executor to use for background tasks * @param reapingThresholdMs threshold in milliseconds that determines that a path can be deleted * @param mode reaping mode * @param leaderPath if not null, uses a leader selection so that only 1 reaper is active in the cluster */ public ChildReaper(CuratorFramework client, String path, Reaper.Mode mode, ScheduledExecutorService executor, int reapingThresholdMs, String leaderPath) { this.client = client; this.mode = mode; this.executor = new CloseableScheduledExecutorService(executor); this.reapingThresholdMs = reapingThresholdMs; this.reaper = new Reaper(client, executor, reapingThresholdMs, leaderPath); addPath(path); }
/** * The reaper must be started * * @throws Exception errors */ public void start() throws Exception { Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Cannot be started more than once"); task = executor.scheduleWithFixedDelay ( new Runnable() { @Override public void run() { doWork(); } }, reapingThresholdMs, reapingThresholdMs, TimeUnit.MILLISECONDS ); if (leaderLatch != null) { leaderLatch.start(); } reaper.start(); }
/** * @param client the client * @param path path to reap children from * @param executor executor to use for background tasks * @param reapingThresholdMs threshold in milliseconds that determines that a path can be deleted * @param mode reaping mode * @param leaderPath if not null, uses a leader selection so that only 1 reaper is active in the cluster */ public ChildReaper(CuratorFramework client, String path, Reaper.Mode mode, ScheduledExecutorService executor, int reapingThresholdMs, String leaderPath) { this.client = client; this.mode = mode; this.executor = new CloseableScheduledExecutorService(executor); this.reapingThresholdMs = reapingThresholdMs; this.reaper = new Reaper(client, executor, reapingThresholdMs, leaderPath); addPath(path); }
/** * The reaper must be started * * @throws Exception errors */ public void start() throws Exception { Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Cannot be started more than once"); task = executor.scheduleWithFixedDelay ( new Runnable() { @Override public void run() { doWork(); } }, reapingThresholdMs, reapingThresholdMs, TimeUnit.MILLISECONDS ); reaper.start(); }
/** * @param client the client * @param path path to reap children from * @param executor executor to use for background tasks * @param reapingThresholdMs threshold in milliseconds that determines that a path can be deleted * @param mode reaping mode * @param leaderPath if not null, uses a leader selection so that only 1 reaper is active in the cluster * @param lockSchema a set of the possible subnodes of the children of path that must be reaped in addition to the child nodes */ public ChildReaper(CuratorFramework client, String path, Reaper.Mode mode, ScheduledExecutorService executor, int reapingThresholdMs, String leaderPath, Set<String> lockSchema) { this.client = client; this.mode = mode; this.executor = new CloseableScheduledExecutorService(executor); this.reapingThresholdMs = reapingThresholdMs; if (leaderPath != null) { leaderLatch = new LeaderLatch(client, leaderPath); } else { leaderLatch = null; } this.reaper = new Reaper(client, executor, reapingThresholdMs, leaderLatch); this.lockSchema = lockSchema; addPath(path); }