001/* 002 * (C) Copyright 2017 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bdelbosc 018 */ 019package org.nuxeo.ecm.platform.importer.mqueues.computation; 020 021import java.time.Duration; 022 023/** 024 * @since 9.2 025 */ 026public interface ComputationManager { 027 /** 028 * Run the computations 029 */ 030 void start(); 031 032 /** 033 * Wait for the computations to have assigned partitions ready to process records. 034 * <p/> 035 * Returns {@code true} if all computations have assigned partitions during the timeout delay. 036 */ 037 boolean waitForAssignments(Duration timeout) throws InterruptedException; 038 039 /** 040 * Stop computations gracefully after processing a record or a timer. 041 */ 042 boolean stop(Duration timeout); 043 044 boolean stop(); 045 046 /** 047 * Stop computations when input streams are empty. 048 * The timeout is applied for each computation, the total duration can be up to nb computations * timeout 049 * <p/> 050 * Returns {@code true} if computations are stopped during the timeout delay. 051 */ 052 boolean drainAndStop(Duration timeout); 053 054 /** 055 * Shutdown immediately 056 */ 057 void shutdown(); 058 059 long getLowWatermark(); 060 061 long getLowWatermark(String computationName); 062 063 boolean isDone(long timestamp); 064}