自动启动 JBoss 服务 (MBean)
我正在尝试构建一个 JBoss 服务,该服务应在每次启动服务器时自动启动。
我的服务具有以下类结构:
public interface CumbiaXPMServiceMBean extends org.jboss.system.ServiceMBean
public class CumbiaXPMService extends org.jboss.system.ServiceMBeanSupport implements CumbiaXPMServiceMBean
我的服务还具有以下配置文件 -- jboss-service.xml :
<server>
<mbean code="uniandes.cumbia.xpm.jboss.CumbiaXPMService"
name="jcumbia:service=JCumbiaEngine">
<depends>jcumbia:service=cumbiaConsole</depends>
<attribute name="LocationInCumbia" attributeClass="java.lang.String">XPMEngine</attribute>
</mbean>
</server>
我的问题是:如何自动启动该服务?
我预计 JBoss 将调用 start() 方法作为加载过程的一部分,但事实并非如此:我的 start() 方法中有很多登录代码,但我没有看到任何输出。
但是,当我使用 JMXConsole 查看 MBean 状态时,其状态 (StateString) 为“已启动”。
问题已解决
我找到了问题的解决方案。 我重写了 start( )、stop( )、destroy( ) 和 create( ) 方法; 尽管如此,由于我正在扩展抽象类 ServiceMBeanSupport,因此我应该重写方法 startService( )、stopService( ) 等。
我刚刚将代码从方法 start( ) 移至方法 startService( ),现在一切正常根据我的需要:一旦满足其依赖关系,我的服务就会启动并执行 startService( ) 方法。
我认为结论是:虽然MBean的生命周期涉及调用create()、start()、stop()和destroy(),但抽象类ServiceMBeanSupport的实现使用这些方法来处理生命周期。 尽管如此,它还是提供了受保护的方法*Service()以允许程序员参与生命周期。
I'm trying to build a JBoss service that should be started automatically, each time the server is initiated.
I've got the following class structure for my service:
public interface CumbiaXPMServiceMBean extends org.jboss.system.ServiceMBean
public class CumbiaXPMService extends org.jboss.system.ServiceMBeanSupport implements CumbiaXPMServiceMBean
I've also got the following configuration file -- jboss-service.xml -- for my service :
<server>
<mbean code="uniandes.cumbia.xpm.jboss.CumbiaXPMService"
name="jcumbia:service=JCumbiaEngine">
<depends>jcumbia:service=cumbiaConsole</depends>
<attribute name="LocationInCumbia" attributeClass="java.lang.String">XPMEngine</attribute>
</mbean>
</server>
My question is: how do I automatically start this service?
I expected that JBoss will call the method start( ) as part as the loading process, but it is not: I've got a lot of loggin code in my start( ) method, but I haven't seen any output.
However, when I look at the MBean status using the JMXConsole, its state (StateString) is 'Started'.
Problem Solved
I found the solution to my problem. I was overriding the methods start( ), stop( ), destroy( ) and create( ); nevertheless, since I'm extending the abstract class ServiceMBeanSupport, I should be overriding the methods startService( ), stopService( ), etc.
I just moved my code from the method start( ) to the method startService( ) and now everything is behaving as I needed: as soon as its dependencies are fulfilled, my service is started and the method startService( ) is executed.
I think the conclusion is: although the life-cycle of an MBean involves calling create( ), start( ), stop( ) and destroy( ), the implementation of the abstract class ServiceMBeanSupport uses those methods to handle the life cycle. Nevertheless, it provides the protected methods *Service( ) in order to allow the programmer to participate in the life cycle.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题已解决
我找到了问题的解决方案。 我重写了 start( )、stop( )、destroy( ) 和 create( ) 方法; 尽管如此,由于我正在扩展抽象类 ServiceMBeanSupport,因此我应该重写方法 startService( )、stopService( ) 等。
我刚刚将代码从方法 start( ) 移至方法 startService( ),现在一切正常根据我的需要:一旦满足其依赖关系,我的服务就会启动并执行 startService( ) 方法。
我认为结论是:虽然MBean的生命周期涉及调用create()、start()、stop()和destroy(),但抽象类ServiceMBeanSupport的实现使用这些方法来处理生命周期。 尽管如此,它还是提供了受保护的方法*Service()以允许程序员参与生命周期。
Problem Solved
I found the solution to my problem. I was overriding the methods start( ), stop( ), destroy( ) and create( ); nevertheless, since I'm extending the abstract class ServiceMBeanSupport, I should be overriding the methods startService( ), stopService( ), etc.
I just moved my code from the method start( ) to the method startService( ) and now everything is behaving as I needed: as soon as its dependencies are fulfilled, my service is started and the method startService( ) is executed.
I think the conclusion is: although the life-cycle of an MBean involves calling create( ), start( ), stop( ) and destroy( ), the implementation of the abstract class ServiceMBeanSupport uses those methods to handle the life cycle. Nevertheless, it provides the protected methods *Service( ) in order to allow the programmer to participate in the life cycle.
对我来说,它有助于在 MBean 接口中定义停止和启动方法:
优点是您不必扩展 ServiceMBean 或 ServiceMBeanSupport。
For me it helped defining the stop and start methods in the MBean Interface:
The advantage is that you don't have to extend ServiceMBean oder ServiceMBeanSupport.