---
title: "Flume源代码解读四"
author: "xcly"
date: "2012-03-15T13:01:06Z"
tags: []
categories: ["开源软件"]
slug: "flume"
draft: false
lastmod: "2012-03-15T17:01:41Z"
id: 1454129
url: "https://xcly.iteye.com/blog/1454129"
---

\[ xcly原创于iteye,见[http://xcly.iteye.com](/) ]

 

    今天介绍Flume里面用到的BackoffAlgo算法，接口由BackoffPolicy定义，让我们看看下面的几个关键的方法

reset：Reset backoff state. Call this after successful attempts.每一次成功调用之后reset状态。

backoff：Modify state as if a backoff had just happened. Call this after failed attempts。失败发生时调用的回退犯法。

isFailed：Has so much time passed that we assume the failure is irrecoverable? 如果返回true，不再尝试。

sleepIncrement：Wait time in millis until RetryOk should be true

waitUntilRetryOk：Wait until it's ok to retry.

 

    在InsistentAppendDecorator， InsistentOpenDecorator中调用了BackoffPolicy的子类CumulativeCappedExponentialBackoff，CumulativeCappedExponentialBackoff中的isfailed总是返回true,永远不会失败；总是不断尝试。