private ChangeEventQueue(Duration pollInterval, int maxQueueSize, int maxBatchSize, Supplier<LoggingContext.PreviousContext> loggingContextSupplier) { this.pollInterval = pollInterval; this.maxBatchSize = maxBatchSize; this.queue = new LinkedBlockingDeque<>(maxQueueSize); this.metronome = Metronome.sleeper(pollInterval, Clock.SYSTEM); this.loggingContextSupplier = loggingContextSupplier; }
public static Metronome sleeper(Duration period, Clock timeSystem) { return sleeper(period.toNanos(), TimeUnit.NANOSECONDS, timeSystem); }
/** * @param monitor the component used to periodically obtain the replica set specifications; may not be null * @param period the time period between polling checks; must be non-negative * @param unit the time unit for the {@code period}; may not be null * @param clock the clock to use; may be null if the system clock should be used * @param onStartup the function to call when the thread is started; may be null if not needed * @param onChange the function to call when the set of replica set specifications has changed; may be null if not needed */ public ReplicaSetMonitorThread(Supplier<ReplicaSets> monitor, long period, TimeUnit unit, Clock clock, Runnable onStartup, Consumer<ReplicaSets> onChange) { if (clock == null) clock = Clock.system(); this.monitor = monitor; this.metronome = Metronome.sleeper(period, unit, clock); this.onChange = onChange != null ? onChange : (rsSpecs) -> {}; this.onStartup = onStartup != null ? onStartup : () -> {}; }
/** * Execute the supplied operation using the primary, blocking until a primary is available. Whenever the operation stops * (e.g., if the primary is no longer primary), then restart the operation using the current primary. * * @param desc the description of the operation, for logging purposes * @param operation the operation to be performed on the primary * @return return value of the executed operation */ public <T> T execute(String desc, Function<MongoClient, T> operation) { final Metronome errorMetronome = Metronome.sleeper(PAUSE_AFTER_ERROR, Clock.SYSTEM); while (true) { MongoClient primary = primaryConnectionSupplier.get(); try { return operation.apply(primary); } catch (Throwable t) { errorHandler.accept(desc, t); if (!isRunning()) { throw new ConnectException("Operation failed and MongoDB primary termination requested", t); } try { errorMetronome.pause(); } catch (InterruptedException e) { // Interruption is not propagated } } } }
/** * Execute the supplied operation using the primary, blocking until a primary is available. Whenever the operation stops * (e.g., if the primary is no longer primary), then restart the operation using the current primary. * * @param desc the description of the operation, for logging purposes * @param operation the operation to be performed on the primary. */ public void execute(String desc, Consumer<MongoClient> operation) { final Metronome errorMetronome = Metronome.sleeper(PAUSE_AFTER_ERROR, Clock.SYSTEM); while (true) { MongoClient primary = primaryConnectionSupplier.get(); try { operation.accept(primary); return; } catch (Throwable t) { errorHandler.accept(desc, t); if (!isRunning()) { throw new ConnectException("Operation failed and MongoDB primary termination requested", t); } try { errorMetronome.pause(); } catch (InterruptedException e) { // Interruption is not propagated } } } }
/** * Execute the supplied operation using the primary, blocking until a primary is available. Whenever the operation stops * (e.g., if the primary is no longer primary), then restart the operation using the current primary. * * @param desc the description of the operation, for logging purposes * @param operation the operation to be performed on the primary. * @throws InterruptedException if the operation was interrupted */ public void executeBlocking(String desc, BlockingConsumer<MongoClient> operation) throws InterruptedException { final Metronome errorMetronome = Metronome.sleeper(PAUSE_AFTER_ERROR, Clock.SYSTEM); while (true) { MongoClient primary = primaryConnectionSupplier.get(); try { operation.accept(primary); return; } catch (InterruptedException e) { throw e; } catch (Throwable t) { errorHandler.accept(desc, t); if (!isRunning()) { throw new ConnectException("Operation failed and MongoDB primary termination requested", t); } errorMetronome.pause(); } } }
Metronome metronome = Metronome.sleeper(50, TimeUnit.MILLISECONDS, Clock.SYSTEM); Future<?> result = executorService.submit(() -> { while (!Thread.interrupted()) {
public static void waitForSnapshotToBeCompleted() throws InterruptedException { int waitForSeconds = 60; final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); final Metronome metronome = Metronome.sleeper(Duration.ofSeconds(1), Clock.system()); while (true) { if (waitForSeconds-- <= 0) { Assert.fail("Snapshot was not completed on time"); } try { final boolean completed = (boolean)mbeanServer.getAttribute(new ObjectName("debezium.sql_server:type=connector-metrics,context=snapshot,server=server1"), "SnapshotCompleted"); if (completed) { break; } } catch (InstanceNotFoundException e) { // Metrics has not started yet } catch (Exception e) { throw new IllegalStateException(e); } metronome.pause(); } } }
@Override public void execute(ChangeEventSourceContext context) throws InterruptedException { final Metronome metronome = Metronome.sleeper(pollInterval, clock); final Queue<ChangeTable> schemaChangeCheckpoints = new PriorityQueue<>((x, y) -> x.getStopLsn().compareTo(y.getStopLsn())); try {
private ChangeEventQueue(Duration pollInterval, int maxQueueSize, int maxBatchSize, Supplier<LoggingContext.PreviousContext> loggingContextSupplier) { this.pollInterval = pollInterval; this.maxBatchSize = maxBatchSize; this.maxQueueSize = maxQueueSize; this.queue = new LinkedBlockingDeque<>(maxQueueSize); this.metronome = Metronome.sleeper(pollInterval, Clock.SYSTEM); this.loggingContextSupplier = loggingContextSupplier; }
public static Metronome sleeper(Duration period, Clock timeSystem) { return sleeper(period.toNanos(), TimeUnit.NANOSECONDS, timeSystem); }
Metronome metronome = Metronome.sleeper(50, TimeUnit.MILLISECONDS, Clock.SYSTEM); Future<?> result = executorService.submit(() -> { while (!Thread.interrupted()) {