All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netflix.hystrix.strategy.properties.HystrixDynamicProperties Maven / Gradle / Ivy

There is a newer version: 1.5.18
Show newest version
/**
 * Copyright 2016 Netflix, Inc.
 * 

* Licensed 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 com.netflix.hystrix.strategy.properties; import java.util.ServiceLoader; /** * A hystrix plugin (SPI) for resolving dynamic configuration properties. This * SPI allows for varying configuration sources. * * The HystrixPlugin singleton will load only one implementation of this SPI * throught the {@link ServiceLoader} mechanism. * * @author agentgt * */ public interface HystrixDynamicProperties { /** * Requests a property that may or may not actually exist. * @param name property name, never null * @param fallback default value, maybe null * @return never null */ public HystrixDynamicProperty getString(String name, String fallback); /** * Requests a property that may or may not actually exist. * @param name property name, never null * @param fallback default value, maybe null * @return never null */ public HystrixDynamicProperty getInteger(String name, Integer fallback); /** * Requests a property that may or may not actually exist. * @param name property name, never null * @param fallback default value, maybe null * @return never null */ public HystrixDynamicProperty getLong(String name, Long fallback); /** * Requests a property that may or may not actually exist. * @param name property name * @param fallback default value * @return never null */ public HystrixDynamicProperty getBoolean(String name, Boolean fallback); /** * @ExcludeFromJavadoc */ public static class Util { /** * A convenience method to get a property by type (Class). * @param properties never null * @param name never null * @param fallback maybe null * @param type never null * @return a dynamic property with type T. */ @SuppressWarnings("unchecked") public static HystrixDynamicProperty getProperty( HystrixDynamicProperties properties, String name, T fallback, Class type) { return (HystrixDynamicProperty) doProperty(properties, name, fallback, type); } private static HystrixDynamicProperty doProperty( HystrixDynamicProperties delegate, String name, Object fallback, Class type) { if(type == String.class) { return delegate.getString(name, (String) fallback); } else if (type == Integer.class) { return delegate.getInteger(name, (Integer) fallback); } else if (type == Long.class) { return delegate.getLong(name, (Long) fallback); } else if (type == Boolean.class) { return delegate.getBoolean(name, (Boolean) fallback); } throw new IllegalStateException(); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy