/** Returns locks that have been successfully acquired */ protected synchronized List<Tuple<String,Owner>> getLockInfo() { List<Tuple<String,Owner>> l=new ArrayList<>(); // table.forEach((key, value) -> value.keySet().forEach(owner -> l.add(new Tuple<>(key, owner)))); table.forEach((k,v) -> v.forEach((owner, cl) -> { if(cl.acquired && !cl.denied) l.add(new Tuple<>(k, owner)); })); return l; }
protected void removeFromAddressMappings(Address client_addr) { if(client_addr == null) return; Set<Tuple<String,Address>> suspects=null; // group/address pairs for(Map.Entry<String,ConcurrentMap<Address,Entry>> entry: address_mappings.entrySet()) { ConcurrentMap<Address,Entry> map=entry.getValue(); for(Map.Entry<Address,Entry> entry2: map.entrySet()) { Entry e=entry2.getValue(); if(client_addr.equals(e.client_addr)) { map.remove(entry2.getKey()); log.debug("connection to %s closed", client_addr); if(map.isEmpty()) address_mappings.remove(entry.getKey()); if(suspects == null) suspects=new HashSet<>(); suspects.add(new Tuple<>(entry.getKey(), entry2.getKey())); break; } } } if(emit_suspect_events && suspects != null && !suspects.isEmpty()) { for(Tuple<String,Address> suspect: suspects) { String group=suspect.getVal1(); Address addr=suspect.getVal2(); ConcurrentMap<Address,Entry> map=address_mappings.get(group); if(map == null) continue; GossipData data=new GossipData(GossipType.SUSPECT, group, addr); sendToAllMembersInGroup(map.entrySet(), data); } } }
/** * Installs a new rule * @param name The name of the rule * @param interval Number of ms between executions of the rule * @param rule The rule */ public void installRule(String name, long interval, Rule rule) { rule.supervisor(this).log(log).init(); Future<?> future=timer.scheduleAtFixedRate(rule, interval, interval, TimeUnit.MILLISECONDS); Tuple<Rule,Future<?>> existing=rules.put(name != null? name : rule.name(), new Tuple<>(rule, future)); if(existing != null) existing.getVal2().cancel(true); }
public void destroy() { for(Tuple<Rule,Future<?>> tuple: rules.values()) tuple.getVal2().cancel(true); rules.clear(); super.destroy(); }
@ManagedOperation(description="Dumps all pending requests") public String dumpPendingRequests() { StringBuilder sb=new StringBuilder(); for(Tuple<Request,Promise> tuple: pending_requests.values()) { Request tmp=tuple.getVal1(); sb.append(tmp + " (" + tmp.getClass().getCanonicalName() + ") "); } return sb.toString(); }
public Object up(Event evt) { switch(evt.type()) { case Event.GET_SECRET_KEY: return new Tuple<>(secret_key, sym_version); case Event.SET_SECRET_KEY: Tuple<SecretKey,byte[]> tuple=evt.arg(); try { setKeys(null, tuple.getVal1(), tuple.getVal2()); } catch(Exception ex) { log.error("failed setting secret key", ex); } return null; } return up_prot.up(evt); }
public Object down(Event evt) { Object retval=super.down(evt); switch(evt.getType()) { case Event.VIEW_CHANGE: for(Address logical_addr: view.getMembersRaw()) { PhysicalAddress physical_addr=(PhysicalAddress)down_prot.down(new Event(Event.GET_PHYSICAL_ADDRESS, logical_addr)); if(physical_addr != null && !initial_hosts.contains(physical_addr)) { dynamic_hosts.addIfAbsent(physical_addr); } } break; case Event.ADD_PHYSICAL_ADDRESS: Tuple<Address,PhysicalAddress> tuple=evt.getArg(); PhysicalAddress physical_addr=tuple.getVal2(); if(physical_addr != null && !initial_hosts.contains(physical_addr)) dynamic_hosts.addIfAbsent(physical_addr); break; } return retval; }
/** * Installs a new rule * @param name The name of the rule * @param interval Number of ms between executions of the rule * @param rule The rule */ public void installRule(String name, long interval, Rule rule) { rule.supervisor(this).log(log).init(); Future<?> future=timer.scheduleAtFixedRate(rule, interval, interval, TimeUnit.MILLISECONDS); Tuple<Rule,Future<?>> existing=rules.put(name != null? name : rule.name(), new Tuple<>(rule, future)); if(existing != null) existing.getVal2().cancel(true); }
@ManagedOperation(description="Prints all currently installed rules") public String dumpRules() { StringBuilder sb=new StringBuilder(); for(Map.Entry<String,Tuple<Rule,Future<?>>> entry: rules.entrySet()) { String key=entry.getKey(); Tuple<Rule,Future<?>> tuple=entry.getValue(); Rule rule=tuple.getVal1(); sb.append(key + ": " + rule.description() + "\n"); } return sb.toString(); }
public List<Tuple<Address,Long>> getMembersWithCreditsLessThan(long min_credits) { List<Tuple<Address,Long>> retval=new LinkedList<>(); lock.lock(); try { flushAccumulatedCredits(); credits.entrySet().stream().filter(entry -> entry.getValue() <= min_credits) .forEach(entry -> retval.add(new Tuple<>(entry.getKey(), entry.getValue()))); return retval; } finally { lock.unlock(); } }
/** * Takes the list of configured tag names and compares it with tagsUtils on the ec2 instance. * FilterUtils (tag:key=value) will be created for all matches. * * @return a list of filters for instances that share common tags with * this instance. */ @SuppressWarnings("OptionalUsedAsFieldOrParameterType") public List<Filter> instanceTagNamesToFilters() { return tagsUtils.getAwsTagNames().map(Stream::of).orElseGet(Stream::empty) .map(tagNames -> new Tuple<>(tagNames, tagsUtils.getInstanceTags())) .flatMap(namesAndTags -> namesAndTags.getVal2() .stream() .filter(tag -> namesAndTags.getVal1().contains(tag.getKey()))) .map(tag -> new Filter("tag:" + tag.getKey(), Collections.singletonList(tag.getValue()))) .collect(Collectors.toList()); }
return; Promise promise=tuple.getVal2(); if(rsp instanceof ValueResponse) { ValueResponse tmp=(ValueResponse)rsp;
flushCoordinator = flushStarter; flushMembers.clear(); if (tuple.getVal1() != null) { flushMembers.addAll(tuple.getVal1()); Message start_msg = new Message(flushStarter) .putHeader(this.id, new FlushHeader(FlushHeader.FLUSH_COMPLETED, fh.viewID)) .setBuffer(marshal(tuple.getVal1(),digest)); down_prot.down(start_msg); log.debug(localAddress + ": received START_FLUSH, responded with FLUSH_COMPLETED to " + flushStarter);
protected boolean addDiscoveryResponseToCaches(Address mbr, String logical_name, PhysicalAddress physical_addr) { if(mbr == null) return false; if(logical_name != null) NameCache.add(mbr, logical_name); if(physical_addr != null) return (Boolean)down(new Event(Event.ADD_PHYSICAL_ADDRESS, new Tuple<>(mbr, physical_addr))); return false; }
protected void removeFromAddressMappings(Address client_addr) { if(client_addr == null) return; Set<Tuple<String,Address>> suspects=null; // group/address pairs for(Map.Entry<String,ConcurrentMap<Address,Entry>> entry: address_mappings.entrySet()) { ConcurrentMap<Address,Entry> map=entry.getValue(); for(Map.Entry<Address,Entry> entry2: map.entrySet()) { Entry e=entry2.getValue(); if(client_addr.equals(e.client_addr)) { map.remove(entry2.getKey()); log.debug("connection to %s closed", client_addr); if(map.isEmpty()) address_mappings.remove(entry.getKey()); if(suspects == null) suspects=new HashSet<>(); suspects.add(new Tuple<>(entry.getKey(), entry2.getKey())); break; } } } if(emit_suspect_events && suspects != null && !suspects.isEmpty()) { for(Tuple<String,Address> suspect: suspects) { String group=suspect.getVal1(); Address addr=suspect.getVal2(); ConcurrentMap<Address,Entry> map=address_mappings.get(group); if(map == null) continue; GossipData data=new GossipData(GossipType.SUSPECT, group, addr); sendToAllMembersInGroup(map.entrySet(), data); } } }
private void handleFlushReconcile(Message msg) { Address requester = msg.getSrc(); Tuple<Collection<? extends Address>,Digest> tuple=readParticipantsAndDigest(msg.getRawBuffer(), msg.getOffset(),msg.getLength()); Digest reconcileDigest = tuple.getVal2(); if (log.isDebugEnabled()) log.debug(localAddress + ": received FLUSH_RECONCILE, passing digest to NAKACK " + reconcileDigest); // Let NAKACK reconcile missing messages down_prot.down(new Event(Event.REBROADCAST, reconcileDigest)); if (log.isDebugEnabled()) log.debug(localAddress + ": returned from FLUSH_RECONCILE, " + " sending RECONCILE_OK to " + requester); Message reconcileOk = new Message(requester).setFlag(Message.Flag.OOB, Message.Flag.INTERNAL) .putHeader(this.id,new FlushHeader(FlushHeader.FLUSH_RECONCILE_OK)); down_prot.down(reconcileOk); }
case RESEND_PENDING_REQUESTS: for(Tuple<Request,Promise> tuple: pending_requests.values()) { Request request=tuple.getVal1(); if(log.isTraceEnabled()) log.trace("[" + local_addr + "] --> [" + coord + "] resending " + request);