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.kestrel;
018    
019    import net.spy.memcached.MemcachedClient;
020    import org.apache.camel.Consumer;
021    import org.apache.camel.Processor;
022    import org.apache.camel.Producer;
023    import org.apache.camel.impl.DefaultEndpoint;
024    import org.apache.camel.util.ServiceHelper;
025    
026    /**
027     * Camel endpoint for communication with a kestrel based queue.
028     */
029    public class KestrelEndpoint extends DefaultEndpoint {
030    
031        /**
032         * The configuration of this endpoint
033         */
034        private KestrelConfiguration configuration;
035    
036        /**
037         * The queue we are polling
038         */
039        private String queue;
040    
041        /**
042         * The kestrel component itself
043         */
044        private KestrelComponent component;
045    
046        public KestrelEndpoint(String endPointURI, KestrelComponent component, KestrelConfiguration configuration, String queue) {
047            super(endPointURI, component);
048            this.component = component;
049            this.configuration = configuration;
050            this.queue = queue;
051        }
052    
053        public KestrelConfiguration getConfiguration() {
054            return configuration;
055        }
056    
057        public void setConfiguration(KestrelConfiguration configuration) {
058            this.configuration = configuration;
059        }
060    
061        public String getQueue() {
062            return queue;
063        }
064    
065        public void setQueue(String queue) {
066            this.queue = queue;
067        }
068    
069        public Producer createProducer() throws Exception {
070            return new KestrelProducer(this, getMemcachedClient());
071        }
072    
073        public Consumer createConsumer(Processor processor) throws Exception {
074            return new KestrelConsumer(this, processor, getMemcachedClient());
075        }
076    
077        /**
078         * @return a client to kestrel using the memcached client as configured by this endpoint
079         */
080        private MemcachedClient getMemcachedClient() {
081            return component.getMemcachedClient(configuration, queue);
082        }
083    
084        @Override
085        public boolean isLenientProperties() {
086            return false;
087        }
088    
089        public boolean isSingleton() {
090            return false;
091        }
092    }