repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1
value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
belaban/JGroups | src/org/jgroups/protocols/pbcast/ServerGmsImpl.java | ServerGmsImpl.sendLeaveReqToCoord | protected boolean sendLeaveReqToCoord(final Address coord) {
if(coord == null) {
log.warn("%s: cannot send LEAVE request to null coord", gms.getLocalAddress());
return false;
}
Promise<Address> leave_promise=gms.getLeavePromise();
gms.setLeaving(true);
log.trace("%s: sending LEAVE request to %s", gms.local_addr, coord);
long start=System.currentTimeMillis();
sendLeaveMessage(coord, gms.local_addr);
Address sender=leave_promise.getResult(gms.leave_timeout);
if(!Objects.equals(coord, sender))
return false;
long time=System.currentTimeMillis()-start;
if(sender != null)
log.trace("%s: got LEAVE response from %s in %d ms", gms.local_addr, coord, time);
else
log.trace("%s: timed out waiting for LEAVE response from %s (after %d ms)", gms.local_addr, coord, time);
return true;
} | java | protected boolean sendLeaveReqToCoord(final Address coord) {
if(coord == null) {
log.warn("%s: cannot send LEAVE request to null coord", gms.getLocalAddress());
return false;
}
Promise<Address> leave_promise=gms.getLeavePromise();
gms.setLeaving(true);
log.trace("%s: sending LEAVE request to %s", gms.local_addr, coord);
long start=System.currentTimeMillis();
sendLeaveMessage(coord, gms.local_addr);
Address sender=leave_promise.getResult(gms.leave_timeout);
if(!Objects.equals(coord, sender))
return false;
long time=System.currentTimeMillis()-start;
if(sender != null)
log.trace("%s: got LEAVE response from %s in %d ms", gms.local_addr, coord, time);
else
log.trace("%s: timed out waiting for LEAVE response from %s (after %d ms)", gms.local_addr, coord, time);
return true;
} | [
"protected",
"boolean",
"sendLeaveReqToCoord",
"(",
"final",
"Address",
"coord",
")",
"{",
"if",
"(",
"coord",
"==",
"null",
")",
"{",
"log",
".",
"warn",
"(",
"\"%s: cannot send LEAVE request to null coord\"",
",",
"gms",
".",
"getLocalAddress",
"(",
")",
")",
... | Sends a leave request to coord and blocks until a leave response has been received,
or the leave timeout has elapsed | [
"Sends",
"a",
"leave",
"request",
"to",
"coord",
"and",
"blocks",
"until",
"a",
"leave",
"response",
"has",
"been",
"received",
"or",
"the",
"leave",
"timeout",
"has",
"elapsed"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/protocols/pbcast/ServerGmsImpl.java#L85-L105 | train |
belaban/JGroups | src/org/jgroups/Version.java | Version.isBinaryCompatible | public static boolean isBinaryCompatible(short ver) {
if(version == ver)
return true;
short tmp_major=(short)((ver & MAJOR_MASK) >> MAJOR_SHIFT);
short tmp_minor=(short)((ver & MINOR_MASK) >> MINOR_SHIFT);
return major == tmp_major && minor == tmp_minor;
} | java | public static boolean isBinaryCompatible(short ver) {
if(version == ver)
return true;
short tmp_major=(short)((ver & MAJOR_MASK) >> MAJOR_SHIFT);
short tmp_minor=(short)((ver & MINOR_MASK) >> MINOR_SHIFT);
return major == tmp_major && minor == tmp_minor;
} | [
"public",
"static",
"boolean",
"isBinaryCompatible",
"(",
"short",
"ver",
")",
"{",
"if",
"(",
"version",
"==",
"ver",
")",
"return",
"true",
";",
"short",
"tmp_major",
"=",
"(",
"short",
")",
"(",
"(",
"ver",
"&",
"MAJOR_MASK",
")",
">>",
"MAJOR_SHIFT",... | Checks whether ver is binary compatible with the current version. The rule for binary compatibility is that
the major and minor versions have to match, whereas micro versions can differ.
@param ver
@return | [
"Checks",
"whether",
"ver",
"is",
"binary",
"compatible",
"with",
"the",
"current",
"version",
".",
"The",
"rule",
"for",
"binary",
"compatibility",
"is",
"that",
"the",
"major",
"and",
"minor",
"versions",
"have",
"to",
"match",
"whereas",
"micro",
"versions"... | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/Version.java#L143-L149 | train |
belaban/JGroups | src/org/jgroups/stack/RouterStub.java | RouterStub.connect | public void connect(String group, Address addr, String logical_name, PhysicalAddress phys_addr) throws Exception {
synchronized(this) {
_doConnect();
}
try {
writeRequest(new GossipData(GossipType.REGISTER, group, addr, logical_name, phys_addr));
}
catch(Exception ex) {
throw new Exception(String.format("connection to %s failed: %s", group, ex));
}
} | java | public void connect(String group, Address addr, String logical_name, PhysicalAddress phys_addr) throws Exception {
synchronized(this) {
_doConnect();
}
try {
writeRequest(new GossipData(GossipType.REGISTER, group, addr, logical_name, phys_addr));
}
catch(Exception ex) {
throw new Exception(String.format("connection to %s failed: %s", group, ex));
}
} | [
"public",
"void",
"connect",
"(",
"String",
"group",
",",
"Address",
"addr",
",",
"String",
"logical_name",
",",
"PhysicalAddress",
"phys_addr",
")",
"throws",
"Exception",
"{",
"synchronized",
"(",
"this",
")",
"{",
"_doConnect",
"(",
")",
";",
"}",
"try",
... | Registers mbr with the GossipRouter under the given group, with the given logical name and physical address.
Establishes a connection to the GossipRouter and sends a CONNECT message.
@param group The group cluster) name under which to register the member
@param addr The address of the member
@param logical_name The logical name of the member
@param phys_addr The physical address of the member
@throws Exception Thrown when the registration failed | [
"Registers",
"mbr",
"with",
"the",
"GossipRouter",
"under",
"the",
"given",
"group",
"with",
"the",
"given",
"logical",
"name",
"and",
"physical",
"address",
".",
"Establishes",
"a",
"connection",
"to",
"the",
"GossipRouter",
"and",
"sends",
"a",
"CONNECT",
"m... | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/stack/RouterStub.java#L118-L128 | train |
belaban/JGroups | src/org/jgroups/stack/IpAddress.java | IpAddress.compareTo | public int compareTo(Address o) {
int h1, h2, rc; // added Nov 7 2005, makes sense with canonical addresses
if(this == o) return 0;
if(!(o instanceof IpAddress))
throw new ClassCastException("comparison between different classes: the other object is " +
(o != null? o.getClass() : o));
IpAddress other = (IpAddress) o;
if(ip_addr == null)
if (other.ip_addr == null) return port < other.port ? -1 : (port > other.port ? 1 : 0);
else return -1;
h1=ip_addr.hashCode();
h2=other.ip_addr.hashCode();
rc=h1 < h2? -1 : h1 > h2? 1 : 0;
return rc != 0 ? rc : port < other.port ? -1 : (port > other.port ? 1 : 0);
} | java | public int compareTo(Address o) {
int h1, h2, rc; // added Nov 7 2005, makes sense with canonical addresses
if(this == o) return 0;
if(!(o instanceof IpAddress))
throw new ClassCastException("comparison between different classes: the other object is " +
(o != null? o.getClass() : o));
IpAddress other = (IpAddress) o;
if(ip_addr == null)
if (other.ip_addr == null) return port < other.port ? -1 : (port > other.port ? 1 : 0);
else return -1;
h1=ip_addr.hashCode();
h2=other.ip_addr.hashCode();
rc=h1 < h2? -1 : h1 > h2? 1 : 0;
return rc != 0 ? rc : port < other.port ? -1 : (port > other.port ? 1 : 0);
} | [
"public",
"int",
"compareTo",
"(",
"Address",
"o",
")",
"{",
"int",
"h1",
",",
"h2",
",",
"rc",
";",
"// added Nov 7 2005, makes sense with canonical addresses",
"if",
"(",
"this",
"==",
"o",
")",
"return",
"0",
";",
"if",
"(",
"!",
"(",
"o",
"instanceof",... | implements the java.lang.Comparable interface
@see java.lang.Comparable
@param o - the Object to be compared
@return a negative integer, zero, or a positive integer as this object is less than,
equal to, or greater than the specified object.
@exception java.lang.ClassCastException - if the specified object's type prevents it
from being compared to this Object. | [
"implements",
"the",
"java",
".",
"lang",
".",
"Comparable",
"interface"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/stack/IpAddress.java#L103-L119 | train |
belaban/JGroups | src/org/jgroups/Membership.java | Membership.add | public Membership add(Collection<Address> v) {
if(v != null)
v.forEach(this::add);
return this;
} | java | public Membership add(Collection<Address> v) {
if(v != null)
v.forEach(this::add);
return this;
} | [
"public",
"Membership",
"add",
"(",
"Collection",
"<",
"Address",
">",
"v",
")",
"{",
"if",
"(",
"v",
"!=",
"null",
")",
"v",
".",
"forEach",
"(",
"this",
"::",
"add",
")",
";",
"return",
"this",
";",
"}"
] | Adds a list of members to this membership
@param v - a listof addresses
@throws ClassCastException if v contains objects that don't implement the Address interface | [
"Adds",
"a",
"list",
"of",
"members",
"to",
"this",
"membership"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/Membership.java#L85-L89 | train |
belaban/JGroups | src/org/jgroups/Membership.java | Membership.remove | public Membership remove(Address old_member) {
if(old_member != null) {
synchronized(members) {
members.remove(old_member);
}
}
return this;
} | java | public Membership remove(Address old_member) {
if(old_member != null) {
synchronized(members) {
members.remove(old_member);
}
}
return this;
} | [
"public",
"Membership",
"remove",
"(",
"Address",
"old_member",
")",
"{",
"if",
"(",
"old_member",
"!=",
"null",
")",
"{",
"synchronized",
"(",
"members",
")",
"{",
"members",
".",
"remove",
"(",
"old_member",
")",
";",
"}",
"}",
"return",
"this",
";",
... | Removes an member from the membership. If this member doesn't exist, no action will be
performed on the existing membership
@param old_member
- the member to be removed | [
"Removes",
"an",
"member",
"from",
"the",
"membership",
".",
"If",
"this",
"member",
"doesn",
"t",
"exist",
"no",
"action",
"will",
"be",
"performed",
"on",
"the",
"existing",
"membership"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/Membership.java#L99-L106 | train |
belaban/JGroups | src/org/jgroups/Membership.java | Membership.remove | public Membership remove(Collection<Address> v) {
if(v != null) {
synchronized(members) {
members.removeAll(v);
}
}
return this;
} | java | public Membership remove(Collection<Address> v) {
if(v != null) {
synchronized(members) {
members.removeAll(v);
}
}
return this;
} | [
"public",
"Membership",
"remove",
"(",
"Collection",
"<",
"Address",
">",
"v",
")",
"{",
"if",
"(",
"v",
"!=",
"null",
")",
"{",
"synchronized",
"(",
"members",
")",
"{",
"members",
".",
"removeAll",
"(",
"v",
")",
";",
"}",
"}",
"return",
"this",
... | Removes all the members contained in v from this membership
@param v a list of all the members to be removed | [
"Removes",
"all",
"the",
"members",
"contained",
"in",
"v",
"from",
"this",
"membership"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/Membership.java#L114-L121 | train |
belaban/JGroups | src/org/jgroups/Membership.java | Membership.merge | public Membership merge(Collection<Address> new_mems, Collection<Address> suspects) {
remove(suspects);
return add(new_mems);
} | java | public Membership merge(Collection<Address> new_mems, Collection<Address> suspects) {
remove(suspects);
return add(new_mems);
} | [
"public",
"Membership",
"merge",
"(",
"Collection",
"<",
"Address",
">",
"new_mems",
",",
"Collection",
"<",
"Address",
">",
"suspects",
")",
"{",
"remove",
"(",
"suspects",
")",
";",
"return",
"add",
"(",
"new_mems",
")",
";",
"}"
] | Merges membership with the new members and removes suspects.
The Merge method will remove all the suspects and add in the new members.
It will do it in the order
1. Remove suspects
2. Add new members
the order is very important to notice.
@param new_mems - a vector containing a list of members (Address) to be added to this membership
@param suspects - a vector containing a list of members (Address) to be removed from this membership | [
"Merges",
"membership",
"with",
"the",
"new",
"members",
"and",
"removes",
"suspects",
".",
"The",
"Merge",
"method",
"will",
"remove",
"all",
"the",
"suspects",
"and",
"add",
"in",
"the",
"new",
"members",
".",
"It",
"will",
"do",
"it",
"in",
"the",
"or... | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/Membership.java#L183-L186 | train |
belaban/JGroups | src/org/jgroups/Membership.java | Membership.contains | public boolean contains(Address member) {
if(member == null) return false;
synchronized(members) {
return members.contains(member);
}
} | java | public boolean contains(Address member) {
if(member == null) return false;
synchronized(members) {
return members.contains(member);
}
} | [
"public",
"boolean",
"contains",
"(",
"Address",
"member",
")",
"{",
"if",
"(",
"member",
"==",
"null",
")",
"return",
"false",
";",
"synchronized",
"(",
"members",
")",
"{",
"return",
"members",
".",
"contains",
"(",
"member",
")",
";",
"}",
"}"
] | Returns true if the provided member belongs to this membership
@param member
@return true if the member belongs to this membership | [
"Returns",
"true",
"if",
"the",
"provided",
"member",
"belongs",
"to",
"this",
"membership"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/Membership.java#L195-L200 | train |
belaban/JGroups | src/org/jgroups/blocks/ReplicatedTree.java | ReplicatedTree.getChildrenNames | public Set getChildrenNames(String fqn) {
Node n=findNode(fqn);
Map m;
if(n == null) return null;
m=n.getChildren();
if(m != null)
return m.keySet();
else
return null;
} | java | public Set getChildrenNames(String fqn) {
Node n=findNode(fqn);
Map m;
if(n == null) return null;
m=n.getChildren();
if(m != null)
return m.keySet();
else
return null;
} | [
"public",
"Set",
"getChildrenNames",
"(",
"String",
"fqn",
")",
"{",
"Node",
"n",
"=",
"findNode",
"(",
"fqn",
")",
";",
"Map",
"m",
";",
"if",
"(",
"n",
"==",
"null",
")",
"return",
"null",
";",
"m",
"=",
"n",
".",
"getChildren",
"(",
")",
";",
... | Returns all children of a given node
@param fqn The fully qualified name of the node
@return Set A list of child names (as Strings) | [
"Returns",
"all",
"children",
"of",
"a",
"given",
"node"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/blocks/ReplicatedTree.java#L360-L370 | train |
belaban/JGroups | src/org/jgroups/blocks/LazyRemovalCache.java | LazyRemovalCache.containsKeys | public boolean containsKeys(Collection<K> keys) {
for(K key: keys)
if(!map.containsKey(key))
return false;
return true;
} | java | public boolean containsKeys(Collection<K> keys) {
for(K key: keys)
if(!map.containsKey(key))
return false;
return true;
} | [
"public",
"boolean",
"containsKeys",
"(",
"Collection",
"<",
"K",
">",
"keys",
")",
"{",
"for",
"(",
"K",
"key",
":",
"keys",
")",
"if",
"(",
"!",
"map",
".",
"containsKey",
"(",
"key",
")",
")",
"return",
"false",
";",
"return",
"true",
";",
"}"
] | Returns true if all of the keys in keys are present. Returns false if one or more of the keys are absent | [
"Returns",
"true",
"if",
"all",
"of",
"the",
"keys",
"in",
"keys",
"are",
"present",
".",
"Returns",
"false",
"if",
"one",
"or",
"more",
"of",
"the",
"keys",
"are",
"absent"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/blocks/LazyRemovalCache.java#L71-L76 | train |
belaban/JGroups | src/org/jgroups/blocks/LazyRemovalCache.java | LazyRemovalCache.nonRemovedValues | public Set<V> nonRemovedValues() {
return map.values().stream().filter(entry -> !entry.removable).map(entry -> entry.val).collect(Collectors.toSet());
} | java | public Set<V> nonRemovedValues() {
return map.values().stream().filter(entry -> !entry.removable).map(entry -> entry.val).collect(Collectors.toSet());
} | [
"public",
"Set",
"<",
"V",
">",
"nonRemovedValues",
"(",
")",
"{",
"return",
"map",
".",
"values",
"(",
")",
".",
"stream",
"(",
")",
".",
"filter",
"(",
"entry",
"->",
"!",
"entry",
".",
"removable",
")",
".",
"map",
"(",
"entry",
"->",
"entry",
... | Adds all value which have not been marked as removable to the returned set
@return | [
"Adds",
"all",
"value",
"which",
"have",
"not",
"been",
"marked",
"as",
"removable",
"to",
"the",
"returned",
"set"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/blocks/LazyRemovalCache.java#L190-L192 | train |
belaban/JGroups | src/org/jgroups/blocks/LazyRemovalCache.java | LazyRemovalCache.removeMarkedElements | public void removeMarkedElements(boolean force) {
long curr_time=System.nanoTime();
for(Iterator<Map.Entry<K,Entry<V>>> it=map.entrySet().iterator(); it.hasNext();) {
Map.Entry<K, Entry<V>> entry=it.next();
Entry<V> tmp=entry.getValue();
if(tmp == null)
continue;
if(tmp.removable && (force || (curr_time - tmp.timestamp) >= max_age)) {
it.remove();
}
}
} | java | public void removeMarkedElements(boolean force) {
long curr_time=System.nanoTime();
for(Iterator<Map.Entry<K,Entry<V>>> it=map.entrySet().iterator(); it.hasNext();) {
Map.Entry<K, Entry<V>> entry=it.next();
Entry<V> tmp=entry.getValue();
if(tmp == null)
continue;
if(tmp.removable && (force || (curr_time - tmp.timestamp) >= max_age)) {
it.remove();
}
}
} | [
"public",
"void",
"removeMarkedElements",
"(",
"boolean",
"force",
")",
"{",
"long",
"curr_time",
"=",
"System",
".",
"nanoTime",
"(",
")",
";",
"for",
"(",
"Iterator",
"<",
"Map",
".",
"Entry",
"<",
"K",
",",
"Entry",
"<",
"V",
">",
">",
">",
"it",
... | Removes elements marked as removable
@param force If set to true, all elements marked as 'removable' will get removed, regardless of expiration | [
"Removes",
"elements",
"marked",
"as",
"removable"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/blocks/LazyRemovalCache.java#L244-L255 | train |
belaban/JGroups | src/org/jgroups/util/MatchingPromise.java | MatchingPromise.setResult | public void setResult(T result) {
lock.lock();
try {
if(Objects.equals(expected_result, result))
super.setResult(result);
}
finally {
lock.unlock();
}
} | java | public void setResult(T result) {
lock.lock();
try {
if(Objects.equals(expected_result, result))
super.setResult(result);
}
finally {
lock.unlock();
}
} | [
"public",
"void",
"setResult",
"(",
"T",
"result",
")",
"{",
"lock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"if",
"(",
"Objects",
".",
"equals",
"(",
"expected_result",
",",
"result",
")",
")",
"super",
".",
"setResult",
"(",
"result",
")",
";",
"... | Sets the result only if expected_result matches result | [
"Sets",
"the",
"result",
"only",
"if",
"expected_result",
"matches",
"result"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/MatchingPromise.java#L22-L31 | train |
belaban/JGroups | src/org/jgroups/protocols/S3_PING.java | S3_PING.sanitize | protected static String sanitize(final String name) {
String retval=name;
retval=retval.replace('/', '-');
retval=retval.replace('\\', '-');
return retval;
} | java | protected static String sanitize(final String name) {
String retval=name;
retval=retval.replace('/', '-');
retval=retval.replace('\\', '-');
return retval;
} | [
"protected",
"static",
"String",
"sanitize",
"(",
"final",
"String",
"name",
")",
"{",
"String",
"retval",
"=",
"name",
";",
"retval",
"=",
"retval",
".",
"replace",
"(",
"'",
"'",
",",
"'",
"'",
")",
";",
"retval",
"=",
"retval",
".",
"replace",
"("... | Sanitizes bucket and folder names according to AWS guidelines | [
"Sanitizes",
"bucket",
"and",
"folder",
"names",
"according",
"to",
"AWS",
"guidelines"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/protocols/S3_PING.java#L278-L283 | train |
belaban/JGroups | src/org/jgroups/blocks/executor/ExecutionRunner.java | ExecutionRunner.getCurrentRunningTasks | public Map<Thread, Runnable> getCurrentRunningTasks() {
Map<Thread, Runnable> map = new HashMap<>();
for (Entry<Thread, Holder<Runnable>> entry : _runnables.entrySet()) {
map.put(entry.getKey(), entry.getValue().value);
}
return map;
} | java | public Map<Thread, Runnable> getCurrentRunningTasks() {
Map<Thread, Runnable> map = new HashMap<>();
for (Entry<Thread, Holder<Runnable>> entry : _runnables.entrySet()) {
map.put(entry.getKey(), entry.getValue().value);
}
return map;
} | [
"public",
"Map",
"<",
"Thread",
",",
"Runnable",
">",
"getCurrentRunningTasks",
"(",
")",
"{",
"Map",
"<",
"Thread",
",",
"Runnable",
">",
"map",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"for",
"(",
"Entry",
"<",
"Thread",
",",
"Holder",
"<",
"Run... | Returns a copy of the runners being used with the runner and what threads.
If a thread is not currently running a task it will return with a null
value. This map is a copy and can be modified if necessary without
causing issues.
@return map of all threads that are active with this runner. If the
thread is currently running a job the runnable value will be
populated otherwise null would mean the thread is waiting | [
"Returns",
"a",
"copy",
"of",
"the",
"runners",
"being",
"used",
"with",
"the",
"runner",
"and",
"what",
"threads",
".",
"If",
"a",
"thread",
"is",
"not",
"currently",
"running",
"a",
"task",
"it",
"will",
"return",
"with",
"a",
"null",
"value",
".",
"... | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/blocks/executor/ExecutionRunner.java#L153-L159 | train |
belaban/JGroups | src/org/jgroups/util/BoundedList.java | BoundedList.add | public boolean add(T obj) {
if(obj == null) return false;
while(size() >= max_capacity && size() > 0) {
poll();
}
return super.add(obj);
} | java | public boolean add(T obj) {
if(obj == null) return false;
while(size() >= max_capacity && size() > 0) {
poll();
}
return super.add(obj);
} | [
"public",
"boolean",
"add",
"(",
"T",
"obj",
")",
"{",
"if",
"(",
"obj",
"==",
"null",
")",
"return",
"false",
";",
"while",
"(",
"size",
"(",
")",
">=",
"max_capacity",
"&&",
"size",
"(",
")",
">",
"0",
")",
"{",
"poll",
"(",
")",
";",
"}",
... | Adds an element at the tail. Removes an object from the head if capacity is exceeded
@param obj The object to be added | [
"Adds",
"an",
"element",
"at",
"the",
"tail",
".",
"Removes",
"an",
"object",
"from",
"the",
"head",
"if",
"capacity",
"is",
"exceeded"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/BoundedList.java#L30-L36 | train |
belaban/JGroups | src/org/jgroups/fork/ForkChannel.java | ForkChannel.getFORK | protected static FORK getFORK(JChannel ch, ProtocolStack.Position position, Class<? extends Protocol> neighbor,
boolean create_fork_if_absent) throws Exception {
ProtocolStack stack=ch.getProtocolStack();
FORK fork=stack.findProtocol(FORK.class);
if(fork == null) {
if(!create_fork_if_absent)
throw new IllegalArgumentException("FORK not found in main stack");
fork = new FORK();
fork.setProtocolStack(stack);
stack.insertProtocol(fork, position, neighbor);
}
return fork;
} | java | protected static FORK getFORK(JChannel ch, ProtocolStack.Position position, Class<? extends Protocol> neighbor,
boolean create_fork_if_absent) throws Exception {
ProtocolStack stack=ch.getProtocolStack();
FORK fork=stack.findProtocol(FORK.class);
if(fork == null) {
if(!create_fork_if_absent)
throw new IllegalArgumentException("FORK not found in main stack");
fork = new FORK();
fork.setProtocolStack(stack);
stack.insertProtocol(fork, position, neighbor);
}
return fork;
} | [
"protected",
"static",
"FORK",
"getFORK",
"(",
"JChannel",
"ch",
",",
"ProtocolStack",
".",
"Position",
"position",
",",
"Class",
"<",
"?",
"extends",
"Protocol",
">",
"neighbor",
",",
"boolean",
"create_fork_if_absent",
")",
"throws",
"Exception",
"{",
"Protoco... | Creates a new FORK protocol, or returns the existing one, or throws an exception. Never returns null. | [
"Creates",
"a",
"new",
"FORK",
"protocol",
"or",
"returns",
"the",
"existing",
"one",
"or",
"throws",
"an",
"exception",
".",
"Never",
"returns",
"null",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/fork/ForkChannel.java#L272-L284 | train |
belaban/JGroups | src/org/jgroups/fork/ForkChannel.java | ForkChannel.copyFields | protected void copyFields() {
for(Field field: copied_fields) {
Object value=Util.getField(field,main_channel);
Util.setField(field, this, value);
}
} | java | protected void copyFields() {
for(Field field: copied_fields) {
Object value=Util.getField(field,main_channel);
Util.setField(field, this, value);
}
} | [
"protected",
"void",
"copyFields",
"(",
")",
"{",
"for",
"(",
"Field",
"field",
":",
"copied_fields",
")",
"{",
"Object",
"value",
"=",
"Util",
".",
"getField",
"(",
"field",
",",
"main_channel",
")",
";",
"Util",
".",
"setField",
"(",
"field",
",",
"t... | Copies state from main-channel to this fork-channel | [
"Copies",
"state",
"from",
"main",
"-",
"channel",
"to",
"this",
"fork",
"-",
"channel"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/fork/ForkChannel.java#L298-L303 | train |
belaban/JGroups | src/org/jgroups/JChannelProbeHandler.java | JChannelProbeHandler.dumpAttrsSelectedProtocol | protected Map<String,Map<String,Object>> dumpAttrsSelectedProtocol(String protocol_name, List<String> attrs) {
return ch.dumpStats(protocol_name, attrs);
} | java | protected Map<String,Map<String,Object>> dumpAttrsSelectedProtocol(String protocol_name, List<String> attrs) {
return ch.dumpStats(protocol_name, attrs);
} | [
"protected",
"Map",
"<",
"String",
",",
"Map",
"<",
"String",
",",
"Object",
">",
">",
"dumpAttrsSelectedProtocol",
"(",
"String",
"protocol_name",
",",
"List",
"<",
"String",
">",
"attrs",
")",
"{",
"return",
"ch",
".",
"dumpStats",
"(",
"protocol_name",
... | Dumps attributes and their values of a given protocol.
@param protocol_name The name of the protocol
@param attrs A list of attributes that need to be returned. If null, all attributes of the given protocol will
be returned
@return A map of protocol names as keys and maps (of attribute names and values) as values | [
"Dumps",
"attributes",
"and",
"their",
"values",
"of",
"a",
"given",
"protocol",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/JChannelProbeHandler.java#L193-L195 | train |
belaban/JGroups | src/org/jgroups/JChannelProbeHandler.java | JChannelProbeHandler.handleOperation | protected void handleOperation(Map<String, String> map, String operation) throws Exception {
int index=operation.indexOf('.');
if(index == -1)
throw new IllegalArgumentException("operation " + operation + " is missing the protocol name");
String prot_name=operation.substring(0, index);
Protocol prot=ch.getProtocolStack().findProtocol(prot_name);
if(prot == null) {
log.error("protocol %s not found", prot_name);
return; // less drastic than throwing an exception...
}
int args_index=operation.indexOf('[');
String method_name;
if(args_index != -1)
method_name=operation.substring(index +1, args_index).trim();
else
method_name=operation.substring(index+1).trim();
String[] args=null;
if(args_index != -1) {
int end_index=operation.indexOf(']');
if(end_index == -1)
throw new IllegalArgumentException("] not found");
List<String> str_args=Util.parseCommaDelimitedStrings(operation.substring(args_index + 1, end_index));
Object[] strings=str_args.toArray();
args=new String[strings.length];
for(int i=0; i < strings.length; i++)
args[i]=(String)strings[i];
}
Method method=findMethod(prot, method_name, args);
MethodCall call=new MethodCall(method);
Object[] converted_args=null;
if(args != null) {
converted_args=new Object[args.length];
Class<?>[] types=method.getParameterTypes();
for(int i=0; i < args.length; i++)
converted_args[i]=Util.convert(args[i], types[i]);
}
Object retval=call.invoke(prot, converted_args);
if(retval != null)
map.put(prot_name + "." + method_name, retval.toString());
} | java | protected void handleOperation(Map<String, String> map, String operation) throws Exception {
int index=operation.indexOf('.');
if(index == -1)
throw new IllegalArgumentException("operation " + operation + " is missing the protocol name");
String prot_name=operation.substring(0, index);
Protocol prot=ch.getProtocolStack().findProtocol(prot_name);
if(prot == null) {
log.error("protocol %s not found", prot_name);
return; // less drastic than throwing an exception...
}
int args_index=operation.indexOf('[');
String method_name;
if(args_index != -1)
method_name=operation.substring(index +1, args_index).trim();
else
method_name=operation.substring(index+1).trim();
String[] args=null;
if(args_index != -1) {
int end_index=operation.indexOf(']');
if(end_index == -1)
throw new IllegalArgumentException("] not found");
List<String> str_args=Util.parseCommaDelimitedStrings(operation.substring(args_index + 1, end_index));
Object[] strings=str_args.toArray();
args=new String[strings.length];
for(int i=0; i < strings.length; i++)
args[i]=(String)strings[i];
}
Method method=findMethod(prot, method_name, args);
MethodCall call=new MethodCall(method);
Object[] converted_args=null;
if(args != null) {
converted_args=new Object[args.length];
Class<?>[] types=method.getParameterTypes();
for(int i=0; i < args.length; i++)
converted_args[i]=Util.convert(args[i], types[i]);
}
Object retval=call.invoke(prot, converted_args);
if(retval != null)
map.put(prot_name + "." + method_name, retval.toString());
} | [
"protected",
"void",
"handleOperation",
"(",
"Map",
"<",
"String",
",",
"String",
">",
"map",
",",
"String",
"operation",
")",
"throws",
"Exception",
"{",
"int",
"index",
"=",
"operation",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"index",
"=... | Invokes an operation and puts the return value into map
@param map
@param operation Protocol.OperationName[args], e.g. STABLE.foo[arg1 arg2 arg3] | [
"Invokes",
"an",
"operation",
"and",
"puts",
"the",
"return",
"value",
"into",
"map"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/JChannelProbeHandler.java#L241-L283 | train |
belaban/JGroups | src/org/jgroups/protocols/SenderSendsBundler.java | SenderSendsBundler.send | public void send(Message msg) throws Exception {
num_senders.incrementAndGet();
long size=msg.size();
lock.lock();
try {
if(count + size >= transport.getMaxBundleSize())
sendBundledMessages();
addMessage(msg, size);
// at this point, we haven't sent our message yet !
if(num_senders.decrementAndGet() == 0) // no other sender threads present at this time
sendBundledMessages();
// else there are other sender threads waiting, so our message will be sent by a different thread
}
finally {
lock.unlock();
}
} | java | public void send(Message msg) throws Exception {
num_senders.incrementAndGet();
long size=msg.size();
lock.lock();
try {
if(count + size >= transport.getMaxBundleSize())
sendBundledMessages();
addMessage(msg, size);
// at this point, we haven't sent our message yet !
if(num_senders.decrementAndGet() == 0) // no other sender threads present at this time
sendBundledMessages();
// else there are other sender threads waiting, so our message will be sent by a different thread
}
finally {
lock.unlock();
}
} | [
"public",
"void",
"send",
"(",
"Message",
"msg",
")",
"throws",
"Exception",
"{",
"num_senders",
".",
"incrementAndGet",
"(",
")",
";",
"long",
"size",
"=",
"msg",
".",
"size",
"(",
")",
";",
"lock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"if",
"(... | current senders adding msgs to the bundler | [
"current",
"senders",
"adding",
"msgs",
"to",
"the",
"bundler"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/protocols/SenderSendsBundler.java#L14-L33 | train |
belaban/JGroups | src/org/jgroups/util/Table.java | Table.getNumDeliverable | public int getNumDeliverable() {
NumDeliverable visitor=new NumDeliverable();
lock.lock();
try {
forEach(hd+1, hr, visitor);
return visitor.getResult();
}
finally {
lock.unlock();
}
} | java | public int getNumDeliverable() {
NumDeliverable visitor=new NumDeliverable();
lock.lock();
try {
forEach(hd+1, hr, visitor);
return visitor.getResult();
}
finally {
lock.unlock();
}
} | [
"public",
"int",
"getNumDeliverable",
"(",
")",
"{",
"NumDeliverable",
"visitor",
"=",
"new",
"NumDeliverable",
"(",
")",
";",
"lock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"forEach",
"(",
"hd",
"+",
"1",
",",
"hr",
",",
"visitor",
")",
";",
"retur... | Returns the number of messages that can be delivered | [
"Returns",
"the",
"number",
"of",
"messages",
"that",
"can",
"be",
"delivered"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Table.java#L167-L177 | train |
belaban/JGroups | src/org/jgroups/util/Table.java | Table.add | public boolean add(final List<LongTuple<T>> list, boolean remove_added_elements) {
return add(list, remove_added_elements, null);
} | java | public boolean add(final List<LongTuple<T>> list, boolean remove_added_elements) {
return add(list, remove_added_elements, null);
} | [
"public",
"boolean",
"add",
"(",
"final",
"List",
"<",
"LongTuple",
"<",
"T",
">",
">",
"list",
",",
"boolean",
"remove_added_elements",
")",
"{",
"return",
"add",
"(",
"list",
",",
"remove_added_elements",
",",
"null",
")",
";",
"}"
] | Adds elements from list to the table, removes elements from list that were not added to the table
@param list
@return True if at least 1 element was added successfully. This guarantees that the list has at least 1 element | [
"Adds",
"elements",
"from",
"list",
"to",
"the",
"table",
"removes",
"elements",
"from",
"list",
"that",
"were",
"not",
"added",
"to",
"the",
"table"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Table.java#L244-L246 | train |
belaban/JGroups | src/org/jgroups/util/Table.java | Table.add | public boolean add(final List<LongTuple<T>> list, boolean remove_added_elements, T const_value) {
if(list == null || list.isEmpty())
return false;
boolean added=false;
// find the highest seqno (unfortunately, the list is not ordered by seqno)
long highest_seqno=findHighestSeqno(list);
lock.lock();
try {
if(highest_seqno != -1 && computeRow(highest_seqno) >= matrix.length)
resize(highest_seqno);
for(Iterator<LongTuple<T>> it=list.iterator(); it.hasNext();) {
LongTuple<T> tuple=it.next();
long seqno=tuple.getVal1();
T element=const_value != null? const_value : tuple.getVal2();
if(_add(seqno, element, false, null))
added=true;
else if(remove_added_elements)
it.remove();
}
return added;
}
finally {
lock.unlock();
}
} | java | public boolean add(final List<LongTuple<T>> list, boolean remove_added_elements, T const_value) {
if(list == null || list.isEmpty())
return false;
boolean added=false;
// find the highest seqno (unfortunately, the list is not ordered by seqno)
long highest_seqno=findHighestSeqno(list);
lock.lock();
try {
if(highest_seqno != -1 && computeRow(highest_seqno) >= matrix.length)
resize(highest_seqno);
for(Iterator<LongTuple<T>> it=list.iterator(); it.hasNext();) {
LongTuple<T> tuple=it.next();
long seqno=tuple.getVal1();
T element=const_value != null? const_value : tuple.getVal2();
if(_add(seqno, element, false, null))
added=true;
else if(remove_added_elements)
it.remove();
}
return added;
}
finally {
lock.unlock();
}
} | [
"public",
"boolean",
"add",
"(",
"final",
"List",
"<",
"LongTuple",
"<",
"T",
">",
">",
"list",
",",
"boolean",
"remove_added_elements",
",",
"T",
"const_value",
")",
"{",
"if",
"(",
"list",
"==",
"null",
"||",
"list",
".",
"isEmpty",
"(",
")",
")",
... | Adds elements from the list to the table
@param list The list of tuples of seqnos and elements. If remove_added_elements is true, if elements could
not be added to the table (e.g. because they were already present or the seqno was < HD), those
elements will be removed from list
@param remove_added_elements If true, elements that could not be added to the table are removed from list
@param const_value If non-null, this value should be used rather than the values of the list tuples
@return True if at least 1 element was added successfully, false otherwise. | [
"Adds",
"elements",
"from",
"the",
"list",
"to",
"the",
"table"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Table.java#L257-L282 | train |
belaban/JGroups | src/org/jgroups/util/Table.java | Table.get | public T get(long seqno) {
lock.lock();
try {
if(seqno - low <= 0 || seqno - hr > 0)
return null;
int row_index=computeRow(seqno);
if(row_index < 0 || row_index >= matrix.length)
return null;
T[] row=matrix[row_index];
if(row == null)
return null;
int index=computeIndex(seqno);
return index >= 0? row[index] : null;
}
finally {
lock.unlock();
}
} | java | public T get(long seqno) {
lock.lock();
try {
if(seqno - low <= 0 || seqno - hr > 0)
return null;
int row_index=computeRow(seqno);
if(row_index < 0 || row_index >= matrix.length)
return null;
T[] row=matrix[row_index];
if(row == null)
return null;
int index=computeIndex(seqno);
return index >= 0? row[index] : null;
}
finally {
lock.unlock();
}
} | [
"public",
"T",
"get",
"(",
"long",
"seqno",
")",
"{",
"lock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"if",
"(",
"seqno",
"-",
"low",
"<=",
"0",
"||",
"seqno",
"-",
"hr",
">",
"0",
")",
"return",
"null",
";",
"int",
"row_index",
"=",
"computeRo... | Returns an element at seqno
@param seqno
@return | [
"Returns",
"an",
"element",
"at",
"seqno"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Table.java#L290-L307 | train |
belaban/JGroups | src/org/jgroups/util/Table.java | Table._get | public T _get(long seqno) {
lock.lock();
try {
int row_index=computeRow(seqno);
if(row_index < 0 || row_index >= matrix.length)
return null;
T[] row=matrix[row_index];
if(row == null)
return null;
int index=computeIndex(seqno);
return index >= 0? row[index] : null;
}
finally {
lock.unlock();
}
} | java | public T _get(long seqno) {
lock.lock();
try {
int row_index=computeRow(seqno);
if(row_index < 0 || row_index >= matrix.length)
return null;
T[] row=matrix[row_index];
if(row == null)
return null;
int index=computeIndex(seqno);
return index >= 0? row[index] : null;
}
finally {
lock.unlock();
}
} | [
"public",
"T",
"_get",
"(",
"long",
"seqno",
")",
"{",
"lock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"int",
"row_index",
"=",
"computeRow",
"(",
"seqno",
")",
";",
"if",
"(",
"row_index",
"<",
"0",
"||",
"row_index",
">=",
"matrix",
".",
"length"... | To be used only for testing; doesn't do any index or sanity checks
@param seqno
@return | [
"To",
"be",
"used",
"only",
"for",
"testing",
";",
"doesn",
"t",
"do",
"any",
"index",
"or",
"sanity",
"checks"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Table.java#L315-L330 | train |
belaban/JGroups | src/org/jgroups/util/Table.java | Table.remove | public T remove(boolean nullify) {
lock.lock();
try {
int row_index=computeRow(hd+1);
if(row_index < 0 || row_index >= matrix.length)
return null;
T[] row=matrix[row_index];
if(row == null)
return null;
int index=computeIndex(hd+1);
if(index < 0)
return null;
T existing_element=row[index];
if(existing_element != null) {
hd++;
size=Math.max(size-1, 0); // cannot be < 0 (well that would be a bug, but let's have this 2nd line of defense !)
if(nullify) {
row[index]=null;
if(hd - low > 0)
low=hd;
}
}
return existing_element;
}
finally {
lock.unlock();
}
} | java | public T remove(boolean nullify) {
lock.lock();
try {
int row_index=computeRow(hd+1);
if(row_index < 0 || row_index >= matrix.length)
return null;
T[] row=matrix[row_index];
if(row == null)
return null;
int index=computeIndex(hd+1);
if(index < 0)
return null;
T existing_element=row[index];
if(existing_element != null) {
hd++;
size=Math.max(size-1, 0); // cannot be < 0 (well that would be a bug, but let's have this 2nd line of defense !)
if(nullify) {
row[index]=null;
if(hd - low > 0)
low=hd;
}
}
return existing_element;
}
finally {
lock.unlock();
}
} | [
"public",
"T",
"remove",
"(",
"boolean",
"nullify",
")",
"{",
"lock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"int",
"row_index",
"=",
"computeRow",
"(",
"hd",
"+",
"1",
")",
";",
"if",
"(",
"row_index",
"<",
"0",
"||",
"row_index",
">=",
"matrix",... | Removes the next non-null element and nulls the index if nullify=true | [
"Removes",
"the",
"next",
"non",
"-",
"null",
"element",
"and",
"nulls",
"the",
"index",
"if",
"nullify",
"=",
"true"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Table.java#L338-L365 | train |
belaban/JGroups | src/org/jgroups/util/Table.java | Table.removeMany | public <R> R removeMany(boolean nullify, int max_results, Predicate<T> filter,
Supplier<R> result_creator, BiConsumer<R,T> accumulator) {
lock.lock();
try {
Remover<R> remover=new Remover<>(nullify, max_results, filter, result_creator, accumulator);
forEach(hd+1, hr, remover);
return remover.getResult();
}
finally {
lock.unlock();
}
} | java | public <R> R removeMany(boolean nullify, int max_results, Predicate<T> filter,
Supplier<R> result_creator, BiConsumer<R,T> accumulator) {
lock.lock();
try {
Remover<R> remover=new Remover<>(nullify, max_results, filter, result_creator, accumulator);
forEach(hd+1, hr, remover);
return remover.getResult();
}
finally {
lock.unlock();
}
} | [
"public",
"<",
"R",
">",
"R",
"removeMany",
"(",
"boolean",
"nullify",
",",
"int",
"max_results",
",",
"Predicate",
"<",
"T",
">",
"filter",
",",
"Supplier",
"<",
"R",
">",
"result_creator",
",",
"BiConsumer",
"<",
"R",
",",
"T",
">",
"accumulator",
")... | Removes elements from the table and adds them to the result created by result_creator. Between 0 and max_results
elements are removed. If no elements were removed, processing will be set to true while the table lock is held.
@param nullify if true, the x,y location of the removed element in the matrix will be nulled
@param max_results the max number of results to be returned, even if more elements would be removable
@param filter a filter which accepts (or rejects) elements into the result. If null, all elements will be accepted
@param result_creator a supplier required to create the result, e.g. ArrayList::new
@param accumulator an accumulator accepting the result and an element, e.g. ArrayList::add
@param <R> the type of the result
@return the result | [
"Removes",
"elements",
"from",
"the",
"table",
"and",
"adds",
"them",
"to",
"the",
"result",
"created",
"by",
"result_creator",
".",
"Between",
"0",
"and",
"max_results",
"elements",
"are",
"removed",
".",
"If",
"no",
"elements",
"were",
"removed",
"processing... | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Table.java#L388-L399 | train |
belaban/JGroups | src/org/jgroups/util/Table.java | Table.findHighestSeqno | protected long findHighestSeqno(List<LongTuple<T>> list) {
long seqno=-1;
for(LongTuple<T> tuple: list) {
long val=tuple.getVal1();
if(val - seqno > 0)
seqno=val;
}
return seqno;
} | java | protected long findHighestSeqno(List<LongTuple<T>> list) {
long seqno=-1;
for(LongTuple<T> tuple: list) {
long val=tuple.getVal1();
if(val - seqno > 0)
seqno=val;
}
return seqno;
} | [
"protected",
"long",
"findHighestSeqno",
"(",
"List",
"<",
"LongTuple",
"<",
"T",
">",
">",
"list",
")",
"{",
"long",
"seqno",
"=",
"-",
"1",
";",
"for",
"(",
"LongTuple",
"<",
"T",
">",
"tuple",
":",
"list",
")",
"{",
"long",
"val",
"=",
"tuple",
... | list must not be null or empty | [
"list",
"must",
"not",
"be",
"null",
"or",
"empty"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Table.java#L561-L569 | train |
belaban/JGroups | src/org/jgroups/util/Table.java | Table.getMissing | public SeqnoList getMissing(int max_msgs) {
lock.lock();
try {
if(size == 0)
return null;
long start_seqno=getHighestDeliverable() +1;
int capacity=(int)(hr - start_seqno);
int max_size=max_msgs > 0? Math.min(max_msgs, capacity) : capacity;
if(max_size <= 0)
return null;
Missing missing=new Missing(start_seqno, max_size);
long to=max_size > 0? Math.min(start_seqno + max_size-1, hr-1) : hr-1;
forEach(start_seqno, to, missing);
return missing.getMissingElements();
}
finally {
lock.unlock();
}
} | java | public SeqnoList getMissing(int max_msgs) {
lock.lock();
try {
if(size == 0)
return null;
long start_seqno=getHighestDeliverable() +1;
int capacity=(int)(hr - start_seqno);
int max_size=max_msgs > 0? Math.min(max_msgs, capacity) : capacity;
if(max_size <= 0)
return null;
Missing missing=new Missing(start_seqno, max_size);
long to=max_size > 0? Math.min(start_seqno + max_size-1, hr-1) : hr-1;
forEach(start_seqno, to, missing);
return missing.getMissingElements();
}
finally {
lock.unlock();
}
} | [
"public",
"SeqnoList",
"getMissing",
"(",
"int",
"max_msgs",
")",
"{",
"lock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"if",
"(",
"size",
"==",
"0",
")",
"return",
"null",
";",
"long",
"start_seqno",
"=",
"getHighestDeliverable",
"(",
")",
"+",
"1",
... | Returns a list of missing messages
@param max_msgs If > 0, the max number of missing messages to be returned (oldest first), else no limit
@return A SeqnoList of missing messages, or null if no messages are missing | [
"Returns",
"a",
"list",
"of",
"missing",
"messages"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Table.java#L667-L685 | train |
belaban/JGroups | src/org/jgroups/util/Table.java | Table.dump | public String dump() {
lock.lock();
try {
return stream(low, hr).filter(Objects::nonNull).map(Object::toString)
.collect(Collectors.joining(", "));
}
finally {
lock.unlock();
}
} | java | public String dump() {
lock.lock();
try {
return stream(low, hr).filter(Objects::nonNull).map(Object::toString)
.collect(Collectors.joining(", "));
}
finally {
lock.unlock();
}
} | [
"public",
"String",
"dump",
"(",
")",
"{",
"lock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"return",
"stream",
"(",
"low",
",",
"hr",
")",
".",
"filter",
"(",
"Objects",
"::",
"nonNull",
")",
".",
"map",
"(",
"Object",
"::",
"toString",
")",
".",... | Dumps the seqnos in the table as a list | [
"Dumps",
"the",
"seqnos",
"in",
"the",
"table",
"as",
"a",
"list"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Table.java#L704-L713 | train |
belaban/JGroups | src/org/jgroups/util/Table.java | Table.getRow | @GuardedBy("lock")
protected T[] getRow(int index) {
T[] row=matrix[index];
if(row == null) {
row=(T[])new Object[elements_per_row];
matrix[index]=row;
}
return row;
} | java | @GuardedBy("lock")
protected T[] getRow(int index) {
T[] row=matrix[index];
if(row == null) {
row=(T[])new Object[elements_per_row];
matrix[index]=row;
}
return row;
} | [
"@",
"GuardedBy",
"(",
"\"lock\"",
")",
"protected",
"T",
"[",
"]",
"getRow",
"(",
"int",
"index",
")",
"{",
"T",
"[",
"]",
"row",
"=",
"matrix",
"[",
"index",
"]",
";",
"if",
"(",
"row",
"==",
"null",
")",
"{",
"row",
"=",
"(",
"T",
"[",
"]"... | Returns a row. Creates a new row and inserts it at index if the row at index doesn't exist
@param index
@return A row | [
"Returns",
"a",
"row",
".",
"Creates",
"a",
"new",
"row",
"and",
"inserts",
"it",
"at",
"index",
"if",
"the",
"row",
"at",
"index",
"doesn",
"t",
"exist"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Table.java#L722-L730 | train |
belaban/JGroups | src/org/jgroups/protocols/KeyExchange.java | KeyExchange.getSecretKeyFromAbove | protected Tuple<SecretKey,byte[]> getSecretKeyFromAbove() {
return (Tuple<SecretKey,byte[]>)up_prot.up(new Event(Event.GET_SECRET_KEY));
} | java | protected Tuple<SecretKey,byte[]> getSecretKeyFromAbove() {
return (Tuple<SecretKey,byte[]>)up_prot.up(new Event(Event.GET_SECRET_KEY));
} | [
"protected",
"Tuple",
"<",
"SecretKey",
",",
"byte",
"[",
"]",
">",
"getSecretKeyFromAbove",
"(",
")",
"{",
"return",
"(",
"Tuple",
"<",
"SecretKey",
",",
"byte",
"[",
"]",
">",
")",
"up_prot",
".",
"up",
"(",
"new",
"Event",
"(",
"Event",
".",
"GET_... | Fetches the secret key from a protocol above us
@return The secret key and its version | [
"Fetches",
"the",
"secret",
"key",
"from",
"a",
"protocol",
"above",
"us"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/protocols/KeyExchange.java#L56-L58 | train |
belaban/JGroups | src/org/jgroups/protocols/KeyExchange.java | KeyExchange.setSecretKeyAbove | protected void setSecretKeyAbove(Tuple<SecretKey,byte[]> key) {
up_prot.up(new Event(Event.SET_SECRET_KEY, key));
} | java | protected void setSecretKeyAbove(Tuple<SecretKey,byte[]> key) {
up_prot.up(new Event(Event.SET_SECRET_KEY, key));
} | [
"protected",
"void",
"setSecretKeyAbove",
"(",
"Tuple",
"<",
"SecretKey",
",",
"byte",
"[",
"]",
">",
"key",
")",
"{",
"up_prot",
".",
"up",
"(",
"new",
"Event",
"(",
"Event",
".",
"SET_SECRET_KEY",
",",
"key",
")",
")",
";",
"}"
] | Sets the secret key in a protocol above us
@param key The secret key and its version | [
"Sets",
"the",
"secret",
"key",
"in",
"a",
"protocol",
"above",
"us"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/protocols/KeyExchange.java#L63-L65 | train |
belaban/JGroups | src/org/jgroups/conf/ConfiguratorFactory.java | ConfiguratorFactory.getStackConfigurator | public static ProtocolStackConfigurator getStackConfigurator(File file) throws Exception {
checkJAXPAvailability();
InputStream input=getConfigStream(file);
return XmlConfigurator.getInstance(input);
} | java | public static ProtocolStackConfigurator getStackConfigurator(File file) throws Exception {
checkJAXPAvailability();
InputStream input=getConfigStream(file);
return XmlConfigurator.getInstance(input);
} | [
"public",
"static",
"ProtocolStackConfigurator",
"getStackConfigurator",
"(",
"File",
"file",
")",
"throws",
"Exception",
"{",
"checkJAXPAvailability",
"(",
")",
";",
"InputStream",
"input",
"=",
"getConfigStream",
"(",
"file",
")",
";",
"return",
"XmlConfigurator",
... | Returns a protocol stack configurator based on the XML configuration provided by the specified File.
@param file a File with a JGroups XML configuration.
@return a {@code ProtocolStackConfigurator} containing the stack configuration.
@throws Exception if problems occur during the configuration of the protocol stack. | [
"Returns",
"a",
"protocol",
"stack",
"configurator",
"based",
"on",
"the",
"XML",
"configuration",
"provided",
"by",
"the",
"specified",
"File",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/conf/ConfiguratorFactory.java#L42-L46 | train |
belaban/JGroups | src/org/jgroups/conf/ConfiguratorFactory.java | ConfiguratorFactory.getStackConfigurator | public static ProtocolStackConfigurator getStackConfigurator(URL url) throws Exception {
checkForNullConfiguration(url);
checkJAXPAvailability();
return XmlConfigurator.getInstance(url);
} | java | public static ProtocolStackConfigurator getStackConfigurator(URL url) throws Exception {
checkForNullConfiguration(url);
checkJAXPAvailability();
return XmlConfigurator.getInstance(url);
} | [
"public",
"static",
"ProtocolStackConfigurator",
"getStackConfigurator",
"(",
"URL",
"url",
")",
"throws",
"Exception",
"{",
"checkForNullConfiguration",
"(",
"url",
")",
";",
"checkJAXPAvailability",
"(",
")",
";",
"return",
"XmlConfigurator",
".",
"getInstance",
"("... | Returns a protocol stack configurator based on the XML configuration provided at the specified URL.
@param url a URL pointing to a JGroups XML configuration.
@return a {@code ProtocolStackConfigurator} containing the stack configuration.
@throws Exception if problems occur during the configuration of the protocol stack. | [
"Returns",
"a",
"protocol",
"stack",
"configurator",
"based",
"on",
"the",
"XML",
"configuration",
"provided",
"at",
"the",
"specified",
"URL",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/conf/ConfiguratorFactory.java#L59-L63 | train |
belaban/JGroups | src/org/jgroups/conf/ConfiguratorFactory.java | ConfiguratorFactory.getStackConfigurator | public static ProtocolStackConfigurator getStackConfigurator(Element element) throws Exception {
checkForNullConfiguration(element);
return XmlConfigurator.getInstance(element);
} | java | public static ProtocolStackConfigurator getStackConfigurator(Element element) throws Exception {
checkForNullConfiguration(element);
return XmlConfigurator.getInstance(element);
} | [
"public",
"static",
"ProtocolStackConfigurator",
"getStackConfigurator",
"(",
"Element",
"element",
")",
"throws",
"Exception",
"{",
"checkForNullConfiguration",
"(",
"element",
")",
";",
"return",
"XmlConfigurator",
".",
"getInstance",
"(",
"element",
")",
";",
"}"
] | Returns a protocol stack configurator based on the XML configuration provided by the specified XML element.
@param element a XML element containing a JGroups XML configuration.
@return a {@code ProtocolStackConfigurator} containing the stack configuration.
@throws Exception if problems occur during the configuration of the protocol stack. | [
"Returns",
"a",
"protocol",
"stack",
"configurator",
"based",
"on",
"the",
"XML",
"configuration",
"provided",
"by",
"the",
"specified",
"XML",
"element",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/conf/ConfiguratorFactory.java#L72-L75 | train |
belaban/JGroups | src/org/jgroups/conf/ConfiguratorFactory.java | ConfiguratorFactory.getStackConfigurator | public static ProtocolStackConfigurator getStackConfigurator(String properties) throws Exception {
if(properties == null)
properties=Global.DEFAULT_PROTOCOL_STACK;
// Attempt to treat the properties string as a pointer to an XML configuration.
XmlConfigurator configurator = null;
checkForNullConfiguration(properties);
configurator=getXmlConfigurator(properties);
if(configurator != null) // did the properties string point to a JGroups XML configuration ?
return configurator;
throw new IllegalStateException(String.format("configuration %s not found or invalid", properties));
} | java | public static ProtocolStackConfigurator getStackConfigurator(String properties) throws Exception {
if(properties == null)
properties=Global.DEFAULT_PROTOCOL_STACK;
// Attempt to treat the properties string as a pointer to an XML configuration.
XmlConfigurator configurator = null;
checkForNullConfiguration(properties);
configurator=getXmlConfigurator(properties);
if(configurator != null) // did the properties string point to a JGroups XML configuration ?
return configurator;
throw new IllegalStateException(String.format("configuration %s not found or invalid", properties));
} | [
"public",
"static",
"ProtocolStackConfigurator",
"getStackConfigurator",
"(",
"String",
"properties",
")",
"throws",
"Exception",
"{",
"if",
"(",
"properties",
"==",
"null",
")",
"properties",
"=",
"Global",
".",
"DEFAULT_PROTOCOL_STACK",
";",
"// Attempt to treat the p... | Returns a protocol stack configurator based on the provided properties string.
@param properties a string representing a system resource containing a JGroups XML configuration, a URL pointing
to a JGroups XML configuration or a string representing a file name that contains a JGroups
XML configuration. | [
"Returns",
"a",
"protocol",
"stack",
"configurator",
"based",
"on",
"the",
"provided",
"properties",
"string",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/conf/ConfiguratorFactory.java#L83-L96 | train |
belaban/JGroups | src/org/jgroups/conf/ConfiguratorFactory.java | ConfiguratorFactory.getConfigStream | public static InputStream getConfigStream(String properties) throws IOException {
InputStream configStream = null;
// Check to see if the properties string is the name of a file.
try {
configStream=new FileInputStream(properties);
}
catch(FileNotFoundException | AccessControlException fnfe) {
// the properties string is likely not a file
}
// Check to see if the properties string is a URL.
if(configStream == null) {
try {
configStream=new URL(properties).openStream();
}
catch (MalformedURLException mre) {
// the properties string is not a URL
}
}
// Check to see if the properties string is the name of a resource, e.g. udp.xml.
if(configStream == null && properties.endsWith("xml"))
configStream=Util.getResourceAsStream(properties, ConfiguratorFactory.class);
return configStream;
} | java | public static InputStream getConfigStream(String properties) throws IOException {
InputStream configStream = null;
// Check to see if the properties string is the name of a file.
try {
configStream=new FileInputStream(properties);
}
catch(FileNotFoundException | AccessControlException fnfe) {
// the properties string is likely not a file
}
// Check to see if the properties string is a URL.
if(configStream == null) {
try {
configStream=new URL(properties).openStream();
}
catch (MalformedURLException mre) {
// the properties string is not a URL
}
}
// Check to see if the properties string is the name of a resource, e.g. udp.xml.
if(configStream == null && properties.endsWith("xml"))
configStream=Util.getResourceAsStream(properties, ConfiguratorFactory.class);
return configStream;
} | [
"public",
"static",
"InputStream",
"getConfigStream",
"(",
"String",
"properties",
")",
"throws",
"IOException",
"{",
"InputStream",
"configStream",
"=",
"null",
";",
"// Check to see if the properties string is the name of a file.",
"try",
"{",
"configStream",
"=",
"new",
... | Returns a JGroups XML configuration InputStream based on the provided properties string.
@param properties a string representing a system resource containing a JGroups XML configuration, a string
representing a URL pointing to a JGroups ML configuration, or a string representing
a file name that contains a JGroups XML configuration.
@throws IOException if the provided properties string appears to be a valid URL but is unreachable. | [
"Returns",
"a",
"JGroups",
"XML",
"configuration",
"InputStream",
"based",
"on",
"the",
"provided",
"properties",
"string",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/conf/ConfiguratorFactory.java#L122-L147 | train |
belaban/JGroups | src/org/jgroups/conf/ConfiguratorFactory.java | ConfiguratorFactory.checkJAXPAvailability | static void checkJAXPAvailability() {
try {
XmlConfigurator.class.getName();
}
catch (NoClassDefFoundError error) {
Error tmp=new NoClassDefFoundError(JAXP_MISSING_ERROR_MSG);
tmp.initCause(error);
throw tmp;
}
} | java | static void checkJAXPAvailability() {
try {
XmlConfigurator.class.getName();
}
catch (NoClassDefFoundError error) {
Error tmp=new NoClassDefFoundError(JAXP_MISSING_ERROR_MSG);
tmp.initCause(error);
throw tmp;
}
} | [
"static",
"void",
"checkJAXPAvailability",
"(",
")",
"{",
"try",
"{",
"XmlConfigurator",
".",
"class",
".",
"getName",
"(",
")",
";",
"}",
"catch",
"(",
"NoClassDefFoundError",
"error",
")",
"{",
"Error",
"tmp",
"=",
"new",
"NoClassDefFoundError",
"(",
"JAXP... | Checks the availability of the JAXP classes on the classpath.
@throws NoClassDefFoundError if the required JAXP classes are not availabile on the classpath. | [
"Checks",
"the",
"availability",
"of",
"the",
"JAXP",
"classes",
"on",
"the",
"classpath",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/conf/ConfiguratorFactory.java#L231-L240 | train |
belaban/JGroups | src/org/jgroups/util/RspList.java | RspList.getValue | public T getValue(Object key) {
Rsp<T> rsp=get(key);
return rsp != null? rsp.getValue() : null;
} | java | public T getValue(Object key) {
Rsp<T> rsp=get(key);
return rsp != null? rsp.getValue() : null;
} | [
"public",
"T",
"getValue",
"(",
"Object",
"key",
")",
"{",
"Rsp",
"<",
"T",
">",
"rsp",
"=",
"get",
"(",
"key",
")",
";",
"return",
"rsp",
"!=",
"null",
"?",
"rsp",
".",
"getValue",
"(",
")",
":",
"null",
";",
"}"
] | Returns the value associated with address key
@param key
@return Object value | [
"Returns",
"the",
"value",
"associated",
"with",
"address",
"key"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/RspList.java#L35-L38 | train |
belaban/JGroups | src/org/jgroups/util/RspList.java | RspList.getFirst | public T getFirst() {
Optional<Rsp<T>> retval=values().stream().filter(rsp -> rsp.getValue() != null).findFirst();
return retval.isPresent()? retval.get().getValue() : null;
} | java | public T getFirst() {
Optional<Rsp<T>> retval=values().stream().filter(rsp -> rsp.getValue() != null).findFirst();
return retval.isPresent()? retval.get().getValue() : null;
} | [
"public",
"T",
"getFirst",
"(",
")",
"{",
"Optional",
"<",
"Rsp",
"<",
"T",
">>",
"retval",
"=",
"values",
"(",
")",
".",
"stream",
"(",
")",
".",
"filter",
"(",
"rsp",
"->",
"rsp",
".",
"getValue",
"(",
")",
"!=",
"null",
")",
".",
"findFirst",
... | Returns the first value in the response set. This is random, but we try to return a non-null value first | [
"Returns",
"the",
"first",
"value",
"in",
"the",
"response",
"set",
".",
"This",
"is",
"random",
"but",
"we",
"try",
"to",
"return",
"a",
"non",
"-",
"null",
"value",
"first"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/RspList.java#L66-L69 | train |
belaban/JGroups | src/org/jgroups/util/RspList.java | RspList.getResults | public List<T> getResults() {
return values().stream().filter(rsp -> rsp.wasReceived() && rsp.getValue() != null)
.collect(() -> new ArrayList<>(size()), (list,rsp) -> list.add(rsp.getValue()), (l,r) -> {});
} | java | public List<T> getResults() {
return values().stream().filter(rsp -> rsp.wasReceived() && rsp.getValue() != null)
.collect(() -> new ArrayList<>(size()), (list,rsp) -> list.add(rsp.getValue()), (l,r) -> {});
} | [
"public",
"List",
"<",
"T",
">",
"getResults",
"(",
")",
"{",
"return",
"values",
"(",
")",
".",
"stream",
"(",
")",
".",
"filter",
"(",
"rsp",
"->",
"rsp",
".",
"wasReceived",
"(",
")",
"&&",
"rsp",
".",
"getValue",
"(",
")",
"!=",
"null",
")",
... | Returns the results from non-suspected members that are not null. | [
"Returns",
"the",
"results",
"from",
"non",
"-",
"suspected",
"members",
"that",
"are",
"not",
"null",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/RspList.java#L75-L78 | train |
belaban/JGroups | src/org/jgroups/util/DefaultThreadFactory.java | DefaultThreadFactory.renameThread | public void renameThread(String base_name, Thread thread, String addr, String cluster_name) {
String thread_name=getThreadName(base_name, thread, addr, cluster_name);
if(thread_name != null)
thread.setName(thread_name);
} | java | public void renameThread(String base_name, Thread thread, String addr, String cluster_name) {
String thread_name=getThreadName(base_name, thread, addr, cluster_name);
if(thread_name != null)
thread.setName(thread_name);
} | [
"public",
"void",
"renameThread",
"(",
"String",
"base_name",
",",
"Thread",
"thread",
",",
"String",
"addr",
",",
"String",
"cluster_name",
")",
"{",
"String",
"thread_name",
"=",
"getThreadName",
"(",
"base_name",
",",
"thread",
",",
"addr",
",",
"cluster_na... | Names a thread according to base_name, cluster name and local address. If includeClusterName and includeLocalAddress
are null, but cluster_name is set, then we assume we have a shared transport and name the thread shared=clusterName.
In the latter case, clusterName points to the singleton_name of TP.
@param base_name
@param thread
@param addr
@param cluster_name | [
"Names",
"a",
"thread",
"according",
"to",
"base_name",
"cluster",
"name",
"and",
"local",
"address",
".",
"If",
"includeClusterName",
"and",
"includeLocalAddress",
"are",
"null",
"but",
"cluster_name",
"is",
"set",
"then",
"we",
"assume",
"we",
"have",
"a",
"... | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/DefaultThreadFactory.java#L88-L92 | train |
belaban/JGroups | src/org/jgroups/util/RingBuffer.java | RingBuffer.put | public RingBuffer<T> put(T element) throws InterruptedException {
if(element == null)
return this;
lock.lock();
try {
while(count == buf.length)
not_full.await();
buf[wi]=element;
if(++wi == buf.length)
wi=0;
count++;
not_empty.signal();
return this;
}
finally {
lock.unlock();
}
} | java | public RingBuffer<T> put(T element) throws InterruptedException {
if(element == null)
return this;
lock.lock();
try {
while(count == buf.length)
not_full.await();
buf[wi]=element;
if(++wi == buf.length)
wi=0;
count++;
not_empty.signal();
return this;
}
finally {
lock.unlock();
}
} | [
"public",
"RingBuffer",
"<",
"T",
">",
"put",
"(",
"T",
"element",
")",
"throws",
"InterruptedException",
"{",
"if",
"(",
"element",
"==",
"null",
")",
"return",
"this",
";",
"lock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"while",
"(",
"count",
"=="... | Tries to add a new element at the current write index and advances the write index. If the write index is at the
same position as the read index, this will block until the read index is advanced.
@param element the element to be added. Must not be null, or else this operation returns immediately | [
"Tries",
"to",
"add",
"a",
"new",
"element",
"at",
"the",
"current",
"write",
"index",
"and",
"advances",
"the",
"write",
"index",
".",
"If",
"the",
"write",
"index",
"is",
"at",
"the",
"same",
"position",
"as",
"the",
"read",
"index",
"this",
"will",
... | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/RingBuffer.java#L100-L118 | train |
belaban/JGroups | src/org/jgroups/util/RingBuffer.java | RingBuffer.drainTo | public int drainTo(T[] c) {
int num=Math.min(count, c.length); // count may increase in the mean time, but that's ok
if(num == 0)
return num;
int read_index=ri; // no lock as we're the only reader
for(int i=0; i < num; i++) {
int real_index=realIndex(read_index +i);
c[i]=(buf[real_index]);
buf[real_index]=null;
}
publishReadIndex(num);
return num;
} | java | public int drainTo(T[] c) {
int num=Math.min(count, c.length); // count may increase in the mean time, but that's ok
if(num == 0)
return num;
int read_index=ri; // no lock as we're the only reader
for(int i=0; i < num; i++) {
int real_index=realIndex(read_index +i);
c[i]=(buf[real_index]);
buf[real_index]=null;
}
publishReadIndex(num);
return num;
} | [
"public",
"int",
"drainTo",
"(",
"T",
"[",
"]",
"c",
")",
"{",
"int",
"num",
"=",
"Math",
".",
"min",
"(",
"count",
",",
"c",
".",
"length",
")",
";",
"// count may increase in the mean time, but that's ok",
"if",
"(",
"num",
"==",
"0",
")",
"return",
... | Removes messages and adds them to c.
@param c The array to add messages to.
@return The number of messages removed and added to c. This is min(count, c.length). If no messages are present,
this method returns immediately | [
"Removes",
"messages",
"and",
"adds",
"them",
"to",
"c",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/RingBuffer.java#L214-L226 | train |
belaban/JGroups | src/org/jgroups/util/RingBuffer.java | RingBuffer.waitForMessages | public int waitForMessages(int num_spins, final BiConsumer<Integer,Integer> wait_strategy) throws InterruptedException {
// try spinning first (experimental)
for(int i=0; i < num_spins && count == 0; i++) {
if(wait_strategy != null)
wait_strategy.accept(i, num_spins);
else
Thread.yield();
}
if(count == 0)
_waitForMessages();
return count; // whatever is the last count; could have been updated since lock release
} | java | public int waitForMessages(int num_spins, final BiConsumer<Integer,Integer> wait_strategy) throws InterruptedException {
// try spinning first (experimental)
for(int i=0; i < num_spins && count == 0; i++) {
if(wait_strategy != null)
wait_strategy.accept(i, num_spins);
else
Thread.yield();
}
if(count == 0)
_waitForMessages();
return count; // whatever is the last count; could have been updated since lock release
} | [
"public",
"int",
"waitForMessages",
"(",
"int",
"num_spins",
",",
"final",
"BiConsumer",
"<",
"Integer",
",",
"Integer",
">",
"wait_strategy",
")",
"throws",
"InterruptedException",
"{",
"// try spinning first (experimental)",
"for",
"(",
"int",
"i",
"=",
"0",
";"... | Blocks until messages are available
@param num_spins the number of times we should spin before acquiring a lock
@param wait_strategy the strategy used to spin. The first parameter is the iteration count and the second
parameter is the max number of spins | [
"Blocks",
"until",
"messages",
"are",
"available"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/RingBuffer.java#L274-L285 | train |
belaban/JGroups | src/org/jgroups/nio/Buffers.java | Buffers.readLengthAndData | public ByteBuffer readLengthAndData(SocketChannel ch) throws Exception {
if(bufs[0].hasRemaining() && ch.read(bufs[0]) < 0)
throw new EOFException();
if(bufs[0].hasRemaining())
return null;
int len=bufs[0].getInt(0);
if(bufs[1] == null || len > bufs[1].capacity())
bufs[1]=ByteBuffer.allocate(len);
bufs[1].limit(len);
if(bufs[1].hasRemaining() && ch.read(bufs[1]) < 0)
throw new EOFException();
if(bufs[1].hasRemaining())
return null;
try {
return (ByteBuffer)bufs[1].duplicate().flip();
}
finally {
bufs[0].clear();
bufs[1].clear();
}
} | java | public ByteBuffer readLengthAndData(SocketChannel ch) throws Exception {
if(bufs[0].hasRemaining() && ch.read(bufs[0]) < 0)
throw new EOFException();
if(bufs[0].hasRemaining())
return null;
int len=bufs[0].getInt(0);
if(bufs[1] == null || len > bufs[1].capacity())
bufs[1]=ByteBuffer.allocate(len);
bufs[1].limit(len);
if(bufs[1].hasRemaining() && ch.read(bufs[1]) < 0)
throw new EOFException();
if(bufs[1].hasRemaining())
return null;
try {
return (ByteBuffer)bufs[1].duplicate().flip();
}
finally {
bufs[0].clear();
bufs[1].clear();
}
} | [
"public",
"ByteBuffer",
"readLengthAndData",
"(",
"SocketChannel",
"ch",
")",
"throws",
"Exception",
"{",
"if",
"(",
"bufs",
"[",
"0",
"]",
".",
"hasRemaining",
"(",
")",
"&&",
"ch",
".",
"read",
"(",
"bufs",
"[",
"0",
"]",
")",
"<",
"0",
")",
"throw... | Reads length and then length bytes into the data buffer, which is grown if needed.
@param ch The channel to read data from
@return The data buffer (position is 0 and limit is length), or null if not all data could be read. | [
"Reads",
"length",
"and",
"then",
"length",
"bytes",
"into",
"the",
"data",
"buffer",
"which",
"is",
"grown",
"if",
"needed",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/nio/Buffers.java#L123-L148 | train |
belaban/JGroups | src/org/jgroups/nio/Buffers.java | Buffers.copy | public Buffers copy() {
for(int i=Math.max(position, next_to_copy); i < limit; i++) {
this.bufs[i]=copyBuffer(this.bufs[i]);
next_to_copy=(short)(i+1);
}
return this;
} | java | public Buffers copy() {
for(int i=Math.max(position, next_to_copy); i < limit; i++) {
this.bufs[i]=copyBuffer(this.bufs[i]);
next_to_copy=(short)(i+1);
}
return this;
} | [
"public",
"Buffers",
"copy",
"(",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"Math",
".",
"max",
"(",
"position",
",",
"next_to_copy",
")",
";",
"i",
"<",
"limit",
";",
"i",
"++",
")",
"{",
"this",
".",
"bufs",
"[",
"i",
"]",
"=",
"copyBuffer",
"("... | Copies the data that has not yet been written and moves last_copied. Typically done after an unsuccessful
write, if copying is required. This is typically needed if the output buffer is reused. Note that
direct buffers will be converted to heap-based buffers | [
"Copies",
"the",
"data",
"that",
"has",
"not",
"yet",
"been",
"written",
"and",
"moves",
"last_copied",
".",
"Typically",
"done",
"after",
"an",
"unsuccessful",
"write",
"if",
"copying",
"is",
"required",
".",
"This",
"is",
"typically",
"needed",
"if",
"the"... | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/nio/Buffers.java#L198-L204 | train |
belaban/JGroups | src/org/jgroups/nio/Buffers.java | Buffers.copyBuffer | public static ByteBuffer copyBuffer(final ByteBuffer buf) {
if(buf == null)
return null;
int offset=buf.hasArray()? buf.arrayOffset() + buf.position() : buf.position(), len=buf.remaining();
byte[] tmp=new byte[len];
if(!buf.isDirect())
System.arraycopy(buf.array(), offset, tmp, 0, len);
else {
// buf.get(tmp, 0, len);
for(int i=0; i < len; i++)
tmp[i]=buf.get(i+offset);
}
return ByteBuffer.wrap(tmp);
} | java | public static ByteBuffer copyBuffer(final ByteBuffer buf) {
if(buf == null)
return null;
int offset=buf.hasArray()? buf.arrayOffset() + buf.position() : buf.position(), len=buf.remaining();
byte[] tmp=new byte[len];
if(!buf.isDirect())
System.arraycopy(buf.array(), offset, tmp, 0, len);
else {
// buf.get(tmp, 0, len);
for(int i=0; i < len; i++)
tmp[i]=buf.get(i+offset);
}
return ByteBuffer.wrap(tmp);
} | [
"public",
"static",
"ByteBuffer",
"copyBuffer",
"(",
"final",
"ByteBuffer",
"buf",
")",
"{",
"if",
"(",
"buf",
"==",
"null",
")",
"return",
"null",
";",
"int",
"offset",
"=",
"buf",
".",
"hasArray",
"(",
")",
"?",
"buf",
".",
"arrayOffset",
"(",
")",
... | Copies a ByteBuffer by copying and wrapping the underlying array of a heap-based buffer. Direct buffers
are converted to heap-based buffers | [
"Copies",
"a",
"ByteBuffer",
"by",
"copying",
"and",
"wrapping",
"the",
"underlying",
"array",
"of",
"a",
"heap",
"-",
"based",
"buffer",
".",
"Direct",
"buffers",
"are",
"converted",
"to",
"heap",
"-",
"based",
"buffers"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/nio/Buffers.java#L287-L300 | train |
belaban/JGroups | src/org/jgroups/protocols/BaseBundler.java | BaseBundler.sendBundledMessages | @GuardedBy("lock") protected void sendBundledMessages() {
for(Map.Entry<Address,List<Message>> entry: msgs.entrySet()) {
List<Message> list=entry.getValue();
if(list.isEmpty())
continue;
output.position(0);
if(list.size() == 1)
sendSingleMessage(list.get(0));
else {
Address dst=entry.getKey();
sendMessageList(dst, list.get(0).getSrc(), list);
if(transport.statsEnabled())
transport.incrBatchesSent(1);
}
}
clearMessages();
count=0;
} | java | @GuardedBy("lock") protected void sendBundledMessages() {
for(Map.Entry<Address,List<Message>> entry: msgs.entrySet()) {
List<Message> list=entry.getValue();
if(list.isEmpty())
continue;
output.position(0);
if(list.size() == 1)
sendSingleMessage(list.get(0));
else {
Address dst=entry.getKey();
sendMessageList(dst, list.get(0).getSrc(), list);
if(transport.statsEnabled())
transport.incrBatchesSent(1);
}
}
clearMessages();
count=0;
} | [
"@",
"GuardedBy",
"(",
"\"lock\"",
")",
"protected",
"void",
"sendBundledMessages",
"(",
")",
"{",
"for",
"(",
"Map",
".",
"Entry",
"<",
"Address",
",",
"List",
"<",
"Message",
">",
">",
"entry",
":",
"msgs",
".",
"entrySet",
"(",
")",
")",
"{",
"Lis... | Sends all messages in the map. Messages for the same destination are bundled into a message list.
The map will be cleared when done. | [
"Sends",
"all",
"messages",
"in",
"the",
"map",
".",
"Messages",
"for",
"the",
"same",
"destination",
"are",
"bundled",
"into",
"a",
"message",
"list",
".",
"The",
"map",
"will",
"be",
"cleared",
"when",
"done",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/protocols/BaseBundler.java#L60-L78 | train |
belaban/JGroups | src/org/jgroups/blocks/ReplCache.java | ReplCache.get | @ManagedOperation
public V get(K key) {
// 1. Try the L1 cache first
if(l1_cache != null) {
V val=l1_cache.get(key);
if(val != null) {
if(log.isTraceEnabled())
log.trace("returned value " + val + " for " + key + " from L1 cache");
return val;
}
}
// 2. Try the local cache
Cache.Value<Value<V>> val=l2_cache.getEntry(key);
Value<V> tmp;
if(val != null) {
tmp=val.getValue();
if(tmp !=null) {
V real_value=tmp.getVal();
if(real_value != null && l1_cache != null && val.getTimeout() >= 0)
l1_cache.put(key, real_value, val.getTimeout());
return tmp.getVal();
}
}
// 3. Execute a cluster wide GET
try {
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();
if(tmp != null) {
V real_value=tmp.getVal();
if(real_value != null && l1_cache != null && val.getTimeout() >= 0)
l1_cache.put(key, real_value, val.getTimeout());
return real_value;
}
}
}
return null;
}
catch(Throwable t) {
if(log.isWarnEnabled())
log.warn("get() failed", t);
return null;
}
} | java | @ManagedOperation
public V get(K key) {
// 1. Try the L1 cache first
if(l1_cache != null) {
V val=l1_cache.get(key);
if(val != null) {
if(log.isTraceEnabled())
log.trace("returned value " + val + " for " + key + " from L1 cache");
return val;
}
}
// 2. Try the local cache
Cache.Value<Value<V>> val=l2_cache.getEntry(key);
Value<V> tmp;
if(val != null) {
tmp=val.getValue();
if(tmp !=null) {
V real_value=tmp.getVal();
if(real_value != null && l1_cache != null && val.getTimeout() >= 0)
l1_cache.put(key, real_value, val.getTimeout());
return tmp.getVal();
}
}
// 3. Execute a cluster wide GET
try {
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();
if(tmp != null) {
V real_value=tmp.getVal();
if(real_value != null && l1_cache != null && val.getTimeout() >= 0)
l1_cache.put(key, real_value, val.getTimeout());
return real_value;
}
}
}
return null;
}
catch(Throwable t) {
if(log.isWarnEnabled())
log.warn("get() failed", t);
return null;
}
} | [
"@",
"ManagedOperation",
"public",
"V",
"get",
"(",
"K",
"key",
")",
"{",
"// 1. Try the L1 cache first",
"if",
"(",
"l1_cache",
"!=",
"null",
")",
"{",
"V",
"val",
"=",
"l1_cache",
".",
"get",
"(",
"key",
")",
";",
"if",
"(",
"val",
"!=",
"null",
")... | Returns the value associated with key
@param key The key, has to be serializable
@return The value associated with key, or null | [
"Returns",
"the",
"value",
"associated",
"with",
"key"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/blocks/ReplCache.java#L385-L438 | train |
belaban/JGroups | src/org/jgroups/blocks/ReplCache.java | ReplCache.remove | @ManagedOperation
public void remove(K key, boolean synchronous) {
try {
disp.callRemoteMethods(null, new MethodCall(REMOVE, key),
new RequestOptions(synchronous? ResponseMode.GET_ALL : ResponseMode.GET_NONE, call_timeout));
if(l1_cache != null)
l1_cache.remove(key);
}
catch(Throwable t) {
if(log.isWarnEnabled())
log.warn("remove() failed", t);
}
} | java | @ManagedOperation
public void remove(K key, boolean synchronous) {
try {
disp.callRemoteMethods(null, new MethodCall(REMOVE, key),
new RequestOptions(synchronous? ResponseMode.GET_ALL : ResponseMode.GET_NONE, call_timeout));
if(l1_cache != null)
l1_cache.remove(key);
}
catch(Throwable t) {
if(log.isWarnEnabled())
log.warn("remove() failed", t);
}
} | [
"@",
"ManagedOperation",
"public",
"void",
"remove",
"(",
"K",
"key",
",",
"boolean",
"synchronous",
")",
"{",
"try",
"{",
"disp",
".",
"callRemoteMethods",
"(",
"null",
",",
"new",
"MethodCall",
"(",
"REMOVE",
",",
"key",
")",
",",
"new",
"RequestOptions"... | Removes key in all nodes in the cluster, both from their local hashmaps and L1 caches
@param key The key, needs to be serializable | [
"Removes",
"key",
"in",
"all",
"nodes",
"in",
"the",
"cluster",
"both",
"from",
"their",
"local",
"hashmaps",
"and",
"L1",
"caches"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/blocks/ReplCache.java#L454-L466 | train |
belaban/JGroups | src/org/jgroups/blocks/ReplCache.java | ReplCache.clear | @ManagedOperation
public void clear() {
Set<K> keys=new HashSet<>(l2_cache.getInternalMap().keySet());
mcastClear(keys, false);
} | java | @ManagedOperation
public void clear() {
Set<K> keys=new HashSet<>(l2_cache.getInternalMap().keySet());
mcastClear(keys, false);
} | [
"@",
"ManagedOperation",
"public",
"void",
"clear",
"(",
")",
"{",
"Set",
"<",
"K",
">",
"keys",
"=",
"new",
"HashSet",
"<>",
"(",
"l2_cache",
".",
"getInternalMap",
"(",
")",
".",
"keySet",
"(",
")",
")",
";",
"mcastClear",
"(",
"keys",
",",
"false"... | Removes all keys and values in the L2 and L1 caches | [
"Removes",
"all",
"keys",
"and",
"values",
"in",
"the",
"L2",
"and",
"L1",
"caches"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/blocks/ReplCache.java#L472-L476 | train |
belaban/JGroups | src/org/jgroups/protocols/pbcast/ClientGmsImpl.java | ClientGmsImpl.installViewIfValidJoinRsp | protected boolean installViewIfValidJoinRsp(final Promise<JoinRsp> join_promise, boolean block_for_rsp) {
boolean success=false;
JoinRsp rsp=null;
try {
if(join_promise.hasResult())
rsp=join_promise.getResult(1, true);
else if(block_for_rsp)
rsp=join_promise.getResult(gms.join_timeout, true);
return success=rsp != null && isJoinResponseValid(rsp) && installView(rsp.getView(), rsp.getDigest());
}
finally {
if(success)
gms.sendViewAck(rsp.getView().getCreator());
}
} | java | protected boolean installViewIfValidJoinRsp(final Promise<JoinRsp> join_promise, boolean block_for_rsp) {
boolean success=false;
JoinRsp rsp=null;
try {
if(join_promise.hasResult())
rsp=join_promise.getResult(1, true);
else if(block_for_rsp)
rsp=join_promise.getResult(gms.join_timeout, true);
return success=rsp != null && isJoinResponseValid(rsp) && installView(rsp.getView(), rsp.getDigest());
}
finally {
if(success)
gms.sendViewAck(rsp.getView().getCreator());
}
} | [
"protected",
"boolean",
"installViewIfValidJoinRsp",
"(",
"final",
"Promise",
"<",
"JoinRsp",
">",
"join_promise",
",",
"boolean",
"block_for_rsp",
")",
"{",
"boolean",
"success",
"=",
"false",
";",
"JoinRsp",
"rsp",
"=",
"null",
";",
"try",
"{",
"if",
"(",
... | go through discovery and JOIN-REQ again in a next iteration | [
"go",
"through",
"discovery",
"and",
"JOIN",
"-",
"REQ",
"again",
"in",
"a",
"next",
"iteration"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/protocols/pbcast/ClientGmsImpl.java#L138-L153 | train |
belaban/JGroups | src/org/jgroups/protocols/pbcast/ClientGmsImpl.java | ClientGmsImpl.getCoords | private static List<Address> getCoords(Iterable<PingData> mbrs) {
if(mbrs == null)
return null;
List<Address> coords=null;
for(PingData mbr: mbrs) {
if(mbr.isCoord()) {
if(coords == null)
coords=new ArrayList<>();
if(!coords.contains(mbr.getAddress()))
coords.add(mbr.getAddress());
}
}
return coords;
} | java | private static List<Address> getCoords(Iterable<PingData> mbrs) {
if(mbrs == null)
return null;
List<Address> coords=null;
for(PingData mbr: mbrs) {
if(mbr.isCoord()) {
if(coords == null)
coords=new ArrayList<>();
if(!coords.contains(mbr.getAddress()))
coords.add(mbr.getAddress());
}
}
return coords;
} | [
"private",
"static",
"List",
"<",
"Address",
">",
"getCoords",
"(",
"Iterable",
"<",
"PingData",
">",
"mbrs",
")",
"{",
"if",
"(",
"mbrs",
"==",
"null",
")",
"return",
"null",
";",
"List",
"<",
"Address",
">",
"coords",
"=",
"null",
";",
"for",
"(",
... | Returns all members whose PingData is flagged as coordinator | [
"Returns",
"all",
"members",
"whose",
"PingData",
"is",
"flagged",
"as",
"coordinator"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/protocols/pbcast/ClientGmsImpl.java#L229-L243 | train |
belaban/JGroups | src/org/jgroups/stack/Configurator.java | Configurator.createProtocol | public static Protocol createProtocol(String prot_spec, ProtocolStack stack) throws Exception {
ProtocolConfiguration config;
Protocol prot;
if(prot_spec == null) throw new Exception("Configurator.createProtocol(): prot_spec is null");
// parse the configuration for this protocol
config=new ProtocolConfiguration(prot_spec);
// create an instance of the protocol class and configure it
prot=createLayer(stack, config);
prot.init();
return prot;
} | java | public static Protocol createProtocol(String prot_spec, ProtocolStack stack) throws Exception {
ProtocolConfiguration config;
Protocol prot;
if(prot_spec == null) throw new Exception("Configurator.createProtocol(): prot_spec is null");
// parse the configuration for this protocol
config=new ProtocolConfiguration(prot_spec);
// create an instance of the protocol class and configure it
prot=createLayer(stack, config);
prot.init();
return prot;
} | [
"public",
"static",
"Protocol",
"createProtocol",
"(",
"String",
"prot_spec",
",",
"ProtocolStack",
"stack",
")",
"throws",
"Exception",
"{",
"ProtocolConfiguration",
"config",
";",
"Protocol",
"prot",
";",
"if",
"(",
"prot_spec",
"==",
"null",
")",
"throw",
"ne... | Creates a new protocol given the protocol specification. Initializes the properties and starts the
up and down handler threads.
@param prot_spec The specification of the protocol. Same convention as for specifying a protocol stack.
An exception will be thrown if the class cannot be created. Example:
<pre>"VERIFY_SUSPECT(timeout=1500)"</pre> Note that no colons (:) have to be
specified
@param stack The protocol stack
@return Protocol The newly created protocol
@exception Exception Will be thrown when the new protocol cannot be created | [
"Creates",
"a",
"new",
"protocol",
"given",
"the",
"protocol",
"specification",
".",
"Initializes",
"the",
"properties",
"and",
"starts",
"the",
"up",
"and",
"down",
"handler",
"threads",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/stack/Configurator.java#L155-L168 | train |
belaban/JGroups | src/org/jgroups/stack/Configurator.java | Configurator.connectProtocols | public static Protocol connectProtocols(List<Protocol> protocol_list) throws Exception {
Protocol current_layer=null, next_layer=null;
for(int i=0; i < protocol_list.size(); i++) {
current_layer=protocol_list.get(i);
if(i + 1 >= protocol_list.size())
break;
next_layer=protocol_list.get(i + 1);
next_layer.setDownProtocol(current_layer);
current_layer.setUpProtocol(next_layer);
}
// basic protocol sanity check
sanityCheck(protocol_list);
return current_layer;
} | java | public static Protocol connectProtocols(List<Protocol> protocol_list) throws Exception {
Protocol current_layer=null, next_layer=null;
for(int i=0; i < protocol_list.size(); i++) {
current_layer=protocol_list.get(i);
if(i + 1 >= protocol_list.size())
break;
next_layer=protocol_list.get(i + 1);
next_layer.setDownProtocol(current_layer);
current_layer.setUpProtocol(next_layer);
}
// basic protocol sanity check
sanityCheck(protocol_list);
return current_layer;
} | [
"public",
"static",
"Protocol",
"connectProtocols",
"(",
"List",
"<",
"Protocol",
">",
"protocol_list",
")",
"throws",
"Exception",
"{",
"Protocol",
"current_layer",
"=",
"null",
",",
"next_layer",
"=",
"null",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"... | Creates a protocol stack by iterating through the protocol list and connecting
adjacent layers. The list starts with the topmost layer and has the bottommost
layer at the tail.
@param protocol_list List of Protocol elements (from top to bottom)
@return Protocol stack | [
"Creates",
"a",
"protocol",
"stack",
"by",
"iterating",
"through",
"the",
"protocol",
"list",
"and",
"connecting",
"adjacent",
"layers",
".",
"The",
"list",
"starts",
"with",
"the",
"topmost",
"layer",
"and",
"has",
"the",
"bottommost",
"layer",
"at",
"the",
... | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/stack/Configurator.java#L183-L197 | train |
belaban/JGroups | src/org/jgroups/stack/Configurator.java | Configurator.createProtocols | public static List<Protocol> createProtocols(List<ProtocolConfiguration> protocol_configs, final ProtocolStack stack) throws Exception {
List<Protocol> retval=new LinkedList<>();
for(int i=0; i < protocol_configs.size(); i++) {
ProtocolConfiguration protocol_config=protocol_configs.get(i);
Protocol layer=createLayer(stack, protocol_config);
if(layer == null)
return null;
retval.add(layer);
}
return retval;
} | java | public static List<Protocol> createProtocols(List<ProtocolConfiguration> protocol_configs, final ProtocolStack stack) throws Exception {
List<Protocol> retval=new LinkedList<>();
for(int i=0; i < protocol_configs.size(); i++) {
ProtocolConfiguration protocol_config=protocol_configs.get(i);
Protocol layer=createLayer(stack, protocol_config);
if(layer == null)
return null;
retval.add(layer);
}
return retval;
} | [
"public",
"static",
"List",
"<",
"Protocol",
">",
"createProtocols",
"(",
"List",
"<",
"ProtocolConfiguration",
">",
"protocol_configs",
",",
"final",
"ProtocolStack",
"stack",
")",
"throws",
"Exception",
"{",
"List",
"<",
"Protocol",
">",
"retval",
"=",
"new",
... | Takes vector of ProtocolConfigurations, iterates through it, creates Protocol for
each ProtocolConfiguration and returns all Protocols in a list.
@param protocol_configs List of ProtocolConfigurations
@param stack The protocol stack
@return List of Protocols | [
"Takes",
"vector",
"of",
"ProtocolConfigurations",
"iterates",
"through",
"it",
"creates",
"Protocol",
"for",
"each",
"ProtocolConfiguration",
"and",
"returns",
"all",
"Protocols",
"in",
"a",
"list",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/stack/Configurator.java#L209-L219 | train |
belaban/JGroups | src/org/jgroups/stack/Configurator.java | Configurator.sanityCheck | public static void sanityCheck(List<Protocol> protocols) throws Exception {
// check for unique IDs
Set<Short> ids=new HashSet<>();
for(Protocol protocol: protocols) {
short id=protocol.getId();
if(id > 0 && !ids.add(id))
throw new Exception("Protocol ID " + id + " (name=" + protocol.getName() +
") is duplicate; protocol IDs have to be unique");
}
// For each protocol, get its required up and down services and check (if available) if they're satisfied
for(Protocol protocol: protocols) {
List<Integer> required_down_services=protocol.requiredDownServices();
List<Integer> required_up_services=protocol.requiredUpServices();
if(required_down_services != null && !required_down_services.isEmpty()) {
// the protocols below 'protocol' have to provide the services listed in required_down_services
List<Integer> tmp=new ArrayList<>(required_down_services);
removeProvidedUpServices(protocol, tmp);
if(!tmp.isEmpty())
throw new Exception("events " + printEvents(tmp) + " are required by " + protocol.getName() +
", but not provided by any of the protocols below it");
}
if(required_up_services != null && !required_up_services.isEmpty()) {
// the protocols above 'protocol' have to provide the services listed in required_up_services
List<Integer> tmp=new ArrayList<>(required_up_services);
removeProvidedDownServices(protocol, tmp);
if(!tmp.isEmpty())
throw new Exception("events " + printEvents(tmp) + " are required by " + protocol.getName() +
", but not provided by any of the protocols above it");
}
}
} | java | public static void sanityCheck(List<Protocol> protocols) throws Exception {
// check for unique IDs
Set<Short> ids=new HashSet<>();
for(Protocol protocol: protocols) {
short id=protocol.getId();
if(id > 0 && !ids.add(id))
throw new Exception("Protocol ID " + id + " (name=" + protocol.getName() +
") is duplicate; protocol IDs have to be unique");
}
// For each protocol, get its required up and down services and check (if available) if they're satisfied
for(Protocol protocol: protocols) {
List<Integer> required_down_services=protocol.requiredDownServices();
List<Integer> required_up_services=protocol.requiredUpServices();
if(required_down_services != null && !required_down_services.isEmpty()) {
// the protocols below 'protocol' have to provide the services listed in required_down_services
List<Integer> tmp=new ArrayList<>(required_down_services);
removeProvidedUpServices(protocol, tmp);
if(!tmp.isEmpty())
throw new Exception("events " + printEvents(tmp) + " are required by " + protocol.getName() +
", but not provided by any of the protocols below it");
}
if(required_up_services != null && !required_up_services.isEmpty()) {
// the protocols above 'protocol' have to provide the services listed in required_up_services
List<Integer> tmp=new ArrayList<>(required_up_services);
removeProvidedDownServices(protocol, tmp);
if(!tmp.isEmpty())
throw new Exception("events " + printEvents(tmp) + " are required by " + protocol.getName() +
", but not provided by any of the protocols above it");
}
}
} | [
"public",
"static",
"void",
"sanityCheck",
"(",
"List",
"<",
"Protocol",
">",
"protocols",
")",
"throws",
"Exception",
"{",
"// check for unique IDs",
"Set",
"<",
"Short",
">",
"ids",
"=",
"new",
"HashSet",
"<>",
"(",
")",
";",
"for",
"(",
"Protocol",
"pro... | Throws an exception if sanity check fails. Possible sanity check is uniqueness of all protocol names | [
"Throws",
"an",
"exception",
"if",
"sanity",
"check",
"fails",
".",
"Possible",
"sanity",
"check",
"is",
"uniqueness",
"of",
"all",
"protocol",
"names"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/stack/Configurator.java#L295-L332 | train |
belaban/JGroups | src/org/jgroups/stack/Configurator.java | Configurator.removeProvidedUpServices | protected static void removeProvidedUpServices(Protocol protocol, List<Integer> events) {
if(protocol == null || events == null)
return;
for(Protocol prot=protocol.getDownProtocol(); prot != null && !events.isEmpty(); prot=prot.getDownProtocol()) {
List<Integer> provided_up_services=prot.providedUpServices();
if(provided_up_services != null && !provided_up_services.isEmpty())
events.removeAll(provided_up_services);
}
} | java | protected static void removeProvidedUpServices(Protocol protocol, List<Integer> events) {
if(protocol == null || events == null)
return;
for(Protocol prot=protocol.getDownProtocol(); prot != null && !events.isEmpty(); prot=prot.getDownProtocol()) {
List<Integer> provided_up_services=prot.providedUpServices();
if(provided_up_services != null && !provided_up_services.isEmpty())
events.removeAll(provided_up_services);
}
} | [
"protected",
"static",
"void",
"removeProvidedUpServices",
"(",
"Protocol",
"protocol",
",",
"List",
"<",
"Integer",
">",
"events",
")",
"{",
"if",
"(",
"protocol",
"==",
"null",
"||",
"events",
"==",
"null",
")",
"return",
";",
"for",
"(",
"Protocol",
"pr... | Removes all events provided by the protocol below protocol from events
@param protocol
@param events | [
"Removes",
"all",
"events",
"provided",
"by",
"the",
"protocol",
"below",
"protocol",
"from",
"events"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/stack/Configurator.java#L343-L351 | train |
belaban/JGroups | src/org/jgroups/stack/Configurator.java | Configurator.removeProvidedDownServices | protected static void removeProvidedDownServices(Protocol protocol, List<Integer> events) {
if(protocol == null || events == null)
return;
for(Protocol prot=protocol.getUpProtocol(); prot != null && !events.isEmpty(); prot=prot.getUpProtocol()) {
List<Integer> provided_down_services=prot.providedDownServices();
if(provided_down_services != null && !provided_down_services.isEmpty())
events.removeAll(provided_down_services);
}
} | java | protected static void removeProvidedDownServices(Protocol protocol, List<Integer> events) {
if(protocol == null || events == null)
return;
for(Protocol prot=protocol.getUpProtocol(); prot != null && !events.isEmpty(); prot=prot.getUpProtocol()) {
List<Integer> provided_down_services=prot.providedDownServices();
if(provided_down_services != null && !provided_down_services.isEmpty())
events.removeAll(provided_down_services);
}
} | [
"protected",
"static",
"void",
"removeProvidedDownServices",
"(",
"Protocol",
"protocol",
",",
"List",
"<",
"Integer",
">",
"events",
")",
"{",
"if",
"(",
"protocol",
"==",
"null",
"||",
"events",
"==",
"null",
")",
"return",
";",
"for",
"(",
"Protocol",
"... | Removes all events provided by the protocol above protocol from events
@param protocol
@param events | [
"Removes",
"all",
"events",
"provided",
"by",
"the",
"protocol",
"above",
"protocol",
"from",
"events"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/stack/Configurator.java#L358-L366 | train |
belaban/JGroups | src/org/jgroups/stack/Configurator.java | Configurator.getAddresses | public static Collection<InetAddress> getAddresses(Map<String, Map<String, InetAddressInfo>> inetAddressMap) throws Exception {
Set<InetAddress> addrs=new HashSet<>();
for(Map.Entry<String, Map<String, InetAddressInfo>> inetAddressMapEntry : inetAddressMap.entrySet()) {
Map<String, InetAddressInfo> protocolInetAddressMap=inetAddressMapEntry.getValue();
for(Map.Entry<String, InetAddressInfo> protocolInetAddressMapEntry : protocolInetAddressMap.entrySet()) {
InetAddressInfo inetAddressInfo=protocolInetAddressMapEntry.getValue();
// add InetAddressInfo to sets based on IP version
List<InetAddress> addresses=inetAddressInfo.getInetAddresses();
for(InetAddress address : addresses) {
if(address == null)
throw new RuntimeException("failed converting address info to IP address: " + inetAddressInfo);
addrs.add(address);
}
}
}
return addrs;
} | java | public static Collection<InetAddress> getAddresses(Map<String, Map<String, InetAddressInfo>> inetAddressMap) throws Exception {
Set<InetAddress> addrs=new HashSet<>();
for(Map.Entry<String, Map<String, InetAddressInfo>> inetAddressMapEntry : inetAddressMap.entrySet()) {
Map<String, InetAddressInfo> protocolInetAddressMap=inetAddressMapEntry.getValue();
for(Map.Entry<String, InetAddressInfo> protocolInetAddressMapEntry : protocolInetAddressMap.entrySet()) {
InetAddressInfo inetAddressInfo=protocolInetAddressMapEntry.getValue();
// add InetAddressInfo to sets based on IP version
List<InetAddress> addresses=inetAddressInfo.getInetAddresses();
for(InetAddress address : addresses) {
if(address == null)
throw new RuntimeException("failed converting address info to IP address: " + inetAddressInfo);
addrs.add(address);
}
}
}
return addrs;
} | [
"public",
"static",
"Collection",
"<",
"InetAddress",
">",
"getAddresses",
"(",
"Map",
"<",
"String",
",",
"Map",
"<",
"String",
",",
"InetAddressInfo",
">",
">",
"inetAddressMap",
")",
"throws",
"Exception",
"{",
"Set",
"<",
"InetAddress",
">",
"addrs",
"="... | Returns all inet addresses found | [
"Returns",
"all",
"inet",
"addresses",
"found"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/stack/Configurator.java#L372-L389 | train |
belaban/JGroups | src/org/jgroups/stack/Configurator.java | Configurator.ensureValidBindAddresses | public static void ensureValidBindAddresses(List<Protocol> protocols) throws Exception {
for(Protocol protocol : protocols) {
String protocolName=protocol.getName();
//traverse class hierarchy and find all annotated fields and add them to the list if annotated
Field[] fields=Util.getAllDeclaredFieldsWithAnnotations(protocol.getClass(), LocalAddress.class);
for(int i=0; i < fields.length; i++) {
Object val=getValueFromProtocol(protocol, fields[i]);
if(val == null)
continue;
if(!(val instanceof InetAddress))
throw new Exception("field " + protocolName + "." + fields[i].getName() + " is not an InetAddress");
Util.checkIfValidAddress((InetAddress)val, protocolName);
}
}
} | java | public static void ensureValidBindAddresses(List<Protocol> protocols) throws Exception {
for(Protocol protocol : protocols) {
String protocolName=protocol.getName();
//traverse class hierarchy and find all annotated fields and add them to the list if annotated
Field[] fields=Util.getAllDeclaredFieldsWithAnnotations(protocol.getClass(), LocalAddress.class);
for(int i=0; i < fields.length; i++) {
Object val=getValueFromProtocol(protocol, fields[i]);
if(val == null)
continue;
if(!(val instanceof InetAddress))
throw new Exception("field " + protocolName + "." + fields[i].getName() + " is not an InetAddress");
Util.checkIfValidAddress((InetAddress)val, protocolName);
}
}
} | [
"public",
"static",
"void",
"ensureValidBindAddresses",
"(",
"List",
"<",
"Protocol",
">",
"protocols",
")",
"throws",
"Exception",
"{",
"for",
"(",
"Protocol",
"protocol",
":",
"protocols",
")",
"{",
"String",
"protocolName",
"=",
"protocol",
".",
"getName",
... | Makes sure that all fields annotated with @LocalAddress is (1) an InetAddress and (2) a valid address on any
local network interface
@param protocols
@throws Exception | [
"Makes",
"sure",
"that",
"all",
"fields",
"annotated",
"with"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/stack/Configurator.java#L694-L709 | train |
belaban/JGroups | src/org/jgroups/stack/Configurator.java | Configurator.addPropertyToDependencyList | static void addPropertyToDependencyList(List<AccessibleObject> orderedList, Map<String, AccessibleObject> props, Stack<AccessibleObject> stack, AccessibleObject obj) {
if (orderedList.contains(obj))
return ;
if (stack.search(obj) > 0) {
throw new RuntimeException("Deadlock in @Property dependency processing") ;
}
// record the fact that we are processing obj
stack.push(obj) ;
// process dependencies for this object before adding it to the list
Property annotation = obj.getAnnotation(Property.class) ;
String dependsClause = annotation.dependsUpon() ;
StringTokenizer st = new StringTokenizer(dependsClause, ",") ;
while (st.hasMoreTokens()) {
String token = st.nextToken().trim();
AccessibleObject dep = props.get(token) ;
// if null, throw exception
addPropertyToDependencyList(orderedList, props, stack, dep) ;
}
// indicate we're done with processing dependencies
stack.pop() ;
// we can now add in dependency order
orderedList.add(obj) ;
} | java | static void addPropertyToDependencyList(List<AccessibleObject> orderedList, Map<String, AccessibleObject> props, Stack<AccessibleObject> stack, AccessibleObject obj) {
if (orderedList.contains(obj))
return ;
if (stack.search(obj) > 0) {
throw new RuntimeException("Deadlock in @Property dependency processing") ;
}
// record the fact that we are processing obj
stack.push(obj) ;
// process dependencies for this object before adding it to the list
Property annotation = obj.getAnnotation(Property.class) ;
String dependsClause = annotation.dependsUpon() ;
StringTokenizer st = new StringTokenizer(dependsClause, ",") ;
while (st.hasMoreTokens()) {
String token = st.nextToken().trim();
AccessibleObject dep = props.get(token) ;
// if null, throw exception
addPropertyToDependencyList(orderedList, props, stack, dep) ;
}
// indicate we're done with processing dependencies
stack.pop() ;
// we can now add in dependency order
orderedList.add(obj) ;
} | [
"static",
"void",
"addPropertyToDependencyList",
"(",
"List",
"<",
"AccessibleObject",
">",
"orderedList",
",",
"Map",
"<",
"String",
",",
"AccessibleObject",
">",
"props",
",",
"Stack",
"<",
"AccessibleObject",
">",
"stack",
",",
"AccessibleObject",
"obj",
")",
... | DFS of dependency graph formed by Property annotations and dependsUpon parameter
This is used to create a list of Properties in dependency order | [
"DFS",
"of",
"dependency",
"graph",
"formed",
"by",
"Property",
"annotations",
"and",
"dependsUpon",
"parameter",
"This",
"is",
"used",
"to",
"create",
"a",
"list",
"of",
"Properties",
"in",
"dependency",
"order"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/stack/Configurator.java#L803-L827 | train |
belaban/JGroups | src/org/jgroups/util/ExtendedUUID.java | ExtendedUUID.length | public int length() {
if(keys == null)
return 0;
int retval=0;
for(byte[] key: keys)
if(key != null)
retval++;
return retval;
} | java | public int length() {
if(keys == null)
return 0;
int retval=0;
for(byte[] key: keys)
if(key != null)
retval++;
return retval;
} | [
"public",
"int",
"length",
"(",
")",
"{",
"if",
"(",
"keys",
"==",
"null",
")",
"return",
"0",
";",
"int",
"retval",
"=",
"0",
";",
"for",
"(",
"byte",
"[",
"]",
"key",
":",
"keys",
")",
"if",
"(",
"key",
"!=",
"null",
")",
"retval",
"++",
";... | The number of non-null keys | [
"The",
"number",
"of",
"non",
"-",
"null",
"keys"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/ExtendedUUID.java#L171-L179 | train |
belaban/JGroups | src/org/jgroups/util/ExtendedUUID.java | ExtendedUUID.resize | protected void resize(int new_length) {
if(keys == null) {
keys=new byte[Math.min(new_length, 0xff)][];
values=new byte[Math.min(new_length, 0xff)][];
return;
}
if(new_length > 0xff) {
if(keys.length < 0xff)
new_length=0xff;
else
throw new ArrayIndexOutOfBoundsException("the hashmap cannot exceed " + 0xff + " entries");
}
keys=Arrays.copyOf(keys, new_length);
values=Arrays.copyOf(values, new_length);
} | java | protected void resize(int new_length) {
if(keys == null) {
keys=new byte[Math.min(new_length, 0xff)][];
values=new byte[Math.min(new_length, 0xff)][];
return;
}
if(new_length > 0xff) {
if(keys.length < 0xff)
new_length=0xff;
else
throw new ArrayIndexOutOfBoundsException("the hashmap cannot exceed " + 0xff + " entries");
}
keys=Arrays.copyOf(keys, new_length);
values=Arrays.copyOf(values, new_length);
} | [
"protected",
"void",
"resize",
"(",
"int",
"new_length",
")",
"{",
"if",
"(",
"keys",
"==",
"null",
")",
"{",
"keys",
"=",
"new",
"byte",
"[",
"Math",
".",
"min",
"(",
"new_length",
",",
"0xff",
")",
"]",
"[",
"",
"]",
";",
"values",
"=",
"new",
... | Resizes the arrays | [
"Resizes",
"the",
"arrays"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/ExtendedUUID.java#L270-L285 | train |
belaban/JGroups | src/org/jgroups/fork/ForkConfig.java | ForkConfig.parse | public static Map<String,List<ProtocolConfiguration>> parse(InputStream input) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false); // for now
DocumentBuilder builder=factory.newDocumentBuilder();
Document document=builder.parse(input);
Element root=document.getDocumentElement();
return parse(root);
} | java | public static Map<String,List<ProtocolConfiguration>> parse(InputStream input) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false); // for now
DocumentBuilder builder=factory.newDocumentBuilder();
Document document=builder.parse(input);
Element root=document.getDocumentElement();
return parse(root);
} | [
"public",
"static",
"Map",
"<",
"String",
",",
"List",
"<",
"ProtocolConfiguration",
">",
">",
"parse",
"(",
"InputStream",
"input",
")",
"throws",
"Exception",
"{",
"DocumentBuilderFactory",
"factory",
"=",
"DocumentBuilderFactory",
".",
"newInstance",
"(",
")",
... | Parses the input and returns a map of fork-stack IDs and lists of ProtocolConfigurations | [
"Parses",
"the",
"input",
"and",
"returns",
"a",
"map",
"of",
"fork",
"-",
"stack",
"IDs",
"and",
"lists",
"of",
"ProtocolConfigurations"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/fork/ForkConfig.java#L32-L39 | train |
belaban/JGroups | src/org/jgroups/util/Bits.java | Bits.writeInt | public static void writeInt(int num, ByteBuffer buf) {
if(num == 0) {
buf.put((byte)0);
return;
}
final byte bytes_needed=bytesRequiredFor(num);
buf.put(bytes_needed);
for(int i=0; i < bytes_needed; i++)
buf.put(getByteAt(num, i));
} | java | public static void writeInt(int num, ByteBuffer buf) {
if(num == 0) {
buf.put((byte)0);
return;
}
final byte bytes_needed=bytesRequiredFor(num);
buf.put(bytes_needed);
for(int i=0; i < bytes_needed; i++)
buf.put(getByteAt(num, i));
} | [
"public",
"static",
"void",
"writeInt",
"(",
"int",
"num",
",",
"ByteBuffer",
"buf",
")",
"{",
"if",
"(",
"num",
"==",
"0",
")",
"{",
"buf",
".",
"put",
"(",
"(",
"byte",
")",
"0",
")",
";",
"return",
";",
"}",
"final",
"byte",
"bytes_needed",
"=... | Writes an int to a ByteBuffer
@param num the int to be written
@param buf the buffer | [
"Writes",
"an",
"int",
"to",
"a",
"ByteBuffer"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Bits.java#L86-L95 | train |
belaban/JGroups | src/org/jgroups/util/Bits.java | Bits.writeInt | public static void writeInt(int num, DataOutput out) throws IOException {
if(num == 0) {
out.write(0);
return;
}
final byte bytes_needed=bytesRequiredFor(num);
out.write(bytes_needed);
for(int i=0; i < bytes_needed; i++)
out.write(getByteAt(num, i));
} | java | public static void writeInt(int num, DataOutput out) throws IOException {
if(num == 0) {
out.write(0);
return;
}
final byte bytes_needed=bytesRequiredFor(num);
out.write(bytes_needed);
for(int i=0; i < bytes_needed; i++)
out.write(getByteAt(num, i));
} | [
"public",
"static",
"void",
"writeInt",
"(",
"int",
"num",
",",
"DataOutput",
"out",
")",
"throws",
"IOException",
"{",
"if",
"(",
"num",
"==",
"0",
")",
"{",
"out",
".",
"write",
"(",
"0",
")",
";",
"return",
";",
"}",
"final",
"byte",
"bytes_needed... | Writes an int to an output stream
@param num the int to be written
@param out the output stream | [
"Writes",
"an",
"int",
"to",
"an",
"output",
"stream"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Bits.java#L102-L111 | train |
belaban/JGroups | src/org/jgroups/util/Bits.java | Bits.readInt | public static int readInt(ByteBuffer buf) {
byte len=buf.get();
if(len == 0)
return 0;
return makeInt(buf, len);
} | java | public static int readInt(ByteBuffer buf) {
byte len=buf.get();
if(len == 0)
return 0;
return makeInt(buf, len);
} | [
"public",
"static",
"int",
"readInt",
"(",
"ByteBuffer",
"buf",
")",
"{",
"byte",
"len",
"=",
"buf",
".",
"get",
"(",
")",
";",
"if",
"(",
"len",
"==",
"0",
")",
"return",
"0",
";",
"return",
"makeInt",
"(",
"buf",
",",
"len",
")",
";",
"}"
] | Reads an int from a buffer.
@param buf the buffer
@return the int read from the buffer | [
"Reads",
"an",
"int",
"from",
"a",
"buffer",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Bits.java#L137-L142 | train |
belaban/JGroups | src/org/jgroups/util/Bits.java | Bits.readInt | public static int readInt(DataInput in) throws IOException {
byte len=in.readByte();
if(len == 0)
return 0;
return makeInt(in, len);
} | java | public static int readInt(DataInput in) throws IOException {
byte len=in.readByte();
if(len == 0)
return 0;
return makeInt(in, len);
} | [
"public",
"static",
"int",
"readInt",
"(",
"DataInput",
"in",
")",
"throws",
"IOException",
"{",
"byte",
"len",
"=",
"in",
".",
"readByte",
"(",
")",
";",
"if",
"(",
"len",
"==",
"0",
")",
"return",
"0",
";",
"return",
"makeInt",
"(",
"in",
",",
"l... | Reads an int from an input stream
@param in the input stream
@return the int read from the input stream | [
"Reads",
"an",
"int",
"from",
"an",
"input",
"stream"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Bits.java#L149-L154 | train |
belaban/JGroups | src/org/jgroups/util/Bits.java | Bits.readLong | public static long readLong(ByteBuffer buf) {
byte len=buf.get();
if(len == 0)
return 0;
return makeLong(buf, len);
} | java | public static long readLong(ByteBuffer buf) {
byte len=buf.get();
if(len == 0)
return 0;
return makeLong(buf, len);
} | [
"public",
"static",
"long",
"readLong",
"(",
"ByteBuffer",
"buf",
")",
"{",
"byte",
"len",
"=",
"buf",
".",
"get",
"(",
")",
";",
"if",
"(",
"len",
"==",
"0",
")",
"return",
"0",
";",
"return",
"makeLong",
"(",
"buf",
",",
"len",
")",
";",
"}"
] | Reads a long from a buffer.
@param buf the buffer
@return the long read from the buffer | [
"Reads",
"a",
"long",
"from",
"a",
"buffer",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Bits.java#L248-L253 | train |
belaban/JGroups | src/org/jgroups/util/Bits.java | Bits.writeFloat | public static void writeFloat(float num, DataOutput out) throws IOException {
writeInt(Float.floatToIntBits(num), out);
} | java | public static void writeFloat(float num, DataOutput out) throws IOException {
writeInt(Float.floatToIntBits(num), out);
} | [
"public",
"static",
"void",
"writeFloat",
"(",
"float",
"num",
",",
"DataOutput",
"out",
")",
"throws",
"IOException",
"{",
"writeInt",
"(",
"Float",
".",
"floatToIntBits",
"(",
"num",
")",
",",
"out",
")",
";",
"}"
] | Writes a float to an output stream
@param num the float to be written
@param out the output stream | [
"Writes",
"a",
"float",
"to",
"an",
"output",
"stream"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Bits.java#L490-L492 | train |
belaban/JGroups | src/org/jgroups/util/Bits.java | Bits.writeDouble | public static void writeDouble(double num, DataOutput out) throws IOException {
writeLong(Double.doubleToLongBits(num), out);
} | java | public static void writeDouble(double num, DataOutput out) throws IOException {
writeLong(Double.doubleToLongBits(num), out);
} | [
"public",
"static",
"void",
"writeDouble",
"(",
"double",
"num",
",",
"DataOutput",
"out",
")",
"throws",
"IOException",
"{",
"writeLong",
"(",
"Double",
".",
"doubleToLongBits",
"(",
"num",
")",
",",
"out",
")",
";",
"}"
] | Writes a double to an output stream
@param num the double to be written
@param out the output stream | [
"Writes",
"a",
"double",
"to",
"an",
"output",
"stream"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Bits.java#L548-L550 | train |
belaban/JGroups | src/org/jgroups/util/Bits.java | Bits.size | public static int size(AsciiString str) {
return str == null? Global.SHORT_SIZE : Global.SHORT_SIZE + str.length();
} | java | public static int size(AsciiString str) {
return str == null? Global.SHORT_SIZE : Global.SHORT_SIZE + str.length();
} | [
"public",
"static",
"int",
"size",
"(",
"AsciiString",
"str",
")",
"{",
"return",
"str",
"==",
"null",
"?",
"Global",
".",
"SHORT_SIZE",
":",
"Global",
".",
"SHORT_SIZE",
"+",
"str",
".",
"length",
"(",
")",
";",
"}"
] | Measures the number of bytes required to encode an AsciiSring.
@param str the string
@return the number of bytes required for encoding str | [
"Measures",
"the",
"number",
"of",
"bytes",
"required",
"to",
"encode",
"an",
"AsciiSring",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Bits.java#L748-L750 | train |
belaban/JGroups | src/org/jgroups/util/SubmitToThreadPool.java | SubmitToThreadPool.removeAndDispatchNonBundledMessages | protected void removeAndDispatchNonBundledMessages(MessageBatch oob_batch) {
if(oob_batch == null)
return;
AsciiString tmp=oob_batch.clusterName();
byte[] cname=tmp != null? tmp.chars() : null;
for(Iterator<Message> it=oob_batch.iterator(); it.hasNext();) {
Message msg=it.next();
if(msg.isFlagSet(Message.Flag.DONT_BUNDLE) && msg.isFlagSet(Message.Flag.OOB)) {
boolean internal=msg.isFlagSet(Message.Flag.INTERNAL);
it.remove();
if(tp.statsEnabled())
tp.getMessageStats().incrNumOOBMsgsReceived(1);
tp.submitToThreadPool(new SingleMessageHandlerWithClusterName(msg, cname), internal);
}
}
} | java | protected void removeAndDispatchNonBundledMessages(MessageBatch oob_batch) {
if(oob_batch == null)
return;
AsciiString tmp=oob_batch.clusterName();
byte[] cname=tmp != null? tmp.chars() : null;
for(Iterator<Message> it=oob_batch.iterator(); it.hasNext();) {
Message msg=it.next();
if(msg.isFlagSet(Message.Flag.DONT_BUNDLE) && msg.isFlagSet(Message.Flag.OOB)) {
boolean internal=msg.isFlagSet(Message.Flag.INTERNAL);
it.remove();
if(tp.statsEnabled())
tp.getMessageStats().incrNumOOBMsgsReceived(1);
tp.submitToThreadPool(new SingleMessageHandlerWithClusterName(msg, cname), internal);
}
}
} | [
"protected",
"void",
"removeAndDispatchNonBundledMessages",
"(",
"MessageBatch",
"oob_batch",
")",
"{",
"if",
"(",
"oob_batch",
"==",
"null",
")",
"return",
";",
"AsciiString",
"tmp",
"=",
"oob_batch",
".",
"clusterName",
"(",
")",
";",
"byte",
"[",
"]",
"cnam... | Removes messages with flags DONT_BUNDLE and OOB set and executes them in the oob or internal thread pool. JGRP-1737 | [
"Removes",
"messages",
"with",
"flags",
"DONT_BUNDLE",
"and",
"OOB",
"set",
"and",
"executes",
"them",
"in",
"the",
"oob",
"or",
"internal",
"thread",
"pool",
".",
"JGRP",
"-",
"1737"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/SubmitToThreadPool.java#L47-L62 | train |
belaban/JGroups | src/org/jgroups/util/CondVar.java | CondVar.waitFor | public void waitFor(Condition condition) {
boolean intr=false;
lock.lock();
try {
while(!condition.isMet()) {
try {
cond.await();
}
catch(InterruptedException e) {
intr=true;
}
}
}
finally {
lock.unlock();
if(intr) Thread.currentThread().interrupt();
}
} | java | public void waitFor(Condition condition) {
boolean intr=false;
lock.lock();
try {
while(!condition.isMet()) {
try {
cond.await();
}
catch(InterruptedException e) {
intr=true;
}
}
}
finally {
lock.unlock();
if(intr) Thread.currentThread().interrupt();
}
} | [
"public",
"void",
"waitFor",
"(",
"Condition",
"condition",
")",
"{",
"boolean",
"intr",
"=",
"false",
";",
"lock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"while",
"(",
"!",
"condition",
".",
"isMet",
"(",
")",
")",
"{",
"try",
"{",
"cond",
".",
... | Blocks until condition is true.
@param condition The condition. Must be non-null | [
"Blocks",
"until",
"condition",
"is",
"true",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/CondVar.java#L30-L47 | train |
belaban/JGroups | src/org/jgroups/util/CondVar.java | CondVar.waitFor | public boolean waitFor(Condition condition, long timeout, TimeUnit unit) {
boolean intr=false;
final long timeout_ns=TimeUnit.NANOSECONDS.convert(timeout, unit);
lock.lock();
try {
for(long wait_time=timeout_ns, start=System.nanoTime(); wait_time > 0 && !condition.isMet();) {
try {
wait_time=cond.awaitNanos(wait_time);
}
catch(InterruptedException e) {
wait_time=timeout_ns - (System.nanoTime() - start);
intr=true;
}
}
return condition.isMet();
}
finally {
lock.unlock();
if(intr) Thread.currentThread().interrupt();
}
} | java | public boolean waitFor(Condition condition, long timeout, TimeUnit unit) {
boolean intr=false;
final long timeout_ns=TimeUnit.NANOSECONDS.convert(timeout, unit);
lock.lock();
try {
for(long wait_time=timeout_ns, start=System.nanoTime(); wait_time > 0 && !condition.isMet();) {
try {
wait_time=cond.awaitNanos(wait_time);
}
catch(InterruptedException e) {
wait_time=timeout_ns - (System.nanoTime() - start);
intr=true;
}
}
return condition.isMet();
}
finally {
lock.unlock();
if(intr) Thread.currentThread().interrupt();
}
} | [
"public",
"boolean",
"waitFor",
"(",
"Condition",
"condition",
",",
"long",
"timeout",
",",
"TimeUnit",
"unit",
")",
"{",
"boolean",
"intr",
"=",
"false",
";",
"final",
"long",
"timeout_ns",
"=",
"TimeUnit",
".",
"NANOSECONDS",
".",
"convert",
"(",
"timeout"... | Blocks until condition is true or the time elapsed
@param condition The condition
@param timeout The timeout to wait. A value <= 0 causes immediate return
@param unit TimeUnit
@return The condition's status | [
"Blocks",
"until",
"condition",
"is",
"true",
"or",
"the",
"time",
"elapsed"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/CondVar.java#L56-L76 | train |
belaban/JGroups | src/org/jgroups/protocols/tom/DeliveryManagerImpl.java | DeliveryManagerImpl.deliverSingleDestinationMessage | void deliverSingleDestinationMessage(Message msg, MessageID messageID) {
synchronized (deliverySet) {
long sequenceNumber = sequenceNumberManager.get();
MessageInfo messageInfo = new MessageInfo(messageID, msg, sequenceNumber);
messageInfo.updateAndMarkReadyToDeliver(sequenceNumber);
deliverySet.add(messageInfo);
notifyIfNeeded();
}
} | java | void deliverSingleDestinationMessage(Message msg, MessageID messageID) {
synchronized (deliverySet) {
long sequenceNumber = sequenceNumberManager.get();
MessageInfo messageInfo = new MessageInfo(messageID, msg, sequenceNumber);
messageInfo.updateAndMarkReadyToDeliver(sequenceNumber);
deliverySet.add(messageInfo);
notifyIfNeeded();
}
} | [
"void",
"deliverSingleDestinationMessage",
"(",
"Message",
"msg",
",",
"MessageID",
"messageID",
")",
"{",
"synchronized",
"(",
"deliverySet",
")",
"{",
"long",
"sequenceNumber",
"=",
"sequenceNumberManager",
".",
"get",
"(",
")",
";",
"MessageInfo",
"messageInfo",
... | delivers a message that has only as destination member this node
@param msg the message | [
"delivers",
"a",
"message",
"that",
"has",
"only",
"as",
"destination",
"member",
"this",
"node"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/protocols/tom/DeliveryManagerImpl.java#L123-L131 | train |
belaban/JGroups | src/org/jgroups/protocols/tom/DeliveryManagerImpl.java | DeliveryManagerImpl.getNextMessagesToDeliver | @Override
public List<Message> getNextMessagesToDeliver() throws InterruptedException {
LinkedList<Message> toDeliver = new LinkedList<>();
synchronized (deliverySet) {
while (deliverySet.isEmpty() || !deliverySet.first().isReadyToDeliver()) {
deliverySet.wait();
}
Iterator<MessageInfo> iterator = deliverySet.iterator();
while (iterator.hasNext()) {
MessageInfo messageInfo = iterator.next();
if (messageInfo.isReadyToDeliver()) {
toDeliver.add(messageInfo.getMessage());
iterator.remove();
} else {
break;
}
}
}
return toDeliver;
} | java | @Override
public List<Message> getNextMessagesToDeliver() throws InterruptedException {
LinkedList<Message> toDeliver = new LinkedList<>();
synchronized (deliverySet) {
while (deliverySet.isEmpty() || !deliverySet.first().isReadyToDeliver()) {
deliverySet.wait();
}
Iterator<MessageInfo> iterator = deliverySet.iterator();
while (iterator.hasNext()) {
MessageInfo messageInfo = iterator.next();
if (messageInfo.isReadyToDeliver()) {
toDeliver.add(messageInfo.getMessage());
iterator.remove();
} else {
break;
}
}
}
return toDeliver;
} | [
"@",
"Override",
"public",
"List",
"<",
"Message",
">",
"getNextMessagesToDeliver",
"(",
")",
"throws",
"InterruptedException",
"{",
"LinkedList",
"<",
"Message",
">",
"toDeliver",
"=",
"new",
"LinkedList",
"<>",
"(",
")",
";",
"synchronized",
"(",
"deliverySet"... | see the interface javadoc | [
"see",
"the",
"interface",
"javadoc"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/protocols/tom/DeliveryManagerImpl.java#L175-L196 | train |
belaban/JGroups | src/org/jgroups/View.java | View.containsMember | public boolean containsMember(Address mbr) {
if(mbr == null || members == null)
return false;
for(Address member: members)
if(Objects.equals(member, mbr))
return true;
return false;
} | java | public boolean containsMember(Address mbr) {
if(mbr == null || members == null)
return false;
for(Address member: members)
if(Objects.equals(member, mbr))
return true;
return false;
} | [
"public",
"boolean",
"containsMember",
"(",
"Address",
"mbr",
")",
"{",
"if",
"(",
"mbr",
"==",
"null",
"||",
"members",
"==",
"null",
")",
"return",
"false",
";",
"for",
"(",
"Address",
"member",
":",
"members",
")",
"if",
"(",
"Objects",
".",
"equals... | Returns true if this view contains a certain member
@param mbr - the address of the member,
@return true if this view contains the member, false if it doesn't | [
"Returns",
"true",
"if",
"this",
"view",
"contains",
"a",
"certain",
"member"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/View.java#L141-L148 | train |
belaban/JGroups | src/org/jgroups/View.java | View.containsMembers | public boolean containsMembers(Address ... mbrs) {
if(mbrs == null || members == null)
return false;
for(Address mbr: mbrs) {
if(!containsMember(mbr))
return false;
}
return true;
} | java | public boolean containsMembers(Address ... mbrs) {
if(mbrs == null || members == null)
return false;
for(Address mbr: mbrs) {
if(!containsMember(mbr))
return false;
}
return true;
} | [
"public",
"boolean",
"containsMembers",
"(",
"Address",
"...",
"mbrs",
")",
"{",
"if",
"(",
"mbrs",
"==",
"null",
"||",
"members",
"==",
"null",
")",
"return",
"false",
";",
"for",
"(",
"Address",
"mbr",
":",
"mbrs",
")",
"{",
"if",
"(",
"!",
"contai... | Returns true if all mbrs are elements of this view, false otherwise | [
"Returns",
"true",
"if",
"all",
"mbrs",
"are",
"elements",
"of",
"this",
"view",
"false",
"otherwise"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/View.java#L151-L159 | train |
belaban/JGroups | src/org/jgroups/View.java | View.leftMembers | public static List<Address> leftMembers(View one, View two) {
if(one == null || two == null)
return null;
List<Address> retval=new ArrayList<>(one.getMembers());
retval.removeAll(two.getMembers());
return retval;
} | java | public static List<Address> leftMembers(View one, View two) {
if(one == null || two == null)
return null;
List<Address> retval=new ArrayList<>(one.getMembers());
retval.removeAll(two.getMembers());
return retval;
} | [
"public",
"static",
"List",
"<",
"Address",
">",
"leftMembers",
"(",
"View",
"one",
",",
"View",
"two",
")",
"{",
"if",
"(",
"one",
"==",
"null",
"||",
"two",
"==",
"null",
")",
"return",
"null",
";",
"List",
"<",
"Address",
">",
"retval",
"=",
"ne... | Returns a list of members which left from view one to two
@param one
@param two | [
"Returns",
"a",
"list",
"of",
"members",
"which",
"left",
"from",
"view",
"one",
"to",
"two"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/View.java#L223-L229 | train |
belaban/JGroups | src/org/jgroups/View.java | View.diff | public static Address[][] diff(final View from, final View to) {
if(to == null)
throw new IllegalArgumentException("the second view cannot be null");
if(from == to)
return new Address[][]{{},{}};
if(from == null) {
Address[] joined=new Address[to.size()];
int index=0;
for(Address addr: to.getMembers())
joined[index++]=addr;
return new Address[][]{joined,{}};
}
Address[] joined=null, left=null;
int num_joiners=0, num_left=0;
// determine joiners
for(Address addr: to)
if(!from.containsMember(addr))
num_joiners++;
if(num_joiners > 0) {
joined=new Address[num_joiners];
int index=0;
for(Address addr: to)
if(!from.containsMember(addr))
joined[index++]=addr;
}
// determine leavers
for(Address addr: from)
if(!to.containsMember(addr))
num_left++;
if(num_left > 0) {
left=new Address[num_left];
int index=0;
for(Address addr: from)
if(!to.containsMember(addr))
left[index++]=addr;
}
return new Address[][]{joined != null? joined : new Address[]{}, left != null? left : new Address[]{}};
} | java | public static Address[][] diff(final View from, final View to) {
if(to == null)
throw new IllegalArgumentException("the second view cannot be null");
if(from == to)
return new Address[][]{{},{}};
if(from == null) {
Address[] joined=new Address[to.size()];
int index=0;
for(Address addr: to.getMembers())
joined[index++]=addr;
return new Address[][]{joined,{}};
}
Address[] joined=null, left=null;
int num_joiners=0, num_left=0;
// determine joiners
for(Address addr: to)
if(!from.containsMember(addr))
num_joiners++;
if(num_joiners > 0) {
joined=new Address[num_joiners];
int index=0;
for(Address addr: to)
if(!from.containsMember(addr))
joined[index++]=addr;
}
// determine leavers
for(Address addr: from)
if(!to.containsMember(addr))
num_left++;
if(num_left > 0) {
left=new Address[num_left];
int index=0;
for(Address addr: from)
if(!to.containsMember(addr))
left[index++]=addr;
}
return new Address[][]{joined != null? joined : new Address[]{}, left != null? left : new Address[]{}};
} | [
"public",
"static",
"Address",
"[",
"]",
"[",
"]",
"diff",
"(",
"final",
"View",
"from",
",",
"final",
"View",
"to",
")",
"{",
"if",
"(",
"to",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"the second view cannot be null\"",
")",
"... | Returns the difference between 2 views from and to. It is assumed that view 'from' is logically prior to view 'to'.
@param from The first view
@param to The second view
@return an array of 2 Address arrays: index 0 has the addresses of the joined member, index 1 those of the left members | [
"Returns",
"the",
"difference",
"between",
"2",
"views",
"from",
"and",
"to",
".",
"It",
"is",
"assumed",
"that",
"view",
"from",
"is",
"logically",
"prior",
"to",
"view",
"to",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/View.java#L245-L286 | train |
belaban/JGroups | src/org/jgroups/View.java | View.sameViews | public static boolean sameViews(View ... views) {
ViewId first_view_id=views[0].getViewId();
return Stream.of(views).allMatch(v -> v.getViewId().equals(first_view_id));
} | java | public static boolean sameViews(View ... views) {
ViewId first_view_id=views[0].getViewId();
return Stream.of(views).allMatch(v -> v.getViewId().equals(first_view_id));
} | [
"public",
"static",
"boolean",
"sameViews",
"(",
"View",
"...",
"views",
")",
"{",
"ViewId",
"first_view_id",
"=",
"views",
"[",
"0",
"]",
".",
"getViewId",
"(",
")",
";",
"return",
"Stream",
".",
"of",
"(",
"views",
")",
".",
"allMatch",
"(",
"v",
"... | Returns true if all views are the same. Uses the view IDs for comparison | [
"Returns",
"true",
"if",
"all",
"views",
"are",
"the",
"same",
".",
"Uses",
"the",
"view",
"IDs",
"for",
"comparison"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/View.java#L289-L292 | train |
belaban/JGroups | src/org/jgroups/Message.java | Message.getBuffer | public byte[] getBuffer() {
if(buf == null)
return null;
if(offset == 0 && length == buf.length)
return buf;
else {
byte[] retval=new byte[length];
System.arraycopy(buf, offset, retval, 0, length);
return retval;
}
} | java | public byte[] getBuffer() {
if(buf == null)
return null;
if(offset == 0 && length == buf.length)
return buf;
else {
byte[] retval=new byte[length];
System.arraycopy(buf, offset, retval, 0, length);
return retval;
}
} | [
"public",
"byte",
"[",
"]",
"getBuffer",
"(",
")",
"{",
"if",
"(",
"buf",
"==",
"null",
")",
"return",
"null",
";",
"if",
"(",
"offset",
"==",
"0",
"&&",
"length",
"==",
"buf",
".",
"length",
")",
"return",
"buf",
";",
"else",
"{",
"byte",
"[",
... | Returns a copy of the buffer if offset and length are used, otherwise a reference.
@return byte array with a copy of the buffer. | [
"Returns",
"a",
"copy",
"of",
"the",
"buffer",
"if",
"offset",
"and",
"length",
"are",
"used",
"otherwise",
"a",
"reference",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/Message.java#L198-L208 | train |
belaban/JGroups | src/org/jgroups/Message.java | Message.setFlag | public Message setFlag(Flag ... flags) {
if(flags != null) {
short tmp=this.flags;
for(Flag flag : flags) {
if(flag != null)
tmp|=flag.value();
}
this.flags=tmp;
}
return this;
} | java | public Message setFlag(Flag ... flags) {
if(flags != null) {
short tmp=this.flags;
for(Flag flag : flags) {
if(flag != null)
tmp|=flag.value();
}
this.flags=tmp;
}
return this;
} | [
"public",
"Message",
"setFlag",
"(",
"Flag",
"...",
"flags",
")",
"{",
"if",
"(",
"flags",
"!=",
"null",
")",
"{",
"short",
"tmp",
"=",
"this",
".",
"flags",
";",
"for",
"(",
"Flag",
"flag",
":",
"flags",
")",
"{",
"if",
"(",
"flag",
"!=",
"null"... | Sets a number of flags in a message
@param flags The flag or flags
@return A reference to the message | [
"Sets",
"a",
"number",
"of",
"flags",
"in",
"a",
"message"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/Message.java#L337-L347 | train |
belaban/JGroups | src/org/jgroups/Message.java | Message.clearFlag | public Message clearFlag(Flag ... flags) {
if(flags != null) {
short tmp=this.flags;
for(Flag flag : flags)
if(flag != null)
tmp&=~flag.value();
this.flags=tmp;
}
return this;
} | java | public Message clearFlag(Flag ... flags) {
if(flags != null) {
short tmp=this.flags;
for(Flag flag : flags)
if(flag != null)
tmp&=~flag.value();
this.flags=tmp;
}
return this;
} | [
"public",
"Message",
"clearFlag",
"(",
"Flag",
"...",
"flags",
")",
"{",
"if",
"(",
"flags",
"!=",
"null",
")",
"{",
"short",
"tmp",
"=",
"this",
".",
"flags",
";",
"for",
"(",
"Flag",
"flag",
":",
"flags",
")",
"if",
"(",
"flag",
"!=",
"null",
"... | Clears a number of flags in a message
@param flags The flags
@return A reference to the message | [
"Clears",
"a",
"number",
"of",
"flags",
"in",
"a",
"message"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/Message.java#L398-L407 | train |
belaban/JGroups | src/org/jgroups/Message.java | Message.putHeader | public Message putHeader(short id, Header hdr) {
if(id < 0)
throw new IllegalArgumentException("An ID of " + id + " is invalid");
if(hdr != null)
hdr.setProtId(id);
synchronized(this) {
Header[] resized_array=Headers.putHeader(this.headers, id, hdr, true);
if(resized_array != null)
this.headers=resized_array;
}
return this;
} | java | public Message putHeader(short id, Header hdr) {
if(id < 0)
throw new IllegalArgumentException("An ID of " + id + " is invalid");
if(hdr != null)
hdr.setProtId(id);
synchronized(this) {
Header[] resized_array=Headers.putHeader(this.headers, id, hdr, true);
if(resized_array != null)
this.headers=resized_array;
}
return this;
} | [
"public",
"Message",
"putHeader",
"(",
"short",
"id",
",",
"Header",
"hdr",
")",
"{",
"if",
"(",
"id",
"<",
"0",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"An ID of \"",
"+",
"id",
"+",
"\" is invalid\"",
")",
";",
"if",
"(",
"hdr",
"!=",
... | Puts a header given an ID into the hashmap. Overwrites potential existing entry. | [
"Puts",
"a",
"header",
"given",
"an",
"ID",
"into",
"the",
"hashmap",
".",
"Overwrites",
"potential",
"existing",
"entry",
"."
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/Message.java#L460-L471 | train |
belaban/JGroups | src/org/jgroups/Message.java | Message.getHeader | public <T extends Header> T getHeader(short ... ids) {
if(ids == null || ids.length == 0)
return null;
return Headers.getHeader(this.headers, ids);
} | java | public <T extends Header> T getHeader(short ... ids) {
if(ids == null || ids.length == 0)
return null;
return Headers.getHeader(this.headers, ids);
} | [
"public",
"<",
"T",
"extends",
"Header",
">",
"T",
"getHeader",
"(",
"short",
"...",
"ids",
")",
"{",
"if",
"(",
"ids",
"==",
"null",
"||",
"ids",
".",
"length",
"==",
"0",
")",
"return",
"null",
";",
"return",
"Headers",
".",
"getHeader",
"(",
"th... | Returns a header for a range of IDs, or null if not found | [
"Returns",
"a",
"header",
"for",
"a",
"range",
"of",
"IDs",
"or",
"null",
"if",
"not",
"found"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/Message.java#L483-L487 | train |
belaban/JGroups | src/org/jgroups/Message.java | Message.copy | public Message copy(boolean copy_buffer, short starting_id, short ... copy_only_ids) {
Message retval=copy(copy_buffer, false);
for(Map.Entry<Short,Header> entry: getHeaders().entrySet()) {
short id=entry.getKey();
if(id >= starting_id || Util.containsId(id, copy_only_ids))
retval.putHeader(id, entry.getValue());
}
return retval;
} | java | public Message copy(boolean copy_buffer, short starting_id, short ... copy_only_ids) {
Message retval=copy(copy_buffer, false);
for(Map.Entry<Short,Header> entry: getHeaders().entrySet()) {
short id=entry.getKey();
if(id >= starting_id || Util.containsId(id, copy_only_ids))
retval.putHeader(id, entry.getValue());
}
return retval;
} | [
"public",
"Message",
"copy",
"(",
"boolean",
"copy_buffer",
",",
"short",
"starting_id",
",",
"short",
"...",
"copy_only_ids",
")",
"{",
"Message",
"retval",
"=",
"copy",
"(",
"copy_buffer",
",",
"false",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"... | Copies a message. Copies only headers with IDs >= starting_id or IDs which are in the copy_only_ids list
@param copy_buffer
@param starting_id
@param copy_only_ids
@return | [
"Copies",
"a",
"message",
".",
"Copies",
"only",
"headers",
"with",
"IDs",
">",
"=",
"starting_id",
"or",
"IDs",
"which",
"are",
"in",
"the",
"copy_only_ids",
"list"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/Message.java#L554-L562 | train |
belaban/JGroups | src/org/jgroups/Message.java | Message.writeTo | @Override public void writeTo(DataOutput out) throws IOException {
byte leading=0;
if(dest != null)
leading=Util.setFlag(leading, DEST_SET);
if(sender != null)
leading=Util.setFlag(leading, SRC_SET);
if(buf != null)
leading=Util.setFlag(leading, BUF_SET);
// 1. write the leading byte first
out.write(leading);
// 2. the flags (e.g. OOB, LOW_PRIO), skip the transient flags
out.writeShort(flags);
// 3. dest_addr
if(dest != null)
Util.writeAddress(dest, out);
// 4. src_addr
if(sender != null)
Util.writeAddress(sender, out);
// 5. headers
Header[] hdrs=this.headers;
int size=Headers.size(hdrs);
out.writeShort(size);
if(size > 0) {
for(Header hdr : hdrs) {
if(hdr == null)
break;
out.writeShort(hdr.getProtId());
writeHeader(hdr, out);
}
}
// 6. buf
if(buf != null) {
out.writeInt(length);
out.write(buf, offset, length);
}
} | java | @Override public void writeTo(DataOutput out) throws IOException {
byte leading=0;
if(dest != null)
leading=Util.setFlag(leading, DEST_SET);
if(sender != null)
leading=Util.setFlag(leading, SRC_SET);
if(buf != null)
leading=Util.setFlag(leading, BUF_SET);
// 1. write the leading byte first
out.write(leading);
// 2. the flags (e.g. OOB, LOW_PRIO), skip the transient flags
out.writeShort(flags);
// 3. dest_addr
if(dest != null)
Util.writeAddress(dest, out);
// 4. src_addr
if(sender != null)
Util.writeAddress(sender, out);
// 5. headers
Header[] hdrs=this.headers;
int size=Headers.size(hdrs);
out.writeShort(size);
if(size > 0) {
for(Header hdr : hdrs) {
if(hdr == null)
break;
out.writeShort(hdr.getProtId());
writeHeader(hdr, out);
}
}
// 6. buf
if(buf != null) {
out.writeInt(length);
out.write(buf, offset, length);
}
} | [
"@",
"Override",
"public",
"void",
"writeTo",
"(",
"DataOutput",
"out",
")",
"throws",
"IOException",
"{",
"byte",
"leading",
"=",
"0",
";",
"if",
"(",
"dest",
"!=",
"null",
")",
"leading",
"=",
"Util",
".",
"setFlag",
"(",
"leading",
",",
"DEST_SET",
... | Writes the message to the output stream | [
"Writes",
"the",
"message",
"to",
"the",
"output",
"stream"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/Message.java#L594-L638 | train |
belaban/JGroups | src/org/jgroups/Message.java | Message.writeToNoAddrs | public void writeToNoAddrs(Address src, DataOutput out, short ... excluded_headers) throws IOException {
byte leading=0;
boolean write_src_addr=src == null || sender != null && !sender.equals(src);
if(write_src_addr)
leading=Util.setFlag(leading, SRC_SET);
if(buf != null)
leading=Util.setFlag(leading, BUF_SET);
// 1. write the leading byte first
out.write(leading);
// 2. the flags (e.g. OOB, LOW_PRIO)
out.writeShort(flags);
// 4. src_addr
if(write_src_addr)
Util.writeAddress(sender, out);
// 5. headers
Header[] hdrs=this.headers;
int size=Headers.size(hdrs, excluded_headers);
out.writeShort(size);
if(size > 0) {
for(Header hdr : hdrs) {
if(hdr == null)
break;
short id=hdr.getProtId();
if(Util.containsId(id, excluded_headers))
continue;
out.writeShort(id);
writeHeader(hdr, out);
}
}
// 6. buf
if(buf != null) {
out.writeInt(length);
out.write(buf, offset, length);
}
} | java | public void writeToNoAddrs(Address src, DataOutput out, short ... excluded_headers) throws IOException {
byte leading=0;
boolean write_src_addr=src == null || sender != null && !sender.equals(src);
if(write_src_addr)
leading=Util.setFlag(leading, SRC_SET);
if(buf != null)
leading=Util.setFlag(leading, BUF_SET);
// 1. write the leading byte first
out.write(leading);
// 2. the flags (e.g. OOB, LOW_PRIO)
out.writeShort(flags);
// 4. src_addr
if(write_src_addr)
Util.writeAddress(sender, out);
// 5. headers
Header[] hdrs=this.headers;
int size=Headers.size(hdrs, excluded_headers);
out.writeShort(size);
if(size > 0) {
for(Header hdr : hdrs) {
if(hdr == null)
break;
short id=hdr.getProtId();
if(Util.containsId(id, excluded_headers))
continue;
out.writeShort(id);
writeHeader(hdr, out);
}
}
// 6. buf
if(buf != null) {
out.writeInt(length);
out.write(buf, offset, length);
}
} | [
"public",
"void",
"writeToNoAddrs",
"(",
"Address",
"src",
",",
"DataOutput",
"out",
",",
"short",
"...",
"excluded_headers",
")",
"throws",
"IOException",
"{",
"byte",
"leading",
"=",
"0",
";",
"boolean",
"write_src_addr",
"=",
"src",
"==",
"null",
"||",
"s... | Writes the message to the output stream, but excludes the dest and src addresses unless the
src address given as argument is different from the message's src address
@param excluded_headers Don't marshal headers that are part of excluded_headers | [
"Writes",
"the",
"message",
"to",
"the",
"output",
"stream",
"but",
"excludes",
"the",
"dest",
"and",
"src",
"addresses",
"unless",
"the",
"src",
"address",
"given",
"as",
"argument",
"is",
"different",
"from",
"the",
"message",
"s",
"src",
"address"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/Message.java#L645-L687 | train |
belaban/JGroups | src/org/jgroups/Message.java | Message.readFrom | @Override public void readFrom(DataInput in) throws IOException, ClassNotFoundException {
// 1. read the leading byte first
byte leading=in.readByte();
// 2. the flags
flags=in.readShort();
// 3. dest_addr
if(Util.isFlagSet(leading, DEST_SET))
dest=Util.readAddress(in);
// 4. src_addr
if(Util.isFlagSet(leading, SRC_SET))
sender=Util.readAddress(in);
// 5. headers
int len=in.readShort();
this.headers=createHeaders(len);
for(int i=0; i < len; i++) {
short id=in.readShort();
Header hdr=readHeader(in).setProtId(id);
this.headers[i]=hdr;
}
// 6. buf
if(Util.isFlagSet(leading, BUF_SET)) {
len=in.readInt();
buf=new byte[len];
in.readFully(buf, 0, len);
length=len;
}
} | java | @Override public void readFrom(DataInput in) throws IOException, ClassNotFoundException {
// 1. read the leading byte first
byte leading=in.readByte();
// 2. the flags
flags=in.readShort();
// 3. dest_addr
if(Util.isFlagSet(leading, DEST_SET))
dest=Util.readAddress(in);
// 4. src_addr
if(Util.isFlagSet(leading, SRC_SET))
sender=Util.readAddress(in);
// 5. headers
int len=in.readShort();
this.headers=createHeaders(len);
for(int i=0; i < len; i++) {
short id=in.readShort();
Header hdr=readHeader(in).setProtId(id);
this.headers[i]=hdr;
}
// 6. buf
if(Util.isFlagSet(leading, BUF_SET)) {
len=in.readInt();
buf=new byte[len];
in.readFully(buf, 0, len);
length=len;
}
} | [
"@",
"Override",
"public",
"void",
"readFrom",
"(",
"DataInput",
"in",
")",
"throws",
"IOException",
",",
"ClassNotFoundException",
"{",
"// 1. read the leading byte first",
"byte",
"leading",
"=",
"in",
".",
"readByte",
"(",
")",
";",
"// 2. the flags",
"flags",
... | Reads the message's contents from an input stream | [
"Reads",
"the",
"message",
"s",
"contents",
"from",
"an",
"input",
"stream"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/Message.java#L690-L721 | train |
belaban/JGroups | src/org/jgroups/stack/RouterStubManager.java | RouterStubManager.forEach | public void forEach(Consumer<RouterStub> action) {
stubs.stream().filter(RouterStub::isConnected).forEach(action::accept);
} | java | public void forEach(Consumer<RouterStub> action) {
stubs.stream().filter(RouterStub::isConnected).forEach(action::accept);
} | [
"public",
"void",
"forEach",
"(",
"Consumer",
"<",
"RouterStub",
">",
"action",
")",
"{",
"stubs",
".",
"stream",
"(",
")",
".",
"filter",
"(",
"RouterStub",
"::",
"isConnected",
")",
".",
"forEach",
"(",
"action",
"::",
"accept",
")",
";",
"}"
] | Applies action to all RouterStubs that are connected
@param action | [
"Applies",
"action",
"to",
"all",
"RouterStubs",
"that",
"are",
"connected"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/stack/RouterStubManager.java#L74-L76 | train |
belaban/JGroups | src/org/jgroups/stack/RouterStubManager.java | RouterStubManager.forAny | public void forAny(Consumer<RouterStub> action) {
while(!stubs.isEmpty()) {
RouterStub stub=Util.pickRandomElement(stubs);
if(stub != null && stub.isConnected()) {
action.accept(stub);
return;
}
}
} | java | public void forAny(Consumer<RouterStub> action) {
while(!stubs.isEmpty()) {
RouterStub stub=Util.pickRandomElement(stubs);
if(stub != null && stub.isConnected()) {
action.accept(stub);
return;
}
}
} | [
"public",
"void",
"forAny",
"(",
"Consumer",
"<",
"RouterStub",
">",
"action",
")",
"{",
"while",
"(",
"!",
"stubs",
".",
"isEmpty",
"(",
")",
")",
"{",
"RouterStub",
"stub",
"=",
"Util",
".",
"pickRandomElement",
"(",
"stubs",
")",
";",
"if",
"(",
"... | Applies action to a randomly picked RouterStub that's connected
@param action | [
"Applies",
"action",
"to",
"a",
"randomly",
"picked",
"RouterStub",
"that",
"s",
"connected"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/stack/RouterStubManager.java#L82-L90 | train |
belaban/JGroups | src/org/jgroups/util/Pool.java | Pool.get | public Element<T> get() {
// start at a random index, so different threads don't all start at index 0 and compete for the lock
int starting_index=((int)(Math.random() * pool.length)) & (pool.length - 1);
for(int i=0; i < locks.length; i++) {
int index=(starting_index + i) & (pool.length -1);
Lock lock=locks[index];
if(lock.tryLock()) {
if(pool[index] != null)
return new Element<>(pool[index], lock);
return new Element<>(pool[index]=creator.get(), lock);
}
}
return new Element<>(creator.get(), null);
} | java | public Element<T> get() {
// start at a random index, so different threads don't all start at index 0 and compete for the lock
int starting_index=((int)(Math.random() * pool.length)) & (pool.length - 1);
for(int i=0; i < locks.length; i++) {
int index=(starting_index + i) & (pool.length -1);
Lock lock=locks[index];
if(lock.tryLock()) {
if(pool[index] != null)
return new Element<>(pool[index], lock);
return new Element<>(pool[index]=creator.get(), lock);
}
}
return new Element<>(creator.get(), null);
} | [
"public",
"Element",
"<",
"T",
">",
"get",
"(",
")",
"{",
"// start at a random index, so different threads don't all start at index 0 and compete for the lock",
"int",
"starting_index",
"=",
"(",
"(",
"int",
")",
"(",
"Math",
".",
"random",
"(",
")",
"*",
"pool",
"... | Gets the next available resource for which the lock can be acquired and returns it and its associated
lock, which needs to be released when the caller is done using the resource. If no resource in the pool can be
locked, returns a newly created resource and a null lock. This means that no lock was acquired and thus
doesn't need to be released.
@return An Element with T and a lock (possibly null if newly created) | [
"Gets",
"the",
"next",
"available",
"resource",
"for",
"which",
"the",
"lock",
"can",
"be",
"acquired",
"and",
"returns",
"it",
"and",
"its",
"associated",
"lock",
"which",
"needs",
"to",
"be",
"released",
"when",
"the",
"caller",
"is",
"done",
"using",
"t... | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/util/Pool.java#L49-L62 | train |
belaban/JGroups | src/org/jgroups/jmx/ResourceDMBean.java | ResourceDMBean.toLowerCase | protected static String toLowerCase(String input) {
if(Character.isUpperCase(input.charAt(0)))
return input.substring(0, 1).toLowerCase() + input.substring(1);
return input;
} | java | protected static String toLowerCase(String input) {
if(Character.isUpperCase(input.charAt(0)))
return input.substring(0, 1).toLowerCase() + input.substring(1);
return input;
} | [
"protected",
"static",
"String",
"toLowerCase",
"(",
"String",
"input",
")",
"{",
"if",
"(",
"Character",
".",
"isUpperCase",
"(",
"input",
".",
"charAt",
"(",
"0",
")",
")",
")",
"return",
"input",
".",
"substring",
"(",
"0",
",",
"1",
")",
".",
"to... | Returns a string with the first letter being lowercase | [
"Returns",
"a",
"string",
"with",
"the",
"first",
"letter",
"being",
"lowercase"
] | bd3ca786aa57fed41dfbc10a94b1281e388be03b | https://github.com/belaban/JGroups/blob/bd3ca786aa57fed41dfbc10a94b1281e388be03b/src/org/jgroups/jmx/ResourceDMBean.java#L386-L390 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.