public static Field getField(final Class clazz, String field_name) { try { return getField(clazz, field_name, false); } catch(NoSuchFieldException e) { return null; } }
public String toString() { StringBuilder sb=new StringBuilder(); Field[] fields=MsgStats.class.getDeclaredFields(); for(Field field: fields) { try { Object val=Util.getField(field, this); sb.append(field.getName()).append(": ").append(val).append("\n"); } catch(Throwable t) { } } return sb.toString(); } }
/** Copies state from main-channel to this fork-channel */ protected void copyFields() { for(Field field: copied_fields) { Object value=Util.getField(field,main_channel); Util.setField(field, this, value); } }
public static Object getValueFromProtocol(Protocol protocol, String field_name) throws IllegalAccessException { if(protocol == null || field_name == null) return null; Field field=Util.getField(protocol.getClass(), field_name); return field != null? getValueFromProtocol(protocol, field) : null; }
protected void applyConfig(Config config) { for(Map.Entry<String,Object> entry: config.values.entrySet()) { Field field=Util.getField(getClass(), entry.getKey()); Util.setField(field, this, entry.getValue()); } }
public void set(String field_name, Object value) { Field field=Util.getField(this.getClass(),field_name); if(field == null) System.err.println("Field " + field_name + " not found"); else { Util.setField(field, this, value); System.out.println(field.getName() + "=" + value); } }
private static void setBindAddress(Protocol protocol, InetAddress bind_addr) throws Exception { Field f=Util.getField(protocol.getClass(), "bind_addr"); Util.setField(f, protocol, bind_addr) ; }
protected void handleConfigChange(ConfigChange config_change) { String attr_name=config_change.attr_name; try { Object attr_value=config_change.getValue(); Field field=Util.getField(this.getClass(), attr_name); Util.setField(field,this,attr_value); System.out.println(config_change.attr_name + "=" + attr_value); log_interval=num_msgs / 10; receive_log_interval=Math.max(1, num_msgs * Math.max(1, members.size()) / 10); } catch(Exception e) { System.err.println("failed applying config change for attr " + attr_name + ": " + e); } }
public Config getConfig() { Config config=new Config(); for(Field field: Util.getAllDeclaredFields(UPerf.class)) { if(field.isAnnotationPresent(Property.class)) { config.add(field.getName(), Util.getField(field, this)); } } return config; }
public void configChange(ConfigChange config_change) { // 5 String attr_name=config_change.attr_name; try { Object attr_value=config_change.getValue(); Field field=Util.getField(this.getClass(), attr_name); Util.setField(field, this, attr_value); System.out.println(config_change.attr_name + "=" + attr_value); log_interval=num_msgs / 10; receive_log_interval=num_msgs * Math.max(1, members.size()) / 10; send_options.mode(sync? ResponseMode.GET_ALL : ResponseMode.GET_NONE); if(oob) send_options.flags(Message.Flag.OOB); } catch(Exception e) { System.err.println("failed applying config change for attr " + attr_name + ": " + e); } }
public <T extends Protocol> T setValue(String name, Object value) { if(name == null || value == null) return (T)this; Field field=Util.getField(getClass(), name); if(field == null) throw new IllegalArgumentException("field " + name + " not found"); Property prop=field.getAnnotation(Property.class); if(prop != null) { String deprecated_msg=prop.deprecatedMessage(); if(deprecated_msg != null && !deprecated_msg.isEmpty()) log.warn("Field " + getName() + "." + name + " is deprecated: " + deprecated_msg); } Util.setField(field, this, value); return (T)this; }
for(Field field: fields) { if(field.isAnnotationPresent(Property.class)) { Object value=Util.getField(field, prot); Util.setField(field, new_prot, value); Field field=Util.findField(prot, possible_names); if(field != null) { Object value=Util.getField(field, prot); Util.setField(field, new_prot, value);
/** Finds an accessor for an attribute. Tries to find setAttrName(), attrName() methods. If not * found, tries to use reflection to set the value of attr_name. If still not found, creates a NullAccessor. */ public static Accessor findSetter(Object target, String attr_name) { final String name=Util.attributeNameToMethodName(attr_name); final String fluent_name=toLowerCase(name); Class<?> clazz=target.getClass(); Class<?> field_type=null; Field field=Util.getField(clazz, attr_name); field_type=field != null? field.getType() : null; String setter_name="set" + name; if(field_type != null) { Method method=Util.findMethod(target, Arrays.asList(fluent_name, setter_name), field_type); if(method != null && isSetMethod(method)) return new MethodAccessor(method, target); } // Find all methods but don't include methods from Object class List<Method> methods=new ArrayList<>(Arrays.asList(clazz.getMethods())); methods.removeAll(OBJECT_METHODS); for(Method method: methods) { String method_name=method.getName(); if((method_name.equals(name) || method_name.equals(fluent_name) || method_name.equals(setter_name)) && isSetMethod(method)) return new MethodAccessor(method, target); } // Find a field last_name if(field != null) return new FieldAccessor(field, target); return null; }
for(Field field: fields) { if(field.isAnnotationPresent(Property.class)) { Object value=Util.getField(field, prot); if(value != null) { annotation=field.getAnnotation(Property.class); Field field=Util.findField(prot, possible_names); if(field != null) { Object value=Util.getField(field, prot); if(value != null) { Class<?> conv_class=annotation.converter();
/** Finds an accessor for an attribute. Tries to find getAttrName(), isAttrName(), attrName() methods. If not * found, tries to use reflection to get the value of attr_name. If still not found, creates a NullAccessor. */ protected static Accessor findGetter(Object target, String attr_name) { final String name=Util.attributeNameToMethodName(attr_name); Class<?> clazz=target.getClass(); Method method=Util.findMethod(target, Arrays.asList("get" + name, "is" + name, toLowerCase(name))); if(method != null && (isGetMethod(method) || isIsMethod(method))) return new MethodAccessor(method, target); // 4. Find a field last_name Field field=Util.getField(clazz, attr_name); if(field != null) return new FieldAccessor(field, target); return new NoopAccessor(); }
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;
public void set(String field_name, Object value) { Field field=Util.getField(this.getClass(),field_name); if(field == null) System.err.println("Field " + field_name + " not found"); else { Util.setField(field, this, value); System.out.println(field.getName() + "=" + value); } }
public Config getConfig() { Config config=new Config(); for(Field field: Util.getAllDeclaredFields(UPerf.class)) { if(field.isAnnotationPresent(Property.class)) { config.add(field.getName(), Util.getField(field, this)); } } return config; }