use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class ProtocolConfigurationTest method testDefaultAssignment.
/*
* Checks assignment of defaults
*/
public void testDefaultAssignment() throws Exception {
List<ProtocolConfiguration> protocol_configs = new ArrayList<>();
List<Protocol> protocols = new ArrayList<>();
// create the layer described by DEFAULTS
protocol = Configurator.createProtocol(defaultProps, stack);
// process the defaults
protocol_configs.add(new ProtocolConfiguration(defaultProps));
protocols.add(protocol);
Configurator.setDefaultAddressValues(protocols, StackType.IPv4);
// get the value which should have been assigned a default
int a = ((DEFAULTS) protocol).getA();
System.out.println("value of a = " + a);
// get the value which should not have been assigned a default
int b = ((DEFAULTS) protocol).getB();
System.out.println("value of b = " + b);
// assert b == 333 ;
if (b != 333) {
throw new RuntimeException("default property value set when it should not have been");
}
// get the value which should not have been assigned a default
InetAddress c = ((DEFAULTS) protocol).getC();
System.out.println("value of c = " + c);
assert c != null;
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class JChannelProbeHandler method handleOperation.
/**
* Invokes an operation and puts the return value into map
* @param map
* @param operation Protocol.OperationName[args], e.g. STABLE.foo[arg1 arg2 arg3]
*/
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 = null;
try {
Class<? extends Protocol> cl = Util.loadProtocolClass(prot_name, this.getClass());
prot = ch.getProtocolStack().findProtocol(cl);
} catch (Exception e) {
}
if (prot == null)
prot = ch.getProtocolStack().findProtocol(prot_name);
if (prot == null) {
log.error("protocol %s not found", prot_name);
// less drastic than throwing an exception...
return;
}
operation = operation.substring(index + 1);
ReflectUtils.invokeOperation(map, operation, prot);
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class PropertyHelper method getConvertedValue.
public static Object getConvertedValue(Object obj, Method method, Map<String, String> props, String prop, boolean check_scope, StackType ip_version) throws Exception {
if (obj == null)
throw new IllegalArgumentException("Cannot get converted value: Object is null");
if (method == null)
throw new IllegalArgumentException("Cannot get converted value: Method is null");
if (!Configurator.isSetPropertyMethod(method, obj.getClass()))
throw new IllegalArgumentException("Cannot get converted value: Method is not set property method");
if (props == null)
throw new IllegalArgumentException("Cannot get converted value: Properties is null");
Property annotation = method.getAnnotation(Property.class);
if (annotation == null)
throw new IllegalArgumentException("Cannot get property name for method " + method.getName() + ": not annotated with @Property");
String propertyName = getPropertyName(method);
String name = obj instanceof Protocol ? ((Protocol) obj).getName() : obj.getClass().getName();
PropertyConverter propertyConverter = (PropertyConverter) annotation.converter().getDeclaredConstructor().newInstance();
if (propertyConverter == null)
throw new Exception("Could not find property converter for method " + propertyName + " in " + name);
Object converted = null;
try {
String tmp = obj instanceof Protocol ? ((Protocol) obj).getName() + "." + propertyName : propertyName;
converted = propertyConverter.convert(obj, method.getParameterTypes()[0], tmp, prop, check_scope, ip_version);
} catch (Exception e) {
throw new Exception("Conversion of " + propertyName + " in " + name + " with original property value " + prop + " failed. Exception is " + e, e);
}
return converted;
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class ConfiguratorTest method testInsertion.
public void testInsertion() throws Exception {
List<Protocol> protocols = stack.getProtocols();
assert protocols != null;
Assert.assertEquals(6, protocols.size());
for (int i = 0; i < names.length; i++) {
String name = names[i];
Protocol p = protocols.get(i);
Assert.assertEquals(name, p.getName());
}
// insert below
Protocol new_prot = (Protocol) Class.forName("org.jgroups.protocols.TRACE").getDeclaredConstructor().newInstance();
stack.insertProtocol(new_prot, ProtocolStack.Position.BELOW, UNICAST3.class);
protocols = stack.getProtocols();
Assert.assertEquals(7, protocols.size());
for (int i = 0; i < below.length; i++) {
String name = below[i];
Protocol p = protocols.get(i);
Assert.assertEquals(name, p.getName());
}
// remove
Protocol prot = stack.removeProtocol("TRACE");
assert prot != null;
protocols = stack.getProtocols();
Assert.assertEquals(6, protocols.size());
for (int i = 0; i < names.length; i++) {
String name = names[i];
Protocol p = protocols.get(i);
Assert.assertEquals(name, p.getName());
}
// insert above
new_prot = (Protocol) Class.forName("org.jgroups.protocols.TRACE").getDeclaredConstructor().newInstance();
stack.insertProtocol(new_prot, ProtocolStack.Position.ABOVE, UNICAST3.class);
protocols = stack.getProtocols();
Assert.assertEquals(7, protocols.size());
for (int i = 0; i < above.length; i++) {
String name = above[i];
Protocol p = protocols.get(i);
Assert.assertEquals(name, p.getName());
}
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class ConfiguratorTest method testRemovalOfTop.
public void testRemovalOfTop() throws Exception {
Protocol prot = stack.removeProtocol("MFC");
assert prot != null;
List<Protocol> protocols = stack.getProtocols();
Assert.assertEquals(5, protocols.size());
assert protocols.get(0).getName().endsWith("UNICAST3");
assert stack.getTopProtocol().getUpProtocol() != null;
assert stack.getTopProtocol().getDownProtocol() != null;
assert stack.getTopProtocol().getDownProtocol().getUpProtocol() != null;
assert stack.getTopProtocol().getDownProtocol().getDownProtocol() != null;
}
Aggregations