// 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;
// 	}
// }


import java.net.URI;
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;
package com.cisco.pxgrid.samples.ise;





/**
 * Demonstrates how to subscribe a topic from a custom service
 * 
 * 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 ServiceLookup for the custom service
 * 4. pxGrid ServiceLookup for ISE pubsub service
 * 5. pxGrid get AccessSecret for the ISE pubsub node
 * 6. Establish WebSocket connection with the ISE pubsub node
 * 7. Establish STOMP connection for pubsub messaging
 * 8. Subscribe to the topic in the custom service
 * 9. Wait for keyboard input for stopping the application
 */
public class CustomServiceConsumer {
	private static Logger logger = LoggerFactory.getLogger(CustomServiceProvider.class);

	// Subscribe handler class
	private static class MessageHandler implements StompSubscription.Handler {
		@Override
		public void handle(StompFrame message) {
			System.out.println(new String(message.getContent()));
		}
	}

	public static void main(String [] args) throws Exception {
		// Parse arguments
		SampleConfiguration config = new SampleConfiguration();
		try {
			config.parse(args);
		} catch (ParseException e) {
			config.printHelp("CustomServiceConsumer");
			System.exit(1);
		}
		
		// AccountActivate
		PxgridControl control = new PxgridControl(config);
		while (control.accountActivate() != AccountState.ENABLED) {
			Thread.sleep(60000);
		}
		logger.info("pxGrid controller version={}", control.getControllerVersion());
		
		
		// pxGrid ServiceLookup for custom 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/CustomServiceConsumer.java
import java.net.URI;
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;

package com.cisco.pxgrid.samples.ise;





/**
 * Demonstrates how to subscribe a topic from a custom service
 * 
 * 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 ServiceLookup for the custom service
 * 4. pxGrid ServiceLookup for ISE pubsub service
 * 5. pxGrid get AccessSecret for the ISE pubsub node
 * 6. Establish WebSocket connection with the ISE pubsub node
 * 7. Establish STOMP connection for pubsub messaging
 * 8. Subscribe to the topic in the custom service
 * 9. Wait for keyboard input for stopping the application
 */
public class CustomServiceConsumer {
	private static Logger logger = LoggerFactory.getLogger(CustomServiceProvider.class);

	// Subscribe handler class
	private static class MessageHandler implements StompSubscription.Handler {
		@Override
		public void handle(StompFrame message) {
			System.out.println(new String(message.getContent()));
		}
	}

	public static void main(String [] args) throws Exception {
		// Parse arguments
		SampleConfiguration config = new SampleConfiguration();
		try {
			config.parse(args);
		} catch (ParseException e) {
			config.printHelp("CustomServiceConsumer");
			System.exit(1);
		}
		
		// AccountActivate
		PxgridControl control = new PxgridControl(config);
		while (control.accountActivate() != AccountState.ENABLED) {
			Thread.sleep(60000);
		}
		logger.info("pxGrid controller version={}", control.getControllerVersion());
		
		
		// pxGrid ServiceLookup for custom service
		Service[] services = control.serviceLookup("com.example.custom");