/** * Start cluster * * @throws Exception */ protected void startBookKeeper() throws Exception { zkc = MockZooKeeper.newInstance(); for (int i = 0; i < numBookies; i++) { ZkUtils.createFullPathOptimistic(zkc, "/ledgers/available/192.168.1.1:" + (5000 + i), "".getBytes(), null, null); } zkc.create("/ledgers/LAYOUT", "1\nflat:1".getBytes(), null, null); bkc = new PulsarMockBookKeeper(zkc, executor.chooseThread(this)); }
@VisibleForTesting ScheduledExecutorService getFuturePool() { return scheduler.chooseThread(streamName); }
RootRangeClientImpl(OrderedScheduler scheduler, StorageContainerChannelManager channelManager) { this.executor = scheduler.chooseThread(ROOT_STORAGE_CONTAINER_ID); this.scClient = channelManager.getOrCreate(ROOT_STORAGE_CONTAINER_ID); }
/** * schedules a one time action to execute with an ordering guarantee on the key. * * @param orderingKey * @param callable */ public <T> ListenableFuture<T> submitOrdered(Object orderingKey, Callable<T> callable) { return chooseThread(orderingKey).submit(callable); }
public StorageContainerChannelManager(StorageServerChannelManager channelManager, LocationClient locationClient, OrderedScheduler scheduler) { this((scId) -> new StorageContainerChannel( scId, channelManager, locationClient, scheduler.chooseThread(scId))); }
/** * Creates and executes a one-shot action that becomes enabled after the given delay. * * @param orderingKey - the key used for ordering * @param command - the SafeRunnable to execute * @param delay - the time from now to delay execution * @param unit - the time unit of the delay parameter * @return a ScheduledFuture representing pending completion of the task and whose get() method * will return null upon completion */ public ScheduledFuture<?> scheduleOrdered(Object orderingKey, SafeRunnable command, long delay, TimeUnit unit) { return chooseThread(orderingKey).schedule(command, delay, unit); }
/** * Creates and executes a periodic action that becomes enabled first after * the given initial delay, and subsequently with the given period. * * <p>For more details check {@link ScheduledExecutorService#scheduleAtFixedRate(Runnable, long, long, TimeUnit)}. * * @param orderingKey - the key used for ordering * @param command - the SafeRunnable to execute * @param initialDelay - the time to delay first execution * @param period - the period between successive executions * @param unit - the time unit of the initialDelay and period parameters * @return a ScheduledFuture representing pending completion of the task, and whose get() method * will throw an exception upon cancellation */ public ScheduledFuture<?> scheduleAtFixedRateOrdered(Object orderingKey, SafeRunnable command, long initialDelay, long period, TimeUnit unit) { return chooseThread(orderingKey).scheduleAtFixedRate(command, initialDelay, period, unit); }
/** * Completing the {@code future} in the thread in the scheduler identified by * the {@code scheduleKey}. * * @param future future to complete * @param action action to execute when complete * @param scheduler scheduler to execute the action. * @param scheduleKey key to choose the thread to execute the action * @param <T> * @return */ public static <T> CompletableFuture<T> whenCompleteAsync( CompletableFuture<T> future, BiConsumer<? super T, ? super Throwable> action, OrderedScheduler scheduler, Object scheduleKey) { return future.whenCompleteAsync(action, scheduler.chooseThread(scheduleKey)); }
/** * Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently * with the given delay between the termination of one execution and the commencement of the next. * * <p>For more details check {@link ScheduledExecutorService#scheduleWithFixedDelay(Runnable, long, long, TimeUnit)} * . * * @param orderingKey - the key used for ordering * @param command - the SafeRunnable to execute * @param initialDelay - the time to delay first execution * @param delay - the delay between the termination of one execution and the commencement of the next * @param unit - the time unit of the initialDelay and delay parameters * @return a ScheduledFuture representing pending completion of the task, and whose get() method * will throw an exception upon cancellation */ public ScheduledFuture<?> scheduleWithFixedDelayOrdered(Object orderingKey, SafeRunnable command, long initialDelay, long delay, TimeUnit unit) { return chooseThread(orderingKey).scheduleWithFixedDelay(command, initialDelay, delay, unit); }
/** * {@inheritDoc} */ @Override public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) { return chooseThread().schedule(timedCallable(callable), delay, unit); }
/** * {@inheritDoc} */ @Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { return chooseThread().schedule(timedRunnable(command), delay, unit); }
/** * {@inheritDoc} */ @Override public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) { return chooseThread().scheduleWithFixedDelay(timedRunnable(command), initialDelay, delay, unit); }
/** * Creates and executes a one-shot action that becomes enabled after the given delay. * * @param command - the SafeRunnable to execute * @param delay - the time from now to delay execution * @param unit - the time unit of the delay parameter * @return a ScheduledFuture representing pending completion of the task and whose get() method * will return null upon completion */ public ScheduledFuture<?> schedule(SafeRunnable command, long delay, TimeUnit unit) { return chooseThread().schedule(timedRunnable(command), delay, unit); }
/** * {@inheritDoc} */ @Override public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) { return chooseThread().scheduleAtFixedRate(timedRunnable(command), initialDelay, period, unit); }
/** * Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently * with the given delay between the termination of one execution and the commencement of the next. * * <p>For more details check {@link ScheduledExecutorService#scheduleWithFixedDelay(Runnable, long, long, TimeUnit)} * . * * @param command - the SafeRunnable to execute * @param initialDelay - the time to delay first execution * @param delay - the delay between the termination of one execution and the commencement of the next * @param unit - the time unit of the initialDelay and delay parameters * @return a ScheduledFuture representing pending completion of the task, and whose get() method * will throw an exception upon cancellation */ public ScheduledFuture<?> scheduleWithFixedDelay(SafeRunnable command, long initialDelay, long delay, TimeUnit unit) { return chooseThread().scheduleWithFixedDelay(timedRunnable(command), initialDelay, delay, unit); }
/** * Creates and executes a periodic action that becomes enabled first after * the given initial delay, and subsequently with the given period. * * <p>For more details check {@link ScheduledExecutorService#scheduleAtFixedRate(Runnable, long, long, TimeUnit)}. * * @param command - the SafeRunnable to execute * @param initialDelay - the time to delay first execution * @param period - the period between successive executions * @param unit - the time unit of the initialDelay and period parameters * @return a ScheduledFuture representing pending completion of the task, and whose get() * method will throw an exception upon cancellation */ public ScheduledFuture<?> scheduleAtFixedRate(SafeRunnable command, long initialDelay, long period, TimeUnit unit) { return chooseThread().scheduleAtFixedRate(timedRunnable(command), initialDelay, period, unit); }
void interruptTryLock(final CompletableFuture<LockWaiter> tryLockFuture, final CompletableFuture<Void> closePromise) { if (null == tryLockFuture) { unlockInternalLock(closePromise); } else { tryLockFuture.whenCompleteAsync( new FutureEventListener<LockWaiter>() { @Override public void onSuccess(LockWaiter waiter) { closeWaiter(waiter, closePromise); } @Override public void onFailure(Throwable cause) { unlockInternalLock(closePromise); } }, lockStateExecutor.chooseThread(lockPath)); tryLockFuture.cancel(true); } }
MetaRangeClientImpl(StreamProperties streamProps, OrderedScheduler scheduler, StorageContainerChannelManager channelManager, Backoff.Policy backoffPolicy) { this.streamProps = streamProps; this.executor = scheduler.chooseThread(streamProps.getStreamId()); this.scClient = channelManager.getOrCreate(streamProps.getStorageContainerId()); this.backoffPolicy = backoffPolicy; }
void closeWaiter(final LockWaiter waiter, final CompletableFuture<Void> closePromise) { if (null == waiter) { interruptTryLock(tryLockFuture, closePromise); } else { waiter.getAcquireFuture().whenCompleteAsync( new FutureEventListener<Boolean>() { @Override public void onSuccess(Boolean value) { unlockInternalLock(closePromise); } @Override public void onFailure(Throwable cause) { unlockInternalLock(closePromise); } }, lockStateExecutor.chooseThread(lockPath)); waiter.getAcquireFuture().cancel(true); } }
@Override public CompletableFuture<DistributedLock> createReadLock(final LogMetadataForReader metadata, Optional<String> readerId) { final String readLockPath = metadata.getReadLockPath(readerId); return ensureReadLockPathExist(metadata, readLockPath) .thenApplyAsync((value) -> { DistributedLock lock = new ZKDistributedLock( getLockStateExecutor(true), getLockFactory(true), readLockPath, conf.getLockTimeoutMilliSeconds(), statsLogger.scope("read_lock")); return lock; }, scheduler.chooseThread(readLockPath)); }