3 Replies Latest reply on Feb 21, 2008 2:53 PM by alesj

    syntax for specifying dependencies?

    jhalliday

      Scott or any other guru

      I have a .sar file, inside which is a .war file containing a servlet (FooServlet).
      The .sar file has a jboss-service.xml:

      <server>
       <mbean name="jboss.xts:service=XTSService" code="org.jboss.transactions.XTSService">
       <depends>jboss.web:service=WebServer</depends>
       </mbean>
      </server>


      which is all well and good as far as it goes.

      However, in addition to the above dependency, I want to ensure that XTSService does not start until FooServlet has been deployed by the web server. Does the server provide a way to express such a dependency? If so, how do I figure out the name of the FooServlet to use?

      Thanks

      Jonathan.

        • 1. Re: syntax for specifying dependencies?

          Ask in the Tomcat forum, there's no such feature AFAIK.

          You should be able to depend upon the mbean that represents the war though (which will
          be less fine-grained than what you want).
          http://wiki.jboss.org/wiki/Wiki.jsp?page=MyDependencyDoesntWork

          • 2. Re: syntax for specifying dependencies?
            jhalliday

            Thanks Adrian. As it happens the .war is fairly small and won't take long to deploy, so depending on it probably is not too much of a kludge.

            • 3. Re: syntax for specifying dependencies?
              alesj

              Check org.jboss.web.deployers.AbstractWarDeployer for the mbean Adrian mentioned.

               protected void deployWebModule(VFSDeploymentUnit unit, JBossWebMetaData metaData,
               AbstractWarDeployment deployment)
               throws Exception
               {
               log.debug("deployWebModule: " + unit.getName());
               try
               {
               ServiceMetaData webModule = new ServiceMetaData();
               String name = getObjectName(metaData);
               ObjectName objectName = new ObjectName(name);
               webModule.setObjectName(objectName);
               webModule.setCode(WebModule.class.getName());
               // WebModule(DeploymentUnit, AbstractWarDeployer, AbstractWarDeployment)
               ServiceConstructorMetaData constructor = new ServiceConstructorMetaData();
               constructor.setSignature(new String[] { VFSDeploymentUnit.class.getName(),
               AbstractWarDeployer.class.getName(), AbstractWarDeployment.class.getName()});
               constructor.setParameters(new Object[] {unit, this, deployment});
               webModule.setConstructor(constructor);
              
               // Dependencies...Still have old jmx names here
               Collection<String> depends = metaData.getDepends();
               List<ServiceDependencyMetaData> dependencies = new ArrayList<ServiceDependencyMetaData>();
               if (depends != null && depends.isEmpty() == false)
               {
               if (log.isTraceEnabled())
               log.trace(name + " has dependencies: " + depends);
              
               for(String iDependOn : depends)
               {
               ServiceDependencyMetaData sdmd = new ServiceDependencyMetaData();
               sdmd.setIDependOn(iDependOn);
               dependencies.add(sdmd);
               }
               }
               webModule.setDependencies(dependencies);
              
               // Here's where a bit of magic happens. By attaching the ServiceMetaData
               // to the deployment, we now make the deployment "relevant" to
               // deployers that use ServiceMetaData as an input (e.g. the
               // org.jboss.system.deployers.ServiceDeployer). Those deployers
               // can now take over deploying the web module.
              
               // TODO could create multiple components for the deployment
               // The ServiceConstructorMetaData is not serializable due to its args
               unit.addAttachment(ServiceMetaData.class, webModule);
               }
               catch (Exception e)
               {
               throw DeploymentException.rethrowAsDeploymentException("Error creating rar deployment " + unit.getName(), e);
               }
               }
              
               /**
               * Get the object name of the ServiceMetaData instance associated with
               * the WebMetaData. This uses the pattern:
               * "jboss.web.deployment:war="+metaData.getContextRoot()
               *
               * @param metaData - the web app metaData
               * @return "jboss.web.deployment:war="+metaData.getContextRoot();
               */
               protected String getObjectName(JBossWebMetaData metaData)
               {
               String ctxPath = metaData.getContextRoot();
               // The ctx path value cannot be empty in the object name
               if( ctxPath == null || ctxPath.length() == 0 )
               ctxPath = "/";
               String objectName = "jboss.web.deployment:war="+ctxPath;
               return objectName;
               }