Refine search
/** * @param corr The request correlator to be used. A request correlator sends requests tagged with a unique ID and * notifies the sender when matching responses are received. The reason {@code GroupRequest} uses * it instead of a {@code Transport} is that multiple requests/responses might be sent/received concurrently * @param targets The targets, which are supposed to receive the message. Any receiver not in this set will * discard the message. Targets are always a subset of the current membership * @param options The request options to be used for this call */ public GroupRequest(RequestCorrelator corr, Collection<Address> targets, RequestOptions options) { super(corr, options); rsps=new RspList<>(targets.size()); targets.forEach(target -> rsps.put(target, new Rsp<>())); }
public List<Address> getSuspectedMembers() { return entrySet().stream().filter(entry -> entry.getValue() != null && entry.getValue().wasSuspected()) .map(Entry::getKey).collect(Collectors.toList()); }
private <T> T futureDone(RspList<T> rspList) { Collection<Rsp<T>> values = rspList.values(); values.parallelStream() .filter(Rsp::hasException) .forEach(rsp -> logWarn(() -> String.format("Execute method failed. Sender [%s], with exception [%s]", rsp.getSender(), rsp.getException()))); T value = values.stream() .filter(Rsp::wasReceived) .filter(((Predicate<Rsp<T>>) Rsp::hasException).negate()) .filter(((Predicate<Rsp<T>>) Rsp::wasUnreachable).negate()) .map(Rsp::getValue) .filter((t) -> t != null) .reduce((a, b) -> a) .orElse(null); if (value instanceof DataHolder) { return ((DataHolder<T>) value).unwrap(); } else { return value; } }
RspList<Object> quotes=disp.callRemoteMethods(null, "getQuote", new Object[]{stock_name}, new Class[]{String.class}, new RequestOptions(ResponseMode.GET_ALL, 10000)); for(Rsp<Object> rsp : quotes.values()) { Object quote=rsp.getValue(); if(quote == null || quote instanceof Throwable) continue; disp.callRemoteMethods(null, "setQuote", new Object[]{stock_name, val}, new Class[]{String.class, Float.class}, new RequestOptions(ResponseMode.GET_FIRST, 0)); listbox.removeAll(); showMsg("Getting all stocks:"); RspList<Object> rsp_list=disp.callRemoteMethods(null, "getAllStocks", null, null, new RequestOptions(ResponseMode.GET_ALL, 5000)); for(Rsp rsp : rsp_list.values()) { Object obj=rsp.getValue(); if(obj == null || obj instanceof Throwable) continue; all_stocks.entrySet().stream().filter(entry -> entry.getValue() != null) .forEach(entry -> listbox.add(entry.getKey() + ": " + entry.getValue().toString())); break; case "Quit":
System.out.println("invoking method in " + dest + ": "); try { Object rsp=disp.callRemoteMethod(dest, call, new RequestOptions(ResponseMode.GET_ALL, RPC_TIMEOUT)); System.out.println("rsp from " + dest + ": " + rsp); SiteMaster dest=new SiteMaster(site_master); System.out.println("invoking method in " + dest + ": "); Object rsp=disp.callRemoteMethod(dest, call, new RequestOptions(ResponseMode.GET_ALL, RPC_TIMEOUT)); System.out.println("rsp from " + dest + ": " + rsp); System.out.println("invoking method in " + dests + ": "); RspList<Object> rsps=disp.callRemoteMethods(dests, call, new RequestOptions(ResponseMode.GET_ALL, RPC_TIMEOUT).anycasting(true)); for(Map.Entry<Address,Rsp<Object>> entry: rsps.entrySet()) { Address sender=entry.getKey(); Rsp<Object> rsp=entry.getValue(); if(rsp.wasUnreachable()) System.out.println("<< unreachable: " + sender); else System.out.println("<< " + rsp.getValue() + " from " + sender); RspList<Object> rsps=disp.callRemoteMethods(null, call, new RequestOptions(ResponseMode.GET_ALL, RPC_TIMEOUT).anycasting(false)); rsps.entrySet().stream().forEach( entry -> { Rsp<Object> val=entry.getValue(); System.out.println("<< " + val.getValue() + " from " + entry.getKey()); });
protected void invokeRpcs() throws Exception { Average avg=new Average(); long min=Long.MAX_VALUE, max=0; RequestOptions opts=new RequestOptions(ResponseMode.GET_FIRST, 0).transientFlags(Message.TransientFlag.DONT_LOOPBACK); MethodCall call=new MethodCall((short)0); int print=num/10; opts.flags(Message.Flag.OOB); if(dont_bundle) opts.flags(Message.Flag.DONT_BUNDLE); for(int i=0; i < num; i++) { long start=System.nanoTime(); RspList<Void> rsps=disp.callRemoteMethods(null, call, opts); long time_ns=System.nanoTime() - start; if(i > 0 && i % print == 0) System.out.print("."); boolean all_received=rsps.values().stream().allMatch(Rsp::wasReceived); if(!all_received) System.err.printf("didn't receive all responses: %s\n", rsps);
private <T> List<T> processResponseList(RspList<T> rspList, String serviceName, String methodName, Object[] args, boolean trace) { List<T> result = new ArrayList<T>(rspList.size()); if (rspList != null) { for (Rsp<T> response : rspList.values()) { // Only include successful received responses if (response.hasException()) { Throwable e = response.getException(); ClusteringImplLogger.ROOT_LOGGER.debugf(e, "%s invocation failure from %s: %s(%s)", serviceName, response.getSender(), methodName, (args != null) ? Arrays.asList(args) : ""); } else if (response.wasReceived()) { result.add(response.getValue()); } else if (trace) { ClusteringImplLogger.ROOT_LOGGER.tracef("Ignoring non-received response: %s", response); } } } return result; }
RspList<Object> rsps=disp.callRemoteMethods(null, new MethodCall(GET, key), new RequestOptions(ResponseMode.GET_ALL, call_timeout)); for(Rsp rsp: rsps.values()) { Object obj=rsp.getValue(); if(obj == null || obj instanceof Throwable) continue; val=(Cache.Value<Value<V>>)rsp.getValue(); if(val != null) { tmp=val.getValue();
RspList<Results> responses=null; try { RequestOptions options=new RequestOptions(ResponseMode.GET_ALL, 0); options.flags(Message.Flag.OOB, Message.Flag.DONT_BUNDLE, Message.Flag.NO_FC); responses=disp.callRemoteMethods(null, new MethodCall(START), options); for(Map.Entry<Address,Rsp<Results>> entry: responses.entrySet()) { Address mbr=entry.getKey(); Rsp<Results> rsp=entry.getValue(); Results result=rsp.getValue(); if(result != null) { total_reqs+=result.num_gets + result.num_puts;
List<Object> retval = new ArrayList<Object>(rsps.size()); for (Rsp rsp : rsps.values()) if (rsp.wasSuspected() || !rsp.wasReceived()) if (rsp.wasSuspected()) ex = new SuspectException("Suspected member: " + rsp.getSender());
List<Object> retval = new ArrayList<Object>(rsps.size()); for (Address dest : dests) Rsp rsp = rsps.get(dest); if (rsp == null || (rsp.wasSuspected() && !rsp.wasReceived())) + ", this member has probably left the cluster.")); else if (!rsp.wasReceived()) retval.add(new RPCException("Replication timeout for " + rsp.getSender() + ", rsp=" + rsp));
private boolean containsOnlyNulls(RspList l) { for (Rsp r : l.values()) { if (r.getValue() != null || !r.wasReceived() || r.wasSuspected()) return false; } return true; }
public void receiveResponse(Object response_value, Address sender, boolean is_exception) { Rsp<T> rsp; if(isDone() || (rsp=rsps.get(sender)) == null) return; RspFilter rsp_filter=options.rspFilter(); lock.lock(); try { if(!rsp.wasReceived()) { if(!(rsp.wasSuspected() || rsp.wasUnreachable())) num_received++; if(rsp_filter == null || rsp_filter.isAcceptable(response_value, sender)) {
if(rsp_list.isEmpty()) { if(log.isWarnEnabled()) log.warn(" response list is empty"); return null; if(rsp_list.size() > 1) { if(log.isWarnEnabled()) log.warn("response list contains more that 1 response; returning first response !"); rsp=(Rsp)rsp_list.elementAt(0); if(rsp.wasSuspected()) { throw new SuspectedException(dest); if(!rsp.wasReceived()) { throw new TimeoutException(); return rsp.getValue();
/** * Returns the results from non-suspected members that are not null. */ public Vector getResults() { Vector ret=new Vector(); Rsp rsp; Object val; for(Iterator it=values().iterator(); it.hasNext();) { rsp=(Rsp)it.next(); if(rsp.wasReceived() && (val=rsp.getValue()) != null) ret.addElement(val); } return ret; }