public void setup(ProtocolStack stack) throws Exception { if(top_prot == null) { top_prot=new Configurator(this).setupProtocolStack(stack); top_prot.setUpProtocol(this); this.setDownProtocol(top_prot); bottom_prot=getBottomProtocol(); initProtocolStack(); } }
List<Protocol> protocols=createProtocols(protocol_configs, st); if(protocols == null) return null; Map<String, Map<String,InetAddressInfo>> inetAddressMap = createInetAddressMap(protocol_configs, protocols) ; Collection<InetAddress> addrs=getAddresses(inetAddressMap); setDefaultValues(protocol_configs, protocols, ip_version); ensureValidBindAddresses(protocols); return connectProtocols(protocols);
retval.setProtocolStack(stack); removeDeprecatedProperties(retval, properties); AccessibleObject[] dependencyOrderedFieldsAndMethods = computePropertyDependencies(retval, properties) ; for(AccessibleObject ordered: dependencyOrderedFieldsAndMethods) { if (ordered instanceof Field) { resolveAndAssignField(retval, (Field)ordered, properties) ; resolveAndInvokePropertyMethod(retval, (Method)ordered, properties) ; if(additional_objects != null && !additional_objects.isEmpty()) { for(Object obj: additional_objects) { resolveAndAssignFields(obj, properties); resolveAndInvokePropertyMethods(obj, properties);
/** * Resolves and applies the specified properties to this protocol. * @param properties a map of property string values * @return this protocol * @throws Exception if any of the specified properties are unresolvable or unrecognized. */ public <T extends Protocol> T setProperties(Map<String, String> properties) throws Exception { // These Configurator methods are destructive, so make a defensive copy Map<String, String> copy = new HashMap<>(properties); Configurator.removeDeprecatedProperties(this, copy); Configurator.resolveAndAssignFields(this, copy); Configurator.resolveAndInvokePropertyMethods(this, copy); List<Object> objects = this.getConfigurableObjects(); if (objects != null) { for (Object object : objects) { Configurator.removeDeprecatedProperties(object, copy); Configurator.resolveAndAssignFields(object, copy); Configurator.resolveAndInvokePropertyMethods(object, copy); } } if (!copy.isEmpty()) { throw new IllegalArgumentException(String.format("Unrecognized %s properties: %s", this.getName(), copy.keySet())); } return (T)this; }
public static void main(String args[]) { if(args.length != 1) { System.err.println("Configurator <string>"); System.exit(0); } String config_str=args[0]; Configurator conf=new Configurator(); Vector<ProtocolConfiguration> protocol_configs; Vector<Protocol> protocols=null; Protocol protocol_stack; try { protocol_configs=Configurator.parseConfigurations(config_str); protocols=Configurator.createProtocols(protocol_configs, null); if(protocols == null) return; protocol_stack=Configurator.connectProtocols(protocols); Thread.sleep(3000); Configurator.destroyProtocolStack(protocol_stack); // conf.stopProtocolStackInternal(protocol_stack); } catch(Exception e) { System.err.println(e); } System.err.println(protocols); }
Vector<Protocol> protocols; protocol_configs=parseConfigurations(configuration); protocols=createProtocols(protocol_configs, st); if(protocols == null) return null; protocol_stack=connectProtocols(protocols); return protocol_stack;
if (methods[i].isAnnotationPresent(Property.class) && isSetPropertyMethod(methods[i], obj.getClass())) { String propertyName = PropertyHelper.getPropertyName(methods[i]) ; unorderedFieldsAndMethods.add(methods[i]) ; checkDependencyReferencesPresent(unorderedFieldsAndMethods, propertiesInventory) ; orderedFieldsAndMethods = orderFieldsAndMethodsByDependency(unorderedFieldsAndMethods, propertiesInventory) ;
public void init() throws Exception { List<Protocol> protocols=getProtocols(); Collections.reverse(protocols); top_prot=Configurator.connectProtocols(protocols); top_prot.setUpProtocol(this); this.setDownProtocol(top_prot); bottom_prot=getBottomProtocol(); Configurator.setDefaultValues(protocols); initProtocolStack(); }
public void setup() throws Exception { if(top_prot == null) { top_prot=Configurator.setupProtocolStack(setup_string, this); top_prot.setUpProtocol(this); bottom_prot=Configurator.getBottommostProtocol(top_prot); Configurator.initProtocolStack(bottom_prot); // calls init() on each protocol, from bottom to top } }
/** Creates a fork-stack from the configuration, initializes all protocols (setting values), * sets the protocol stack as top protocol, connects the protocols and calls init() on them. Returns * the protocols in a list, from bottom to top */ protected static List<Protocol> createProtocols(ProtocolStack stack, List<ProtocolConfiguration> protocol_configs) throws Exception { return Configurator.createProtocols(protocol_configs,stack); }
if(INSTANCE == null) return new Configurator(); return INSTANCE; }
Configurator.resolveAndAssignFields(relay, relayConfig.getProperties()); Configurator.resolveAndInvokePropertyMethods(relay, relayConfig.getProperties()); stack.addProtocol(relay); relay.init(); clusterRole != null ? clusterRole : id, saslProps)); props.put("sasl_props", new PropertyConverters.StringProperties().toString(saslProps)); Configurator.resolveAndAssignFields(sasl, props); Configurator.resolveAndInvokePropertyMethods(sasl, props); channel.getProtocolStack().insertProtocol(sasl, ProtocolStack.Position.BELOW, GMS.class); sasl.init();
/** * Creates a channel from a list of protocols. Note that after a {@link org.jgroups.JChannel#close()}, the protocol * list <em>should not</em> be reused, ie. new JChannel(protocols) would reuse the same protocol list, and this * might lead to problems ! * @param protocols The list of protocols, from bottom to top, ie. the first protocol in the list is the transport, * the last the top protocol * @deprecated Use {@link JChannel#JChannel(List)} instead */ @Deprecated public JChannel(Collection<Protocol> protocols) throws Exception { prot_stack=new ProtocolStack().setChannel(this); for(Protocol prot: protocols) { prot_stack.addProtocol(prot); prot.setProtocolStack(prot_stack); } prot_stack.init(); // Substitute vars with defined system props (if any) List<Protocol> prots=prot_stack.getProtocols(); Map<String,String> map=new HashMap<>(); for(Protocol prot: prots) Configurator.resolveAndAssignFields(prot, map); }
Configurator config=new Configurator(); String cfg=inputAsString(input); Vector tmp=config.parseConfigurations(cfg); System.out.println(dump(tmp));
/** * Creates a protocol stack by iterating through the protocol list and connecting * adjacent layers. The list starts with the topmost layer and has the bottommost * layer at the tail. * @param protocol_list List of Protocol elements (from top to bottom) * @return Protocol stack */ public static Protocol connectProtocols(List<Protocol> protocol_list) throws Exception { Protocol current_layer=null, next_layer=null; for(int i=0; i < protocol_list.size(); i++) { current_layer=protocol_list.get(i); if(i + 1 >= protocol_list.size()) break; next_layer=protocol_list.get(i + 1); next_layer.setDownProtocol(current_layer); current_layer.setUpProtocol(next_layer); } // basic protocol sanity check sanityCheck(protocol_list); return current_layer; }
public Protocol setupProtocolStack(ProtocolStack copySource) throws Exception { List<Protocol> protocols=copySource.copyProtocols(stack); Collections.reverse(protocols); return connectProtocols(protocols); }
public Protocol setupProtocolStack(List<ProtocolConfiguration> config) throws Exception { return setupProtocolStack(config, stack); }
static List<AccessibleObject> orderFieldsAndMethodsByDependency(List<AccessibleObject> unorderedList, Map<String, AccessibleObject> propertiesMap) { // Stack to detect cycle in depends relation Stack<AccessibleObject> stack = new Stack<>() ; // the result list List<AccessibleObject> orderedList = new LinkedList<>() ; // add the elements from the unordered list to the ordered list // any dependencies will be checked and added first, in recursive manner for(int i = 0; i < unorderedList.size(); i++) { AccessibleObject obj = unorderedList.get(i) ; addPropertyToDependencyList(orderedList, propertiesMap, stack, obj) ; } return orderedList ; }
/** * Resolves and applies the specified properties to this protocol. * @param properties a map of property string values * @return this protocol * @throws Exception if any of the specified properties are unresolvable or unrecognized. */ public <T extends Protocol> T setProperties(Map<String, String> properties) throws Exception { // These Configurator methods are destructive, so make a defensive copy Map<String, String> copy = new HashMap<>(properties); Configurator.removeDeprecatedProperties(this, copy); Configurator.resolveAndAssignFields(this, copy); Configurator.resolveAndInvokePropertyMethods(this, copy); List<Object> objects = this.getConfigurableObjects(); if (objects != null) { for (Object object : objects) { Configurator.removeDeprecatedProperties(object, copy); Configurator.resolveAndAssignFields(object, copy); Configurator.resolveAndInvokePropertyMethods(object, copy); } } if (!copy.isEmpty()) { throw new IllegalArgumentException(String.format("Unrecognized %s properties: %s", this.getName(), copy.keySet())); } return (T)this; }
if (methods[i].isAnnotationPresent(Property.class) && isSetPropertyMethod(methods[i], obj.getClass())) { String propertyName = PropertyHelper.getPropertyName(methods[i]) ; unorderedFieldsAndMethods.add(methods[i]) ; checkDependencyReferencesPresent(unorderedFieldsAndMethods, propertiesInventory) ; orderedFieldsAndMethods = orderFieldsAndMethodsByDependency(unorderedFieldsAndMethods, propertiesInventory) ;