View Javadoc

1   /*
2    * $Id: ScheduleConfigBuilder.java 22048 2011-05-31 14:39:03Z dfeist $
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.NameableObject;
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 NameableObject
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  
36          endpointBuilder = muleContext.getEndpointFactory().getEndpointBuilder("quartz://" + scheduleId);
37          endpointBuilder.setMuleContext(muleContext);
38          endpointBuilder.setName(scheduleId);
39  
40          connector = new QuartzConnector(muleContext);
41          connector.setName(scheduleId);
42  
43          endpointBuilder.setConnector(connector);
44          endpointBuilder.setExchangePattern(MessageExchangePattern.ONE_WAY);
45      }
46  
47      public ScheduleConfigBuilder addSchedulerFactoryProperty(String key, String value)
48      {
49          connector.getFactoryProperties().put(key, value);
50          return this;
51      }
52  
53      public ScheduleConfigBuilder setScheduler(Scheduler scheduler)
54      {
55          connector.setQuartzScheduler(scheduler);
56          return this;
57      }
58  
59      public ScheduleConfigBuilder setCron(String cron)
60      {
61          endpointBuilder.setProperty(QuartzConnector.PROPERTY_CRON_EXPRESSION, cron);
62          return this;
63      }
64  
65      public ScheduleConfigBuilder setInterval(long interval)
66      {
67          endpointBuilder.setProperty(QuartzConnector.PROPERTY_REPEAT_INTERVAL, interval);
68          return this;
69      }
70  
71      public ScheduleConfigBuilder setStartDelay(long delay)
72      {
73          endpointBuilder.setProperty(QuartzConnector.PROPERTY_START_DELAY, delay);
74          return this;
75      }
76  
77      public InboundEndpoint buildScheduler() throws MuleException
78      {
79          return endpointBuilder.buildInboundEndpoint();
80      }
81  
82      public void setName(String name)
83      {
84          throw new UnsupportedOperationException("setName");
85      }
86  
87      public String getName()
88      {
89          return scheduleId + ".builder";
90      }
91  }