예제 #1
0
        /**
         * Start up a KinesisProducer instance.
         *
         * <p>
         * Since this creates a child process, it is fairly expensive. Avoid
         * creating more than one per application, unless putting to multiple
         * regions at the same time. All streams in the same region can share the
         * same instance.
         *
         * <p>
         * All methods in KinesisProducer are thread-safe.
         *
         * @param config
         *            Configuration for the KinesisProducer. See the docs for that
         *            class for details.
         *
         * @see KinesisProducerConfiguration
         */
        public KinesisDotNetProducer(ILogger log, KPLNETConfiguration config)
        {
            this.config = config;
            this.log    = log;
            if (config.runAsDaemon)
            {
                extractBinaries();
            }

            if (config.AWSCredentials == null)
            {
                string akid = Environment.GetEnvironmentVariable(AWS_ACCESS_KEY_ID);
                string sKey = Environment.GetEnvironmentVariable(AWS_SECRET_ACCESS_KEY);
                if (akid == null || sKey == null)
                {
                    throw new ArgumentNullException("AWSCredentials is null. AWS_ACCESS_KEY_ID or AWS_SECRET_KEY is not available in Environment variable. Either set the environment variables or pass AWSCredentials in the config object.");
                }

                config.AWSCredentials = new AWSCredentials()
                {
                    Akid = akid, SecretKey = sKey
                };
            }

            env = new Dictionary <string, string>()
            {
                { "LD_LIBRARY_PATH", pathToLibDir },
                { "DYLD_LIBRARY_PATH", pathToLibDir },
                { "CA_DIR", pathToTmpDir }
            };

            child = KPLRepBuilder.GetKPLRep(pathToExecutable, OnMessage, OnError, pathToTmpDir, config, env, log);
        }
예제 #2
0
        private void OnError(Exception t)
        {
            // Don't log error if the user called destroy
            if (!destroyed)
            {
                log.error("Error in child process", t);
            }

            // Fail all outstanding futures
            foreach (var entry in futures)
            {
                Task.Run(() =>
                {
                    entry.Value.SetException(t);
                });
            }
            futures.Clear();

            if (processFailureBehavior == ProcessFailureBehavior.AutoRestart && !destroyed)
            {
                log.info("Restarting native producer process.");
                child = KPLRepBuilder.GetKPLRep(pathToExecutable, OnMessage, OnError, pathToTmpDir, config, env, log);
            }
            else
            {
                // Only restart child if it's not an irrecoverable error, and if
                // there has been some time (3 seconds) between the last child
                // creation. If the child process crashes almost immediately, we're
                // going to abort to avoid going into a loop.
                if (!(t is IrrecoverableError) && DateTime.Now > lastChild.AddSeconds(3))
                {
                    lastChild = DateTime.Now;
                    child     = KPLRepBuilder.GetKPLRep(pathToExecutable, OnMessage, OnError, pathToTmpDir, config, env, log);
                }
            }
        }