Esempio n. 1
0
        internal override JSONNode ToJsonNode()
        {
            JSONObject o = new JSONObject();

            AddField(o, ApiConstants.Description, Description);
            AddField(o, ApiConstants.DurableName, Durable);
            AddField(o, ApiConstants.DeliverPolicy, DeliverPolicy.GetString());
            AddField(o, ApiConstants.DeliverSubject, DeliverSubject);
            AddField(o, ApiConstants.DeliverGroup, DeliverGroup);
            AddField(o, ApiConstants.OptStartSeq, StartSeq);
            AddField(o, ApiConstants.OptStartTime, JsonUtils.ToString(StartTime));
            AddField(o, ApiConstants.AckPolicy, AckPolicy.GetString());
            AddField(o, ApiConstants.AckWait, AckWait);
            AddField(o, ApiConstants.MaxDeliver, MaxDeliver);
            AddField(o, ApiConstants.FilterSubject, FilterSubject);
            AddField(o, ApiConstants.ReplayPolicy, ReplayPolicy.GetString());
            AddField(o, ApiConstants.SampleFreq, SampleFrequency);
            AddField(o, ApiConstants.RateLimitBps, RateLimitBps);
            AddField(o, ApiConstants.MaxAckPending, MaxAckPending);
            AddField(o, ApiConstants.IdleHeartbeat, IdleHeartbeat);
            AddField(o, ApiConstants.FlowControl, FlowControl);
            AddField(o, ApiConstants.MaxWaiting, MaxPullWaiting);
            AddField(o, ApiConstants.HeadersOnly, HeadersOnly);
            AddField(o, ApiConstants.MaxBatch, MaxBatch);
            AddField(o, ApiConstants.MaxBytes, MaxBytes);
            AddField(o, ApiConstants.MaxExpires, MaxExpires);
            AddField(o, ApiConstants.InactiveThreshold, InactiveThreshold);
            AddField(o, ApiConstants.Backoff, Backoff);

            return(o);
        }
Esempio n. 2
0
 // For the builder
 private ConsumerConfig(string durableName,
                        DeliverPolicy deliverPolicy,
                        long?startSequence,
                        DateTime?startTime,
                        AckPolicy ackPolicy,
                        long ackWait,
                        long?maxDeliver,
                        string filterSubject,
                        ReplayPolicy replayPolicy,
                        string sampleFrequency,
                        long?rateLimit,
                        string deliverSubject,
                        string deliverGroup,
                        long?maxAckPending,
                        long?heartbeat,
                        bool?flowControl)
 {
     this.DurableName     = durableName;
     this.DeliverPolicy   = deliverPolicy;
     this.StartSequence   = startSequence;
     this.StartTime       = startTime;
     this.AckPolicy       = ackPolicy;
     this.AckWait         = ackWait;
     this.MaxDeliver      = maxDeliver;
     this.FilterSubject   = filterSubject;
     this.ReplayPolicy    = replayPolicy;
     this.SampleFrequency = sampleFrequency;
     this.RateLimit       = rateLimit;
     this.DeliverSubject  = deliverSubject;
     this.DeliverGroup    = deliverGroup;
     this.MaxAckPending   = maxAckPending;
     this.Heartbeat       = heartbeat;
     this.FlowControl     = flowControl;
 }
Esempio n. 3
0
        public RepConfig()
        {
            ackPolicy   = AckPolicy.QUORUM;
            bulk        = false;
            home        = "";
            localSite   = new DbSiteConfig();
            priority    = 100;
            remoteSites = new List <DbSiteConfig>();
            startPolicy = StartPolicy.ELECTION;

            verbose = false;
        }
Esempio n. 4
0
        public static string GetString(this AckPolicy ackPolicy)
        {
            switch (ackPolicy)
            {
            case AckPolicy.None:     return("none");

            case AckPolicy.All:      return("all");

            case AckPolicy.Explicit: return("explicit");
            }
            return(null);
        }
Esempio n. 5
0
        public RepConfig()
        {
            ackPolicy   = AckPolicy.QUORUM;
            bulk        = false;
            home        = "";
            host        = new ReplicationHostAddress();
            priority    = 100;
            remote      = new List <RemoteSite>();
            startPolicy = StartPolicy.ELECTION;

            totalSites = 0;
            verbose    = false;
        }
