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