// Path: robota/src/main/java/com/uphyca/robota/data/api/BackoffPolicy.java
// public interface BackoffPolicy {
// 
//     void backoff();
// 
//     void reset();
// 
//     long getNextBackOffMillis();
// 
//     boolean isFailed();
// }
// 
// Path: robota/src/main/java/com/uphyca/robota/data/api/Environment.java
// public interface Environment {
// 
//     long elapsedRealtime();
// 
//     long currentTimeMillis();
// }


import com.uphyca.robota.data.api.BackoffPolicy;
import com.uphyca.robota.data.api.Environment;
/*
 * Copyright (C) 2014 uPhyca Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.uphyca.robota.data;


/**
 * @author Sosuke Masui (masui@uphyca.com)
 */
public class ExponentialBackoff implements BackoffPolicy {

    private static final double MULTPLIER = 2;

    private final Environment mEnvironment;
    private final long mInitialSleepTimeMillis;
    private final int mMaxTries;

    private long mSleepTimeMillis;
    private int mBackoffCount;

// Path: robota/src/main/java/com/uphyca/robota/data/api/BackoffPolicy.java
// public interface BackoffPolicy {
// 
//     void backoff();
// 
//     void reset();
// 
//     long getNextBackOffMillis();
// 
//     boolean isFailed();
// }
// 
// Path: robota/src/main/java/com/uphyca/robota/data/api/Environment.java
// public interface Environment {
// 
//     long elapsedRealtime();
// 
//     long currentTimeMillis();
// }


// Path: robota/src/main/java/com/uphyca/robota/data/ExponentialBackoff.java
import com.uphyca.robota.data.api.BackoffPolicy;
import com.uphyca.robota.data.api.Environment;

/*
 * Copyright (C) 2014 uPhyca Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.uphyca.robota.data;


/**
 * @author Sosuke Masui (masui@uphyca.com)
 */
public class ExponentialBackoff implements BackoffPolicy {

    private static final double MULTPLIER = 2;

    private final Environment mEnvironment;
    private final long mInitialSleepTimeMillis;
    private final int mMaxTries;

    private long mSleepTimeMillis;
    private int mBackoffCount;

    public ExponentialBackoff(Environment environment, long initialSleepMillis, int maxTries) {