001/*******************************************************************************
002 * Copyright (c) 2006-2014 Nuxeo SA (http://nuxeo.com/) and others.
003 * 
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 ******************************************************************************/
009package org.nuxeo.ecm.core.redis.retry;
010
011import java.util.concurrent.TimeUnit;
012
013public class ExponentialBackofDelay extends SimpleDelay {
014
015    protected int attempt;
016
017    public ExponentialBackofDelay(int base, int delay) {
018        super(base, delay);
019    }
020
021    @Override
022    protected long computeDelay() {
023        int delay = base * (1 << ++attempt);
024        return TimeUnit.MILLISECONDS.convert(delay, TimeUnit.SECONDS);
025    }
026
027}