2 * Copyright 2016 Facebook, Inc.
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
31 * Base interface to be implemented by all classes expecting to manage
32 * timeouts. AsyncTimeout will use implementations of this interface
33 * to schedule/cancel timeouts.
35 class TimeoutManager {
37 typedef std::chrono::milliseconds timeout_type;
39 enum class InternalEnum {
44 virtual ~TimeoutManager() = default;
47 * Attaches/detaches TimeoutManager to AsyncTimeout
49 virtual void attachTimeoutManager(AsyncTimeout* obj,
50 InternalEnum internal) = 0;
51 virtual void detachTimeoutManager(AsyncTimeout* obj) = 0;
54 * Schedules AsyncTimeout to fire after `timeout` milliseconds
56 virtual bool scheduleTimeout(AsyncTimeout* obj,
57 timeout_type timeout) = 0;
60 * Cancels the AsyncTimeout, if scheduled
62 virtual void cancelTimeout(AsyncTimeout* obj) = 0;
65 * This is used to mark the beginning of a new loop cycle by the
66 * first handler fired within that cycle.
68 virtual void bumpHandlingTime() = 0;
71 * Helper method to know whether we are running in the timeout manager
74 virtual bool isInTimeoutManagerThread() = 0;