RM源码之org.apache.hadoop.service.AbstractService分析
2015-08-19 14:05
736 查看
org.apache.hadoop.service.AbstractService父类为org.apache.hadoop.service.Service
其中Service主要变量和方法为:
![](http://images0.cnblogs.com/blog/759696/201508/191404235507522.png)
状态改变枚举
/** Constructed but not initialized */
NOTINITED(0, "NOTINITED"),
/** Initialized but not started or stopped */
INITED(1, "INITED"),
/** started and not stopped */
STARTED(2, "STARTED"),
/** stopped. No further state transitions are permitted */
STOPPED(3, "STOPPED");
Service中主要是服务通用一些功能
1.初始化
2.服务状态
3.生命周期记录
4.状态改变
5.监听器
---服务器可以处于状态---
=====================================================================
org.apache.hadoop.service.AbstractService实现了Service
主要功能三个方面如下:
1.状态改变
2.状态改变,启动相应监听
3.记录状态改变事件
4.Blocker操作
----------------------------
初始化过程
1.初始化过程是由NOTINITED->INITED状态过程
1.1状态改变是通过一个二维数据来维护状态之间切换是否有效
2.实际初始化过程是由serviceInit来实现,应该会有子类来实现具体初始化过程
3.当从NOTINITED->INITED切换完成会唤醒监听器
4.如果有状态改变失败将退出
5.记录状态改变
1.初始化过程是由NOTINITED->INITED状态过程
1.1状态间切换关系
private static final boolean[][] statemap =
{
// uninited inited started stopped
/* uninited */ {false, true, false, true},
/* inited */ {false, true, true, true},
/* started */ {false, false, true, true},
/* stopped */ {false, false, false, true},
};
具体初始化流程,还是上图吧,方便一些。
![](http://images0.cnblogs.com/blog/759696/201508/191404255508866.png)
![](http://images0.cnblogs.com/blog/759696/201508/191404270664597.png)
public void start() {
if (isInState(STATE.STARTED)) {
return;
}
//enter the started state
synchronized (stateChangeLock) {
if (stateModel.enterState(STATE.STARTED) != STATE.STARTED) {
try {
startTime = System.currentTimeMillis();
serviceStart();
if (isInState(STATE.STARTED)) {
//if the service started (and isn't now in a later state), notify
if (LOG.isDebugEnabled()) {
LOG.debug("Service " + getName() + " is started");
}
notifyListeners();
}
} catch (Exception e) {
noteFailure(e);
ServiceOperations.stopQuietly(LOG, this);
throw ServiceStateException.convert(e);
}
}
}
}
@Override
public void stop() {
if (isInState(STATE.STOPPED)) {
return;
}
synchronized (stateChangeLock) {
if (enterState(STATE.STOPPED) != STATE.STOPPED) {
try {
serviceStop();
} catch (Exception e) {
//stop-time exceptions are logged if they are the first one,
noteFailure(e);
throw ServiceStateException.convert(e);
} finally {
//report that the service has terminated
terminationNotification.set(true);
synchronized (terminationNotification) {
terminationNotification.notifyAll();
}
//notify anything listening for events
notifyListeners();
}
} else {
//already stopped: note it
if (LOG.isDebugEnabled()) {
LOG.debug("Ignoring re-entrant call to stop()");
}
}
}
}
基本来状态改变都是这个样子,没有太多变化,都是先去检查,是否可以改变,可以改变执行由子类实现的方法。
-------------------------------------------
记录状态改变
![](http://images0.cnblogs.com/blog/759696/201508/191404286132870.png)
唤醒Listener
/**
* Notify local and global listeners of state changes.
* Exceptions raised by listeners are NOT passed up.
*/
private void notifyListeners() {
try {
listeners.notifyListeners(this);
globalListeners.notifyListeners(this);
} catch (Throwable e) {
LOG.warn("Exception while notifying listeners of " + this + ": " + e,
e);
}
}
/**
* List of state change listeners; it is final to ensure
* that it will never be null.
*/
private final ServiceOperations.ServiceListeners listeners
= new ServiceOperations.ServiceListeners();
/**
* Static listeners to all events across all services
*/
private static ServiceOperations.ServiceListeners globalListeners
= new ServiceOperations.ServiceListeners();
其中Service主要变量和方法为:
![](http://images0.cnblogs.com/blog/759696/201508/191404235507522.png)
状态改变枚举
/** Constructed but not initialized */
NOTINITED(0, "NOTINITED"),
/** Initialized but not started or stopped */
INITED(1, "INITED"),
/** started and not stopped */
STARTED(2, "STARTED"),
/** stopped. No further state transitions are permitted */
STOPPED(3, "STOPPED");
Service中主要是服务通用一些功能
1.初始化
2.服务状态
3.生命周期记录
4.状态改变
5.监听器
---服务器可以处于状态---
=====================================================================
org.apache.hadoop.service.AbstractService实现了Service
主要功能三个方面如下:
1.状态改变
2.状态改变,启动相应监听
3.记录状态改变事件
4.Blocker操作
----------------------------
初始化过程
1.初始化过程是由NOTINITED->INITED状态过程
1.1状态改变是通过一个二维数据来维护状态之间切换是否有效
2.实际初始化过程是由serviceInit来实现,应该会有子类来实现具体初始化过程
3.当从NOTINITED->INITED切换完成会唤醒监听器
4.如果有状态改变失败将退出
5.记录状态改变
1.初始化过程是由NOTINITED->INITED状态过程
1.1状态间切换关系
private static final boolean[][] statemap =
{
// uninited inited started stopped
/* uninited */ {false, true, false, true},
/* inited */ {false, true, true, true},
/* started */ {false, false, true, true},
/* stopped */ {false, false, false, true},
};
具体初始化流程,还是上图吧,方便一些。
![](http://images0.cnblogs.com/blog/759696/201508/191404255508866.png)
![](http://images0.cnblogs.com/blog/759696/201508/191404270664597.png)
public void start() {
if (isInState(STATE.STARTED)) {
return;
}
//enter the started state
synchronized (stateChangeLock) {
if (stateModel.enterState(STATE.STARTED) != STATE.STARTED) {
try {
startTime = System.currentTimeMillis();
serviceStart();
if (isInState(STATE.STARTED)) {
//if the service started (and isn't now in a later state), notify
if (LOG.isDebugEnabled()) {
LOG.debug("Service " + getName() + " is started");
}
notifyListeners();
}
} catch (Exception e) {
noteFailure(e);
ServiceOperations.stopQuietly(LOG, this);
throw ServiceStateException.convert(e);
}
}
}
}
@Override
public void stop() {
if (isInState(STATE.STOPPED)) {
return;
}
synchronized (stateChangeLock) {
if (enterState(STATE.STOPPED) != STATE.STOPPED) {
try {
serviceStop();
} catch (Exception e) {
//stop-time exceptions are logged if they are the first one,
noteFailure(e);
throw ServiceStateException.convert(e);
} finally {
//report that the service has terminated
terminationNotification.set(true);
synchronized (terminationNotification) {
terminationNotification.notifyAll();
}
//notify anything listening for events
notifyListeners();
}
} else {
//already stopped: note it
if (LOG.isDebugEnabled()) {
LOG.debug("Ignoring re-entrant call to stop()");
}
}
}
}
基本来状态改变都是这个样子,没有太多变化,都是先去检查,是否可以改变,可以改变执行由子类实现的方法。
-------------------------------------------
记录状态改变
![](http://images0.cnblogs.com/blog/759696/201508/191404286132870.png)
唤醒Listener
/**
* Notify local and global listeners of state changes.
* Exceptions raised by listeners are NOT passed up.
*/
private void notifyListeners() {
try {
listeners.notifyListeners(this);
globalListeners.notifyListeners(this);
} catch (Throwable e) {
LOG.warn("Exception while notifying listeners of " + this + ": " + e,
e);
}
}
/**
* List of state change listeners; it is final to ensure
* that it will never be null.
*/
private final ServiceOperations.ServiceListeners listeners
= new ServiceOperations.ServiceListeners();
/**
* Static listeners to all events across all services
*/
private static ServiceOperations.ServiceListeners globalListeners
= new ServiceOperations.ServiceListeners();
相关文章推荐
- wamp中的Apache开启gzip压缩提高网站的响应速度
- How To Configure Logging And Log Rotation In Apache On An Ubuntu VPS
- linux下 Apache 配置虚拟主机三种方式
- Apache虚拟主机配置
- windows server 已经编译过的apache 源码
- Apache Ant 实例介绍,以及部分标签介绍
- 1.7-Apache用户认证
- Apache服务器CPU利用率、Load值及Running值高导致WEB无法访问
- 安装Apache的时候80端口被PID为4的系统进程所占用
- Linux命令安装Apache
- org.apache.log4j.Logger详解
- apache2.4 虚拟主机配置
- Apache虚拟主机的配置
- 在Apache Spark上跑Logistic Regression算法
- Apache配置虚拟主机(2)
- (0) 什么是Apache Hadoop
- 2.4.16版本Apache配置虚拟目录(1)
- linux 下 apache启动、停止、重启命令
- 禁止apache显示目录索引的常见方法
- Apache Maven 入门篇(下)