// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java
// public final class CreateApplicationInstance {
// 
// 	private final ServiceInstance serviceInstance;
// 
// 	public CreateApplicationInstance(ServiceInstance serviceInstance) {
// 		Assert.notNull(serviceInstance, "serviceInstance must not be null!");
// 		this.serviceInstance = serviceInstance;
// 	}
// 
// 	public ServiceInstance getServiceInstance() {
// 		return this.serviceInstance;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java
// public final class DeleteApplicationInstance {
// 
// 	private final String id;
// 
// 	public DeleteApplicationInstance(String id) {
// 		Assert.notNull(id, "id must not be null!");
// 		this.id = id;
// 	}
// 
// 	public String getId() {
// 		return this.id;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java
// public final class UpdateActuatorEndpoints {
// 
// 	private final String id;
// 	private final Links actuatorEndpoints;
// 
// 	public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) {
// 		Assert.notNull(id, "id must not be null!");
// 		Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!");
// 		this.id = id;
// 		this.actuatorEndpoints = actuatorEndpoints;
// 	}
// 
// 	public String getId() {
// 		return this.id;
// 	}
// 
// 	public Links getActuatorEndpoints() {
// 		return this.actuatorEndpoints;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java
// public class ApplicationInstanceCreated extends ApplicationEvent {
// 
// 	public ApplicationInstanceCreated(ApplicationInstance instance) {
// 		super(instance);
// 	}
// 
// 	public ApplicationInstance getApplicationInstance() {
// 		return (ApplicationInstance) this.source;
// 	}
// 
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java
// public class ServiceInstanceDisappeared extends ApplicationEvent {
// 
// 	public ServiceInstanceDisappeared(String serviceInstanceId) {
// 		super(serviceInstanceId);
// 	}
// 
// 	public String getServiceInstanceId() {
// 		return (String) this.source;
// 	}
// 
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java
// public class ServiceInstanceDiscovered extends ApplicationEvent {
// 
// 	public ServiceInstanceDiscovered(ServiceInstance serviceInstance) {
// 		super(serviceInstance);
// 	}
// 
// 	public ServiceInstance getServiceInstance() {
// 		return (ServiceInstance) this.source;
// 	}
// 
// }


import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance;
import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance;
import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints;
import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated;
import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared;
import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered;
import org.springframework.context.event.EventListener;
/*
 * Copyright 2015-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
 *
 *      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 be.ordina.msdashboard.applicationinstance;



/**
 * Will create, update or delete {@link ApplicationInstance applications instances} based on events
 * that are happening throughout the system.
 *
 * @author Tim Ysewyn
 */
class ApplicationInstanceUpdater {

	private final ApplicationInstanceService applicationInstanceService;
	private final ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService;

	ApplicationInstanceUpdater(ApplicationInstanceService applicationInstanceService,
			ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService) {
		this.applicationInstanceService = applicationInstanceService;
		this.actuatorEndpointsDiscovererService = actuatorEndpointsDiscovererService;
	}

	@EventListener(ServiceInstanceDiscovered.class)
	public void createNewApplicationInstance(ServiceInstanceDiscovered event) {
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java
// public final class CreateApplicationInstance {
// 
// 	private final ServiceInstance serviceInstance;
// 
// 	public CreateApplicationInstance(ServiceInstance serviceInstance) {
// 		Assert.notNull(serviceInstance, "serviceInstance must not be null!");
// 		this.serviceInstance = serviceInstance;
// 	}
// 
// 	public ServiceInstance getServiceInstance() {
// 		return this.serviceInstance;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java
// public final class DeleteApplicationInstance {
// 
// 	private final String id;
// 
// 	public DeleteApplicationInstance(String id) {
// 		Assert.notNull(id, "id must not be null!");
// 		this.id = id;
// 	}
// 
// 	public String getId() {
// 		return this.id;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java
// public final class UpdateActuatorEndpoints {
// 
// 	private final String id;
// 	private final Links actuatorEndpoints;
// 
// 	public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) {
// 		Assert.notNull(id, "id must not be null!");
// 		Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!");
// 		this.id = id;
// 		this.actuatorEndpoints = actuatorEndpoints;
// 	}
// 
// 	public String getId() {
// 		return this.id;
// 	}
// 
// 	public Links getActuatorEndpoints() {
// 		return this.actuatorEndpoints;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java
// public class ApplicationInstanceCreated extends ApplicationEvent {
// 
// 	public ApplicationInstanceCreated(ApplicationInstance instance) {
// 		super(instance);
// 	}
// 
// 	public ApplicationInstance getApplicationInstance() {
// 		return (ApplicationInstance) this.source;
// 	}
// 
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java
// public class ServiceInstanceDisappeared extends ApplicationEvent {
// 
// 	public ServiceInstanceDisappeared(String serviceInstanceId) {
// 		super(serviceInstanceId);
// 	}
// 
// 	public String getServiceInstanceId() {
// 		return (String) this.source;
// 	}
// 
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java
// public class ServiceInstanceDiscovered extends ApplicationEvent {
// 
// 	public ServiceInstanceDiscovered(ServiceInstance serviceInstance) {
// 		super(serviceInstance);
// 	}
// 
// 	public ServiceInstance getServiceInstance() {
// 		return (ServiceInstance) this.source;
// 	}
// 
// }


// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceUpdater.java
import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance;
import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance;
import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints;
import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated;
import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared;
import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered;
import org.springframework.context.event.EventListener;

/*
 * Copyright 2015-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
 *
 *      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 be.ordina.msdashboard.applicationinstance;



/**
 * Will create, update or delete {@link ApplicationInstance applications instances} based on events
 * that are happening throughout the system.
 *
 * @author Tim Ysewyn
 */
class ApplicationInstanceUpdater {

	private final ApplicationInstanceService applicationInstanceService;
	private final ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService;

	ApplicationInstanceUpdater(ApplicationInstanceService applicationInstanceService,
			ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService) {
		this.applicationInstanceService = applicationInstanceService;
		this.actuatorEndpointsDiscovererService = actuatorEndpointsDiscovererService;
	}

	@EventListener(ServiceInstanceDiscovered.class)
	public void createNewApplicationInstance(ServiceInstanceDiscovered event) {
		CreateApplicationInstance command = new CreateApplicationInstance(event.getServiceInstance());