<commit_before>import java.io.*;
import java.net.*;
import java.util.List;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.KeeperException.Code;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.data.Stat;
import org.apache.zookeeper.Watcher.Event.EventType;

public class JobTracker {
	
	String myPath = "/jobTrack";
    ZkConnector zkc;
    Watcher watcher;
    String myInfo = null;   
    ZooKeeper theZoo = null;
    boolean listening = false;
    
	public static void main(String[] args) throws IOException {
		
        ServerSocket mySocket = null;
        String zooInfo = null;

        try {
        	if(args.length == 2) {
        		// set up our server socket
        		mySocket = new ServerSocket(Integer.parseInt(args[0]));
        	} else {
        		System.err.println("ERROR: Invalid arguments!");
        		System.exit(-1);
        	}
        } catch (IOException e) {
            System.err.println("ERROR: Could not listen on port!");
            System.exit(-1);
        }
        
        // format: localhost:port        
        zooInfo = args[1];
        // format: localhost:port
        String myInfo = InetAddress.getLocalHost().getHostName() + ":" + args[0];
        
        // connect to zookeeper
        JobTracker tracker = new JobTracker(zooInfo, myInfo);   
        // set up znode
        tracker.checkpath();       

        while (true) {
        	if (tracker.listening) { // we are the primary
        		new JobTrackerHandlerThread(mySocket.accept(), tracker.theZoo, tracker.zkc).start();
        	} else { // we are the secondary
        		try{ Thread.sleep(5000); } catch (Exception e) {}
        	}
        }

        //mySocket.close();
    }
	
	
	public JobTracker(String hosts, String myInfo) {
		this.myInfo = myInfo;
        zkc = new ZkConnector();
        try {
            zkc.connect(hosts);
        } catch(Exception e) {
            System.out.println("Zookeeper connect "+ e.getMessage());
        }
 
        theZoo = zkc.getZooKeeper();
        
        watcher = new Watcher() { // Anonymous Watcher
                            @Override
                            public void process(WatchedEvent event) {
                                handleEvent(event);
                        
                            } };
    }
    
	// try to create znode and become primary. if we fail, become secondary
    private boolean checkpath() {
    	boolean result = false;
        Stat stat = zkc.exists(myPath, watcher);
        if (stat == null) {              // znode doesn't exist; let's try creating it        	
   
            System.out.println("Creating " + myPath);
            Code ret = zkc.create(
                        myPath,         // Path of znode
                        myInfo,           // Data not needed.
                        CreateMode.EPHEMERAL   // Znode type, set to EPHEMERAL.
                        );
            if (ret == Code.OK) {
            	System.out.println("the boss!");
            	listening = true;
            	result = true;
            }
        } 
        return result;
    }<commit_msg>added code to create jobs node<commit_after>import java.io.*;
import java.net.*;
import java.util.List;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.KeeperException.Code;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.data.Stat;
import org.apache.zookeeper.Watcher.Event.EventType;

public class JobTracker {
	
	String myPath = "/jobTrack";
    ZkConnector zkc;
    Watcher watcher;
    Watcher watcher_jobs;
    String myInfo = null;   
    ZooKeeper theZoo = null;
    boolean listening = false;
    
	public static void main(String[] args) throws IOException {
		
        ServerSocket mySocket = null;
        String zooInfo = null;

        try {
        	if(args.length == 2) {
        		// set up our server socket
        		mySocket = new ServerSocket(Integer.parseInt(args[0]));
        	} else {
        		System.err.println("ERROR: Invalid arguments!");
        		System.exit(-1);
        	}
        } catch (IOException e) {
            System.err.println("ERROR: Could not listen on port!");
            System.exit(-1);
        }
        
        // format: localhost:port        
        zooInfo = args[1];
        // format: localhost:port
        String myInfo = InetAddress.getLocalHost().getHostName() + ":" + args[0];
        
        // connect to zookeeper
        JobTracker tracker = new JobTracker(zooInfo, myInfo);   
        // set up znode
        tracker.checkpath();       

        while (true) {
        	if (tracker.listening) { // we are the primary
        		new JobTrackerHandlerThread(mySocket.accept(), tracker.theZoo, tracker.zkc).start();
        	} else { // we are the secondary
        		try{ Thread.sleep(5000); } catch (Exception e) {}
        	}
        }

        //mySocket.close();
    }
	
	
	public JobTracker(String hosts, String myInfo) {
		this.myInfo = myInfo;
        zkc = new ZkConnector();
        try {
            zkc.connect(hosts);
        } catch(Exception e) {
            System.out.println("Zookeeper connect "+ e.getMessage());
        }
 
        theZoo = zkc.getZooKeeper();
        
        watcher = new Watcher() { // Anonymous Watcher
                            @Override
                            public void process(WatchedEvent event) {
                                handleEvent(event);
                        
                            } };

        watcher_jobs = new Watcher() { // Anonymous Watcher
                            @Override
                            public void process(WatchedEvent event) {
                                handleEvent_jobs(event);
                        
                            } };
    }
    
	protected void handleEvent_jobs(WatchedEvent event) {
		// TODO Auto-generated method stub
		
	}


	// try to create znode and become primary. if we fail, become secondary
    private boolean checkpath() {
    	boolean result = false;
        Stat stat = zkc.exists(myPath, watcher);
        if (stat == null) {              // znode doesn't exist; let's try creating it        	
   
            System.out.println("Creating " + myPath);
            Code ret = zkc.create(
                        myPath,         // Path of znode
                        myInfo,           // Data not needed.
                        CreateMode.EPHEMERAL   // Znode type, set to EPHEMERAL.
                        );
            if (ret == Code.OK) {
            	System.out.println("the boss!");
            	listening = true;
            	result = true;
            }
        } 
        
        // create the job nodes
        stat = zkc.exists("/jobs", watcher_jobs);
        if (stat == null) {              // znode doesn't exist; let's try creating it        	
   
            System.out.println("Creating " + "/jobs");
            Code ret = zkc.create(
            		"/jobs",         // Path of znode
                        null,           // Data not needed.
                        CreateMode.PERSISTENT   // Znode type, set to EPHEMERAL.
                        );
            if (ret == Code.OK) {
            	System.out.println("created jobs root");
            	result = true;
            }
        } 
        
        
        return result;
    }
{'fraction_non_alphanumeric': 0.10155129709294747, 'fraction_numerical': 0.0026072220049537216, 'mean_word_length': 1.494148244473342, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1854455', 'n_tokens_mistral': 2202, 'n_tokens_neox': 2098, 'n_words': 508}