public GridScheduler(String url, String downstream, String upstream, String registry) throws RemoteException {
		// preconditions
		assert(url != null) : "parameter 'url' cannot be null";
		
		// init members
		this.registry = registry;
		this.url = url;
		this.upstream_neighbour = upstream;
		this.downstream_neighbour = downstream;
		this.resourceManagerLoad = new ConcurrentHashMap<String, Integer>();
		this.jobQueue = new ConcurrentLinkedQueue<Job>();
		this.gridschedulers = new ArrayList<String>();
		//this.jobId = 0;
		//logger.info("Like wtf is going on?");
		// create a messaging socket
		/*LocalSocket lSocket = new LocalSocket();
		socket = new SynchronizedSocket(lSocket);
		socket.addMessageReceivedHandler(this);*/
		
		//long seed = System.currentTimeMillis();
		//generator = new Random(seed);
		
		//timer = false;
		maintenance = false;
		// register the socket under the name of the gridscheduler.
		// In this way, messages can be sent between components by name.
		//socket.register(url);
		
		logger = Logger.getLogger("MyLog");
		
		try {  
			tmp = 0;
            // This block configure the logger with handler and formatter  
            fh = new FileHandler(this.getUrl() + "LogFile.log");  
            logger.addHandler(fh);  
            //logger.setLevel(Level.ALL);  
            SimpleFormatter formatter = new SimpleFormatter();  
            fh.setFormatter(formatter);  
            
            logger.setUseParentHandlers(false);
            
            // the following statement is used to log any messages  
            logger.info("Opening log for " + this.getUrl());  
              
        } catch (SecurityException e) {  
            e.printStackTrace();  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
		
		System.setProperty("java.security.policy", "file:./my.policy");
		if (System.getSecurityManager() == null) {
			System.setSecurityManager(new RMISecurityManager());
		}
		
		// Bind the node to the RMI registry.
		try {
			String url2 = "rmi://"+registry+":1099/"+url;
			//System.out.println("Register: " + Arrays.toString(java.rmi.Naming.list(registry)));
			System.out.println("trying to bind to: "+url2);
			java.rmi.Naming.rebind(url2, this);
			//System.out.println("RMI: " + Arrays.toString(java.rmi.Naming.list("rmi://"+registry+":1099/"+url)));
			System.out.println("binded to: "+url2);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}  //catch (AlreadyBoundException e) {
			//e.printStackTrace();
		//}   
		
		/*catch (MalformedURLException | AlreadyBoundException e) {
			e.printStackTrace();
		}*/
		
		final String name = url;
		
		// Let the node unregister from RMI registry on shut down.
		Runtime.getRuntime().addShutdownHook(new Thread() {
			@Override
			public void run() {
				System.out.println("Shutting down " + name + ".");
				try {
					java.rmi.Naming.unbind(name);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	
		//System.out.println(this.url + "started!");
		
		// start the polling thread
		running = true;
		pollingThread = new Thread(this);
		pollingThread.start();
	}