6 Replies Latest reply on Oct 24, 2016 8:30 AM by bfraga

    Wildfly 1.0.0  singleton deployment

    lhelander

      I have tried to use the singleton-deployment feature but can not get it to work. Is there a working example available somewhere?

      Do I need to add a singleton subsystem to my standalone*.xml?

        • 1. Re: Wildfly 1.0.0  singleton deployment
          pferraro

          The standalone-ha.xml and standalone-full-ha.xml already define the "org.wildfly.extension.clustering.singleton" subsystem required for singleton deployments.  The test for this feature is here:

          https://github.com/wildfly/wildfly/tree/master/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/singleton

           

          To define a deployment as a singleton deployment, include a /META-INF/singleton-deployment.xml descriptor in your application archive.

          Alternatively, you can add a

          <singleton-deployment xmlns="urn:jboss:singleton-deployment:1.0"/>
          

          element to your jboss-all.xml descriptor.

          • 2. Re: Wildfly 1.0.0  singleton deployment
            lhelander

            I have created an EAR where I place the singleton-deployment.xml  rootOfEAR/META-INF directory (this is where I interpret it should be)

            The EAR has 1 WAR

             

            When I deploy the application to a cluster of two nodes the application is deployed and the included WAR started on both nodes , not just on a single node.

            From the logs of the two nodes a cluster is properly established.

             

            Do I have to use an EAR or is it possible to use a WAR without being embedded in an EAR? If so, where in the WAR should the singleton-deployment.xml be located?

             

            On both nodes I deploy by copying the EAR to the .../standalone/deployments directory.

             

            I have tested both with standalone-full-ha.xml and standalone-ha.xml

             

            Any idea what I do wrong.

            • 3. Re: Wildfly 1.0.0  singleton deployment
              pferraro

              Singleton deployments can be any type of deployment EAR, WAR, JAR, etc., except for a sub-deployment (e.g. a WAR within an EAR).  How are you starting your servers?  Are the 2 nodes on the same host? or different hosts?

              • 4. Re: Wildfly 1.0.0  singleton deployment
                lhelander

                The nodes are on separate hosts.

                 

                The nodes are started using bin/standalone.sh -c standalone-full-ha.xml

                 

                In addition I set the ip and nodename using system properties. Other cluster functions are working using the nodes e.g. replicated infinispan caches.

                 

                For a WAR deployment, where should the singleton-deployment.xml be located?

                • 5. Re: Wildfly 1.0.0  singleton deployment
                  pferraro

                  WildFly will look at the same location regardless of deployment type:

                  https://github.com/wildfly/wildfly/blob/10.0.0.Final/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/deployment/SingletonDeploymentParsingProcessor.java#L49

                   

                  Have you made any modifications to the default singleton or infinispan subsystems?  Since clustering seems to be working elsewhere, I'm not sure why the "server" cache container should be any different. Can you paste (via gist/pastebin/etc) your server log?

                  • 6. Re: Wildfly 1.0.0  singleton deployment
                    bfraga

                    I have the same problem with Wildfly 10.1.0.

                    Could you solve this problem?

                    My singleton is starting in both server.

                     

                    import java.net.InetAddress;

                    import java.net.UnknownHostException;

                    import javax.ejb.ConcurrencyManagement;

                    import javax.ejb.ConcurrencyManagementType;

                    import javax.ejb.Schedule;

                    import javax.ejb.Singleton;

                    import javax.ejb.Startup;

                    import org.apache.logging.log4j.Level;

                    import org.apache.logging.log4j.LogManager;

                    import org.apache.logging.log4j.Logger;

                     

                     

                    @ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)

                    @Startup

                    @Singleton

                    public class TesteAPP {

                     

                     

                        final Logger logger = LogManager.getLogger(TesteAPP.class);

                     

                     

                        @Schedule(second = "*/1", minute = "*", hour = "*", persistent = false)

                        public void executaTarefa() {

                            try {

                                logger.log(Level.INFO, "Tarefa executada com sucesso! Nome da máquina: {} Endereço da máquina: {}",

                                        InetAddress.getLocalHost().getHostName(),

                                        InetAddress.getLocalHost().getHostAddress());

                                System.out.println(String.format("Tarefa executada com sucesso! Nome da máquina: %s Endereço da máquina: %s",

                                        InetAddress.getLocalHost().getHostName(),

                                        InetAddress.getLocalHost().getHostAddress()));

                            } catch (UnknownHostException e) {

                                logger.log(Level.ALL, "Tarefa executada com sucesso!");

                                System.out.println(String.format("Tarefa executada com sucesso!"));

                            }

                        }

                       

                    }