001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.servicemix.quartz;
018
019 import java.util.List;
020
021 import org.apache.servicemix.common.DefaultComponent;
022 import org.quartz.Scheduler;
023 import org.quartz.SchedulerFactory;
024 import org.quartz.impl.StdSchedulerFactory;
025
026 /**
027 * @org.apache.xbean.XBean element="component"
028 */
029 public class QuartzComponent extends DefaultComponent {
030
031 private QuartzEndpoint[] endpoints;
032 private Scheduler scheduler;
033 private SchedulerFactory factory;
034
035 /**
036 * @return the factory
037 */
038 public SchedulerFactory getFactory() {
039 return factory;
040 }
041
042 /**
043 * @param factory the factory to set
044 */
045 public void setFactory(SchedulerFactory factory) {
046 this.factory = factory;
047 }
048
049 /**
050 * @return the endpoints
051 */
052 public QuartzEndpoint[] getEndpoints() {
053 return endpoints;
054 }
055
056 /**
057 * @param endpoints the endpoints to set
058 */
059 public void setEndpoints(QuartzEndpoint[] endpoints) {
060 this.endpoints = endpoints;
061 }
062
063 /**
064 * @return the scheduler
065 */
066 public Scheduler getScheduler() {
067 return scheduler;
068 }
069
070 /**
071 * @param scheduler the scheduler to set
072 */
073 public void setScheduler(Scheduler scheduler) {
074 this.scheduler = scheduler;
075 }
076
077 /* (non-Javadoc)
078 * @see org.apache.servicemix.common.DefaultComponent#getConfiguredEndpoints()
079 */
080 @Override
081 protected List getConfiguredEndpoints() {
082 return asList(endpoints);
083 }
084
085 /* (non-Javadoc)
086 * @see org.apache.servicemix.common.DefaultComponent#getEndpointClasses()
087 */
088 @Override
089 protected Class[] getEndpointClasses() {
090 return new Class[] {QuartzEndpoint.class };
091 }
092
093 /* (non-Javadoc)
094 * @see org.apache.servicemix.common.DefaultComponent#doInit()
095 */
096 @Override
097 public void doInit() throws Exception {
098 if (scheduler == null) {
099 if (factory == null) {
100 factory = new StdSchedulerFactory();
101 }
102 scheduler = factory.getScheduler();
103 }
104 scheduler.getContext().setAllowsTransientData(true);
105 scheduler.getContext().put(getComponentName(), this);
106 super.doInit();
107 }
108
109 /* (non-Javadoc)
110 * @see org.apache.servicemix.common.DefaultComponent#doStart()
111 */
112 @Override
113 public void doStart() throws Exception {
114 scheduler.start();
115 super.doStart();
116 }
117
118 /* (non-Javadoc)
119 * @see org.apache.servicemix.common.DefaultComponent#doStopt()
120 */
121 @Override
122 public void doStop() throws Exception {
123 super.doStop();
124 scheduler.standby();
125 }
126
127 /* (non-Javadoc)
128 * @see org.apache.servicemix.common.DefaultComponent#doShutDown()
129 */
130 @Override
131 public void doShutDown() throws Exception {
132 super.doShutDown();
133 scheduler.shutdown();
134 scheduler = null;
135 }
136
137 }