RM源码org.apache.hadoop.service.CompositeService分析
2015-08-20 16:03
567 查看
上一篇blog分析了org.apache.hadoop.service.AbstractService主要功能是状态改变,org.apache.hadoop.service.CompositeService主要功能是进行服务的启停。
代码也比较简洁
![](http://images0.cnblogs.com/blog/759696/201508/201602580507128.png)
初始化通过conf
代码也比较简洁
private final List<Service> serviceList = new ArrayList<Service>();
关于serviceList操作均作了同步![](http://images0.cnblogs.com/blog/759696/201508/201602580507128.png)
初始化通过conf
protected void serviceInit(Configuration conf) throws Exception {
List<Service> services = getServices();
if (LOG.isDebugEnabled()) {
LOG.debug(getName() + ": initing services, size=" + services.size());
}
for (Service service : services) {
service.init(conf); //通用一个conf配置文件
}
super.serviceInit(conf);
}
serviceStart均调用具体service的start方法List<Service> services = getServices();
if (LOG.isDebugEnabled()) {
LOG.debug(getName() + ": initing services, size=" + services.size());
}
for (Service service : services) {
service.init(conf); //通用一个conf配置文件
}
super.serviceInit(conf);
}
protected void serviceStart() throws Exception {
List<Service> services = getServices();
if (LOG.isDebugEnabled()) {
LOG.debug(getName() + ": starting services, size=" + services.size());
}
for (Service service : services) {
// start the service. If this fails that service
// will be stopped and an exception raised
service.start();
}
super.serviceStart();
}
停止service操作,最终还是调用的service.stop()List<Service> services = getServices();
if (LOG.isDebugEnabled()) {
LOG.debug(getName() + ": starting services, size=" + services.size());
}
for (Service service : services) {
// start the service. If this fails that service
// will be stopped and an exception raised
service.start();
}
super.serviceStart();
}
protected void serviceStop() throws Exception {
//stop all services that were started
int numOfServicesToStop = serviceList.size();
if (LOG.isDebugEnabled()) {
LOG.debug(getName() + ": stopping services, size=" + numOfServicesToStop);
}
stop(numOfServicesToStop, STOP_ONLY_STARTED_SERVICES);
super.serviceStop();
}
//stop all services that were started
int numOfServicesToStop = serviceList.size();
if (LOG.isDebugEnabled()) {
LOG.debug(getName() + ": stopping services, size=" + numOfServicesToStop);
}
stop(numOfServicesToStop, STOP_ONLY_STARTED_SERVICES);
super.serviceStop();
}
private void stop(int numOfServicesStarted, boolean stopOnlyStartedServices) {
// stop in reverse order of start
Exception firstException = null;
List<Service> services = getServices();
for (int i = numOfServicesStarted - 1; i >= 0; i--) {
Service service = services.get(i);
if (LOG.isDebugEnabled()) {
LOG.debug("Stopping service #" + i + ": " + service);
}
STATE state = service.getServiceState();
//depending on the stop police
if (state == STATE.STARTED //关闭的关键代码
|| (!stopOnlyStartedServices && state == STATE.INITED)) {
Exception ex = ServiceOperations.stopQuietly(LOG, service);
if (ex != null && firstException == null) {
firstException = ex;
}
}
}
//after stopping all services, rethrow the first exception raised
if (firstException != null) {
throw ServiceStateException.convert(firstException);
}
}
// stop in reverse order of start
Exception firstException = null;
List<Service> services = getServices();
for (int i = numOfServicesStarted - 1; i >= 0; i--) {
Service service = services.get(i);
if (LOG.isDebugEnabled()) {
LOG.debug("Stopping service #" + i + ": " + service);
}
STATE state = service.getServiceState();
//depending on the stop police
if (state == STATE.STARTED //关闭的关键代码
|| (!stopOnlyStartedServices && state == STATE.INITED)) {
Exception ex = ServiceOperations.stopQuietly(LOG, service);
if (ex != null && firstException == null) {
firstException = ex;
}
}
}
//after stopping all services, rethrow the first exception raised
if (firstException != null) {
throw ServiceStateException.convert(firstException);
}
}
public static Exception stopQuietly(Log log, Service service) {
try {
stop(service);
} catch (Exception e) {
log.warn("When stopping the service " + service.getName()
+ " : " + e,
e);
return e;
}
return null;
}
try {
stop(service);
} catch (Exception e) {
log.warn("When stopping the service " + service.getName()
+ " : " + e,
e);
return e;
}
return null;
}
public static void stop(Service service) {
if (service != null) {
service.stop();
}
}
if (service != null) {
service.stop();
}
}
相关文章推荐
- win7系统下如何配置php-Apache-mysql环境
- Apache James安装为windows服务
- Apache 403 error, (13)Permission denied: access to / denied问题
- org.apache.subversion.javahl.ClientException: Previous operation has not finished
- Apache DS管理的JAVA实现
- Apache DS 配置与管理
- Unable to parse configuration of mojo org.apache.maven.plugins:maven-archetype-plugin:2.3:
- 8月Web服务器份额:Apache夺冠 份额持续下降
- Apache同时支持PHP和Python的配置方法
- Apache VirtualHost配置
- java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor vers
- 在mac中配置apache+php5.3+mysql的环境,修改hosts
- Apache 隐藏入口文件以及防盗链.htaccess 文件
- apache wicket 7.X让html回归webapp目录下
- Apache JMeter--网站自动测试与性能测评
- 如何配置Mac系统自带的ApacheWeb服务器 测试10.10可用
- Mac 中安装 Apache Ant
- 开发笔记-Linux-Apache-PHP-CI
- Apache Ambari
- RM源码之org.apache.hadoop.service.AbstractService分析