// Path: snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/SnoopEEExtensionHelper.java
// public final class SnoopEEExtensionHelper {
// 
//     private String serviceName;
//     private boolean snoopEnabled;
// 
//     private static final SnoopEEExtensionHelper INSTANCE = new SnoopEEExtensionHelper();
// 
//     public static String getServiceName() {
//         return INSTANCE.serviceName;
//     }
// 
//     public static void setServiceName(String serviceName) {
//         INSTANCE.serviceName = serviceName;
//     }
// 
//     public static boolean isSnoopEnabled() {
//         return INSTANCE.snoopEnabled;
//     }
// 
//     public static void setSnoopEnabled(final boolean snoopEnabled) {
//         INSTANCE.snoopEnabled = snoopEnabled;
//     }
// }
// 
// Path: snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/SnoopEEConfigurationException.java
// public class SnoopEEConfigurationException extends RuntimeException {
// 
//     public SnoopEEConfigurationException(String message) {
//         super(message);
//     }
// }
// 
// Path: snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/client/SnoopEEConfig.java
// public class SnoopEEConfig {
// 
//     private String serviceName;
//     private String serviceHome;
//     private String serviceRoot;
// 
//     public String getServiceName() {
//         return serviceName;
//     }
// 
//     public void setServiceName(String serviceName) {
//         this.serviceName = serviceName;
//     }
// 
//     public String getServiceHome() {
//         return serviceHome;
//     }
// 
//     public void setServiceHome(String serviceHome) {
//         this.serviceHome = serviceHome;
//     }
// 
//     public String getServiceRoot() {
//         return serviceRoot;
//     }
// 
//     public void setServiceRoot(String serviceRoot) {
//         this.serviceRoot = serviceRoot;
//     }
// 
//     public String toJSON() {
// 
//         Writer w = new StringWriter();
//         try (JsonGenerator generator = Json.createGenerator(w)) {
// 
//             generator.writeStartObject()
//                     .write("serviceName", serviceName)
//                     .write("serviceHome", serviceHome)
//                     .write("serviceRoot", serviceRoot)
//                     .writeEnd();
//         }
// 
//         return w.toString();
//     }
// 
//     public static SnoopEEConfig fromJSON(String json) {
// 
//         SnoopEEConfig config = new SnoopEEConfig();
// 
//         try (JsonReader reader = Json.createReader(new StringReader(json))) {
// 
//             JsonObject configJson = reader.readObject();
// 
//             config.setServiceName(configJson.getString("serviceName"));
//             config.setServiceHome(configJson.getString("serviceHome"));
//             config.setServiceRoot(configJson.getString("serviceRoot"));
//         }
// 
//         return config;
//     }
// }


import eu.agilejava.snoopee.SnoopEEExtensionHelper;
import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml;
import com.fasterxml.jackson.dataformat.yaml.snakeyaml.error.YAMLException;
import eu.agilejava.snoopee.SnoopEEConfigurationException;
import eu.agilejava.snoopee.client.SnoopEEConfig;
import java.io.IOException;
import java.net.URI;
import java.util.Calendar;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import javax.ejb.ScheduleExpression;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerConfig;
import javax.ejb.TimerService;
import javax.websocket.ClientEndpoint;
import javax.websocket.ContainerProvider;
import javax.websocket.DeploymentException;
import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
/*
 * The MIT License
 *
 * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com).
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package eu.agilejava.snoopee.scan;


/**
 * Registers with SnoopEE and gives heartbeats every 10 second.
 *
 * @author Ivar Grimstad (ivar.grimstad@gmail.com)
 */
@ClientEndpoint
@Singleton
@Startup
public class SnoopEERegistrationClient {

    private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoopee");
    private static final String REGISTER_ENDPOINT = "snoopee";
    private static final String STATUS_ENDPOINT = "snoopeestatus/";

