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.camel.component.timer;
018
019 import java.util.Date;
020 import java.util.Timer;
021
022 import org.apache.camel.Consumer;
023 import org.apache.camel.Processor;
024 import org.apache.camel.Producer;
025 import org.apache.camel.RuntimeCamelException;
026 import org.apache.camel.impl.DefaultEndpoint;
027
028 /**
029 * Represents a timer endpoint that can generate periodic inbound PojoExchanges.
030 *
031 * @version $Revision: 736322 $
032 */
033 public class TimerEndpoint extends DefaultEndpoint {
034 private String timerName;
035 private Date time;
036 private long period = 1000;
037 private long delay;
038 private boolean fixedRate;
039 private boolean daemon = true;
040 private Timer timer;
041
042 public TimerEndpoint() {
043 }
044
045 public TimerEndpoint(String fullURI, TimerComponent component, String timerName) {
046 super(fullURI, component);
047 this.timer = component.getTimer(this);
048 this.timerName = timerName;
049 }
050
051 public TimerEndpoint(String endpointUri, Timer timer) {
052 this(endpointUri);
053 this.timer = timer;
054 }
055
056 public TimerEndpoint(String endpointUri) {
057 super(endpointUri);
058 }
059
060 public Producer createProducer() throws Exception {
061 throw new RuntimeCamelException("Cannot produce to a TimerEndpoint: " + getEndpointUri());
062 }
063
064 public Consumer createConsumer(Processor processor) throws Exception {
065 return new TimerConsumer(this, processor);
066 }
067
068 public String getTimerName() {
069 if (timerName == null) {
070 timerName = getEndpointUri();
071 }
072 return timerName;
073 }
074
075 public void setTimerName(String timerName) {
076 this.timerName = timerName;
077 }
078
079 public boolean isDaemon() {
080 return daemon;
081 }
082
083 public void setDaemon(boolean daemon) {
084 this.daemon = daemon;
085 }
086
087 public long getDelay() {
088 return delay;
089 }
090
091 public void setDelay(long delay) {
092 this.delay = delay;
093 }
094
095 public boolean isFixedRate() {
096 return fixedRate;
097 }
098
099 public void setFixedRate(boolean fixedRate) {
100 this.fixedRate = fixedRate;
101 }
102
103 public long getPeriod() {
104 return period;
105 }
106
107 public void setPeriod(long period) {
108 this.period = period;
109 }
110
111 public Date getTime() {
112 return time;
113 }
114
115 public void setTime(Date time) {
116 this.time = time;
117 }
118
119 public boolean isSingleton() {
120 return true;
121 }
122
123 public Timer getTimer() {
124 if (timer == null) {
125 timer = new Timer();
126 }
127 return timer;
128 }
129
130 public void setTimer(Timer timer) {
131 this.timer = timer;
132 }
133 }