org.jgroups.util.RspList Java Examples
The following examples show how to use
org.jgroups.util.RspList.
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: JGroupsTransport.java From lams with GNU General Public License v2.0 | 6 votes |
private void throwWorkExceptionIfHasExption(RspList<ResponseValues> rspList) throws WorkException { if (rspList != null && rspList.getFirst() != null) { for (Rsp<ResponseValues> rsp : rspList) { if (rsp.hasException()) { Throwable t = rsp.getException(); if (t instanceof WorkException) { throw (WorkException)t; } else { WorkException we = new WorkException(rsp.getException().getMessage()); we.initCause(rsp.getException()); throw we; } } } } }
Example #2
Source File: SolverContainerWrapper.java From unitime with Apache License 2.0 | 6 votes |
@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 #3
Source File: SolverServerImplementation.java From unitime with Apache License 2.0 | 6 votes |
@Override public boolean isLocalCoordinator() { if (!isLocal()) return false; try { int myIndex = iChannel.getView().getMembers().indexOf(iChannel.getAddress()); RspList<Boolean> ret = iDispatcher.callRemoteMethods(null, "isLocal", new Object[] {}, new Class[] {}, sAllResponses); for (Rsp<Boolean> local: ret) { if (Boolean.TRUE.equals(local.getValue())) { int idx = iChannel.getView().getMembers().indexOf(local.getSender()); if (idx < myIndex) return false; } } return true; } catch (Exception e) { sLog.error("Failed to retrieve local address: " + e.getMessage(), e); return false; } }
Example #4
Source File: RemoteQueueProcessor.java From unitime with Apache License 2.0 | 6 votes |
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 #5
Source File: JGroupsTransport.java From ironjacamar with Eclipse Public License 1.0 | 6 votes |
private void throwWorkExceptionIfHasExption(RspList<ResponseValues> rspList) throws WorkException { if (rspList != null && rspList.getFirst() != null) { for (Rsp<ResponseValues> rsp : rspList) { if (rsp.hasException()) { Throwable t = rsp.getException(); if (t instanceof WorkException) { throw (WorkException)t; } else { WorkException we = new WorkException(rsp.getException().getMessage()); we.initCause(rsp.getException()); throw we; } } } } }
Example #6
Source File: SolverContainerWrapper.java From unitime with Apache License 2.0 | 5 votes |
@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 #7
Source File: SolverContainerWrapper.java From unitime with Apache License 2.0 | 5 votes |
@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 #8
Source File: SolverContainerWrapper.java From unitime with Apache License 2.0 | 5 votes |
@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 #9
Source File: SolverContainerWrapper.java From unitime with Apache License 2.0 | 5 votes |
@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 #10
Source File: SolverContainerWrapper.java From unitime with Apache License 2.0 | 5 votes |
@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 #11
Source File: DummySolverServer.java From unitime with Apache License 2.0 | 5 votes |
@Override public Address getLocalAddress() { try { RspList<Boolean> ret = iDispatcher.callRemoteMethods(null, "isLocal", new Object[] {}, new Class[] {}, sAllResponses); for (Rsp<Boolean> local: ret) { if (Boolean.TRUE.equals(local.getValue())) return local.getSender(); } return null; } catch (Exception e) { sLog.error("Failed to retrieve local address: " + e.getMessage(), e); return null; } }
Example #12
Source File: CourseSolverContainerRemote.java From unitime with Apache License 2.0 | 5 votes |
@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 #13
Source File: CourseSolverContainerRemote.java From unitime with Apache License 2.0 | 5 votes |
@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 #14
Source File: CourseSolverContainerRemote.java From unitime with Apache License 2.0 | 5 votes |
@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; }
Example #15
Source File: SolverServerImplementation.java From unitime with Apache License 2.0 | 5 votes |
@Override public Address getLocalAddress() { if (isLocal()) return getAddress(); try { RspList<Boolean> ret = iDispatcher.callRemoteMethods(null, "isLocal", new Object[] {}, new Class[] {}, sAllResponses); for (Rsp<Boolean> local: ret) { if (Boolean.TRUE.equals(local.getValue())) return local.getSender(); } return null; } catch (Exception e) { sLog.error("Failed to retrieve local address: " + e.getMessage(), e); return null; } }
Example #16
Source File: JavaGroupsCache.java From commons-jcs with Apache License 2.0 | 5 votes |
/** * If 'getFromPeers' is true, this will attempt to get the requested element * from ant other members of the group. * * @param key * @return * @throws IOException * Never thrown by this implementation */ public ICacheElement<K, V> get( K key ) throws IOException { if ( getFromPeers ) { CacheElement element = new CacheElement( cacheName, key, null ); Request request = new Request( element, Request.GET ); // Cast message and wait for all responses. // FIXME: we can stop waiting after the first not null response, // that is more difficult to implement however. RspList responses = dispatcher.castMessage( null, new Message( null, null, request ), GroupRequest.GET_ALL, 0 ); // Get results only gives the responses which were not null Vector results = responses.getResults(); // If there were any non null results, return the first if ( results.size() > 0 ) { return (ICacheElement) results.get( 0 ); } } return null; }