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.activemq.broker.scheduler;
018    
019    import java.util.Collections;
020    import java.util.List;
021    import org.apache.activemq.util.ByteSequence;
022    
023    public class JobSchedulerFacade implements JobScheduler {
024    
025        private final SchedulerBroker broker;
026        
027        JobSchedulerFacade(SchedulerBroker broker){
028            this.broker=broker;
029        }
030        public void addListener(JobListener l) throws Exception {
031            JobScheduler js = this.broker.getInternalScheduler();
032            if (js !=null) {
033                js.addListener(l);
034            }
035        }
036    
037        public List<Job> getAllJobs() throws Exception {
038            JobScheduler js = this.broker.getInternalScheduler();
039            if (js !=null) {
040                return js.getAllJobs();
041            }
042            return Collections.emptyList();
043        }
044    
045        public List<Job> getAllJobs(long start, long finish) throws Exception {
046            JobScheduler js = this.broker.getInternalScheduler();
047            if (js !=null) {
048                return js.getAllJobs(start,finish);
049            }
050            return Collections.emptyList();
051        }
052    
053        public String getName() throws Exception {
054            JobScheduler js = this.broker.getInternalScheduler();
055            if (js !=null) {
056                return js.getName();
057            }
058            return "";
059        }
060    
061        public List<Job> getNextScheduleJobs() throws Exception {
062            JobScheduler js = this.broker.getInternalScheduler();
063            if (js !=null) {
064                return js.getNextScheduleJobs();
065            }
066            return Collections.emptyList();
067        }
068    
069        public long getNextScheduleTime() throws Exception {
070            JobScheduler js = this.broker.getInternalScheduler();
071            if (js !=null) {
072                return js.getNextScheduleTime();
073            }
074            return 0;
075        }
076    
077        public void remove(long time) throws Exception {
078            JobScheduler js = this.broker.getInternalScheduler();
079            if (js !=null) {
080                js.remove(time);
081            }
082        }
083    
084        public void remove(String jobId) throws Exception {
085            JobScheduler js = this.broker.getInternalScheduler();
086            if (js !=null) {
087                js.remove(jobId);
088            }
089    
090        }
091    
092        public void removeAllJobs() throws Exception {
093            JobScheduler js = this.broker.getInternalScheduler();
094            if (js !=null) {
095                js.removeAllJobs();
096            }
097        }
098    
099        public void removeAllJobs(long start, long finish) throws Exception {
100            JobScheduler js = this.broker.getInternalScheduler();
101            if (js !=null) {
102                js.removeAllJobs(start,finish);
103            }
104    
105        }
106    
107        public void removeListener(JobListener l) throws Exception {
108            JobScheduler js = this.broker.getInternalScheduler();
109            if (js !=null) {
110                js.removeListener(l);
111            }
112    
113        }
114    
115        public void schedule(String jobId, ByteSequence payload, long delay) throws Exception {
116            JobScheduler js = this.broker.getInternalScheduler();
117            if (js !=null) {
118                js.schedule(jobId, payload, delay);
119            }
120        }
121    
122        public void schedule(String jobId, ByteSequence payload,String cronEntry, long start, long period, int repeat) throws Exception {
123            JobScheduler js = this.broker.getInternalScheduler();
124            if (js !=null) {
125                js.schedule(jobId, payload, cronEntry,start,period,repeat);
126            }
127        }
128        public void schedule(String jobId, ByteSequence payload, String cronEntry) throws Exception {
129            JobScheduler js = this.broker.getInternalScheduler();
130            if (js !=null) {
131                js.schedule(jobId, payload, cronEntry);
132            }
133            
134        }
135    }