自动启动 JBoss 服务 (MBean)

发布于 2024-07-25 01:12:05 字数 1312 浏览 7 评论 0原文

我正在尝试构建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栖迟 2024-08-01 01:12:05

问题已解决

我找到了问题的解决方案。 我重写了 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.

节枝 2024-08-01 01:12:05

对我来说,它有助于在 MBean 接口中定义停止和启动方法:

public interface MyServiceMBean {
    ...

    // Lifecycle callbacks
    void start() throws Exception;
    void stop();
}

优点是您不必扩展 ServiceMBean 或 ServiceMBeanSupport。

For me it helped defining the stop and start methods in the MBean Interface:

public interface MyServiceMBean {
    ...

    // Lifecycle callbacks
    void start() throws Exception;
    void stop();
}

The advantage is that you don't have to extend ServiceMBean oder ServiceMBeanSupport.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文