use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class JmxConfigurator method registerChannel.
public static void registerChannel(JChannel ch, MBeanServer server, ObjectName namePrefix, String cluster_name, boolean register_protocols) throws Exception {
if (ch == null)
throw new NullPointerException("channel cannot be null");
if (cluster_name == null)
cluster_name = ch.getClusterName();
if (cluster_name == null)
cluster_name = "null";
cluster_name = ObjectName.quote(cluster_name);
if (register_protocols) {
ProtocolStack stack = ch.getProtocolStack();
List<Protocol> protocols = stack.getProtocols();
for (Protocol p : protocols) {
if (p.getClass().isAnnotationPresent(MBean.class)) {
String jmx_name = getProtocolRegistrationName(cluster_name, namePrefix, p);
register(p, server, jmx_name);
}
}
}
register(ch, server, getChannelRegistrationName(namePrefix, cluster_name));
}
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, StackType ip_version) throws Exception {
Objects.requireNonNull(obj, "cannot get converted value: obj is null");
Objects.requireNonNull(field, "cannot get converted value: field is null");
Objects.requireNonNull(props, "cannot get converted value: props 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().getDeclaredConstructor().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, ip_version);
} catch (Exception e) {
throw new Exception("Conversion of " + propertyName + " in " + name + " with property value " + prop + " failed", e);
}
return converted;
}
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, StackType ip_version) throws Exception {
Objects.requireNonNull(obj, "cannot get converted value: obj is null");
Objects.requireNonNull(field, "cannot get converted value: field is null");
String propName = field.getName();
Property annotation = field.getAnnotation(Property.class);
if (annotation == null)
throw new IllegalArgumentException("cannot get property name for " + propName + " (not annotated with @Property)");
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 field " + propName + " in " + name);
Object converted = null;
try {
String tmp = obj instanceof Protocol ? ((Protocol) obj).getName() + "." + propName : propName;
converted = propertyConverter.convert(obj, field.getType(), tmp, value, check_scope, ip_version);
} catch (Exception e) {
throw new Exception("Conversion of " + name + "." + " with original property value " + value + " failed", e);
}
return converted;
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class FORK method setStateInMainAndForkChannels.
protected void setStateInMainAndForkChannels(InputStream in) {
try (DataInputStream input = new DataInputStream(in)) {
for (; ; ) {
String stack_name = Bits.readString(input);
String ch_name = Bits.readString(input);
int len = input.readInt();
if (len > 0) {
byte[] data = new byte[len];
in.read(data, 0, len);
ByteArrayInputStream tmp = new ByteArrayInputStream(data, 0, len);
if (stack_name == null && ch_name == null)
up_prot.up(new Event(Event.STATE_TRANSFER_INPUTSTREAM, tmp));
else {
Protocol prot = fork_stacks.get(stack_name);
if (prot == null) {
log.warn("%s: fork stack %s not found, dropping state for %s:%s", local_addr, stack_name, stack_name, ch_name);
continue;
}
ForkProtocolStack fork_stack = getForkStack(prot);
JChannel fork_ch = fork_stack.get(ch_name);
if (fork_ch == null) {
log.warn("%s: fork channel %s not found, dropping state for %s:%s", local_addr, ch_name, stack_name, ch_name);
continue;
}
fork_ch.up(new Event(Event.STATE_TRANSFER_INPUTSTREAM, tmp));
}
}
}
} catch (EOFException ignored) {
} catch (Throwable ex) {
log.error("%s: failed setting state in main channel", local_addr, ex);
}
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class FORK method up.
public Object up(Message msg) {
ForkHeader hdr = msg.getHeader(id);
if (hdr == null)
return up_prot.up(msg);
if (hdr.fork_stack_id == null)
throw new IllegalArgumentException("header has a null fork_stack_id");
Protocol bottom_prot = get(hdr.fork_stack_id);
return bottom_prot != null ? bottom_prot.up(msg) : this.unknownForkHandler.handleUnknownForkStack(msg, hdr.fork_stack_id);
}
Aggregations