<web-app xmlns="http://caucho.com/ns/resin">
  <!-- 
    - Instantiate an instance of PeriodTaskImpl and store it in jndi.
    - The periodic task is then available for use in the various ways
    - illustrated below.
    -
    - The interface for PeriodicTaskImpl is PeriodicTask, which is the
    - view of the object provided to users of the service.
    -->
  <resource type="example.PeriodicTask" jndi-name="PeriodicTask" 
            mbean-name="type=PeriodicTask,name=PeriodicTask"
            mbean-interface="example.PeriodicTask">
    <init>
      <estimated-average-time>5</estimated-average-time>
    </init>
  </resource>

  <!-- 
     - servlet to manage the PeriodicTask
    -->

  <servlet>
    <servlet-name>PeriodicTaskServlet</servlet-name>
    <servlet-class>example.PeriodicTaskServlet</servlet-class>
    <init>
      <periodic-task>${jndi:lookup("PeriodicTask")}</periodic-task>
    </init>
  </servlet>

  <servlet-mapping>
    <servlet-name>PeriodicTaskServlet</servlet-name>
    <url-pattern>/admin/periodictask</url-pattern>
  </servlet-mapping>

  <!-- 
     - run() the PeriodicTask every minute 
    -->
  <resource type="com.caucho.resources.CronResource">
    <init>
      <cron>*</cron>
      <work>${jndi:lookup("PeriodicTask")}</work>
    </init>
  </resource>

  <!-- 
     - filter to show an unavailable page if the PeriodicTask is active 
    -->

  <filter>
    <filter-name>PeriodicTaskFilter</filter-name>
    <filter-class>example.PeriodicTaskFilter</filter-class>
    <init>
      <periodic-task>${jndi:lookup("PeriodicTask")}</periodic-task>
      <!-- optional url, if not specified a 503 response is sent. -->
      <url>/unavailable.jsp</url>
    </init>
  </filter>

  <filter-mapping>
    <!-- regexp to match all urls except /admin and /index.xtp-->
    <filter-name>PeriodicTaskFilter</filter-name>
    <url-regexp>^(?!/admin|/index.xtp)+</url-regexp>
  </filter-mapping>

</web-app>
