use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class UNICAST_DropFirstAndLastTest method printConnectionTables.
protected void printConnectionTables(JChannel... channels) {
System.out.println("**** CONNECTIONS:");
for (JChannel ch : channels) {
Protocol ucast = ch.getProtocolStack().findProtocol(Util.getUnicastProtocols());
System.out.println(ch.getName() + ":\n" + printConnections(ucast) + "\n");
}
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class ConcurrentStartupTest method create.
protected static JChannel create(Class<? extends TP> tp_cl, Class<? extends Discovery> discovery_cl, String name) throws Exception {
TP tp = tp_cl.getDeclaredConstructor().newInstance().setBindAddress(Util.getLoopback());
Protocol[] protocols = { tp, discovery_cl.getDeclaredConstructor().newInstance(), new NAKACK2(), new UNICAST3(), new STABLE(), new GMS().setJoinTimeout(1000).setLeaveTimeout(100) };
return new JChannel(protocols).name(name);
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class StateTransferTest2 method replaceStateTransferProtocolWith.
protected static void replaceStateTransferProtocolWith(JChannel ch, Class<? extends Protocol> state_transfer_class) throws Exception {
ProtocolStack stack = ch.getProtocolStack();
if (stack.findProtocol(state_transfer_class) != null)
// protocol of the right class is already in stack
return;
Protocol prot = stack.findProtocol(STATE_TRANSFER.class, StreamingStateTransfer.class);
Protocol new_state_transfer_protcol = state_transfer_class.getDeclaredConstructor().newInstance();
if (prot != null) {
stack.replaceProtocol(prot, new_state_transfer_protcol);
} else {
// no state transfer protocol found in stack
Protocol flush = stack.findProtocol(FLUSH.class);
if (flush != null)
stack.insertProtocol(new_state_transfer_protcol, ProtocolStack.Position.BELOW, FLUSH.class);
else
stack.insertProtocolAtTop(new_state_transfer_protcol);
}
}
use of org.jgroups.stack.Protocol in project wildfly by wildfly.
the class AbstractProtocolConfigurationBuilder method createProtocol.
@SuppressWarnings("unchecked")
@Override
public final P createProtocol() {
StringBuilder builder = new StringBuilder();
if (this.moduleName.equals(AbstractProtocolResourceDefinition.Attribute.MODULE.getDefinition().getDefaultValue().asString()) && !this.name.startsWith(org.jgroups.conf.ProtocolConfiguration.protocol_prefix)) {
builder.append(org.jgroups.conf.ProtocolConfiguration.protocol_prefix).append('.');
}
String className = builder.append(this.name).toString();
try {
Module module = this.loader.getValue().loadModule(this.moduleName);
Class<? extends Protocol> protocolClass = module.getClassLoader().loadClass(className).asSubclass(Protocol.class);
Protocol protocol = ProtocolFactory.newInstance(protocolClass);
P result = (P) ProtocolFactory.TRANSFORMER.apply(protocol);
Map<String, String> properties = new HashMap<>(this.defaults.getValue().getProperties(this.name));
properties.putAll(this.properties);
Configurator.resolveAndAssignFields(result, properties);
Configurator.resolveAndInvokePropertyMethods(result, properties);
this.accept(result);
return result;
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class PropertyHelper method getConvertedValue.
public static Object getConvertedValue(Object obj, Field field, Map<String, String> props, String prop, boolean check_scope) throws Exception {
if (obj == null)
throw new IllegalArgumentException("Cannot get converted value: Object is null");
if (field == null)
throw new IllegalArgumentException("Cannot get converted value: Field is null");
if (props == null)
throw new IllegalArgumentException("Cannot get converted value: Properties is null");
Property annotation = field.getAnnotation(Property.class);
if (annotation == null) {
throw new IllegalArgumentException("Cannot get property name for field " + field.getName() + " which is not annotated with @Property");
}
String propertyName = getPropertyName(field, props);
String name = obj instanceof Protocol ? ((Protocol) obj).getName() : obj.getClass().getName();
PropertyConverter propertyConverter = (PropertyConverter) annotation.converter().newInstance();
if (propertyConverter == null) {
throw new Exception("Could not find property converter for field " + propertyName + " in " + name);
}
Object converted = null;
try {
String tmp = obj instanceof Protocol ? ((Protocol) obj).getName() + "." + propertyName : propertyName;
converted = propertyConverter.convert(obj, field.getType(), tmp, prop, check_scope);
} catch (Exception e) {
throw new Exception("Conversion of " + propertyName + " in " + name + " with original property value " + prop + " failed", e);
}
return converted;
}
Aggregations