use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class ClusterSplitLockTest method setUp.
@BeforeMethod
protected void setUp() throws Exception {
for (int i = 0; i < MEMBERS; i++) {
Protocol[] stack = Util.getTestStack(new CENTRAL_LOCK().level("debug").setValue("num_backups", 2));
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.
assertTrue(channels[0].getView().getCoord().equals(channels[0].getAddress()));
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class PropertyHelper method getConvertedValue.
public static Object getConvertedValue(Object obj, Field field, String value, 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");
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 = field.getName();
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, value, check_scope);
} catch (Exception e) {
throw new Exception("Conversion of " + propertyName + " in " + name + " with original property value " + value + " failed", e);
}
return converted;
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class JChannelProbeHandler method handleJmx.
protected void handleJmx(Map<String, String> map, String input) {
Map<String, Object> tmp_stats;
int index = input.indexOf('=');
if (index > -1) {
List<String> list = null;
String protocol_name = input.substring(index + 1);
index = protocol_name.indexOf('.');
if (index > -1) {
String rest = protocol_name;
protocol_name = protocol_name.substring(0, index);
// e.g. "num_sent,msgs,num_received_msgs"
String attrs = rest.substring(index + 1);
list = Util.parseStringList(attrs, ",");
// check if there are any attribute-sets in the list
for (Iterator<String> it = list.iterator(); it.hasNext(); ) {
String tmp = it.next();
index = tmp.indexOf('=');
if (index != -1) {
String attrname = tmp.substring(0, index);
String attrvalue = tmp.substring(index + 1);
Object target = ch.getProtocolStack().findProtocol(protocol_name);
Field field = target != null ? Util.getField(target.getClass(), attrname) : null;
if (field == null && target instanceof AdditionalJmxObjects) {
Object[] objs = ((AdditionalJmxObjects) target).getJmxObjects();
if (objs != null && objs.length > 0) {
for (Object o : objs) {
field = o != null ? Util.getField(o.getClass(), attrname) : null;
if (field != null) {
target = o;
break;
}
}
}
}
if (field != null) {
Object value = Util.convert(attrvalue, field.getType());
if (value != null) {
if (target instanceof Protocol)
((Protocol) target).setValue(attrname, value);
else
Util.setField(field, target, value);
}
} else {
// try to find a setter for X, e.g. x(type-of-x) or setX(type-of-x)
ResourceDMBean.Accessor setter = ResourceDMBean.findSetter(target, attrname);
if (setter == null && target instanceof AdditionalJmxObjects) {
Object[] objs = ((AdditionalJmxObjects) target).getJmxObjects();
if (objs != null && objs.length > 0) {
for (Object o : objs) {
setter = o != null ? ResourceDMBean.findSetter(o, attrname) : null;
if (setter != null)
break;
}
}
}
if (setter != null) {
try {
Class<?> type = setter instanceof ResourceDMBean.FieldAccessor ? ((ResourceDMBean.FieldAccessor) setter).getField().getType() : setter instanceof ResourceDMBean.MethodAccessor ? ((ResourceDMBean.MethodAccessor) setter).getMethod().getParameterTypes()[0] : null;
Object converted_value = Util.convert(attrvalue, type);
setter.invoke(converted_value);
} catch (Exception e) {
log.error("unable to invoke %s() on %s: %s", setter, protocol_name, e);
}
} else {
log.warn(Util.getMessage("FieldNotFound"), attrname, protocol_name);
setter = new ResourceDMBean.NoopAccessor();
}
}
it.remove();
}
}
}
tmp_stats = ch.dumpStats(protocol_name, list);
if (tmp_stats != null) {
for (Map.Entry<String, Object> entry : tmp_stats.entrySet()) {
Map<String, Object> tmp_map = (Map<String, Object>) entry.getValue();
String key = entry.getKey();
map.put(key, tmp_map != null ? tmp_map.toString() : null);
}
}
} else {
tmp_stats = ch.dumpStats();
if (tmp_stats != null) {
for (Map.Entry<String, Object> entry : tmp_stats.entrySet()) {
Map<String, Object> tmp_map = (Map<String, Object>) entry.getValue();
String key = entry.getKey();
map.put(key, tmp_map != null ? tmp_map.toString() : null);
}
}
}
}
use of org.jgroups.stack.Protocol in project fabric8 by jboss-fuse.
the class TestBase method setUp.
@Before
public void setUp() throws Exception {
for (int i = 0; i < NUM; i++) {
Protocol ping = createPing();
channels[i] = new JChannel(new TCP(), ping, new NAKACK2(), new UNICAST3(), new STABLE(), new GMS());
channels[i].setName(Character.toString((char) ('A' + i)));
channels[i].connect(CLUSTER_NAME);
channels[i].setReceiver(receivers[i] = new MyReceiver());
}
}
use of org.jgroups.stack.Protocol in project wildfly by wildfly.
the class AbstractProtocolConfigurationServiceConfigurator method createProtocol.
@Override
public final P createProtocol(ProtocolStackConfiguration stackConfiguration) {
String protocolName = this.name;
String moduleName = this.moduleName;
// A "native" protocol is one that is not specified as a class name
boolean nativeProtocol = moduleName.equals(AbstractProtocolResourceDefinition.Attribute.MODULE.getDefinition().getDefaultValue().asString()) && !protocolName.startsWith(Global.PREFIX);
String className = nativeProtocol ? (Global.PREFIX + protocolName) : protocolName;
try {
Module module = this.loader.get().loadModule(moduleName);
Class<? extends Protocol> protocolClass = module.getClassLoader().loadClass(className).asSubclass(Protocol.class);
Map<String, String> properties = new HashMap<>(this.defaults.get().getProperties(protocolClass));
properties.putAll(this.properties);
PrivilegedExceptionAction<Protocol> action = new PrivilegedExceptionAction<Protocol>() {
@Override
public Protocol run() throws Exception {
try {
Protocol protocol = protocolClass.getConstructor().newInstance();
// These Configurator methods are destructive, so make a defensive copy
Map<String, String> copy = new HashMap<>(properties);
StackType type = Util.getIpStackType();
Configurator.resolveAndAssignFields(protocol, copy, type);
Configurator.resolveAndInvokePropertyMethods(protocol, copy, type);
List<Object> objects = protocol.getConfigurableObjects();
if (objects != null) {
for (Object object : objects) {
Configurator.resolveAndAssignFields(object, copy, type);
Configurator.resolveAndInvokePropertyMethods(object, copy, type);
}
}
if (!copy.isEmpty()) {
for (String property : copy.keySet()) {
JGroupsLogger.ROOT_LOGGER.unrecognizedProtocolProperty(protocolName, property);
}
}
return protocol;
} catch (InstantiationException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
}
};
@SuppressWarnings("unchecked") P protocol = (P) WildFlySecurityManager.doUnchecked(action);
this.accept(protocol);
protocol.enableStats(this.statisticsEnabled != null ? this.statisticsEnabled : stackConfiguration.isStatisticsEnabled());
return protocol;
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
}
Aggregations