    private String serviceUrl;
// Path: snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/SnoopEEExtensionHelper.java
// public final class SnoopEEExtensionHelper {
// 
//     private String serviceName;
//     private boolean snoopEnabled;
// 
//     private static final SnoopEEExtensionHelper INSTANCE = new SnoopEEExtensionHelper();
// 
//     public static String getServiceName() {
//         return INSTANCE.serviceName;
//     }
// 
//     public static void setServiceName(String serviceName) {
//         INSTANCE.serviceName = serviceName;
//     }
// 
//     public static boolean isSnoopEnabled() {
//         return INSTANCE.snoopEnabled;
//     }
// 
//     public static void setSnoopEnabled(final boolean snoopEnabled) {
//         INSTANCE.snoopEnabled = snoopEnabled;
//     }
// }
// 
// Path: snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/SnoopEEConfigurationException.java
// public class SnoopEEConfigurationException extends RuntimeException {
// 
//     public SnoopEEConfigurationException(String message) {
//         super(message);
//     }
// }
// 
// Path: snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/client/SnoopEEConfig.java
// public class SnoopEEConfig {
// 
//     private String serviceName;
//     private String serviceHome;
//     private String serviceRoot;
// 
//     public String getServiceName() {
//         return serviceName;
//     }
// 
//     public void setServiceName(String serviceName) {
//         this.serviceName = serviceName;
//     }
// 
//     public String getServiceHome() {
//         return serviceHome;
//     }
// 
//     public void setServiceHome(String serviceHome) {
//         this.serviceHome = serviceHome;
//     }
// 
//     public String getServiceRoot() {
//         return serviceRoot;
//     }
// 
//     public void setServiceRoot(String serviceRoot) {
//         this.serviceRoot = serviceRoot;
//     }
// 
//     public String toJSON() {
// 
//         Writer w = new StringWriter();
//         try (JsonGenerator generator = Json.createGenerator(w)) {
// 
//             generator.writeStartObject()
//                     .write("serviceName", serviceName)
//                     .write("serviceHome", serviceHome)
//                     .write("serviceRoot", serviceRoot)
//                     .writeEnd();
//         }
// 
//         return w.toString();
//     }
// 
//     public static SnoopEEConfig fromJSON(String json) {
// 
//         SnoopEEConfig config = new SnoopEEConfig();
// 
//         try (JsonReader reader = Json.createReader(new StringReader(json))) {
// 
//             JsonObject configJson = reader.readObject();
// 
//             config.setServiceName(configJson.getString("serviceName"));
//             config.setServiceHome(configJson.getString("serviceHome"));
//             config.setServiceRoot(configJson.getString("serviceRoot"));
//         }
// 
//         return config;
//     }
// }


// Path: snoopee-discovery/snoopee/src/main/java/eu/agilejava/snoopee/scan/SnoopEERegistrationClient.java
import eu.agilejava.snoopee.SnoopEEExtensionHelper;
import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml;
import com.fasterxml.jackson.dataformat.yaml.snakeyaml.error.YAMLException;
import eu.agilejava.snoopee.SnoopEEConfigurationException;
import eu.agilejava.snoopee.client.SnoopEEConfig;
import java.io.IOException;
import java.net.URI;
import java.util.Calendar;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import javax.ejb.ScheduleExpression;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerConfig;
import javax.ejb.TimerService;
import javax.websocket.ClientEndpoint;
import javax.websocket.ContainerProvider;
import javax.websocket.DeploymentException;
import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;

/*
 * The MIT License
 *
 * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com).
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package eu.agilejava.snoopee.scan;


/**
 * Registers with SnoopEE and gives heartbeats every 10 second.
 *
 * @author Ivar Grimstad (ivar.grimstad@gmail.com)
 */
@ClientEndpoint
@Singleton
@Startup
public class SnoopEERegistrationClient {

    private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoopee");
    private static final String REGISTER_ENDPOINT = "snoopee";
    private static final String STATUS_ENDPOINT = "snoopeestatus/";

    private String serviceUrl;
    private final SnoopEEConfig applicationConfig = new SnoopEEConfig();