迁移/创建HA-Singleton到jboss 7

DCa*_*lho 8 migration singleton jboss java-ee jboss7.x

我一直在jboss中使用deploy-hasingleton文件夹作为6,这允许我创建一个单例bean,用于控制来自集群节点的业务信息请求.这些方法是同步的,以便控制节点之间的并发性(相同的数据不能在不同的节点中).

现在我正在迁移到Jboss 7,并且由于那个deploy-hasingleton文件夹消失了,我一直在关注官方的例子:

问题是这些例子太简单了,我无法理解我可以放置业务逻辑方法的位置.所以我尝试将该逻辑放在SingletonService中,它实现了:Service,MyInterface

我已经将getValue方法修改为以下内容:

@Override
    public MyInterface getValue() throws IllegalStateException,
            IllegalArgumentException {

        return this;
    }
Run Code Online (Sandbox Code Playgroud)

在客户端:

@Override
    public List<Long> myMeth(Long arg1, int arg2) {
        LOGGER.log("loadGroups() is called()");
        ServiceController<?> service = CurrentServiceContainer.getServiceContainer().getService(
                GroupDistributorService.SINGLETON_SERVICE_NAME);

        if (service != null) {
            return ((MyInterface ) service.getValue()).getMyMethod(arg1, arg2);
        } else {
            throw new IllegalStateException("Service '" + GroupDistributorService.SINGLETON_SERVICE_NAME + "' not found!");
        }
    }
Run Code Online (Sandbox Code Playgroud)

我怀疑这是正确的做法.其次,这似乎适用于包含主单例服务的节点.但是在其他节点中,它在调用单例服务时会锁定,并且会出现超时.

Jak*_*ski 1

几个月前,我发布了有关在 Jboss 7 中使用 HASingleton 的博客文章: http://www.kubrynski.com/2013/07/using-ha-singleton-in-jboss-7.html 希望它会有所帮助。确保您启用了集群模式:

<subsystem xmlns="urn:jboss:domain:ee:1.0">
  <global-modules>
    <module name="org.jboss.msc" slot="main">
    <module name="org.jboss.as.clustering.singleton" slot="main">
  </global-modules>
</subsystem>
Run Code Online (Sandbox Code Playgroud)

并且你坚持使用osgi系统,通过在你的pom.xml(到jar/war插件)中添加这样的配置:

<configuration>
  <archive>
    <manifestentries>
      <dependencies>
        org.jboss.msc,org.jboss.as.server,
        org.jboss.as.clustering.singleton
      </dependencies>
    </manifestentries>
  </archive>
</configuration>
Run Code Online (Sandbox Code Playgroud)