Esempio n. 6
0
        /*
         * Confirm that the given value is the same with that in
         * xml. If there is no testing data in xml and it is
         * compulsory, the ConfigNotFoundException will be thrown.
         * If there is no testing data and it is optional, nothing
         * will be done. If any testing data is provided, the value
         * will be checked.
         */
        #region Confirm
        public static void ConfirmAckPolicy(XmlElement xmlElem,
                                            string name, AckPolicy ackPolicy, bool compulsory)
        {
            XmlNode xmlNode = XMLReader.GetNode(xmlElem,
                                                name);

            if (xmlNode == null && compulsory == true)
            {
                throw new ConfigNotFoundException(name);
            }
            else if (xmlNode != null)
            {
                string policy = xmlNode.InnerText;
                if (policy == "ALL")
                {
                    Assert.AreEqual(AckPolicy.ALL,
                                    ackPolicy);
                }
                else if (policy == "ALL_PEERS")
                {
                    Assert.AreEqual(AckPolicy.ALL_PEERS,
                                    ackPolicy);
                }
                else if (policy == "NONE")
                {
                    Assert.AreEqual(AckPolicy.NONE,
                                    ackPolicy);
                }
                else if (policy == "ONE")
                {
                    Assert.AreEqual(AckPolicy.ONE,
                                    ackPolicy);
                }
                else if (policy == "ONE_PEER")
                {
                    Assert.AreEqual(AckPolicy.ONE_PEER,
                                    ackPolicy);
                }
                else if (policy == "QUORUM")
                {
                    Assert.AreEqual(AckPolicy.QUORUM,
                                    ackPolicy);
                }
                else
                {
                    throw new InvalidConfigException(name);
                }
            }
        }
Esempio n. 7
0
 public ConsumerConfigBuilder(ConsumerConfig consumerConfig)
 {
     this.DurableName     = consumerConfig.DurableName;
     this.DeliverPolicy   = consumerConfig.DeliverPolicy;
     this.StartSequence   = consumerConfig.StartSequence;
     this.StartTime       = consumerConfig.StartTime;
     this.AckPolicy       = consumerConfig.AckPolicy;
     this.AckWait         = consumerConfig.AckWait;
     this.MaxDeliver      = consumerConfig.MaxDeliver;
     this.FilterSubject   = consumerConfig.FilterSubject;
     this.ReplayPolicy    = consumerConfig.ReplayPolicy;
     this.SampleFrequency = consumerConfig.SampleFrequency;
     this.RateLimit       = consumerConfig.RateLimit;
     this.DeliverSubject  = consumerConfig.DeliverSubject;
     this.DeliverGroup    = consumerConfig.DeliverGroup;
     this.MaxAckPending   = consumerConfig.MaxAckPending;
     this.Heartbeat       = consumerConfig.Heartbeat;
     this.FlowControl     = consumerConfig.FlowControl;
 }
Esempio n. 8
0
        public void SetRepMgrAckPolicy(string home, AckPolicy policy)
        {
            Configuration.ClearDir(home);
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();

            envConfig.Create         = true;
            envConfig.UseLocking     = true;
            envConfig.UseLogging     = true;
            envConfig.UseMPool       = true;
            envConfig.UseReplication = true;
            envConfig.UseTxns        = true;
            DatabaseEnvironment env = DatabaseEnvironment.Open(
                home, envConfig);

            if (policy != null)
            {
                env.RepMgrAckPolicy = policy;
                Assert.AreEqual(policy, env.RepMgrAckPolicy);
            }
            env.Close();
        }
Esempio n. 9
0
 public Arguments AckPolicy(AckPolicy ackPolicy)
 {
     return(Add("kp", ackPolicy));
 }
