/// <summary> The configuration string has a number of entries, separated by a ':' (colon). /// Each entry consists of the name of the protocol, followed by an optional configuration /// of that protocol. The configuration is enclosed in parentheses, and contains entries /// which are name/value pairs connected with an assignment sign (=) and separated by /// a semicolon. /// <pre>UDP(in_port=5555;out_port=4445):FRAG(frag_size=1024)</pre><p> /// The <em>first</em> entry defines the <em>bottommost</em> layer, the string is parsed /// left to right and the protocol stack constructed bottom up. Example: the string /// "UDP(in_port=5555):FRAG(frag_size=32000):DEBUG" results is the following stack:<pre> /// /// ----------------------- /// | DEBUG | /// |-----------------------| /// | FRAG frag_size=32000 | /// |-----------------------| /// | UDP in_port=32000 | /// ----------------------- /// </pre> /// </summary> public virtual Protocol setupProtocolStack(string configuration, ProtocolStack st) { Protocol protocol_stack = null; System.Collections.ArrayList protocol_configs; System.Collections.ArrayList protocols; protocol_configs = parseConfigurations(configuration); protocols = createProtocols(protocol_configs, st); if (protocols == null) return null; protocol_stack = connectProtocols(protocols); return protocol_stack; }
/// <summary> Takes vector of ProtocolConfigurations, iterates through it, creates Protocol for /// each ProtocolConfiguration and returns all Protocols in a vector. /// </summary> /// <param name="protocol_configs">Vector of ProtocolConfigurations /// </param> /// <param name="stack">The protocol stack /// </param> /// <returns> Vector of Protocols /// </returns> private System.Collections.ArrayList createProtocols(System.Collections.ArrayList protocol_configs, ProtocolStack stack) { System.Collections.ArrayList retval = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); ProtocolConfiguration protocol_config; Protocol layer; stack.StackType = ProtocolStackType.TCP; for (int i = 0; i < protocol_configs.Count; i++) { protocol_config = (ProtocolConfiguration)protocol_configs[i]; if (protocol_config != null) { if (protocol_config.ProtocolName == "UDP") { stack.StackType = ProtocolStackType.UDP; break; } } } for (int i = 0; i < protocol_configs.Count; i++) { protocol_config = (ProtocolConfiguration)protocol_configs[i]; layer = protocol_config.createLayer(stack); if (layer == null) { return(null); } retval.Add(layer); } sanityCheck(retval); return(retval); }
/// <summary> Inserts an already created (and initialized) protocol into the protocol list. Sets the links /// to the protocols above and below correctly and adjusts the linked list of protocols accordingly. /// </summary> /// <param name="prot"> The protocol to be inserted. Before insertion, a sanity check will ensure that none /// of the existing protocols have the same name as the new protocol. /// </param> /// <param name="position">Where to place the protocol with respect to the neighbor_prot (ABOVE, BELOW) /// </param> /// <param name="neighbor_prot">The name of the neighbor protocol. An exception will be thrown if this name /// is not found /// </param> /// <param name="stack">The protocol stack /// </param> /// <exception cref=""> Exception Will be thrown when the new protocol cannot be created, or inserted. /// </exception> public virtual void insertProtocol(Protocol prot, int position, string neighbor_prot, ProtocolStack stack) { if (neighbor_prot == null) { throw new System.Exception("Configurator.insertProtocol(): neighbor_prot is null"); } if (position != ProtocolStack.ABOVE && position != ProtocolStack.BELOW) { throw new System.Exception("Configurator.insertProtocol(): position has to be ABOVE or BELOW"); } // find the neighbors below and above // connect to the protocol layer below and above }
/// <summary> Opens the channel.<BR> /// this does the following actions<BR> /// 1. Resets the receiver queue by calling Queue.reset<BR> /// 2. Sets up the protocol stack by calling ProtocolStack.setup<BR> /// 3. Sets the closed flag to false.<BR> /// </summary> public override void open() { lock (this) { if (!closed) throw new ChannelException("GroupChannel.open(): channel is already open."); try { mq.reset(); // new stack is created on open() - bela June 12 2003 prot_stack = new ProtocolStack(this, props); prot_stack.setup(); closed = false; } catch (System.Exception e) { throw new ChannelException("GroupChannel().open(): " + e.Message); } } }
/// <summary> Constructs a <code>GroupChannel</code> instance with the protocol stack /// configuration based upon the specified properties parameter. /// /// </summary> /// <param name="properties">an old style property string, a string representing a /// system resource containing a JGroups XML configuration, /// a string representing a URL pointing to a JGroups XML /// XML configuration, or a string representing a file name /// that contains a JGroups XML configuration. /// /// </param> /// <throws> ChannelException if problems occur during the configuration and </throws> /// <summary> initialization of the protocol stack. /// </summary> public GroupChannel(string properties, ILogger NCacheLog) { props = properties; this._ncacheLog = NCacheLog; /*create the new protocol stack*/ prot_stack = new ProtocolStack(this, props); prot_stack.NCacheLog = NCacheLog; /* Setup protocol stack (create layers, queues between them */ try { prot_stack.setup(); } catch (System.Exception e) { NCacheLog.Error("GroupChannel.GroupChannel()", e.ToString()); throw new ChannelException("GroupChannel(): " + e); } }
public virtual Protocol createLayer(ProtocolStack prot_stack) { if (protocol_name == null) return null; Protocol protocol = null; switch (protocol_name) { case "TCP": protocol = new Alachisoft.NGroups.Protocols.TCP(); break; case "TCPPING": protocol = new Alachisoft.NGroups.Protocols.TCPPING(); break; case "QUEUE": protocol = new Alachisoft.NGroups.Protocols.QUEUE(); break; case "TOTAL": protocol = new Alachisoft.NGroups.Protocols.TOTAL(); break; case "VIEW_ENFORCER": protocol = new Alachisoft.NGroups.Protocols.VIEW_ENFORCER(); break; case "pbcast.GMS": protocol = new Alachisoft.NGroups.Protocols.pbcast.GMS(); break; } if (protocol != null) { prot_stack.NCacheLog.Info("Configurator.createLayer()", "Created Layer " + protocol.GetType().FullName); protocol.Stack = prot_stack; if (properties != null) if (!protocol.setPropertiesInternal(properties)) return null; protocol.init(); } else { prot_stack.NCacheLog.Error("Configurator.createLayer()", "Couldn't create layer: " + protocol_name); } return protocol; }
/// <summary> Takes vector of ProtocolConfigurations, iterates through it, creates Protocol for /// each ProtocolConfiguration and returns all Protocols in a vector. /// </summary> /// <param name="protocol_configs">Vector of ProtocolConfigurations /// </param> /// <param name="stack">The protocol stack /// </param> /// <returns> Vector of Protocols /// </returns> private System.Collections.ArrayList createProtocols(System.Collections.ArrayList protocol_configs, ProtocolStack stack) { System.Collections.ArrayList retval = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); ProtocolConfiguration protocol_config; Protocol layer; stack.StackType = ProtocolStackType.TCP; for (int i = 0; i < protocol_configs.Count; i++) { protocol_config = (ProtocolConfiguration)protocol_configs[i]; if (protocol_config != null) { if (protocol_config.ProtocolName == "UDP") { stack.StackType = ProtocolStackType.UDP; break; } } } for (int i = 0; i < protocol_configs.Count; i++) { protocol_config = (ProtocolConfiguration) protocol_configs[i]; layer = protocol_config.createLayer(stack ); if (layer == null) return null; retval.Add(layer); } sanityCheck(retval); return retval; }
/// <summary> Inserts an already created (and initialized) protocol into the protocol list. Sets the links /// to the protocols above and below correctly and adjusts the linked list of protocols accordingly. /// </summary> /// <param name="prot"> The protocol to be inserted. Before insertion, a sanity check will ensure that none /// of the existing protocols have the same name as the new protocol. /// </param> /// <param name="position">Where to place the protocol with respect to the neighbor_prot (ABOVE, BELOW) /// </param> /// <param name="neighbor_prot">The name of the neighbor protocol. An exception will be thrown if this name /// is not found /// </param> /// <param name="stack">The protocol stack /// </param> /// <exception cref=""> Exception Will be thrown when the new protocol cannot be created, or inserted. /// </exception> public virtual void insertProtocol(Protocol prot, int position, string neighbor_prot, ProtocolStack stack) { if (neighbor_prot == null) throw new System.Exception("Configurator.insertProtocol(): neighbor_prot is null"); if (position != ProtocolStack.ABOVE && position != ProtocolStack.BELOW) throw new System.Exception("Configurator.insertProtocol(): position has to be ABOVE or BELOW"); // find the neighbors below and above // connect to the protocol layer below and above }
/// <summary> Creates a new protocol given the protocol specification. Initializes the properties and starts the /// up and down handler threads. /// </summary> /// <param name="prot_spec">The specification of the protocol. Same convention as for specifying a protocol stack. /// An exception will be thrown if the class cannot be created. Example: /// <pre>"VERIFY_SUSPECT(timeout=1500)"</pre> Note that no colons (:) have to be /// specified /// </param> /// <param name="stack">The protocol stack /// </param> /// <returns> Protocol The newly created protocol /// </returns> /// <exception cref=""> Exception Will be thrown when the new protocol cannot be created /// </exception> public virtual Protocol createProtocol(string prot_spec, ProtocolStack stack) { ProtocolConfiguration config; Protocol prot; if (prot_spec == null) throw new System.Exception("Configurator.createProtocol(): prot_spec is null"); // parse the configuration for this protocol config = new ProtocolConfiguration(this, prot_spec); // create an instance of the protocol class and configure it prot = config.createLayer(stack); // start the handler threads (unless down_thread or up_thread are set to false) prot.startDownHandler(); prot.startUpHandler(); return prot; }