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;
018
019 import java.util.Map;
020
021 import org.apache.camel.CamelContext;
022 import org.apache.camel.Endpoint;
023 import org.apache.camel.component.hazelcast.atomicnumber.HazelcastAtomicnumberEndpoint;
024 import org.apache.camel.component.hazelcast.instance.HazelcastInstanceEndpoint;
025 import org.apache.camel.component.hazelcast.list.HazelcastListEndpoint;
026 import org.apache.camel.component.hazelcast.map.HazelcastMapEndpoint;
027 import org.apache.camel.component.hazelcast.multimap.HazelcastMultimapEndpoint;
028 import org.apache.camel.component.hazelcast.queue.HazelcastQueueEndpoint;
029 import org.apache.camel.component.hazelcast.seda.HazelcastSedaConfiguration;
030 import org.apache.camel.component.hazelcast.seda.HazelcastSedaEndpoint;
031 import org.apache.camel.impl.DefaultComponent;
032
033 import static org.apache.camel.util.ObjectHelper.removeStartingCharacters;
034
035 public class HazelcastComponent extends DefaultComponent {
036
037 public HazelcastComponent() {
038 super();
039 }
040
041 public HazelcastComponent(final CamelContext context) {
042 super(context);
043 }
044
045 @Override
046 protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
047
048 Endpoint endpoint = null;
049
050 // check type of endpoint
051 if (remaining.startsWith(HazelcastConstants.MAP_PREFIX)) {
052 // remaining is the cache name
053 remaining = removeStartingCharacters(remaining.substring(HazelcastConstants.MAP_PREFIX.length()), '/');
054 endpoint = new HazelcastMapEndpoint(uri, remaining, this);
055 }
056
057 if (remaining.startsWith(HazelcastConstants.MULTIMAP_PREFIX)) {
058 // remaining is the cache name
059 remaining = removeStartingCharacters(remaining.substring(HazelcastConstants.MULTIMAP_PREFIX.length()), '/');
060 endpoint = new HazelcastMultimapEndpoint(uri, remaining, this);
061 }
062
063 if (remaining.startsWith(HazelcastConstants.ATOMICNUMBER_PREFIX)) {
064 // remaining is the name of the atomic value
065 remaining = removeStartingCharacters(remaining.substring(HazelcastConstants.INSTANCE_PREFIX.length()), '/');
066 endpoint = new HazelcastAtomicnumberEndpoint(uri, this, remaining);
067 }
068
069 if (remaining.startsWith(HazelcastConstants.INSTANCE_PREFIX)) {
070 // remaining is anything (name it foo ;)
071 remaining = removeStartingCharacters(remaining.substring(HazelcastConstants.INSTANCE_PREFIX.length()), '/');
072 endpoint = new HazelcastInstanceEndpoint(uri, this);
073 }
074
075 if (remaining.startsWith(HazelcastConstants.QUEUE_PREFIX)) {
076 // remaining is anything (name it foo ;)
077 remaining = removeStartingCharacters(remaining.substring(HazelcastConstants.QUEUE_PREFIX.length()), '/');
078 endpoint = new HazelcastQueueEndpoint(uri, this, remaining);
079 }
080
081 if (remaining.startsWith(HazelcastConstants.SEDA_PREFIX)) {
082 final HazelcastSedaConfiguration config = new HazelcastSedaConfiguration();
083 setProperties(config, parameters);
084 config.setQueueName(remaining.substring(remaining.indexOf(":") + 1, remaining.length()));
085
086 endpoint = new HazelcastSedaEndpoint(uri, this, config);
087 }
088
089 if (remaining.startsWith(HazelcastConstants.LIST_PREFIX)) {
090 // remaining is anything (name it foo ;)
091 remaining = removeStartingCharacters(remaining.substring(HazelcastConstants.LIST_PREFIX.length()), '/');
092 endpoint = new HazelcastListEndpoint(uri, this, remaining);
093 }
094
095 if (endpoint == null) {
096 throw new IllegalArgumentException(String.format("Your URI does not provide a correct 'type' prefix. It should be anything like 'hazelcast:[%s|%s|%s|%s|%s|%s|%s]name' but is '%s'.",
097 HazelcastConstants.MAP_PREFIX, HazelcastConstants.MULTIMAP_PREFIX, HazelcastConstants.ATOMICNUMBER_PREFIX, HazelcastConstants.INSTANCE_PREFIX, HazelcastConstants.QUEUE_PREFIX,
098 HazelcastConstants.SEDA_PREFIX, HazelcastConstants.LIST_PREFIX, uri));
099 }
100
101 return endpoint;
102 }
103
104 }