Esempio n. 10
0
        public Context(string[] args)
        {
            if (args == null || args.Length == 0)
            {
                Exit();
            }

            JsmAction _action                 = null;
            bool      _latencyFlag            = false;
            string    _server                 = Defaults.Url;
            string    _optionsFactoryTypeName = null;
            int       _reportFrequency        = 10000;
            string    _subject                = "sub" + UniqueEnough();
            int       _messageCount           = 100_000;
            int       _threads                = 1;
            bool      _connShared             = true;
            int       _jitter                 = 0;
            int       _payloadSize            = 128;
            int       _roundSize              = 100;
            AckPolicy _ackPolicy              = AckPolicy.Explicit;
            int       _ackAllFrequency        = 1;
            int       _batchSize              = 10;

            if (args != null && args.Length > 0)
            {
                try
                {
                    for (int x = 0; x < args.Length; x++)
                    {
                        string arg = args[x].Trim();
                        switch (arg)
                        {
                        case "-s":
                            _server = AsString(args[++x]);
                            break;

                        case "-of":
                            _optionsFactoryTypeName = AsString(args[++x]);
                            break;

                        case "-a":
                            _action = JsmAction.GetInstance(AsString(args[++x]));
                            if (_action == null)
                            {
                                Error("Valid action required!");
                            }

                            break;

                        case "-lf":
                            _latencyFlag = true;
                            break;

                        case "-u":
                            _subject = AsString(args[++x]);
                            break;

                        case "-m":
                            _messageCount = AsNumber("total messages", args[++x], -1);
                            break;

                        case "-ps":
                            _payloadSize = AsNumber("payload size", args[++x], 1048576);
                            break;

                        case "-bs":
                            _batchSize = AsNumber("batch size", args[++x], 200);
                            break;

                        case "-rs":
                            _roundSize = AsNumber("round size", args[++x], 1000);
                            break;

                        case "-d":
                            _threads = AsNumber("number of threads", args[++x], 10);
                            break;

                        case "-j":
                            _jitter = AsNumber("jitter", args[++x], 10_000);
                            break;

                        case "-n":
                            _connShared = TrueFalse("connection strategy", args[++x], "Shared", "Individual");
                            break;

                        case "-kp":
                            AckPolicy?ap = ApiEnums.GetAckPolicy(AsString(args[++x]).ToLower());
                            if (ap == null)
                            {
                                Error("Invalid Ack Policy, must be one of [explicit, none, all]");
                            }
                            _ackPolicy = ap.Value;
                            break;

                        case "-kf":
                            _ackAllFrequency = AsNumber("ack frequency", args[++x], 100);
                            break;

                        case "-rf":
                            _reportFrequency = AsNumber("report frequency", args[++x], -2);
                            break;

                        case "":
                            break;

                        default:
                            Error("Unknown argument: " + arg);
                            break;
                        }
                    }
                }
                catch (Exception)
                {
                    Error("Exception while parsing, most likely missing an argument value.");
                }
            }

            if (_messageCount < 1)
            {
                Error("Message count required!");
            }

            if (_threads == 1 && _action.IsQueue)
            {
                Error("Queue subscribing requires multiple threads!");
            }

            if (_action.IsPull && _ackPolicy != AckPolicy.Explicit)
            {
                Error("Pull subscribing requires AckPolicy.Explicit!");
            }

            Action          = _action;
            LatencyFlag     = _latencyFlag;
            Server          = _server;
            ReportFrequency = _reportFrequency;
            Subject         = _subject;
            MessageCount    = _messageCount;
            Threads         = _threads;
            ConnShared      = _connShared;
            Jitter          = _jitter;
            PayloadSize     = _payloadSize;
            RoundSize       = _roundSize;
            AckPolicy       = _ackPolicy;
            AckAllFrequency = _ackAllFrequency;
            BatchSize       = _batchSize;

            if (_optionsFactoryTypeName == null)
            {
                _optionsFactory = new OptionsFactory();
            }
            else
            {
                try {
                    Type t = Type.GetType(_optionsFactoryTypeName);
                    _optionsFactory = Activator.CreateInstance(t) as IOptionsFactory;
                }
                catch (Exception e) {
                    Error("Error creating OptionsFactory: " + e);
                }
            }

            _payload = new byte[PayloadSize];

            int total = 0;

            _perThread = new int[Threads];
            for (int x = 0; x < Threads; x++)
            {
                _perThread[x] = MessageCount / Threads;
                total        += _perThread[x];
            }

            int ix = 0;

            while (total < MessageCount)
            {
                _perThread[ix++]++;
                total++;
            }
        }
Esempio n. 11
0
 /**
  * Sets the acknowledgement policy of the ConsumerConfiguration.
  * @param policy the acknowledgement policy.
  * @return Builder
  */
 public ConsumerConfigBuilder SetAckPolicy(AckPolicy policy)
 {
     this.AckPolicy = policy;
     return(this);
 }