// Path: java/src/main/java/com/cisco/pxgrid/samples/ise/model/AccountState.java
// public enum AccountState {
// 	/**
// 	 * The internal state when the account is created, but never connected. 
// 	 */
// 	INIT,
// 	
// 	/**
// 	 * The state when the account is pending for approval from administrator
// 	 */
// 	PENDING,
// 	
// 	/**
// 	 * The state where all pxGrid control functionalities are available.
// 	 */
// 	ENABLED,
// 	
// 	/**
// 	 * A disabled account. Administrator can disable or enable the account.
// 	 */
// 	DISABLED;
// }
// 
// Path: java/src/main/java/com/cisco/pxgrid/samples/ise/model/Service.java
// public class Service {
// 	private String name;
// 	private String nodeName;
// 	private Map<String, String> properties;
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 
// 	public String getNodeName() {
// 		return nodeName;
// 	}
// 
// 	public void setNodeName(String nodeName) {
// 		this.nodeName = nodeName;
// 	}
// 
// 	public Map<String, String> getProperties() {
// 		return properties;
// 	}
// 
// 	public void setProperties(Map<String, String> properties) {
// 		this.properties = properties;
// 	}
// }
// 
// Path: java/src/main/java/com/cisco/pxgrid/samples/ise/model/ServiceRegisterResponse.java
// @XmlRootElement
// public class ServiceRegisterResponse {
// 	private String id;
// 	private long reregisterTimeMillis;
// 	
// 	public String getId() {
// 		return id;
// 	}
// 
// 	public void setId(String id) {
// 		this.id = id;
// 	}
// 
// 	public long getReregisterTimeMillis() {
// 		return reregisterTimeMillis;
// 	}
// 
// 	public void setReregisterTimeMillis(long reregisterTimeMillis) {
// 		this.reregisterTimeMillis = reregisterTimeMillis;
// 	}
// }


import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.websocket.Session;
import org.apache.commons.cli.ParseException;
import org.glassfish.tyrus.client.ClientManager;
import org.glassfish.tyrus.client.ClientProperties;
import org.glassfish.tyrus.client.SslEngineConfigurator;
import org.glassfish.tyrus.client.auth.Credentials;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.cisco.pxgrid.samples.ise.model.AccountState;
import com.cisco.pxgrid.samples.ise.model.Service;
import com.cisco.pxgrid.samples.ise.model.ServiceRegisterResponse;
		PxgridControl control = new PxgridControl(config);
		while (control.accountActivate() != AccountState.ENABLED) {
			Thread.sleep(60000);
		}
		logger.info("pxGrid controller version={}", control.getControllerVersion());

		// pxGrid ServiceRegister
		Map<String, String> sessionProperties = new HashMap<>();
		sessionProperties.put("wsPubsubService", "com.cisco.ise.pubsub");
		sessionProperties.put("customTopic", "/topic/com.example.custom");
		ServiceRegisterResponse response = control.serviceRegister("com.example.custom", sessionProperties);
		String registrationId = response.getId();
		long reregisterTimeMillis = response.getReregisterTimeMillis();

		// Schedule pxGrid ServiceReregister
		executor.scheduleWithFixedDelay(() -> {
			try {
				control.serviceReregister(registrationId);
			} catch (IOException e) {
				logger.error("Reregister failure");
			}
		}, reregisterTimeMillis, reregisterTimeMillis, TimeUnit.MILLISECONDS);

		// pxGrid ServiceLookup for pubsub service
		Service[] services = control.serviceLookup("com.cisco.ise.pubsub");
		if (services.length == 0) {
			logger.info("Pubsub service unavailabe");
			return;
		}
		// Use first service
// Path: java/src/main/java/com/cisco/pxgrid/samples/ise/model/AccountState.java
// public enum AccountState {
// 	/**
// 	 * The internal state when the account is created, but never connected. 
// 	 */
// 	INIT,
// 	
// 	/**
// 	 * The state when the account is pending for approval from administrator
// 	 */
// 	PENDING,
// 	
// 	/**
// 	 * The state where all pxGrid control functionalities are available.
// 	 */
// 	ENABLED,
// 	
// 	/**
// 	 * A disabled account. Administrator can disable or enable the account.
// 	 */
// 	DISABLED;
// }
// 
// Path: java/src/main/java/com/cisco/pxgrid/samples/ise/model/Service.java
// public class Service {
// 	private String name;
// 	private String nodeName;
// 	private Map<String, String> properties;
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 
// 	public String getNodeName() {
// 		return nodeName;
// 	}
// 
// 	public void setNodeName(String nodeName) {
// 		this.nodeName = nodeName;
// 	}
// 
// 	public Map<String, String> getProperties() {
// 		return properties;
// 	}
// 
// 	public void setProperties(Map<String, String> properties) {
// 		this.properties = properties;
// 	}
// }
// 
// Path: java/src/main/java/com/cisco/pxgrid/samples/ise/model/ServiceRegisterResponse.java
// @XmlRootElement
// public class ServiceRegisterResponse {
// 	private String id;
// 	private long reregisterTimeMillis;
// 	
// 	public String getId() {
// 		return id;
// 	}
// 
// 	public void setId(String id) {
// 		this.id = id;
// 	}
// 
// 	public long getReregisterTimeMillis() {
// 		return reregisterTimeMillis;
// 	}
// 
// 	public void setReregisterTimeMillis(long reregisterTimeMillis) {
// 		this.reregisterTimeMillis = reregisterTimeMillis;
// 	}
// }


// Path: java/src/main/java/com/cisco/pxgrid/samples/ise/CustomServiceProvider.java
import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.websocket.Session;
import org.apache.commons.cli.ParseException;
import org.glassfish.tyrus.client.ClientManager;
import org.glassfish.tyrus.client.ClientProperties;
import org.glassfish.tyrus.client.SslEngineConfigurator;
import org.glassfish.tyrus.client.auth.Credentials;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.cisco.pxgrid.samples.ise.model.AccountState;
import com.cisco.pxgrid.samples.ise.model.Service;
import com.cisco.pxgrid.samples.ise.model.ServiceRegisterResponse;

		PxgridControl control = new PxgridControl(config);
		while (control.accountActivate() != AccountState.ENABLED) {
			Thread.sleep(60000);
		}
		logger.info("pxGrid controller version={}", control.getControllerVersion());

		// pxGrid ServiceRegister
		Map<String, String> sessionProperties = new HashMap<>();
		sessionProperties.put("wsPubsubService", "com.cisco.ise.pubsub");
		sessionProperties.put("customTopic", "/topic/com.example.custom");
		ServiceRegisterResponse response = control.serviceRegister("com.example.custom", sessionProperties);
		String registrationId = response.getId();
		long reregisterTimeMillis = response.getReregisterTimeMillis();

		// Schedule pxGrid ServiceReregister
		executor.scheduleWithFixedDelay(() -> {
			try {
				control.serviceReregister(registrationId);
			} catch (IOException e) {
				logger.error("Reregister failure");
			}
		}, reregisterTimeMillis, reregisterTimeMillis, TimeUnit.MILLISECONDS);

		// pxGrid ServiceLookup for pubsub service
		Service[] services = control.serviceLookup("com.cisco.ise.pubsub");
		if (services.length == 0) {
			logger.info("Pubsub service unavailabe");
			return;
		}
		// Use first service
		Service wsPubsubService = services[0];