@GET @Path("/{instanceId}/slobrok") @Produces(MediaType.APPLICATION_JSON) public List<SlobrokEntryResponse> getSlobrokEntries( @PathParam("instanceId") String instanceId, @QueryParam("pattern") String pattern) { ApplicationInstanceReference reference = parseInstanceId(instanceId); ApplicationId applicationId = OrchestratorUtil.toApplicationId(reference); if (pattern == null) { pattern = DEFAULT_SLOBROK_PATTERN; } List<Mirror.Entry> entries = slobrokApi.lookup(applicationId, pattern); return entries.stream() .map(entry -> new SlobrokEntryResponse(entry.getName(), entry.getSpec())) .collect(Collectors.toList()); }
/** * Returns the node metrics at a given index. * If there is no entry at the given index it is created by this call. */ private NodeMetrics getNodeMetrics(Mirror.Entry entry) { int index = getIndex(entry.getName()); // expand node array as needed while (nodeWeights.size() < (index + 1)) nodeWeights.add(null); NodeMetrics nodeMetrics = nodeWeights.get(index); if (nodeMetrics == null) { // initialize statistics for this node nodeMetrics = new NodeMetrics("node_" + index, metrics.targets); nodeWeights.set(index, nodeMetrics); } return nodeMetrics; }
/** * Resolve a concrete address from this service. This service may represent multiple remote sessions, so this will * select one that is online. * * @return A concrete service address. */ public RPCServiceAddress resolve() { if (pattern.startsWith("tcp/")) { int pos = pattern.lastIndexOf('/'); if (pos > 0 && pos < pattern.length() - 1) { RPCServiceAddress ret = new RPCServiceAddress(pattern, pattern.substring(0, pos)); if (!ret.isMalformed()) { return ret; } } } else { if (addressGen != mirror.updates()) { addressGen = mirror.updates(); addressList = mirror.lookup(pattern); } if (addressList != null && addressList.length > 0) { addressIdx = ++addressIdx % addressList.length; Mirror.Entry entry = addressList[addressIdx]; return new RPCServiceAddress(entry.getName(), entry.getSpec()); } } return null; }
Map<String, Entry> map = new HashMap<>(); for (Entry e : specs) { map.put(e.getName(), e);
/** * Updates and returns the cache entry for the given routing context. This method assumes that synchronization is * handled outside of it. * * @param ctx The routing context. * @return The updated cache entry. */ private CacheEntry update(RoutingContext ctx) { String key = getCacheKey(ctx); CacheEntry entry = cache.get(key); if (entry == null) { entry = new CacheEntry(); cache.put(key, entry); } int upd = ctx.getMirror().updates(); if (entry.generation != upd) { entry.generation = upd; entry.recipients.clear(); Mirror.Entry[] arr = ctx.getMirror().lookup(ctx.getHopPrefix() + "*" + ctx.getHopSuffix()); String self = localAddress != null ? localAddress : toAddress(ctx.getMessageBus().getConnectionSpec()); for (Mirror.Entry item : arr) { if (self.equals(toAddress(item.getSpec()))) { entry.recipients.add(Hop.parse(item.getName())); } } } return entry; }
/** * Updates and returns the cache entry for the given routing context. This method assumes that synchronization is * handled outside of it. * * @param ctx The routing context. * @return The updated cache entry. */ private CacheEntry update(RoutingContext ctx) { String key = getCacheKey(ctx); CacheEntry entry = cache.get(key); if (entry == null) { entry = new CacheEntry(); cache.put(key, entry); } int upd = ctx.getMirror().updates(); if (entry.generation != upd) { entry.generation = upd; entry.recipients.clear(); for (int i = 0; i < ctx.getNumRecipients(); ++i) { Mirror.Entry[] arr = ctx.getMirror().lookup(ctx.getRecipient(i).getHop(0).toString()); for (Mirror.Entry item : arr) { entry.recipients.add(Hop.parse(item.getName())); } } } return entry; }
/** * Updates and returns the cache entry for the given routing context. This method assumes that synchronization is * handled outside of it. * * @param ctx The routing context. * @return The updated cache entry. */ private CacheEntry update(RoutingContext ctx) { String key = getCacheKey(ctx); CacheEntry entry = cache.get(key); if (entry == null) { entry = new CacheEntry(); cache.put(key, entry); } int upd = ctx.getMirror().updates(); if (entry.generation != upd) { entry.generation = upd; entry.recipients.clear(); Mirror.Entry[] arr = ctx.getMirror().lookup(ctx.getHopPrefix() + "*" + ctx.getHopSuffix()); int pos = ctx.getMessageBus().getConnectionSpec().hashCode(); for (int i = 0; i < subsetSize && i < arr.length; ++i) { entry.recipients.add(Hop.parse(arr[((pos + i) & Integer.MAX_VALUE) % arr.length].getName())); } } return entry; }