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.hazelcast.seda;
018
019 import java.util.concurrent.BlockingQueue;
020
021 import com.hazelcast.core.Hazelcast;
022
023 import org.apache.camel.Consumer;
024 import org.apache.camel.Endpoint;
025 import org.apache.camel.Processor;
026 import org.apache.camel.Producer;
027 import org.apache.camel.component.hazelcast.HazelcastComponent;
028 import org.apache.camel.impl.DefaultEndpoint;
029 import org.apache.camel.util.ObjectHelper;
030
031 /**
032 * Hazelcast SEDA {@link Endpoint} implementation.
033 */
034 public class HazelcastSedaEndpoint extends DefaultEndpoint {
035
036 private final BlockingQueue queue;
037 private final HazelcastSedaConfiguration configuration;
038
039 public HazelcastSedaEndpoint(final String uri, final HazelcastComponent component, final HazelcastSedaConfiguration configuration) {
040 super(uri, component);
041 this.queue = Hazelcast.getQueue(configuration.getQueueName());
042 this.configuration = configuration;
043 if (ObjectHelper.isEmpty(configuration.getQueueName())) {
044 throw new IllegalArgumentException("Queue name is missing.");
045 }
046 }
047
048 public Producer createProducer() throws Exception {
049 return new HazelcastSedaProducer(this, getQueue());
050 }
051
052 public Consumer createConsumer(final Processor processor) throws Exception {
053 return new HazelcastSedaConsumer(this, processor);
054 }
055
056 public BlockingQueue getQueue() {
057 return queue;
058 }
059
060 public HazelcastSedaConfiguration getConfiguration() {
061 return configuration;
062 }
063
064 public boolean isSingleton() {
065 return true;
066 }
067
068 }