贝贝花花包包店,精品555皮具,钱夹,皮夹

字体: | 推荐给好友 上一篇 | 下一篇

ACE程序员教程-第8章 服务配置器:用于服务动态配置的模式

发布: 2008-6-13 14:13 | 作者: Umar Syyid | 来源: 转载 | 查看: 294次

  下面是一个简单的、只是用于启用时间服务的配置文件。可以去掉注释#号来挂起、恢复和移除服务。

 

8-1c

# To configure different services, simply uncomment the appropriate

#lines in this file!

#resume TimeService

#suspend TimeService

#remove TimeService

#set to dynamically configure the TimeService object and do so without

#sending any parameters to its init method

dynamic TimeService Service_Object * ./Server:time_service ""

 

  最后,下面是启动服务配置器的代码段。这些代码还设置了一个信号处理器对象,用于发起重配置。该信号处理器已被设置成响应SIGWINCH信号(在窗口发生变化时产生的信号)。在启动服务配置器之后,应用进入一个反应式循环,等待SIGWINCH信号事件发生。一旦事件发生,就会回调事件处理器,由它调用ACE_Service_Configreconfigure()方法。如先前所讲述的,在此调用发生时,服务配置器重新读取配置文件,并处理用户放在其中的任何新指令。例如,在动态启动TimeService后,在这个例子中你可以改变svc.conf文件,只留下一个挂起命令在里面。当配置器读取它时,它将调用TimeService的挂起方法,从而使它挂起它的底层线程。类似地,如果稍后你又改变了svc.conf,要求恢复服务,配置器就会调用TimeService::resume()方法,从而恢复先前被挂起的线程。

 

8-1d

#include "ace/OS.h"

#include "ace/Service_Config.h"

#include "ace/Event_Handler.h"

#include

//The Signal Handler which is used to issue the reconfigure()

//call on the service configurator.

class Signal_Handler: public ACE_Event_Handler

{

public:

int open()

{

//register the Signal Handler with the Reactor to handle

//re-configuration signals

ACE_Reactor::instance()->register_handler(SIGWINCH,this);

return 0;

}

 

int handle_signal(int signum, siginfo*,ucontext_t *)

{

if(signum==SIGWINCH)

ACE_Service_Config::reconfigure();

return 0;

}

};

 

int main(int argc, char *argv[])

{

//Instantiate and start up the Signal Handler. This is uses to

//handle re-configuration events.

Signal_Handler sh;

sh.open();

 

if (ACE_Service_Config::open (argc, argv) == -1)

ACE_ERROR_RETURN ((LM_ERROR,

"%p\n","ACE_Service_Config::open"),-1);

 

while(1)

ACE_Reactor::instance()->handle_events();

}

 

43/4<1234>
 

评分:0

我来说两句

seccode