/**
 * 
 */
package oci.rom;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.util.logging.Logger;

import oci.locic.ResourceManagerCommunicationThread;

/**
 * The Manager class implements the resource and orchestration manager. It 
 * provides a simple socket interface and protocol for local OCI
 * coordinator in order to communicate with the actual underlying 
 * resource management system.
 * 
 * @author Marc Koerner
 *
 */
public class ResourceAndOrchestrationManager {
	
    		final static Logger			LOGGER			= Logger.getLogger(ResourceAndOrchestrationManager.class.getName());
    public	final static byte[]			LOCIC_IP		= {(byte) 127, (byte) 0, (byte) 0, (byte) 1}; 	// LOCIC IP
    public	final static int			LOCIC_PORT		= ResourceManagerCommunicationThread.PORT;
    
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		LOGGER.info("Resource and orchestration manager started");

		// MockResourceManagement can later on be replaced with the regarding resource management implementation (E2, Mininet, OpenStack, ...)
		GenericResourceManagement resourceManagement = new MockResourceManagement("mockResourceManager");	
	
		try {
			// connect to local OCI coordinator
			LOGGER.info("Try to connect to LOCIC");
			Socket locic							= new Socket(InetAddress.getByAddress(LOCIC_IP), LOCIC_PORT);
			LOGGER.info("Connected to LOCIC");
			
			//  Instantiate and start communication thread
			Thread locicCommunication				= new LocicCommunicationThread(locic, resourceManagement);
			locicCommunication.start();
						
			InputStreamReader	inputStreamReader	= new InputStreamReader(System.in);
			BufferedReader		stdIn		 		= new BufferedReader(inputStreamReader);
			
			// main loop
			String inputLine;
			while ((inputLine = stdIn.readLine()) != null) {
				// System.out.println(inputLine);
				
				// Exit
				if(inputLine.equals("exit")) {
					// close socket and wait for thread 
					locic.close();
					locicCommunication.join();
					break;
				} //if exit
				
			} // while
		
		} catch(Exception error) {
			LOGGER.warning(error.getMessage());
		}
		
		LOGGER.info("Resource and orchestration manager stopped");
		
	} // main

} // class Manager

@@ -164,32 +164,139 @@
 .SocketAddress;%0A
+import java.util.logging.ConsoleHandler;%0Aimport java.util.logging.Handler;%0Aimport java.util.logging.Level;%0A
 import java.util
@@ -1059,24 +1059,242 @@
  args) %7B%0A%09%09%0A
+%09%09// set logging output to console%0A%09%09Handler handlerObj = new ConsoleHandler();%0A%09%09handlerObj.setLevel(Level.ALL);%0A%09%09LOGGER.addHandler(handlerObj);%0A%09%09LOGGER.setLevel(Level.ALL);%0A%09%09LOGGER.setUseParentHandlers(false);%0A%09%09%0A
 %09%09LOGGER.inf

set logging to console