@SuppressWarnings("deprecation")
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input;
		
		//INITIALIZE THE PARAMETERS
		initParams();
		int listenerPort= 9898;
		
		//ASSIGN MACHINE IDs
		String fullMachineID = getFullMachineID();
		String shortMachineID = getShortMachineID();
		
		//LOGGER SETUP 
		try {
		      LogWriter.setup(shortMachineID, LoggingLevel);
		    } catch (IOException e) {
		      e.printStackTrace();
		      throw new RuntimeException("Problems with creating the log files");
		    }
		final Logger LOGGER = Logger.getLogger(runner.class.getName());
		
		//CREATE MEMBERSHIP LIST
		MemberList memberList = new MemberList(fullMachineID);
		
		//INITIALIZE HEART
		
		Heart dil = new Heart(HeartRate, memberList, fullMachineID);
		
		
		
		//INITIALIZE GOSSIP LISTENER
		int lossRate = Integer.parseInt(args[1]);
		
		Gossiper gos_obj = new Gossiper(listenerPort, GossipSendingRate, memberList, fullMachineID, FailureCleanUpRate, FailureTimeOut, lossRate);
		gos_obj.gossip_listener();
		if(args[0].equalsIgnoreCase("contact"))
			gos_obj.gossip();
		
		String[] temp;
		boolean firstTimeJoin = true;
		LOGGER.info(fullMachineID+" # "+"INITIALIZED");
		while(true)
		{
			System.out.println("\nUSAGE: join [contactIP] | leave | exit");
			System.out.print(">");
			
			input = br.readLine();
			temp = input.split(" ");
			if(temp[0].equals("join"))
			{
				if(firstTimeJoin)
				{
					gos_obj.joinRequest(temp[1]);
					gos_obj.gossip();
					firstTimeJoin = false;
				}
				else
				{
					fullMachineID = getFullMachineID();
					shortMachineID = getShortMachineID();
					try {
					      LogWriter.setup(shortMachineID, LoggingLevel);
					    } catch (IOException e) {
					      e.printStackTrace();
					      throw new RuntimeException("Problems with creating the log files");
					    }
					memberList = new MemberList(fullMachineID);
					dil = new Heart(HeartRate, memberList, fullMachineID);
					gos_obj = new Gossiper(listenerPort, GossipSendingRate, memberList, fullMachineID, FailureCleanUpRate, FailureTimeOut, lossRate);
					gos_obj.gossip_listener();
					gos_obj.joinRequest(temp[1]);
					gos_obj.gossip();
					
				}
				
				
			}
			else if(temp[0].equals("leave"))
			{
				LOGGER.info(fullMachineID+" # "+" LEFT");
				gos_obj.stopGossip();
				gos_obj.stopGossipListener();
				dil.stop();
				gos_obj.leaveRequest();
				
			}
			else if(temp[0].equalsIgnoreCase("quit") | temp[0].equalsIgnoreCase("exit") )
			{
				LOGGER.info(fullMachineID+" # "+" CRASHED");
				System.exit(0);
				
			}
			else
			{
				System.out.println("Invalid Command. Please enter again");
			}
		}
		
		
		
		
		
		
	}