org.apache.camel.component.atomix.client.AbstractAtomixClientComponent Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.atomix.client;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import io.atomix.AtomixClient;
import io.atomix.catalyst.transport.Address;
import org.apache.camel.CamelContext;
import org.apache.camel.spi.Metadata;
import org.apache.camel.support.DefaultComponent;
import org.apache.camel.support.EndpointHelper;
import org.apache.camel.util.PropertiesHelper;
public abstract class AbstractAtomixClientComponent extends DefaultComponent {
protected AbstractAtomixClientComponent() {
}
protected AbstractAtomixClientComponent(CamelContext camelContext) {
super(camelContext);
}
// *****************************************
// Properties
// *****************************************
public AtomixClient getAtomix() {
return (AtomixClient) getComponentConfiguration().getAtomix();
}
/**
* The shared AtomixClient instance
*/
@Metadata
public void setAtomix(AtomixClient client) {
getComponentConfiguration().setAtomix(client);
}
public List getNodes() {
return getComponentConfiguration().getNodes();
}
/**
* The nodes the AtomixClient should connect to
*/
@Metadata
public void setNodes(List nodes) {
getComponentConfiguration().setNodes(nodes);
}
public void setNodes(String nodes) {
getComponentConfiguration().setNodes(nodes);
}
public String getConfigurationUri() {
return getComponentConfiguration().getConfigurationUri();
}
/**
* The path to the AtomixClient configuration
*/
@Metadata
public void setConfigurationUri(String configurationUri) {
getComponentConfiguration().setConfigurationUri(configurationUri);
}
// *****************************************
// Properties
// *****************************************
protected C setConfigurationProperties(C configuration, Map parameters) {
// Resolve config for named maps
Map configs = PropertiesHelper.extractProperties(parameters, "resource.config.");
for (Map.Entry entry : configs.entrySet()) {
String ref = (String) entry.getValue();
if (!EndpointHelper.isReferenceParameter(ref)) {
throw new IllegalArgumentException("The option resource.config." + ref + " should be a reference");
}
configuration.addResourceConfig(
entry.getKey(),
EndpointHelper.resolveReferenceParameter(getCamelContext(), ref, Properties.class));
}
// Resolve options for named maps
Map options = PropertiesHelper.extractProperties(parameters, "resource.options.");
for (Map.Entry entry : options.entrySet()) {
String ref = (String) entry.getValue();
if (!EndpointHelper.isReferenceParameter(ref)) {
throw new IllegalArgumentException("The option resource.options." + ref + " should be a reference");
}
configuration.addResourceOption(
entry.getKey(),
EndpointHelper.resolveReferenceParameter(getCamelContext(), ref, Properties.class));
}
return configuration;
}
// *****************************************
// Properties
// *****************************************
protected abstract C getComponentConfiguration();
}