// Path: spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpoint.java
// @Endpoint(id = "busrefresh") // TODO: document new id
// public class RefreshBusEndpoint extends AbstractBusEndpoint {
// 
// 	public RefreshBusEndpoint(ApplicationEventPublisher publisher, String id, Destination.Factory destinationFactory) {
// 		super(publisher, id, destinationFactory);
// 	}
// 
// 	@WriteOperation
// 	public void busRefreshWithDestination(@Selector(match = Match.ALL_REMAINING) String[] destinations) {
// 		String destination = StringUtils.arrayToDelimitedString(destinations, ":");
// 		publish(new RefreshRemoteApplicationEvent(this, getInstanceId(), getDestination(destination)));
// 	}
// 
// 	@WriteOperation
// 	public void busRefresh() {
// 		publish(new RefreshRemoteApplicationEvent(this, getInstanceId(), getDestination(null)));
// 	}
// 
// }
// 
// Path: spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/Destination.java
// public interface Destination {
// 
// 	String getDestinationAsString();
// 
// 	@FunctionalInterface
// 	interface Factory {
// 
// 		Destination getDestination(String originalDestination);
// 
// 	}
// 
// }
// 
// Path: spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RefreshListener.java
// public class RefreshListener implements ApplicationListener<RefreshRemoteApplicationEvent> {
// 
// 	private static Log log = LogFactory.getLog(RefreshListener.class);
// 
// 	private ContextRefresher contextRefresher;
// 
// 	private ServiceMatcher serviceMatcher;
// 
// 	public RefreshListener(ContextRefresher contextRefresher, ServiceMatcher serviceMatcher) {
// 		this.contextRefresher = contextRefresher;
// 		this.serviceMatcher = serviceMatcher;
// 	}
// 
// 	@Override
// 	public void onApplicationEvent(RefreshRemoteApplicationEvent event) {
// 		log.info("Received remote refresh request.");
// 		if (serviceMatcher.isForSelf(event)) {
// 			Set<String> keys = this.contextRefresher.refresh();
// 			log.info("Keys refreshed " + keys);
// 		}
// 		else {
// 			log.info("Refresh not performed, the event was targeting " + event.getDestinationService());
// 		}
// 	}
// 
// }


import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.bus.endpoint.RefreshBusEndpoint;
import org.springframework.cloud.bus.event.Destination;
import org.springframework.cloud.bus.event.RefreshListener;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/*
 * Copyright 2013-2019 the original author or authors.
 *
 * 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
 *
 *      https://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 org.springframework.cloud.bus;


/**
 * @author Ryan Baxter
 */
@Configuration(proxyBeanMethods = false)
@ConditionalOnBusEnabled
@AutoConfigureAfter(name = { "org.springframework.cloud.autoconfigure.RefreshAutoConfiguration" })
public class BusRefreshAutoConfiguration {

	@Bean
// Path: spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpoint.java
// @Endpoint(id = "busrefresh") // TODO: document new id
// public class RefreshBusEndpoint extends AbstractBusEndpoint {
// 
// 	public RefreshBusEndpoint(ApplicationEventPublisher publisher, String id, Destination.Factory destinationFactory) {
// 		super(publisher, id, destinationFactory);
// 	}
// 
// 	@WriteOperation
// 	public void busRefreshWithDestination(@Selector(match = Match.ALL_REMAINING) String[] destinations) {
// 		String destination = StringUtils.arrayToDelimitedString(destinations, ":");
// 		publish(new RefreshRemoteApplicationEvent(this, getInstanceId(), getDestination(destination)));
// 	}
// 
// 	@WriteOperation
// 	public void busRefresh() {
// 		publish(new RefreshRemoteApplicationEvent(this, getInstanceId(), getDestination(null)));
// 	}
// 
// }
// 
// Path: spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/Destination.java
// public interface Destination {
// 
// 	String getDestinationAsString();
// 
// 	@FunctionalInterface
// 	interface Factory {
// 
// 		Destination getDestination(String originalDestination);
// 
// 	}
// 
// }
// 
// Path: spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RefreshListener.java
// public class RefreshListener implements ApplicationListener<RefreshRemoteApplicationEvent> {
// 
// 	private static Log log = LogFactory.getLog(RefreshListener.class);
// 
// 	private ContextRefresher contextRefresher;
// 
// 	private ServiceMatcher serviceMatcher;
// 
// 	public RefreshListener(ContextRefresher contextRefresher, ServiceMatcher serviceMatcher) {
// 		this.contextRefresher = contextRefresher;
// 		this.serviceMatcher = serviceMatcher;
// 	}
// 
// 	@Override
// 	public void onApplicationEvent(RefreshRemoteApplicationEvent event) {
// 		log.info("Received remote refresh request.");
// 		if (serviceMatcher.isForSelf(event)) {
// 			Set<String> keys = this.contextRefresher.refresh();
// 			log.info("Keys refreshed " + keys);
// 		}
// 		else {
// 			log.info("Refresh not performed, the event was targeting " + event.getDestinationService());
// 		}
// 	}
// 
// }


// Path: spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusRefreshAutoConfiguration.java
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.bus.endpoint.RefreshBusEndpoint;
import org.springframework.cloud.bus.event.Destination;
import org.springframework.cloud.bus.event.RefreshListener;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/*
 * Copyright 2013-2019 the original author or authors.
 *
 * 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
 *
 *      https://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 org.springframework.cloud.bus;


/**
 * @author Ryan Baxter
 */
@Configuration(proxyBeanMethods = false)
@ConditionalOnBusEnabled
@AutoConfigureAfter(name = { "org.springframework.cloud.autoconfigure.RefreshAutoConfiguration" })
public class BusRefreshAutoConfiguration {

	@Bean
	@ConditionalOnProperty(value = "spring.cloud.bus.refresh.enabled", matchIfMissing = true)