org.jgroups.protocols.MULTI_PING Maven / Gradle / Ivy
Go to download
This artifact provides a single jar that contains all classes required to use remote Jakarta Enterprise Beans and Jakarta Messaging, including
all dependencies. It is intended for use by those not using maven, maven users should just import the Jakarta Enterprise Beans and
Jakarta Messaging BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up
with different versions on classes on the class path).
package org.jgroups.protocols;
import org.jgroups.Address;
import org.jgroups.annotations.ManagedAttribute;
import org.jgroups.stack.Protocol;
import org.jgroups.util.Responses;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* Protocol to invoke multiple discovery protocols in the same stack. All discovery protocols needs to be _below_ this
* one, e.g.
* {@code
*
*
*
*
*
*
*
* ...
* }
* @author Bela Ban
* @since 4.0.8
*/
public class MULTI_PING extends Discovery {
protected final List discovery_protocols=new ArrayList<>();
@ManagedAttribute(description="List of discovery protocols")
public String getDiscoveryProtocols() {
return discovery_protocols.stream().map(p -> p.getClass().getSimpleName()).collect(Collectors.joining(", "));
}
public boolean isDynamic() {
return discovery_protocols.stream().anyMatch(Discovery::isDynamic);
}
public void init() throws Exception {
super.init();
// sanity check: we cannot have any discovery protocols _above_ us
for(Protocol p=up_prot; p != null; p=p.getUpProtocol())
if(p instanceof Discovery)
throw new IllegalStateException(String.format("found %s above %s: this is invalid; all discovery " +
"protocols must be placed below %s", p.getClass().getSimpleName(),
getClass().getSimpleName(), getClass().getSimpleName()));
// add all discovery protocols below us to the discovery_protocols list
for(Protocol p=down_prot; p != null; p=p.getDownProtocol())
if(p instanceof Discovery)
discovery_protocols.add((Discovery)p);
}
public void weedOutCompletedDiscoveryResponses() {
super.weedOutCompletedDiscoveryResponses();
for(Discovery p: discovery_protocols)
p.weedOutCompletedDiscoveryResponses();
}
protected void findMembers(List members, boolean initial_discovery, Responses responses) {
; // not used
}
@Override
protected void invokeFindMembers(List members, boolean initial_discovery, Responses rsps, boolean async) {
findMembers(members, initial_discovery, rsps, async);
}
protected void findMembers(List members, boolean initial_discovery, Responses rsps, boolean async) {
for(Discovery discovery_protocol: discovery_protocols) {
discovery_protocol.addResponse(rsps);
if(discovery_rsp_callback != null)
discovery_protocol.discovery_rsp_callback=this.discovery_rsp_callback;
if(async || async_discovery)
timer.execute(() -> discovery_protocol.findMembers(members, initial_discovery, rsps));
else
discovery_protocol.findMembers(members, initial_discovery, rsps);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy