// Path: client/src/main/java/com/github/moronicgeek/swagger/cloud/client/ApplicationRegistrationService.java
// public class ApplicationRegistrationService {
// 
//     private static HttpHeaders HTTP_HEADERS = createHttpHeaders();
//     private SwaggerCloudAdminProperties adminProperties;
//     private SwaggerCloudClientProperties clientProperties;
//     private RestTemplate template;
// 
//     public ApplicationRegistrationService(SwaggerCloudClientProperties clientProperties, SwaggerCloudAdminProperties adminProperties, RestTemplate template) {
//         this.adminProperties = adminProperties;
//         this.clientProperties = clientProperties;
//         this.template = template;
//     }
// 
//     private static HttpHeaders createHttpHeaders() {
//         HttpHeaders headers = new HttpHeaders();
//         headers.setContentType(MediaType.APPLICATION_JSON);
//         headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
//         return HttpHeaders.readOnlyHttpHeaders(headers);
//     }
// 
//     public static HttpHeaders getHttpHeaders() {
//         return HTTP_HEADERS;
//     }
// 
//     public static void setHttpHeaders(HttpHeaders httpHeaders) {
//         HTTP_HEADERS = httpHeaders;
//     }
// 
//     public boolean registerApplication() {
//         boolean registrationSuccessful = false;
//         ApplicationRegistrationMetadata self = createMetaDataApplication();
// 
//         ResponseEntity<Boolean> response = template.postForEntity(adminProperties.getUrl() +AdminRoutes.CONTEXT.getPath()+ AdminRoutes.REGISTER.getPath(),
//                 new HttpEntity<>(self, HTTP_HEADERS), Boolean.class);
//         if (response == null){
//             return false;
//         }
// 
//         return registrationSuccessful;
//     }
// 
//     public boolean deregisterApplication() {
//         boolean deregistered = false;
//         ApplicationRegistrationMetadata self = createMetaDataApplication();
//         //this will be used some day
//         ResponseEntity<Boolean> response = template.postForEntity(adminProperties.getUrl() +AdminRoutes.CONTEXT.getPath()+ AdminRoutes.DEREGISTER.getPath(),
//                 new HttpEntity<>(self, HTTP_HEADERS), Boolean.class);
//         if (response == null){
//             return false;
//         }
//         return deregistered;
//     }
// 
//     private ApplicationRegistrationMetadata createMetaDataApplication() {
//         return new ApplicationRegistrationMetadata(clientProperties.getName(),clientProperties.getSwaggerUrl(),clientProperties.getGroupId(),clientProperties.getServerPort(),clientProperties.getServer().getContextPath());
//     }
// 
//     public SwaggerCloudAdminProperties getAdminProperties() {
//         return adminProperties;
//     }
// 
//     public void setAdminProperties(SwaggerCloudAdminProperties adminProperties) {
//         this.adminProperties = adminProperties;
//     }
// 
//     public SwaggerCloudClientProperties getClientProperties() {
//         return clientProperties;
//     }
// 
//     public void setClientProperties(SwaggerCloudClientProperties clientProperties) {
//         this.clientProperties = clientProperties;
//     }
// 
//     public RestTemplate getTemplate() {
//         return template;
//     }
// 
//     public void setTemplate(RestTemplate template) {
//         this.template = template;
//     }
// }


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextStoppedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
import com.github.moronicgeek.swagger.cloud.client.ApplicationRegistrationService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledFuture;
package com.github.moronicgeek.swagger.cloud.client.listener;



/**
 * Created by muhammedpatel on 2016/08/07.
 */
public class RegistrationApplicationListener {

    private static Logger LOGGER = LoggerFactory.getLogger(RegistrationApplicationListener.class);
// Path: client/src/main/java/com/github/moronicgeek/swagger/cloud/client/ApplicationRegistrationService.java
// public class ApplicationRegistrationService {
// 
//     private static HttpHeaders HTTP_HEADERS = createHttpHeaders();
//     private SwaggerCloudAdminProperties adminProperties;
//     private SwaggerCloudClientProperties clientProperties;
//     private RestTemplate template;
// 
//     public ApplicationRegistrationService(SwaggerCloudClientProperties clientProperties, SwaggerCloudAdminProperties adminProperties, RestTemplate template) {
//         this.adminProperties = adminProperties;
//         this.clientProperties = clientProperties;
//         this.template = template;
//     }
// 
//     private static HttpHeaders createHttpHeaders() {
//         HttpHeaders headers = new HttpHeaders();
//         headers.setContentType(MediaType.APPLICATION_JSON);
//         headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
//         return HttpHeaders.readOnlyHttpHeaders(headers);
//     }
// 
//     public static HttpHeaders getHttpHeaders() {
//         return HTTP_HEADERS;
//     }
// 
//     public static void setHttpHeaders(HttpHeaders httpHeaders) {
//         HTTP_HEADERS = httpHeaders;
//     }
// 
//     public boolean registerApplication() {
//         boolean registrationSuccessful = false;
//         ApplicationRegistrationMetadata self = createMetaDataApplication();
// 
//         ResponseEntity<Boolean> response = template.postForEntity(adminProperties.getUrl() +AdminRoutes.CONTEXT.getPath()+ AdminRoutes.REGISTER.getPath(),
//                 new HttpEntity<>(self, HTTP_HEADERS), Boolean.class);
//         if (response == null){
//             return false;
//         }
// 
//         return registrationSuccessful;
//     }
// 
//     public boolean deregisterApplication() {
//         boolean deregistered = false;
//         ApplicationRegistrationMetadata self = createMetaDataApplication();
//         //this will be used some day
//         ResponseEntity<Boolean> response = template.postForEntity(adminProperties.getUrl() +AdminRoutes.CONTEXT.getPath()+ AdminRoutes.DEREGISTER.getPath(),
//                 new HttpEntity<>(self, HTTP_HEADERS), Boolean.class);
//         if (response == null){
//             return false;
//         }
//         return deregistered;
//     }
// 
//     private ApplicationRegistrationMetadata createMetaDataApplication() {
//         return new ApplicationRegistrationMetadata(clientProperties.getName(),clientProperties.getSwaggerUrl(),clientProperties.getGroupId(),clientProperties.getServerPort(),clientProperties.getServer().getContextPath());
//     }
// 
//     public SwaggerCloudAdminProperties getAdminProperties() {
//         return adminProperties;
//     }
// 
//     public void setAdminProperties(SwaggerCloudAdminProperties adminProperties) {
//         this.adminProperties = adminProperties;
//     }
// 
//     public SwaggerCloudClientProperties getClientProperties() {
//         return clientProperties;
//     }
// 
//     public void setClientProperties(SwaggerCloudClientProperties clientProperties) {
//         this.clientProperties = clientProperties;
//     }
// 
//     public RestTemplate getTemplate() {
//         return template;
//     }
// 
//     public void setTemplate(RestTemplate template) {
//         this.template = template;
//     }
// }


// Path: client/src/main/java/com/github/moronicgeek/swagger/cloud/client/listener/RegistrationApplicationListener.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextStoppedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
import com.github.moronicgeek.swagger.cloud.client.ApplicationRegistrationService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledFuture;

package com.github.moronicgeek.swagger.cloud.client.listener;



/**
 * Created by muhammedpatel on 2016/08/07.
 */
public class RegistrationApplicationListener {

    private static Logger LOGGER = LoggerFactory.getLogger(RegistrationApplicationListener.class);
    private final ApplicationRegistrationService register;