001/* 002 * Copyright 2012-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.actuate.autoconfigure.web.server; 018 019import org.springframework.core.env.Environment; 020 021/** 022 * Port types that can be used to control how the management server is started. 023 * 024 * @author Andy Wilkinson 025 * @since 2.0.0 026 */ 027public enum ManagementPortType { 028 029 /** 030 * The management port has been disabled. 031 */ 032 DISABLED, 033 034 /** 035 * The management port is the same as the server port. 036 */ 037 SAME, 038 039 /** 040 * The management port and server port are different. 041 */ 042 DIFFERENT; 043 044 static ManagementPortType get(Environment environment) { 045 Integer serverPort = getPortProperty(environment, "server."); 046 Integer managementPort = getPortProperty(environment, "management.server."); 047 if (managementPort != null && managementPort < 0) { 048 return DISABLED; 049 } 050 return ((managementPort == null 051 || (serverPort == null && managementPort.equals(8080)) 052 || (managementPort != 0 && managementPort.equals(serverPort))) ? SAME 053 : DIFFERENT); 054 } 055 056 private static Integer getPortProperty(Environment environment, String prefix) { 057 return environment.getProperty(prefix + "port", Integer.class); 058 } 059 060}