2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.cluster.datastore;
11 import com.codahale.metrics.Timer;
12 import com.google.common.base.Preconditions;
13 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
16 * TransactionRateLimitingCallback computes the new transaction rate limit on the successful completion of a
19 public class TransactionRateLimitingCallback implements OperationCallback{
20 private final Timer commitTimer;
21 private Timer.Context timerContext;
23 TransactionRateLimitingCallback(ActorContext actorContext){
24 commitTimer = actorContext.getOperationTimer(ActorContext.COMMIT);
29 timerContext = commitTimer.time();
33 public void success() {
34 Preconditions.checkState(timerContext != null, "Call run before success");
39 public void failure() {
40 // This would mean we couldn't get a transaction completed in 30 seconds which is
41 // the default transaction commit timeout. Using the timeout information to figure out the rate limit is
42 // not going to be useful - so we leave it as it is