public Simulation() throws RemoteException {
		
		// Bind the node to the RMI registry.
				try {
					java.rmi.Naming.bind("JobCreator", this);
				} catch (Exception  e) {
					e.printStackTrace();
				}
						
				final String name = "JobCreator";
						
				// 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();
						}
					}
				});
				
		GridScheduler scheduler;
		
		ArrayList<GridScheduler> schedulers = new ArrayList<GridScheduler>();
		for (int i = 0; i < 5; i++)
			schedulers.add(new GridScheduler("scheduler" + i, "scheduler" + ((i + 1) % 5), "scheduler" + ((i - 1 + 5) % 5), "localhost"));
		
		gs = schedulers.get(0);
		
		// Setup the model. Create a grid scheduler and a set of clusters.
		//scheduler = new GridScheduler("scheduler1");
		scheduler = schedulers.get(0);
		
		ArrayList<String> gridschedulers = new ArrayList<String>();
		for (GridScheduler gs : schedulers)
		{
			gridschedulers.add(gs.getUrl());
		}
		//String[] gs_urls = new String[gridschedulers.size()];
		//gs_urls = gridschedulers.toArray(gs_urls);
		//String[] gs_urls = {scheduler.getUrl()};
	
		// Create a new gridscheduler panel so we can monitor our components
		gridSchedulerPanel = new GridSchedulerPanel(schedulers);
		gridSchedulerPanel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		long seed = System.currentTimeMillis();
		Random generator = new Random(seed);
		
		// Startup delay to make sure all GS nodes have started
		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		// Create the clusters and nods
		clusters = new Cluster[nrClusters];
		for (int i = 0; i < nrClusters; i++) {
			int r = generator.nextInt(gridschedulers.size());
			clusters[i] = new Cluster("cluster" + i, gridschedulers.get(r), nrNodes, "localhost"); 
			
			// Now create a cluster status panel for each cluster inside this gridscheduler
			ClusterStatusPanel clusterReporter = new ClusterStatusPanel(clusters[i]);
			gridSchedulerPanel.addStatusPanel(clusterReporter);
		}
		
		// Open the gridscheduler panel
		gridSchedulerPanel.start();
		
		Thread t2 = new Thread() {
     		 public void run() {
        		Scanner sc = new Scanner(System.in);
        		sc.nextInt();
        		gridSchedulerPanel.setVisible(false);
     		 }
    	};
    	t2.start();
		
		// Run the simulation
		Thread runThread = new Thread(this);
		runThread.run(); // This method only returns after the simulation has ended
		System.out.println("What the hell are we waiting for?");
		// Now perform the cleanup
		gridSchedulerPanel.dispose();
		stopEveryone();
		System.out.println("What the hell are we waiting for?2");
		// Stop clusters
		/*for (Cluster cluster : clusters)
			cluster.stopPollThread();
		
		// Stop grid scheduler
		scheduler.stopPollThread();*/
	}