public ResourceManager(Cluster cluster, String gridscheduler, String registry) throws RemoteException	{
		// preconditions
		assert(cluster != null);
		//logger.info("RM in da house");
		this.jobQueue = new ConcurrentLinkedQueue<Job>();

		this.cluster = cluster;
		this.socketURL = cluster.getName();
		
		this.gridschedulers = new ArrayList<String>();
		this.rr = new ArrayList<String>();
		
		this.gridschedulers.add(gridscheduler);
		
		this.registry = registry;
		// Number of jobs in the queue must be larger than the number of nodes, because
		// jobs are kept in queue until finished. The queue is a bit larger than the 
		// number of nodes for efficiency reasons - when there are only a few more jobs than
		// nodes we can assume a node will become available soon to handle that job.
		jobQueueSize = cluster.getNodeCount() + MAX_QUEUE_SIZE;
		
		long seed = System.currentTimeMillis();
		generator = new Random(seed);
		
		this.timer   = true;
		this.timers  = new HashMap<Integer, Boolean>();
		
		logger = Logger.getLogger("MyLog");
		
		try {  
            
            // This block configure the logger with handler and formatter  
            fh = new FileHandler(socketURL + "LogFile.log");  
            logger.addHandler(fh);  
            //logger.setLevel(Level.ALL);  
            SimpleFormatter formatter = new SimpleFormatter();  
            fh.setFormatter(formatter);  
              
            // the following statement is used to log any messages  
            logger.info("Opening log for " + socketURL);  
              
        } catch (SecurityException e) {  
            e.printStackTrace();  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
		
		/*LocalSocket lSocket = new LocalSocket();
		socket = new SynchronizedSocket(lSocket);
		socket.register(socketURL);

		socket.addMessageReceivedHandler(this);*/
		
		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 url = "rmi://"+registry+":1099/"+socketURL;
			//System.out.println("Binding to: "+registry);
			//System.out.println("Register: " + Arrays.toString(java.rmi.Naming.list(registry)));
			System.out.println("trying to bind to: "+url);
			java.rmi.Naming.rebind(url, this);
			System.out.println("binded to: "+url);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} //catch (AlreadyBoundException e) {
			//e.printStackTrace();
		//}
		
		/*catch (MalformedURLException | AlreadyBoundException e) {
			e.printStackTrace();
		}*/
				
		final String name = "rmi://"+registry+":1099/"+socketURL;
				
		// Let the node unregister from RMI registry on shut down.
		Runtime.getRuntime().addShutdownHook(new Thread() {
			@Override
			public void run() {
				logger.info("Shutting down " + name + ".");
				try {
					java.rmi.Naming.unbind(name);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
		
		this.gridSchedulerURL = gridscheduler;
		initGridSchedulers(gridscheduler);
	}