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