1. configurationprovider介面,提供了getconfiguration()方法,用於獲取不同元件的配置。
2. lifecycleaware介面,提供了三個方法,start() stop()和getlifecyclestate(),分別用於元件的啟動 停止以及元件在生命週期中處的狀態,可以說這個介面貫穿於整個flume中。
public synchronized void start()
}
接下來supervisor再被例項化lifecyclesupervisor物件的時候會做哪些工作呢?
即new lifecyclesupervisor(),建構函式做了什麼
public lifecyclesupervisor()
主要初始化了乙個有10個執行緒,上限是20的執行緒池
再回到之前supervise(lifecycleaware lifecycleaware,supervisorpolicy policy, lifecyclestate desiredstate)方法,它是具體執行啟動各個元件的方法
public synchronized void supervise(lifecycleaware lifecycleaware,
supervisorpolicy policy, lifecyclestate desiredstate)
preconditions.checkstate(!supervisedprocesses.containskey(lifecycleaware),
"refusing to supervise " + lifecycleaware + " more than once");
if (logger.isdebugenabled()) policy:{} desiredstate:{}",
new object );
}supervisoree process = new supervisoree();
process.status = new status();
process.policy = policy;
process.status.desiredstate = desiredstate;
process.status.error = false;
monitorrunnable monitorrunnable = new monitorrunnable();
monitorrunnable.lifecycleaware = lifecycleaware;
monitorrunnable.supervisoree = process;
monitorrunnable.monitorservice = monitorservice;
supervisedprocesses.put(lifecycleaware, process);
scheduledfuture<?> future = monitorservice.schedulewithfixeddelay(
monitorrunnable, 0, 3, timeunit.seconds);
monitorfutures.put(lifecycleaware, future);
}
首先會把元件的渴望的狀態desiredstate(如lifecyclestate.start)和策略policy(如new supervisorpolicy.alwaysrestartpolicy())放到靜態內部類supervisoree中,再將元件lifecycleaware及之前的資訊,一併傳值到monitorrunnable執行緒中,下面執行緒類monitorrunnable的run方法會根據switch case匹配的值去執行不同操作,當前回到start流程,執行lifecycleaware.start(),完成元件的啟動
@override
public void run() supervisoree:{}", lifecycleaware,
supervisoree);
long now = system.currenttimemillis();
try ", lifecycleaware);
supervisoree.status.firstseen = now;
}supervisoree.status.lastseen = now;
synchronized (lifecycleaware) ", lifecycleaware);
return;
} else if (supervisoree.status.error) is in error state, and flume will not"
+ "attempt to change its state", lifecycleaware);
return;
}supervisoree.status.lastseenstate = lifecycleaware.getlifecyclestate();
if (!lifecycleaware.getlifecyclestate().equals(
supervisoree.status.desiredstate)) from {} to {} (failures:{})",
new object );
switch (supervisoree.status.desiredstate) catch (throwable e) stopped, since it could not be"
+ "successfully started due to missing dependencies",
lifecycleaware);
} catch (throwable e1) due to missing dependencies."
+ " please shutdown the agent"
+ "or disable this component, or the agent will be"
+ "in an undefined state.", e1);
supervisoree.status.error = true;
if (e1 instanceof error)
// set the state to stop, so that the conf poller can
// proceed.}}
supervisoree.status.failures++;
}break;
case stop:
try catch (throwable e)
supervisoree.status.failures++;
}break;
default:
logger.warn("i refuse to acknowledge {} as a desired state",
supervisoree.status.desiredstate);
}if (!supervisoree.policy.isvalid(lifecycleaware, supervisoree.status)) of {} has been violated - supervisor should exit!",
supervisoree.policy, lifecycleaware);}}
}} catch(throwable t)
logger.debug("status check complete");
}
接下來再呼叫lifecycleaware.start()後,會根據元件的不同,找到對應元件的runner類,這裡以source中的pollablesourcerunner為例,flume source提供了兩種類別的source即:eventdrivensource和pollablesource,eventdrivensource為事件驅動,pollablesource則是輪詢機制,pollablesource型別的啟動依賴於pollablesourcerunner,在pollablesourcerunner內部會有乙個用於輪詢的類
pollingrunner,在執行的過程中會根據pollablesource型別特有的source.process()返回值的狀態,進行sleep
public void run() ", source);
while (!shouldstop.get()) else
} catch (interruptedexception e) catch (eventdeliveryexception e) catch (exception e) catch (interruptedexception ex) }}
logger.debug("polling runner exiting. metrics:{}", countergroup);
}
Flume ng啟動過程分析
入口函式main 載入flume的配置檔案,初始化sink,source,channel的工廠類 propertiesfileconfigurationprovider configurationprovider new propertiesfileconfigurationprovider age...
SpringMVC之原始碼分析 啟動過程
類的繼承關係 spring mvc前端控制器dispatcherservlet frameworkservlet httpservletbean httpservlet httpservlet是servlet規範中的核心類,實現servlet介面,繼承此類用於處理使用者請求。httpservletb...
u boot 原始碼分析 1 啟動過程分析
kbuild 啟動過程 第二階段 總結參考 對於uboot,我一直是雲裡霧裡的乙個狀態,這部分讓我感到自己很菜,不用縱向深入地掌握uboot整個細節,但是相對它有乙個整體流程上的把握,包括uboot的啟動啟動過程,在整個啟動過程中會涉及到哪些檔案,以此的呼叫過程是什麼?抱著這幾個問題,大量蒐集資料,...