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 */
017package org.apache.camel.impl.cloud;
018
019import java.util.Collections;
020import java.util.HashMap;
021import java.util.Map;
022
023import org.apache.camel.CamelContext;
024import org.apache.camel.Ordered;
025import org.apache.camel.cloud.ServiceRegistry;
026import org.apache.camel.support.ServiceSupport;
027
028public abstract class AbstractServiceRegistry extends ServiceSupport implements ServiceRegistry {
029    private final Map<String, Object> attributes;
030    private int order;
031    private String id;
032    private CamelContext camelContext;
033
034    protected AbstractServiceRegistry() {
035        this(null, null);
036    }
037
038    protected AbstractServiceRegistry(String id) {
039        this(id, null);
040    }
041
042    protected AbstractServiceRegistry(String id, CamelContext camelContext) {
043        this.order = Ordered.LOWEST;
044        this.id = id;
045        this.camelContext = camelContext;
046        this.attributes = new HashMap<>();
047    }
048
049    @Override
050    public int getOrder() {
051        return order;
052    }
053
054    public void setOrder(int order) {
055        this.order = order;
056    }
057
058    @Override
059    public void setId(String id) {
060        this.id = id;
061    }
062
063    @Override
064    public String getId() {
065        return id;
066    }
067
068    @Override
069    public void setCamelContext(CamelContext camelContext) {
070        this.camelContext = camelContext;
071    }
072
073    @Override
074    public CamelContext getCamelContext() {
075        return camelContext;
076    }
077
078    public void setAttributes(Map<String, Object> attributes) {
079        this.attributes.clear();
080        this.attributes.putAll(attributes);
081    }
082
083    public void setAttribute(String key, Object value) {
084        this.attributes.put(key, value);
085    }
086
087    @Override
088    public Map<String, Object> getAttributes() {
089        return Collections.unmodifiableMap(attributes);
090    }
091}