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.cloud;
018
019import java.util.Map;
020
021import org.apache.camel.util.StringHelper;
022
023/**
024 * Represents a Service.
025 *
026 * @see ServiceChooser
027 * @see ServiceDiscovery
028 */
029public interface ServiceDefinition {
030    String SERVICE_META_PREFIX = "service.";
031
032    // default service meta-data keys
033    String SERVICE_META_ID = "service.id";
034    String SERVICE_META_NAME = "service.name";
035    String SERVICE_META_HOST = "service.host";
036    String SERVICE_META_PORT = "service.port";
037    String SERVICE_META_ZONE = "service.zone";
038    String SERVICE_META_PROTOCOL = "service.protocol";
039    String SERVICE_META_PATH = "service.path";
040
041    /**
042     * Gets the service id.
043     */
044    String getId();
045
046    /**
047     * Gets the service name.
048     */
049    String getName();
050
051    /**
052     * Gets the IP or hostname of the server hosting the service.
053     */
054    String getHost();
055
056    /**
057     * Gets the port number of the server hosting the service.
058     */
059    int getPort();
060
061    /**
062     * Gets the health.
063     */
064    ServiceHealth getHealth();
065
066    /**
067     * Gets a key/value metadata associated with the service.
068     */
069    Map<String, String> getMetadata();
070
071    /**
072     * Check if a service definition matches.
073     */
074    default boolean matches(ServiceDefinition other) {
075        if (this.equals(other)) {
076            return true;
077        }
078
079        return getPort() == other.getPort()
080            && StringHelper.matches(getName(), other.getName())
081            && StringHelper.matches(getId(), other.getId())
082            && StringHelper.matches(getHost(), other.getHost());
083    }
084}