'2009/02'에 해당되는 글 7건

  1. 2009.02.17 JBoss Deployment 순서와 관련한 팁

이런 일이 있었다.
JBoss의 Scheduer 서비스를 받을려고 하는데, 즉, 내가 Schedulable 클래스를 생성하고 scheduler-service.xml에 내용을 등록하려고 하는데...문제가 생긴다.

내가 만든 클래스는 별도의 jar로 패키징하지 않고, ear 패키징 하여 deploy 한다.
그런데 문제는 ear 패키징 보다 scheduler서비스를 비롯한 다른 서비스가 먼저 로딩된다는데 있다.

Jboss가 Scheduler 서비스를 구동하려 할때 내가 만든 Schedulable 클래스를 실행하려고 시도하는데..
이넘은 아직 로딩되지 않았다. ear 패키징이 아직 로딩 되지 않았기 때문이다.

이런 경우에 간단한 해결책은 Deploy 순서를 바꾸는 것이다. ear 패키징이 먼저 로딩되고, 서비스가 이후에 로딩되면 된다.

이렇게 하기 위한 간단한 팁은 우선 JBoss의 MainDeployer의 행동을 약간 고쳐줄 필요가 있는데
JBoss의 conf 폴더아래에 jboss-service.xml 파일을 열어보면

      <depends optional-attribute-name="Deployer">jboss.system:service=MainDeployer</depends>

      <!-- The URLComparator can be used to specify a deployment ordering
           for deployments found in a scanned directory.  The class specified
           must be an implementation of java.util.Comparator, it must be able
           to compare two URL objects, and it must have a no-arg constructor.
           Two deployment comparators are shipped with JBoss:
             - org.jboss.deployment.DeploymentSorter
               Sorts by file extension, as follows:
                 "sar", "service.xml", "rar", "jar", "war", "wsr", "ear", "zip",
                 "*"
             - org.jboss.deployment.scanner.PrefixDeploymentSorter
               If the name portion of the url begins with 1 or more digits, those
               digits are converted to an int (ignoring leading zeroes), and
               files are deployed in that order.  Files that do not start with
               any digits will be deployed first, and they will be sorted by
               extension as above with DeploymentSorter.
      -->
<!--
      <attribute name="URLComparator">org.jboss.deployment.DeploymentSorter</attribute>
-->
      <attribute name="URLComparator">org.jboss.deployment.scanner.PrefixDeploymentSorter</attribute>

URLComparator의 default를 위와 같이 수정했다. 즉, 나는 PrefixDeploymentSorter를 사용하겠다는 뜻이다.

그런 다음 scheduler-service.xml의 이름 앞에 숫자로 prefix를 붙여준다.
예를 들어 11-scheduler-service.xml로 이름을 변경하면된다.

이렇게 해주면 ear 패키징을 로딩한 후 11-scheduler-service.xml을 로딩하게 된다.

도움이 되었으면 좋겠음.

대안
An alternate approach which has worked well for us is to add a <depends> element to the scheduler mbean's *-service.xml. For example, in our application, this scheduled task uses the PackageExpireSession EJB:

  <mbean code="org.jboss.varia.scheduler.Scheduler"
     name="com.tumbleweed.---">
    <!-- Depends on PackageExpireSession EJB -->
    <depends>jboss.j2ee:service=EJB,jndiName=PackageExpireSession</depends>


    ...
  </mbean>
 
얼마전 날 괴롭힌 일이 있었는데..아직 원인은 모르지만(시간이 넘 없어 일에 바쁘니...추적하지 못함)
위에처럼 해도 안되는 거다. 자꾸 classloader가 스케쥴 클래스를 찾지 못한다고 한다.
그래서 다르게 해결했다.
EAR 패키징 한 속에 있는 클래스를 참조한다는 뜻은 어쨌거나 EAR 패키징한 애플리케이션에 dependent하다는 거고.
아예 EAR 패키징안에 SAR로 구성해서 서비스로 등록시켰다. 오히려 이게 나은듯하다.
내가 패키징한 EAR 구조와 관련된 jboss-app.xml 내용이다.
 
이런것 때문에 고생한 사람이 없으면 좋겠다. 참 이렇게 하면 deploy 폴더에 scheduler-service.xml 없어도 된다.
원래대로 <attribute name="URLComparator">org.jboss.deployment.DeploymentSorter</attribute>
이걸로 써도 되고...
 
amanda.ear
  META-INF
   |-- jboss-app.xml
   |-- application.xml
  amanda-classes.jar
  amanda-ejb.jar
  amanda.sar
    META-INF
     |-- jboss-service.xml
 
jboss-service.xml의 내용은
<?xml version="1.0" encoding="UTF-8"?>
<server>
       <mbean code="org.jboss.varia.scheduler.Scheduler"
          name="com.kisinfo.datapoint:service=SmsMessage">
      <attribute name="StartAtStartup">true</attribute>
      <attribute name="SchedulableClass">com.kisinfo.datapoint.schedule.SmsMessageScheduler</attribute>
      <attribute name="SchedulableArguments">ecredit,0</attribute>
      <attribute name="SchedulableArgumentTypes">java.lang.String,int</attribute>
      <attribute name="InitialStartDate">NOW</attribute>
      <attribute name="SchedulePeriod">60000</attribute>
      <attribute name="InitialRepetitions">-1</attribute>
      <attribute name="FixedRate">true</attribute>
   </mbean>
</server>
jboss-app.xml 내용은
<!DOCTYPE jboss-app
          PUBLIC "-//JBoss//DTD J2EE Application 1.4//EN"
          "http://www.jboss.org/j2ee/dtd/jboss-app_4_0.dtd">
<jboss-app>
   <loader-repository>
   com.kisinfo.datapoint:loader=amanda.ear
   </loader-repository>
    <module>
       <service>amanda.sar</service>
    </module>   
</jboss-app>
 
열심히 팟팅입니다.


 

Posted by
,