public String dumpQueue() { StringBuilder sb = new StringBuilder(); List v = queue.values(); for (Iterator it = v.iterator(); it.hasNext(); ) { sb.append(it.next() + "\n"); } return sb.toString(); }
public void channelConnected(Channel channel) { synchronized (additionalChannelListeners) { for (Iterator i = additionalChannelListeners.iterator(); i.hasNext(); ) { ChannelListener l = (ChannelListener) i.next(); try { l.channelConnected(channel); } catch (Throwable t) { log.warn("channel listener failed", t); } } } }
/** * Removes all members from a given view which don't have us in their view * (https://jira.jboss.org/browse/JGRP-1061). Example: * * <pre> * A: AB * B: AB * C: ABC * </pre> * * becomes * * <pre> * A: AB * B: AB * C: C // A and B don't have C in their views * </pre> * * @param map A map of members and their associated views */ public static void sanitizeViews(Map<Address, View> map) { if (map == null) return; for (Map.Entry<Address, View> entry : map.entrySet()) { Address key = entry.getKey(); List<Address> members = new ArrayList<Address>(entry.getValue().getMembers()); boolean modified = false; for (Iterator<Address> it = members.iterator(); it.hasNext(); ) { Address val = it.next(); if (val.equals(key)) // we can always talk to ourself ! continue; View view = map.get(val); final Collection<Address> tmp_mbrs = view != null ? view.getMembers() : null; if (tmp_mbrs != null && !tmp_mbrs.contains(key)) { it.remove(); modified = true; } } if (modified) { View old_view = entry.getValue(); entry.setValue(new View(old_view.getVid(), members)); } } }
protected void handleJmx(Map<String, String> map, String input) { Map<String, Object> tmp_stats; int index = input.indexOf("="); if (index > -1) { List<String> list = null; String protocol_name = input.substring(index + 1); index = protocol_name.indexOf("."); if (index > -1) { String rest = protocol_name; protocol_name = protocol_name.substring(0, index); String attrs = rest.substring(index + 1); // e.g. "num_sent,msgs,num_received_msgs" list = Util.parseStringList(attrs, ","); // check if there are any attribute-sets in the list for (Iterator<String> it = list.iterator(); it.hasNext(); ) { String tmp = it.next(); index = tmp.indexOf("="); if (index != -1) { String attrname = tmp.substring(0, index); String attrvalue = tmp.substring(index + 1); Protocol prot = prot_stack.findProtocol(protocol_name); Field field = prot != null ? Util.getField(prot.getClass(), attrname) : null; if (field != null) { Object value = MethodCall.convert(attrvalue, field.getType()); if (value != null) prot.setValue(attrname, value); } else { // try to find a setter for X, e.g. x(type-of-x) or setX(type-of-x) ResourceDMBean.Accessor setter = ResourceDMBean.findSetter( prot, attrname); // Util.getSetter(prot.getClass(), attrname); if (setter != null) { try { Class<?> type = setter instanceof ResourceDMBean.FieldAccessor ? ((ResourceDMBean.FieldAccessor) setter).getField().getType() : setter instanceof ResourceDMBean.MethodAccessor ? ((ResourceDMBean.MethodAccessor) setter) .getMethod() .getParameterTypes()[0] .getClass() : null; Object converted_value = MethodCall.convert(attrvalue, type); setter.invoke(converted_value); } catch (Exception e) { log.error("unable to invoke %s() on %s: %s", setter, protocol_name, e); } } else log.warn(Util.getMessage("FieldNotFound"), attrname, protocol_name); } it.remove(); } } } tmp_stats = dumpStats(protocol_name, list); if (tmp_stats != null) { for (Map.Entry<String, Object> entry : tmp_stats.entrySet()) { Map<String, Object> tmp_map = (Map<String, Object>) entry.getValue(); String key = entry.getKey(); map.put(key, tmp_map != null ? tmp_map.toString() : null); } } } else { tmp_stats = dumpStats(); if (tmp_stats != null) { for (Map.Entry<String, Object> entry : tmp_stats.entrySet()) { Map<String, Object> tmp_map = (Map<String, Object>) entry.getValue(); String key = entry.getKey(); map.put(key, tmp_map != null ? tmp_map.toString() : null); } } } }
Address determineCoordinator() { List<Address> mbrs = my_view != null ? my_view.getMembers() : null; if (mbrs == null) return null; if (!mbrs.isEmpty()) return mbrs.iterator().next(); return null; }