protected override Boolean handleDo(DoStatementNode doStatement, HashSet <StatementNode> visited)
        {
            if (!handleStatement(doStatement.Statement, visited) || !ReachabilityChecker.isEndPointReachable(doStatement.Statement))
            {
                return(Boolean.FALSE);
            }
            AssignmentState state = expressionChecker.handleExpression(doStatement.Condition, visited, true);

            switch (state)
            {
            case Assigned:
            case AssignedAfterFalse:
                return(Boolean.FALSE);

            case AssignedAfterTrue:
                return(Boolean.TRUE);

            default:
                var cinfo = doStatement.Condition.getUserData(typeof(ExpressionInfo));
                if (cinfo.IsConstant)
                {
                    return((Boolean)cinfo.Value);
                }
                break;
            }
            return(Boolean.TRUE);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new RemoteHostPool using the specified system name and liveliness checker.
        /// </summary>
        /// <param name="reachabilityChecker">A delegate that checks if a given host is reachable or not. Used for background checks of unreachable hosts.
        /// Should return true if the host is reachable, or false if it is unreachable. It should not throw an exception.</param>
        /// <param name="log">An implementation of <see cref="ILog"/> used for logging.</param>
        public RemoteHostPool(
            DeploymentIdentifier deploymentIdentifier
            , IServiceDiscoverySource discovery
            , ReachabilityChecker reachabilityChecker
            , Func <DiscoveryConfig> getDiscoveryConfig
            , ILog log
            , HealthMonitor healthMonitor
            , MetricsContext metrics
            )
        {
            DiscoverySource      = discovery;
            DeploymentIdentifier = deploymentIdentifier;
            ReachabilityChecker  = reachabilityChecker;
            GetDiscoveryConfig   = getDiscoveryConfig;
            Log = log;
            ReachabilityBroadcaster = new BroadcastBlock <ServiceReachabilityStatus>(null);
            Health = healthMonitor.Get(discovery.Deployment);
            Health.SetHealthData(HealthData);

            ReachableHosts            = new List <RemoteHost>();
            UnreachableHosts          = new List <RemoteHost>();
            EndPointsChangedBlockLink = discovery.EndPointsChanged.LinkTo(new ActionBlock <EndPointsResult>(_ => ReloadEndpoints(_)));
            ReloadEndpoints(discovery.Result);
            Metrics = metrics;
            var metricsContext = Metrics.Context(DiscoverySource.Deployment);

            metricsContext.Gauge("ReachableHosts", () => ReachableHosts.Count, Unit.Custom("EndPoints"));
            metricsContext.Gauge("UnreachableHosts", () => UnreachableHosts.Count, Unit.Custom("EndPoints"));
        }
Ejemplo n.º 3
0
        public ServiceDiscovery(string serviceName,
                                ReachabilityChecker reachabilityChecker,
                                IRemoteHostPoolFactory remoteHostPoolFactory,
                                IDiscoverySourceLoader serviceDiscoveryLoader,
                                ISourceBlock <DiscoveryConfig> configListener,
                                Func <DiscoveryConfig> discoveryConfigFactory,
                                ILog log)
        {
            Log                    = log;
            _serviceName           = serviceName;
            _originatingDeployment = new DeploymentIdentifier(serviceName);
            _masterDeployment      = new DeploymentIdentifier(serviceName);

            _reachabilityChecker    = reachabilityChecker;
            _remoteHostPoolFactory  = remoteHostPoolFactory;
            _serviceDiscoveryLoader = serviceDiscoveryLoader;

            _initTask        = Task.Run(() => ReloadRemoteHost(discoveryConfigFactory()));
            _configBlockLink = configListener.LinkTo(new ActionBlock <DiscoveryConfig>(ReloadRemoteHost));
        }
Ejemplo n.º 4
0
        public ServiceDiscovery(string serviceName,
                                ReachabilityChecker reachabilityChecker,
                                IRemoteHostPoolFactory remoteHostPoolFactory,
                                IDiscoverySourceLoader discoverySourceLoader,
                                IEnvironmentVariableProvider environmentVariableProvider,
                                ISourceBlock <DiscoveryConfig> configListener,
                                Func <DiscoveryConfig> discoveryConfigFactory)
        {
            _serviceName           = serviceName;
            _originatingDeployment = new ServiceDeployment(serviceName, environmentVariableProvider.DeploymentEnvironment);
            _masterDeployment      = new ServiceDeployment(serviceName, MASTER_ENVIRONMENT);

            _reachabilityChecker   = reachabilityChecker;
            _remoteHostPoolFactory = remoteHostPoolFactory;
            _discoverySourceLoader = discoverySourceLoader;

            // Must be run in Task.Run() because of incorrect Orleans scheduling
            _initTask        = Task.Run(() => ReloadRemoteHost(discoveryConfigFactory()));
            _configBlockLink = configListener.LinkTo(new ActionBlock <DiscoveryConfig>(ReloadRemoteHost));
        }
Ejemplo n.º 5
0
        private void CreatePool(string endPoints, ReachabilityChecker isReachableChecker = null)
        {
            _healthMonitor?.Dispose();
            _healthMonitor = new HealthMonitor();

            var unitTesting = new TestingKernel <LogSpy>(mockConfig: new Dictionary <string, string>  {
                { $"Discovery.Services.{SERVICE_NAME}.DelayMultiplier", "1" },
                { $"Discovery.Services.{SERVICE_NAME}.FirstAttemptDelaySeconds", "0.01" }
            });

            Log = (LogSpy)unitTesting.Get <ILog>();
            var factory = unitTesting.Get <IRemoteHostPoolFactory>();

            _discoverySourceMock = new DiscoverySourceMock(serviceContext, endPoints);

            Pool = factory.Create(
                new ServiceDeployment(SERVICE_NAME, "prod"),
                _discoverySourceMock,
                isReachableChecker ?? (rh => Task.FromResult(false)));
        }
Ejemplo n.º 6
0
        public ServiceDiscovery(string serviceName,
                                ReachabilityChecker reachabilityChecker,
                                IRemoteHostPoolFactory remoteHostPoolFactory,
                                IDiscoverySourceLoader serviceDiscoveryLoader,
                                IEnvironment environment,
                                ISourceBlock <DiscoveryConfig> configListener,
                                Func <DiscoveryConfig> discoveryConfigFactory,
                                ILog log)
        {
            Log                    = log;
            _serviceName           = serviceName;
            _originatingDeployment = new DeploymentIdentifier(serviceName, environment.DeploymentEnvironment, environment);

            _reachabilityChecker    = reachabilityChecker;
            _remoteHostPoolFactory  = remoteHostPoolFactory;
            _serviceDiscoveryLoader = serviceDiscoveryLoader;
            _environment            = environment;

            // Must be run in Task.Run() because of incorrect Orleans scheduling
            _initTask        = Task.Run(() => ReloadRemoteHost(discoveryConfigFactory()));
            _configBlockLink = configListener.LinkTo(new ActionBlock <DiscoveryConfig>(ReloadRemoteHost));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a new RemoteHostPool using the specified system name and liveliness checker.
        /// </summary>
        /// <param name="reachabilityChecker">A delegate that checks if a given host is reachable or not. Used for background checks of unreachable hosts.
        /// Should return true if the host is reachable, or false if it is unreachable. It should not throw an exception.</param>
        /// <param name="log">An implementation of <see cref="ILog"/> used for logging.</param>
        public RemoteHostPool(
            DeploymentIdentifier deploymentIdentifier
            , IServiceDiscoverySource discovery
            , ReachabilityChecker reachabilityChecker
            , Func <DiscoveryConfig> getDiscoveryConfig
            , ILog log
            , HealthMonitor healthMonitor
            )
        {
            DiscoverySource      = discovery;
            DeploymentIdentifier = deploymentIdentifier;
            ReachabilityChecker  = reachabilityChecker;
            GetDiscoveryConfig   = getDiscoveryConfig;
            Log = log;
            ReachabilityBroadcaster = new BroadcastBlock <ServiceReachabilityStatus>(null);
            Health = healthMonitor.Get(discovery.Deployment);
            Health.SetHealthData(HealthData);

            ReachableHosts            = new List <RemoteHost>();
            UnreachableHosts          = new List <RemoteHost>();
            EndPointsChangedBlockLink = discovery.EndPointsChanged.LinkTo(new ActionBlock <EndPointsResult>(_ => ReloadEndpoints(_)));
            ReloadEndpoints(discovery.Result);
        }
Ejemplo n.º 8
0
        public CompilerResults compileFromCompilationUnits(CompilerParameters parameters, CompilationUnitNode[] compilationUnits) {
            var results = new CompilerResults();
            this.context = new CompilerContext(parameters, results);
            this.statementValidator = new StatementValidator(this.context);
            this.expressionValidator = new ExpressionValidator(this.context);
            this.statementValidator.ExpressionValidator = this.expressionValidator;
            this.expressionValidator.StatementValidator = this.statementValidator;
            this.reachabilityChecker = new ReachabilityChecker(context);
            this.assignmentChecker = new AssignmentChecker(context);
            this.bytecodeGenerator = new BytecodeGenerator(context);
            
			foreach (var cu in compilationUnits) {
				context.CompilationUnits.add(cu);
			}
			doCompile();
            
            this.context = null;
            this.statementValidator = null;
            this.expressionValidator = null;
            this.reachabilityChecker = null;
            this.assignmentChecker = null;
            this.queryTranslator = null;
            this.documentationBuilder = null;
			
			if (parameters.ProgressTracker != null) {
				parameters.ProgressTracker.compilationFinished();
			}
            return results;
        }
Ejemplo n.º 9
0
        public CompilerResults compileFromFiles(CompilerParameters parameters, File[] files) {
            var results = new CompilerResults();
            this.context = new CompilerContext(parameters, results);
            this.statementValidator = new StatementValidator(this.context);
            this.expressionValidator = new ExpressionValidator(this.context);
            this.statementValidator.ExpressionValidator = this.expressionValidator;
            this.expressionValidator.StatementValidator = this.statementValidator;
            this.reachabilityChecker = new ReachabilityChecker(context);
            this.assignmentChecker = new AssignmentChecker(context);
            this.bytecodeGenerator = new BytecodeGenerator(context);
            bool tragicError = false;
			
            var buffer = new char[4096];
            var sb = new StringBuilder();
            var parser = new Parser();
            
            foreach (var file in files) {
                sb.setLength(0);
                InputStreamReader reader = null;
                try {
                    reader = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"));
                    int read;
                    while ((read = reader.read(buffer)) != -1) {
                        sb.append(buffer, 0, read);
                    }
                    
                    var text = new char[sb.length()];
                    sb.getChars(0, sizeof(text), text, 0);
                    if (sizeof(text) > 0) {
                        if (text[sizeof(text) - 1] == '\u001a') {
                            text[sizeof(text) - 1] = ' ';
                        }
                    }
                    var preprocessor = new Preprocessor(results.codeErrorManager, text);
                    preprocessor.Filename = file.getAbsolutePath();
					preprocessor.Symbols.addAll(parameters.Symbols);
                    
                    var scanner = new PreprocessedTextScanner(results.codeErrorManager, preprocessor.preprocess());
                    scanner.Filename = file.getAbsolutePath();
                    var compilationUnit = parser.parseCompilationUnit(scanner);
                    
                    if (compilationUnit != null) {
                        compilationUnit.Symbols = preprocessor.Symbols;
                        context.CompilationUnits.add(compilationUnit);
                    }
                } catch (CodeErrorException) {
				} catch (Exception e) {
					e.printStackTrace();
					tragicError = true;
					break;
                } finally {
                    if (reader != null) {
                        try {
                            reader.close();
                        } catch (IOException) {
                        }
                    }
                }
            }
            if (!tragicError) {
				if (!context.HasErrors) {
					if (parameters.ProgressTracker != null) {
						parameters.ProgressTracker.compilationStageFinished(CompilationStage.Parsing);
					}
					doCompile();
				}
			}
            this.context = null;
            this.statementValidator = null;
            this.expressionValidator = null;
            this.reachabilityChecker = null;
            this.assignmentChecker = null;
            this.queryTranslator = null;
            this.documentationBuilder = null;
			
			if (parameters.ProgressTracker != null) {
				parameters.ProgressTracker.compilationFinished();
			}
            return results;
        }