// 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;
package com.cisco.pxgrid.samples.ise;





/**
 * Demonstrate how to create a custom service that publishes data
 * 
 * The flow of the application is as follows:
 * 1. Parse arguments for configurations
 * 2. Activate Account. This will then require ISE Admin to approve this new node.
 * 3. pxGrid ServiceRegister to register the new custom service
 * 4. Schedule periodic pxGrid ServiceReregister to signify the service is still alive
 * 5. pxGrid ServiceLookup for ISE pubsub service
 * 6. pxGrid get AccessSecret for the ISE pubsub node
 * 7. Establish WebSocket connection with the ISE pubsub node
 * 8. Establish STOMP connection for pubsub messaging
 * 9. Schedule periodic publish of data
 * 10. Wait for keyboard input for stopping the application
 */
public class CustomServiceProvider {
	private static Logger logger = LoggerFactory.getLogger(CustomServiceProvider.class);

	public static void main(String[] args) throws Exception {
		ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();

		// Parse arguments
		SampleConfiguration config = new SampleConfiguration();
		try {
			config.parse(args);
		} catch (ParseException e) {
			config.printHelp("CustomServiceProvider");
			System.exit(1);
		}

		// AccountActivate
		PxgridControl control = new PxgridControl(config);
// 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;

package com.cisco.pxgrid.samples.ise;





/**
 * Demonstrate how to create a custom service that publishes data
 * 
 * The flow of the application is as follows:
 * 1. Parse arguments for configurations
 * 2. Activate Account. This will then require ISE Admin to approve this new node.
 * 3. pxGrid ServiceRegister to register the new custom service
 * 4. Schedule periodic pxGrid ServiceReregister to signify the service is still alive
 * 5. pxGrid ServiceLookup for ISE pubsub service
 * 6. pxGrid get AccessSecret for the ISE pubsub node
 * 7. Establish WebSocket connection with the ISE pubsub node
 * 8. Establish STOMP connection for pubsub messaging
 * 9. Schedule periodic publish of data
 * 10. Wait for keyboard input for stopping the application
 */
public class CustomServiceProvider {
	private static Logger logger = LoggerFactory.getLogger(CustomServiceProvider.class);

	public static void main(String[] args) throws Exception {
		ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();

		// Parse arguments
		SampleConfiguration config = new SampleConfiguration();
		try {
			config.parse(args);
		} catch (ParseException e) {
			config.printHelp("CustomServiceProvider");
			System.exit(1);
		}

		// AccountActivate
		PxgridControl control = new PxgridControl(config);
		while (control.accountActivate() != AccountState.ENABLED) {