Java Code Examples for org.jgroups.util.Rsp#getValue()

The following examples show how to use org.jgroups.util.Rsp#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolverContainerWrapper.java    From unitime with Apache License 2.0 6 votes vote down vote up
@Override
public long getMemUsage(String user) {
	try {
		if (iCheckLocal && iContainer.hasSolver(user))
			return iContainer.getMemUsage(user);

		RspList<Long> ret = iContainer.getDispatcher().callRemoteMethods(null, "getMemUsage", new Object[] { user }, new Class[] { String.class }, SolverServerImplementation.sAllResponses);
		long total = 0, count = 0;
		for (Rsp<Long> rsp : ret) {
			if (rsp != null && rsp.getValue() != null && rsp.getValue() > 0) {
				total += rsp.getValue();
				count ++;
			}
		}
		
		return count == 0 ? 0 : total / count;
	} catch (Exception e) {
		sLog.error("Failed to retrieve allocated memory " + user + ": " + e.getMessage(), e);
	}
	return 0;
}
 
Example 2
Source File: RemoteQueueProcessor.java    From unitime with Apache License 2.0 6 votes vote down vote up
public String generateId() {
	loop: while (true) {
		String id = UUID.randomUUID().toString();
		if (get(id) != null) continue;
		try {
			RspList<QueueItem> ret = iDispatcher.callRemoteMethods(null, "invoke",  new Object[] { "get",  new Class[] { String.class } , new Object[] { id } }, new Class[] { String.class, Class[].class, Object[].class }, SolverServerImplementation.sAllResponses);
			for (Rsp<QueueItem> rsp : ret) {
				if (rsp != null && rsp.getValue() != null)
					continue loop;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return id;
	}
}
 
Example 3
Source File: SolverContainerWrapper.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> getSolvers() {
	Set<String> solvers = new HashSet<String>(iContainer.getSolvers());
	try {
		RspList<Set<String>> ret = iContainer.getDispatcher().callRemoteMethods(null, "getSolvers", new Object[] {}, new Class[] {}, SolverServerImplementation.sAllResponses);
		for (Rsp<Set<String>> rsp : ret) {
			if (rsp != null && rsp.getValue() != null)
				solvers.addAll(rsp.getValue());
		}
	} catch (Exception e) {
		sLog.error("Failed to retrieve solvers: " + e.getMessage(), e);
	}
	return solvers;
}
 
Example 4
Source File: SolverContainerWrapper.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public T getSolver(String user) {
	try {
		if (iCheckLocal) {
			T solver = iContainer.getSolver(user);
			if (solver != null) return solver;				
		}

		RspList<Boolean> ret = iContainer.getDispatcher().callRemoteMethods(null, "hasSolver", new Object[] { user }, new Class[] { String.class }, SolverServerImplementation.sAllResponses);
		List<Address> senders = new ArrayList<Address>();
		for (Rsp<Boolean> rsp : ret) {
			if (rsp != null && rsp.getValue() != null && rsp.getValue())
				senders.add(rsp.getSender());
		}
		if (senders.isEmpty())
			return null;
		else if (senders.size() == 1)
			return iContainer.createProxy(senders.get(0), user);
		else if (iContainer instanceof ReplicatedSolverContainer)
			return ((ReplicatedSolverContainer<T>)iContainer).createProxy(senders, user);
		else
			return iContainer.createProxy(ToolBox.random(senders), user);
	} catch (Exception e) {
		sLog.error("Failed to retrieve solver " + user + ": " + e.getMessage(), e);
	}
	return null;
}
 
Example 5
Source File: SolverContainerWrapper.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public boolean hasSolver(String user) {
	try {
		if (iContainer.hasSolver(user)) return true;

		RspList<Boolean> ret = iContainer.getDispatcher().callRemoteMethods(null, "hasSolver", new Object[] { user }, new Class[] { String.class }, SolverServerImplementation.sAllResponses);
		for (Rsp<Boolean> rsp : ret)
			if (rsp.getValue()) return true;
		return false;
	} catch (Exception e) {
		sLog.error("Failed to check solver " + user + ": " + e.getMessage(), e);
	}
	return false;
}
 
Example 6
Source File: SolverContainerWrapper.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public void unloadSolver(String user) {
	try {
		if (iContainer.hasSolver(user))
			iContainer.unloadSolver(user);
		
		RspList<Boolean> ret = iContainer.getDispatcher().callRemoteMethods(null, "hasSolver", new Object[] { user }, new Class[] { String.class }, SolverServerImplementation.sAllResponses);
		for (Rsp<Boolean> rsp : ret) {
			if (rsp.getValue())
				iContainer.getDispatcher().callRemoteMethod(rsp.getSender(), "unloadSolver", new Object[] { user }, new Class[] { String.class }, SolverServerImplementation.sFirstResponse);
		}
	} catch (Exception e) {
		sLog.error("Failed to unload solver " + user + ": " + e.getMessage(), e);
	}
}
 
Example 7
Source File: SolverContainerWrapper.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public int getUsage() {
	int usage = 0;
	try {
		RspList<Integer> ret = iContainer.getDispatcher().callRemoteMethods(null, "getUsage", new Object[] {}, new Class[] {}, SolverServerImplementation.sAllResponses);
		for (Rsp<Integer> rsp : ret)
			usage += rsp.getValue();
	} catch (Exception e) {
		sLog.error("Failed to check solver server usage: " + e.getMessage(), e);
	}
	return usage;
}
 
Example 8
Source File: CourseSolverContainerRemote.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public boolean saveToFile(String name, TimetableInfo info) {
	try {
   		RspList<Boolean> ret = iDispatcher.callRemoteMethods(null, "saveToFile", new Object[] { name, info } , new Class[] { String.class, TimetableInfo.class }, SolverServerImplementation.sAllResponses);
   		for (Rsp<Boolean> rsp : ret) {
			if (rsp != null && rsp.getValue() != null && rsp.getValue().booleanValue())
				return true;
   		}
	} catch (Exception e) {
		sLog.error("Failed to save info " + name + ": " + e.getMessage(), e);
	}
	return false;
}
 
Example 9
Source File: CourseSolverContainerRemote.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
 	public TimetableInfo loadFromFile(String name) {
 		try {
 			RspList<TimetableInfo> ret = iDispatcher.callRemoteMethods(null, "loadFromFile", new Object[] { name } , new Class[] { String.class }, SolverServerImplementation.sAllResponses);
 			for (Rsp<TimetableInfo> rsp : ret) {
 				if (rsp != null && rsp.getValue() != null)
 					return rsp.getValue();
 			}
 		} catch (Exception e) {
 			sLog.error("Failed to load info " + name + ": " + e.getMessage(), e);
 		}
return null;
 	}
 
Example 10
Source File: CourseSolverContainerRemote.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
  public boolean deleteFile(String name) {
try {
  		RspList<Boolean> ret = iDispatcher.callRemoteMethods(null, "deleteFile", new Object[] { name } , new Class[] { String.class }, SolverServerImplementation.sFirstResponse);
  		for (Rsp<Boolean> rsp : ret) {
		if (rsp != null && rsp.getValue() != null && rsp.getValue().booleanValue())
			return true;
  		}
} catch (Exception e) {
	sLog.error("Failed to delete info " + name + ": " + e.getMessage(), e);
}
return false;
  }