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.impl;
018
019 import java.util.HashMap;
020 import java.util.Map;
021
022 import org.apache.camel.CamelContext;
023 import org.apache.camel.Component;
024
025 /**
026 * A base class for {@link org.apache.camel.Endpoint} which creates a {@link ScheduledPollConsumer}
027 *
028 * @version
029 */
030 public abstract class ScheduledPollEndpoint extends DefaultEndpoint {
031
032 protected ScheduledPollEndpoint(String endpointUri, Component component) {
033 super(endpointUri, component);
034 }
035
036 @Deprecated
037 protected ScheduledPollEndpoint(String endpointUri, CamelContext context) {
038 super(endpointUri, context);
039 }
040
041 @Deprecated
042 protected ScheduledPollEndpoint(String endpointUri) {
043 super(endpointUri);
044 }
045
046 protected ScheduledPollEndpoint() {
047 }
048
049 public void configureProperties(Map<String, Object> options) {
050 super.configureProperties(options);
051 configureScheduledPollConsumerProperties(options, getConsumerProperties());
052 }
053
054 private void configureScheduledPollConsumerProperties(Map<String, Object> options, Map<String, Object> consumerProperties) {
055 // special for scheduled poll consumers as we want to allow end users to configure its options
056 // from the URI parameters without the consumer. prefix
057 Object startScheduler = options.remove("startScheduler");
058 Object initialDelay = options.remove("initialDelay");
059 Object delay = options.remove("delay");
060 Object timeUnit = options.remove("timeUnit");
061 Object useFixedDelay = options.remove("useFixedDelay");
062 Object pollStrategy = options.remove("pollStrategy");
063 Object runLoggingLevel = options.remove("runLoggingLevel");
064 Object sendEmptyMessageWhenIdle = options.remove("sendEmptyMessageWhenIdle");
065 Object scheduledExecutorService = options.remove("scheduledExecutorService");
066 boolean setConsumerProperties = false;
067
068 // the following is split into two if statements to satisfy the checkstyle max complexity constraint
069 if (initialDelay != null || delay != null || timeUnit != null || useFixedDelay != null || pollStrategy != null) {
070 setConsumerProperties = true;
071 }
072 if (runLoggingLevel != null || startScheduler != null || sendEmptyMessageWhenIdle != null || scheduledExecutorService != null) {
073 setConsumerProperties = true;
074 }
075
076 if (setConsumerProperties) {
077
078 if (consumerProperties == null) {
079 consumerProperties = new HashMap<String, Object>();
080 }
081 if (initialDelay != null) {
082 consumerProperties.put("initialDelay", initialDelay);
083 }
084 if (startScheduler != null) {
085 consumerProperties.put("startScheduler", startScheduler);
086 }
087 if (delay != null) {
088 consumerProperties.put("delay", delay);
089 }
090 if (timeUnit != null) {
091 consumerProperties.put("timeUnit", timeUnit);
092 }
093 if (useFixedDelay != null) {
094 consumerProperties.put("useFixedDelay", useFixedDelay);
095 }
096 if (pollStrategy != null) {
097 consumerProperties.put("pollStrategy", pollStrategy);
098 }
099 if (runLoggingLevel != null) {
100 consumerProperties.put("runLoggingLevel", runLoggingLevel);
101 }
102 if (sendEmptyMessageWhenIdle != null) {
103 consumerProperties.put("sendEmptyMessageWhenIdle", sendEmptyMessageWhenIdle);
104 }
105 if (scheduledExecutorService != null) {
106 consumerProperties.put("scheduledExecutorService", scheduledExecutorService);
107 }
108 }
109 }
110
111 }