Exemple #1
0
        public void configure(String[] args)
        {
            // create app properties, using the default values as initial values
            appProperties = new Dictionary<String, String>(defaultProperties);

            // parse command line on top of defaults
            parseCommandLine(args, appProperties);

            // load properties from application.properties file over the defaults
            loadProperties(appProperties, PROPERTIES_PATH);

            // now load database properties file over the application and the defaults
            loadProperties(appProperties, DB_PROPERTIES_PATH);

            // parse the command line into app properties, as command line overrides all others
            parseCommandLine(args, appProperties);

            resolveReferences(appProperties);

            String[] keys = appProperties.Keys.ToArray();
            Array.Sort(keys);

            String helpOption;
            if (appProperties.TryGetValue("help", out helpOption) && "true".Equals(helpOption, StringComparison.InvariantCultureIgnoreCase)) {
                Console.Out.WriteLine("\nCSNuoTest [option=value [, option=value, ...] ]\nwhere <option> can be any of:\n");

                foreach (String key in keys) {
                    Console.Out.WriteLine(String.Format("{0}\t\t\t\t(default={1})", key, defaultProperties[key]));
                }

                Console.Out.WriteLine("\nHelp called - nothing to do; exiting.");
                Environment.Exit(0);
            }

            appLog.info("command-line properties: {0}",  string.Join(";", appProperties));

            StringBuilder builder = new StringBuilder(1024);
            builder.Append("\n***************** Resolved Properties ********************\n");
            foreach (String key in keys) {
                builder.AppendFormat("{0} = {1}\n", key, appProperties[key]);
            }
            appLog.info("{0}**********************************************************\n", builder.ToString());

            runTime = Int32.Parse(appProperties[RUN_TIME]) * Millis;
            averageRate = Single.Parse(appProperties[AVERAGE_RATE]);
            minViewAfterInsert = Int32.Parse(appProperties[MIN_VIEW_DELAY]);
            maxViewAfterInsert = Int32.Parse(appProperties[MAX_VIEW_DELAY]);
            timingSpeedup = Single.Parse(appProperties[TIMING_SPEEDUP]);
            minGroups = Int32.Parse(appProperties[MIN_GROUPS]);
            maxGroups = Int32.Parse(appProperties[MAX_GROUPS]);
            minData = Int32.Parse(appProperties[MIN_DATA]);
            maxData = Int32.Parse(appProperties[MAX_DATA]);
            burstProbability = Single.Parse(appProperties[BURST_PROBABILITY_PERCENT]);
            minBurst = Int32.Parse(appProperties[MIN_BURST]);
            maxBurst = Int32.Parse(appProperties[MAX_BURST]);
            maxQueued = Int32.Parse(appProperties[MAX_QUEUED]);
            initDb = Boolean.Parse(appProperties[DB_INIT]);
            queryOnly = Boolean.Parse(appProperties[QUERY_ONLY]);
            queryBackoff = Int32.Parse(appProperties[QUERY_BACKOFF]);
            maxRetry = Int32.Parse(appProperties[MAX_RETRY]);
            retrySleep = Int32.Parse(appProperties[RETRY_SLEEP]);

            String threadParam;
            int insertThreads = (appProperties.TryGetValue(INSERT_THREADS, out threadParam) ? Int32.Parse(threadParam) : 1);

            int queryThreads = (appProperties.TryGetValue(QUERY_THREADS, out threadParam) ? Int32.Parse(threadParam) : 1);

            if (maxViewAfterInsert > 0 && maxViewAfterInsert < minViewAfterInsert) {
                maxViewAfterInsert = minViewAfterInsert;
            }

            if (maxBurst <= minBurst) {
                appLog.info("maxBurst ({0}) <= minBurst ({1}); burst disabled", maxBurst, minBurst);
                burstProbability = minBurst = maxBurst = 0;
            }

            // filter out database properties, and strip off the prefix
            Dictionary<String, String> dbProperties = new Dictionary<String, String>();
            String dbPropertyPrefix = appProperties[DB_PROPERTY_PREFIX];
            if (! dbPropertyPrefix.EndsWith(".")) dbPropertyPrefix = dbPropertyPrefix + ".";

            foreach (String key in appProperties.Keys) {
                if (key.StartsWith(dbPropertyPrefix)) {
                    dbProperties[key.Substring(dbPropertyPrefix.Length)] = appProperties[key];
                }
            }

            //String insertIsolation = appProperties.getProperty(UPDATE_ISOLATION);
            //DataSource dataSource = new com.nuodb.jdbc.DataSource(dbProperties);
            SqlSession.init(dbProperties, insertThreads + queryThreads);

            SqlSession.CommunicationMode commsMode;
            if (!Enum.TryParse<SqlSession.CommunicationMode>(appProperties[COMMUNICATION_MODE], out commsMode))
                commsMode = SqlSession.CommunicationMode.SQL;
            SqlSession.globalCommsMode = commsMode;
            appLog.info("SqlSession.globalCommsMode set to {0}", commsMode);

            SqlSession.SpNamePrefix = appProperties[SP_NAME_PREFIX];

            ownerRepository = new OwnerRepository();
            ownerRepository.init();

            groupRepository = new GroupRepository();
            groupRepository.init();

            dataRepository = new DataRepository();
            dataRepository.init();

            eventRepository = new EventRepository(ownerRepository, groupRepository, dataRepository);
            eventRepository.init();

            if (!Enum.TryParse<TxModel>(appProperties[TX_MODEL], out txModel))
                txModel = TxModel.DISCRETE;

            if (!Enum.TryParse<SqlSession.Mode>(appProperties[BULK_COMMIT_MODE], out bulkCommitMode))
                bulkCommitMode = SqlSession.Mode.BATCH;

            //insertExecutor = Executors.newFixedThreadPool(insertThreads);
            //queryExecutor= Executors.newScheduledThreadPool(queryThreads);

            insertExecutor = new ThreadPoolExecutor<EventGenerator>("INSERT", insertThreads);
            queryExecutor = new ThreadPoolExecutor<EventViewTask>("QUERY", queryThreads);

            string checkOnly;
            if (appProperties.TryGetValue("check.config", out checkOnly) && checkOnly.Equals("true", StringComparison.InvariantCultureIgnoreCase)) {
                Console.Out.WriteLine("CheckConfig called - nothing to do; exiting.");
                Environment.Exit(0);
            }

            string silent;
            if (appProperties.TryGetValue("silent", out silent) && silent.Equals("true", StringComparison.InvariantCultureIgnoreCase)) {
                Logger.Silent = true;
            }
        }