View Javadoc

1   /*
2    * $Id: ScheduleConfigBuilder.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  package org.mule.transport.quartz.config;
11  
12  import org.mule.MessageExchangePattern;
13  import org.mule.api.MuleContext;
14  import org.mule.api.MuleException;
15  import org.mule.api.NamedObject;
16  import org.mule.api.endpoint.EndpointBuilder;
17  import org.mule.api.endpoint.InboundEndpoint;
18  import org.mule.transport.quartz.QuartzConnector;
19  
20  import org.quartz.Scheduler;
21  
22  /**
23   * TODO
24   */
25  public class ScheduleConfigBuilder implements NamedObject
26  {
27      private EndpointBuilder endpointBuilder;
28      private QuartzConnector connector;
29      private String scheduleId;
30  
31      public ScheduleConfigBuilder(String scheduleId, MuleContext muleContext) throws MuleException
32      {
33          super();
34          this.scheduleId = scheduleId;
35              endpointBuilder = muleContext.getRegistry().lookupEndpointFactory()
36                      .getEndpointBuilder("quartz://" + scheduleId);
37              endpointBuilder.setMuleContext(muleContext);
38              endpointBuilder.setName(scheduleId);
39  
40              connector = new QuartzConnector(muleContext);
41          connector.setName(scheduleId);
42          endpointBuilder.setConnector(connector);
43          endpointBuilder.setExchangePattern(MessageExchangePattern.ONE_WAY);
44      }
45  
46      public ScheduleConfigBuilder addSchedulerFactoryProperty(String key, String value)
47      {
48          connector.getFactoryProperties().put(key, value);
49          return this;
50      }
51  
52      public ScheduleConfigBuilder setScheduler(Scheduler scheduler)
53      {
54          connector.setQuartzScheduler(scheduler);
55          return this;
56      }
57  
58      public ScheduleConfigBuilder setCron(String cron)
59      {
60          endpointBuilder.setProperty(QuartzConnector.PROPERTY_CRON_EXPRESSION, cron);
61          return this;
62      }
63  
64      public ScheduleConfigBuilder setInterval(long interval)
65      {
66          endpointBuilder.setProperty(QuartzConnector.PROPERTY_REPEAT_INTERVAL, interval);
67          return this;
68      }
69  
70      public ScheduleConfigBuilder setStartDelay(long delay)
71      {
72          endpointBuilder.setProperty(QuartzConnector.PROPERTY_START_DELAY, delay);
73          return this;
74      }
75  
76      public InboundEndpoint buildScheduler() throws MuleException
77      {
78          return endpointBuilder.buildInboundEndpoint();
79      }
80  
81      public void setName(String name)
82      {
83          throw new UnsupportedOperationException("setName");
84      }
85  
86      public String getName()
87      {
88          return scheduleId + ".builder";
89      }
90  }