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