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.web.servlet.context; 018 019import org.springframework.boot.web.context.WebServerInitializedEvent; 020import org.springframework.boot.web.server.WebServer; 021 022/** 023 * Event to be published after the {@link ServletWebServerApplicationContext} is refreshed 024 * and the {@link WebServer} is ready. Useful for obtaining the local port of a running 025 * server. 026 * 027 * <p> 028 * Normally it will have been started, but listeners are free to inspect the server and 029 * stop and start it if they want to. 030 * 031 * @author Dave Syer 032 */ 033@SuppressWarnings("serial") 034public class ServletWebServerInitializedEvent extends WebServerInitializedEvent { 035 036 private final ServletWebServerApplicationContext applicationContext; 037 038 public ServletWebServerInitializedEvent(WebServer webServer, 039 ServletWebServerApplicationContext applicationContext) { 040 super(webServer); 041 this.applicationContext = applicationContext; 042 } 043 044 /** 045 * Access the application context that the server was created in. Sometimes it is 046 * prudent to check that this matches expectations (like being equal to the current 047 * context) before acting on the server itself. 048 * @return the applicationContext that the server was created from 049 */ 050 @Override 051 public ServletWebServerApplicationContext getApplicationContext() { 052 return this.applicationContext; 053 } 054 055}