use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class TUNNEL_Test method createTunnelChannel.
protected JChannel createTunnelChannel(String name, boolean include_failure_detection) throws Exception {
TUNNEL tunnel = new TUNNEL().setBindAddress(gossip_router_bind_addr);
FD_ALL3 fd_all = new FD_ALL3().setTimeout(2000).setInterval(500);
tunnel.setGossipRouterHosts(gossip_router_hosts);
List<Protocol> protocols = new ArrayList<>(Arrays.asList(tunnel, new PING(), new MERGE3().setMinInterval(1000).setMaxInterval(3000)));
if (include_failure_detection) {
List<Protocol> tmp = new ArrayList<>(2);
tmp.add(fd_all);
tmp.add(new VERIFY_SUSPECT());
protocols.addAll(tmp);
}
protocols.addAll(Arrays.asList(new NAKACK2().useMcastXmit(false), new UNICAST3(), new STABLE(), new GMS().setJoinTimeout(1000)));
JChannel ch = new JChannel(protocols);
if (name != null)
ch.setName(name);
return ch;
}
use of org.jgroups.stack.Protocol in project wildfly by wildfly.
the class ProtocolMetricsHandler method executeRuntimeStep.
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
String name = Operations.getAttributeName(operation);
String protocolName = context.getCurrentAddressValue();
ServiceName channelServiceName = JGroupsRequirement.CHANNEL.getServiceName(context, UnaryCapabilityNameResolver.PARENT);
ExceptionFunction<JChannel, ModelNode, Exception> function = new ExceptionFunction<JChannel, ModelNode, Exception>() {
@Override
public ModelNode apply(JChannel channel) throws Exception {
int index = protocolName.lastIndexOf('.');
Protocol protocol = channel.getProtocolStack().findProtocol((index < 0) ? protocolName : protocolName.substring(index + 1));
if (protocol == null) {
throw new IllegalArgumentException(protocolName);
}
Attribute attribute = getAttribute(protocol.getClass(), name);
if (attribute == null) {
throw new OperationFailedException(JGroupsLogger.ROOT_LOGGER.unknownMetric(name));
}
FieldType type = FieldType.valueOf(attribute.getType());
ModelNode result = new ModelNode();
Object value = attribute.read(protocol);
if (value != null) {
type.setValue(result, value);
}
return result;
}
};
FunctionExecutor<JChannel> executor = this.executors.get(channelServiceName);
try {
ModelNode value = (executor != null) ? executor.execute(function) : null;
if (value != null) {
context.getResult().set(value);
}
} catch (Exception e) {
context.getFailureDescription().set(e.getLocalizedMessage());
} finally {
context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER);
}
}
use of org.jgroups.stack.Protocol in project wildfly by wildfly.
the class JChannelFactory method createChannel.
@Override
public JChannel createChannel(String id) throws Exception {
FORK fork = new FORK();
fork.enableStats(this.configuration.isStatisticsEnabled());
fork.setUnknownForkHandler(new UnknownForkHandler() {
private final short id = ClassConfigurator.getProtocolId(RequestCorrelator.class);
@Override
public Object handleUnknownForkStack(Message message, String forkStackId) {
return this.handle(message);
}
@Override
public Object handleUnknownForkChannel(Message message, String forkChannelId) {
return this.handle(message);
}
private Object handle(Message message) {
Header header = (Header) message.getHeader(this.id);
// If this is a request expecting a response, don't leave the requester hanging - send an identifiable response on which it can filter
if ((header != null) && (header.type == Header.REQ) && header.rspExpected()) {
Message response = message.makeReply().setFlag(message.getFlags()).clearFlag(Message.Flag.RSVP, Message.Flag.INTERNAL);
response.putHeader(FORK.ID, message.getHeader(FORK.ID));
response.putHeader(this.id, new Header(Header.RSP, header.req_id, header.corrId));
response.setBuffer(UNKNOWN_FORK_RESPONSE.array());
fork.getProtocolStack().getChannel().down(response);
}
return null;
}
});
Map<String, SocketBinding> bindings = new HashMap<>();
// Transport always resides at the bottom of the stack
List<ProtocolConfiguration<? extends Protocol>> transports = Collections.singletonList(this.configuration.getTransport());
// Add RELAY2 to the top of the stack, if defined
List<ProtocolConfiguration<? extends Protocol>> relays = this.configuration.getRelay().isPresent() ? Collections.singletonList(this.configuration.getRelay().get()) : Collections.emptyList();
List<Protocol> protocols = new ArrayList<>(transports.size() + this.configuration.getProtocols().size() + relays.size() + 1);
for (List<ProtocolConfiguration<? extends Protocol>> protocolConfigs : Arrays.asList(transports, this.configuration.getProtocols(), relays)) {
for (ProtocolConfiguration<? extends Protocol> protocolConfig : protocolConfigs) {
protocols.add(protocolConfig.createProtocol(this.configuration));
bindings.putAll(protocolConfig.getSocketBindings());
}
}
// Add implicit FORK to the top of the stack
protocols.add(fork);
// Override the SocketFactory of the transport
protocols.get(0).setSocketFactory(new ManagedSocketFactory(this.configuration.getSocketBindingManager(), bindings));
JChannel channel = new JChannel(protocols);
channel.setName(this.configuration.getNodeName());
TransportConfiguration.Topology topology = this.configuration.getTransport().getTopology();
if (topology != null) {
channel.addAddressGenerator(new TopologyAddressGenerator(topology));
}
return channel;
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class JChannelProbeHandler method handleProbe.
public Map<String, String> handleProbe(String... keys) {
Map<String, String> map = new TreeMap<>();
for (String key : keys) {
if (key.startsWith("jmx")) {
handleJmx(map, key);
continue;
}
if (key.startsWith("reset-stats")) {
resetAllStats();
continue;
}
if (key.startsWith("ops")) {
listOperations(map, key);
continue;
}
if (key.startsWith("invoke") || key.startsWith("op")) {
int index = key.indexOf('=');
if (index != -1) {
try {
handleOperation(map, key.substring(index + 1));
} catch (Throwable throwable) {
log.error(Util.getMessage("OperationInvocationFailure"), key.substring(index + 1), throwable);
}
}
continue;
}
if (key.startsWith("threads")) {
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
boolean cpu_supported = bean.isThreadCpuTimeSupported();
boolean contention_supported = bean.isThreadContentionMonitoringSupported();
int max_name = 0;
long[] ids = bean.getAllThreadIds();
List<ThreadEntry> entries = new ArrayList<>(ids.length);
for (long id : ids) {
ThreadInfo info = bean.getThreadInfo(id);
if (info == null)
continue;
String thread_name = info.getThreadName();
max_name = Math.max(max_name, thread_name.length());
Thread.State state = info.getThreadState();
long blocked = info.getBlockedCount();
long blocked_time = contention_supported ? info.getBlockedTime() : -1;
long waited = info.getWaitedCount();
long waited_time = contention_supported ? info.getWaitedTime() : -1;
double cpu_time = cpu_supported ? bean.getThreadCpuTime(id) : -1;
if (cpu_time > 0)
cpu_time /= 1_000_000;
double user_time = cpu_supported ? bean.getThreadUserTime(id) : -1;
if (user_time > 0)
user_time /= 1_000_000;
ThreadEntry entry = new ThreadEntry(state, thread_name, blocked, waited, blocked_time, waited_time, cpu_time, user_time);
entries.add(entry);
}
int index = key.indexOf('=');
if (index >= 0) {
Comparator<ThreadEntry> comp = Comparator.comparing(e -> e.thread_name);
String val = key.substring(index + 1);
if (val.startsWith("state"))
comp = Comparator.comparing(e -> e.state);
else if (val.startsWith("cpu"))
comp = Comparator.comparing((ThreadEntry e) -> e.cpu_time).reversed();
else if (val.startsWith("user"))
comp = Comparator.comparing((ThreadEntry e) -> e.user_time).reversed();
else if (val.startsWith("block"))
comp = Comparator.comparing((ThreadEntry e) -> e.blocks).reversed();
else if (val.startsWith("btime"))
comp = Comparator.comparing((ThreadEntry e) -> e.block_time).reversed();
else if (val.startsWith("wait"))
comp = Comparator.comparing((ThreadEntry e) -> e.waits).reversed();
else if (val.startsWith("wtime"))
comp = Comparator.comparing((ThreadEntry e) -> e.wait_time).reversed();
entries.sort(comp);
}
// see if we need to limit the displayed data
index = key.indexOf('=', index + 1);
int limit = 0;
if (index >= 0) {
String val = key.substring(index + 1);
limit = Integer.parseInt(val);
}
max_name = Math.min(max_name, 50) + 1;
String title = "\n[%s] \t%-" + max_name + "s: %10s %10s %6s %9s %10s %10s\n";
String line = "[%s]\t%-" + max_name + "s: %,8.0f %,8.0f %,10d %,9.0f %,10d %,10.0f\n";
StringBuilder sb = new StringBuilder(String.format(title, "state", "thread-name", "cpu (ms)", "user (ms)", "block", "btime (ms)", "wait", "wtime (ms)"));
Stream<ThreadEntry> stream = entries.stream();
if (limit > 0)
stream = stream.limit(limit);
stream.forEach(e -> sb.append(e.print(line)));
map.put(key, sb.toString());
continue;
}
if (key.equals("enable-cpu")) {
map.put(key, enable(1, true));
continue;
}
if (key.startsWith("enable-cont")) {
map.put(key, enable(2, true));
continue;
}
if (key.equals("disable-cpu")) {
map.put(key, enable(1, false));
continue;
}
if (key.startsWith("disable-cont")) {
map.put(key, enable(2, false));
}
// everything else could be an attribute query (without prefix "jmx=") or an operation (without "op=")
// https://issues.redhat.com/browse/JGRP-2413
String protocol;
int index = key.indexOf('.');
if (index == -1)
protocol = key;
else
protocol = key.substring(0, index);
Protocol prot = ch.getProtocolStack().findProtocol(protocol);
if (prot != null) {
String tmp = key.substring(index + 1);
int left = tmp.indexOf('['), right = left != -1 ? tmp.indexOf(']', left) : -1;
if (left != -1 && right != -1) {
// it is most likely an operation
try {
return handleProbe("op=" + key);
} catch (Throwable throwable) {
log.error(Util.getMessage("OperationInvocationFailure"), key.substring(index + 1), throwable);
}
} else
// try JMX
return handleProbe("jmx=" + key);
}
}
return map;
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class ClusterSplitLockTest method setUp.
protected void setUp(Class<? extends Locking> locking_class) throws Exception {
for (int i = 0; i < MEMBERS; i++) {
Locking lock_prot = locking_class.getDeclaredConstructor().newInstance().level("debug");
if (lock_prot instanceof CENTRAL_LOCK)
((CENTRAL_LOCK) lock_prot).setNumberOfBackups(2);
Protocol[] stack = Util.getTestStack(lock_prot);
channels[i] = new JChannel(stack);
lockServices[i] = new LockService(channels[i]);
channels[i].setName(memberName(i));
channels[i].connect("TEST");
execs[i] = Executors.newCachedThreadPool();
if (i == 0)
Util.sleep(500);
}
Util.waitUntilAllChannelsHaveSameView(10000, 1000, channels);
// Make sure A is coordinator, because we blindly assume it is in the tests below.
assertEquals(channels[0].getAddress(), channels[0].getView().getCoord());
}
Aggregations