Exemplo n.º 1
0
 private LocalObserver(
     ProtocolSerializer serializer,
     [Parameter(typeof(MessageObserver))] IInjectionFuture <object> fMessageObserver)
 {
     _serializer       = serializer;
     _fMessageObserver = fMessageObserver;
 }
Exemplo n.º 2
0
 private BridgeClock(
     IInjectionFuture <IDriverServiceClient> driverServiceClient,
     IInjectionFuture <IDriverClientService> driverClientService)
 {
     _driverServiceClient = driverServiceClient;
     _driverClientService = driverClientService;
     _outstandingAlarms   = 0;
 }
Exemplo n.º 3
0
 public RuntimeClock(ITimer timer,
                     [Parameter(typeof(StartHandler))] IInjectionFuture <ISet <IEventHandler <StartTime> > > startHandler,
                     [Parameter(typeof(RuntimeStartHandler))] IInjectionFuture <ISet <IObserver <RuntimeStart> > > runtimeStartHandler,
                     [Parameter(typeof(RuntimeStopHandler))] IInjectionFuture <ISet <IObserver <RuntimeStop> > > runtimeStopHandler)
 {
     this.ClockStartHandler        = startHandler;
     this.ClockRuntimeStartHandler = runtimeStartHandler;
     this.ClockRuntimeStopHandler  = runtimeStopHandler;
 }
Exemplo n.º 4
0
        private TaskRuntime(
            ITask userTask,
            IDriverMessageHandler driverMessageHandler,
            IDriverConnectionMessageHandler driverConnectionMessageHandler,
            TaskStatus taskStatus,
            [Parameter(typeof(TaskConfigurationOptions.SuspendHandler))] IInjectionFuture <IObserver <ISuspendEvent> > suspendHandlerFuture)
        {
            _currentStatus        = taskStatus;
            _driverMessageHandler = Optional <IDriverMessageHandler> .Of(driverMessageHandler);

            _driverConnectionMessageHandler = Optional <IDriverConnectionMessageHandler> .Of(driverConnectionMessageHandler);

            _userTask             = userTask;
            _suspendHandlerFuture = suspendHandlerFuture;
        }
Exemplo n.º 5
0
        private object GetInstance(INode node)
        {
            InjectionPlan plan = (InjectionPlan)GetInjectionPlan(node);
            object        u    = InjectFromPlan(plan);

            while (pendingFutures.Count != 0)
            {
                IEnumerator <object> i = pendingFutures.GetEnumerator();
                i.MoveNext();
                IInjectionFuture <object> f = (IInjectionFuture <object>)i.Current;
                pendingFutures.Remove(f);
                f.Get();
            }
            return(u);
        }
Exemplo n.º 6
0
        internal RuntimeClock(
            ITimer timer,
            [Parameter(typeof(StartHandler))] IInjectionFuture <ISet <IObserver <StartTime> > > startHandler,
            [Parameter(typeof(StopHandler))] IInjectionFuture <ISet <IObserver <StopTime> > > stopHandler,
            [Parameter(typeof(RuntimeStartHandler))] IInjectionFuture <ISet <IObserver <RuntimeStart> > > runtimeStartHandler,
            [Parameter(typeof(RuntimeStopHandler))] IInjectionFuture <ISet <IObserver <RuntimeStop> > > runtimeStopHandler,
            [Parameter(typeof(IdleHandler))] IInjectionFuture <ISet <IObserver <IdleClock> > > idleHandler)
        {
            _timer    = timer;
            _schedule = new SortedSet <Time>();
            _handlers = new PubSubSubject <Time>();

            _startHandler        = startHandler;
            _stopHandler         = stopHandler;
            _runtimeStartHandler = runtimeStartHandler;
            _runtimeStopHandler  = runtimeStopHandler;
            _idleHandler         = idleHandler;
        }
Exemplo n.º 7
0
        public DriverManager(
            IInjector injector,
            ResourceCatalogImpl resourceCatalog,
            IRemoteManager <REEFMessage> remoteManager,
            IInjectionFuture <IClock> clockFuture,
            IInjectionFuture <IResourceRequestHandler> futureResourceRequestHandler,
            ClientJobStatusHandler clientJobStatusHandler,
            string clientRId)
        {
            _injector        = injector;
            _clockFuture     = clockFuture;
            _resourceCatalog = resourceCatalog;
            _futureResourceRequestHandler = futureResourceRequestHandler;
            _clientJobStatusHandler       = clientJobStatusHandler;

            _heartbeatConnectionChannel = null;
            _errorChannel        = null;
            _runtimeErrorHandler = null;
            LOGGER.Log(Level.Info, "DriverManager instantiated");
        }
 private HeartBeatManager(
     EvaluatorSettings settings,
     IInjectionFuture<EvaluatorRuntime> evaluatorRuntime,
     IInjectionFuture<ContextManager> contextManager,
     [Parameter(typeof(ErrorHandlerRid))] string errorHandlerRid)
 {
     using (LOGGER.LogFunction("HeartBeatManager::HeartBeatManager"))
     {
         _evaluatorSettings = settings;
         _evaluatorRuntime = evaluatorRuntime;
         _contextManager = contextManager;
         _remoteManager = settings.RemoteManager;
         _remoteId = new SocketRemoteIdentifier(NetUtilities.ParseIpEndpoint(errorHandlerRid));
         _observer = _remoteManager.GetRemoteObserver(new RemoteEventEndPoint<REEFMessage>(_remoteId));
         _clock = settings.RuntimeClock;
         _heartBeatPeriodInMillSeconds = settings.HeartBeatPeriodInMs;
         _maxHeartbeatRetries = settings.MaxHeartbeatRetries;
         MachineStatus.ToString(); // kick start the CPU perf counter
     }
 }
Exemplo n.º 9
0
 private HeartBeatManager(
     EvaluatorSettings settings,
     IInjectionFuture <EvaluatorRuntime> evaluatorRuntime,
     IInjectionFuture <ContextManager> contextManager,
     [Parameter(typeof(ErrorHandlerRid))] string errorHandlerRid)
 {
     using (LOGGER.LogFunction("HeartBeatManager::HeartBeatManager"))
     {
         _evaluatorSettings            = settings;
         _evaluatorRuntime             = evaluatorRuntime;
         _contextManager               = contextManager;
         _remoteManager                = settings.RemoteManager;
         _remoteId                     = new SocketRemoteIdentifier(NetUtilities.ParseIpEndpoint(errorHandlerRid));
         _observer                     = _remoteManager.GetRemoteObserver(new RemoteEventEndPoint <REEFMessage>(_remoteId));
         _clock                        = settings.RuntimeClock;
         _heartBeatPeriodInMillSeconds = settings.HeartBeatPeriodInMs;
         _maxHeartbeatRetries          = settings.MaxHeartbeatRetries;
         MachineStatus.ToString(); // kick start the CPU perf counter
     }
 }
Exemplo n.º 10
0
        private RuntimeClock(
            ITimer timer,
            [Parameter(typeof(StartHandler))] IInjectionFuture <ISet <IObserver <StartTime> > > startHandler,
            [Parameter(typeof(StopHandler))] IInjectionFuture <ISet <IObserver <StopTime> > > stopHandler,
            [Parameter(typeof(RuntimeStartHandler))] IInjectionFuture <ISet <IObserver <RuntimeStart> > > runtimeStartHandler,
            [Parameter(typeof(RuntimeStopHandler))] IInjectionFuture <ISet <IObserver <RuntimeStop> > > runtimeStopHandler,
            [Parameter(typeof(IdleHandler))] IInjectionFuture <ISet <IObserver <IdleClock> > > idleHandler)
        {
            _timer    = timer;
            _schedule = new PriorityQueue <Time>();
            _handlers = new PubSubSubject <Time>();

            _startHandler        = startHandler;
            _stopHandler         = stopHandler;
            _runtimeStartHandler = runtimeStartHandler;
            _runtimeStopHandler  = runtimeStopHandler;
            _idleHandler         = idleHandler;
            ++numberOfInstantiations;
            if (numberOfInstantiations > 1)
            {
                LOGGER.Log(Level.Warning, "Instantiated `RuntimeClock` instance number " + numberOfInstantiations);
            }
        }
Exemplo n.º 11
0
 public PickyFuturist([Parameter(typeof(MyFlyingCar))] IInjectionFuture <FlyingCar> myFlyingCar) : base(myFlyingCar)
 {
     fCar = myFlyingCar;
 }
Exemplo n.º 12
0
 CyclicDependencyClassTwo(IInjectionFuture<CyclicDependencyClassOne> other) 
 {
     this.other = other;
 }
Exemplo n.º 13
0
 private GroupCommNetworkObserver(
     IInjectionFuture <StreamingNetworkService <GeneralGroupCommunicationMessage> > networkService)
 {
     _networkService = networkService;
 }
Exemplo n.º 14
0
 WantSomeFutureHandlersName(
     [Parameter(typeof(AHandlerName))] IInjectionFuture <IEventHandler <AH> > a,
     [Parameter(typeof(BHandlerName))] IInjectionFuture <IEventHandler <BH> > b)
 {
 }
Exemplo n.º 15
0
 WantSomeFutureHandlers(IInjectionFuture <IAHandler> a, IInjectionFuture <IBHandler> b)
 {
 }
Exemplo n.º 16
0
 NeedsFuture(IInjectionFuture <IsFuture> isFut)
 {
 }
Exemplo n.º 17
0
        public object InjectFromPlan(InjectionPlan plan)
        {
            if (!plan.IsFeasible())
            {
                var ex = new InjectionException("Cannot inject " + plan.GetNode().GetFullName() + ": "
                                                + plan.ToCantInjectString());
                Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
            }

            if (plan.IsAmbiguous())
            {
                var ex = new InjectionException("Cannot inject " + plan.GetNode().GetFullName() + " "
                                                + plan.ToCantInjectString());
                Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
            }

            if (plan is InjectionFuturePlan)
            {
                InjectionFuturePlan fut = (InjectionFuturePlan)plan;
                INode  node             = fut.GetNode();
                string key = node.GetFullName();
                try
                {
                    Type t        = null;
                    Type nodeType = classHierarchy.ClassForName(node.GetFullName());

                    if (node is IClassNode)
                    {
                        t = nodeType;
                    }
                    else if (node is INamedParameterNode)
                    {
                        var nn = (INamedParameterNode)node;
                        t = classHierarchy.ClassForName(nn.GetFullArgName());
                        if (nn.IsSet())
                        {
                            t = typeof(ISet <>).MakeGenericType(new Type[] { t });
                        }
                    }
                    else
                    {
                        var ex = new ApplicationException("Unexpected node type. Wanted ClassNode or NamedParameterNode.  Got: " + node);
                        Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
                    }

                    // Java - InjectionFuture<?> ret = new InjectionFuture<>(this, javaNamespace.classForName(fut.getNode().getFullName()));
                    // C# - InjectionFuture<object> ret = new InjectionFutureImpl<object>(this, classHierarchy.ClassForName(fut.GetNode().GetFullName()));
                    // We cannot simply create an object from generic with object as <T>
                    // typeof(InjectionFutureImpl<>).MakeGenericType(t) will get the InjectionFutureImpl generic Type with <T> as t
                    // for ClassNode, t is the Type of the class, for NamedParameterNode, t is the Type of the argument
                    // we then use reflection to invoke the constructor
                    // To retain generic argument information??
                    Type injectionFuture          = typeof(InjectionFutureImpl <>).MakeGenericType(t);
                    var  constructor              = injectionFuture.GetConstructor(new Type[] { typeof(IInjector), typeof(Type) });
                    IInjectionFuture <object> ret = (IInjectionFuture <object>)constructor.Invoke(new object[] { this, nodeType });

                    pendingFutures.Add(ret);
                    return(ret);
                }
                catch (TypeLoadException e)
                {
                    Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
                    Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new InjectionException("Could not get class for " + key), LOGGER);
                }
            }
            else if (plan.GetNode() is IClassNode && null != GetCachedInstance((IClassNode)plan.GetNode()))
            {
                return(GetCachedInstance((IClassNode)plan.GetNode()));
            }
            else if (plan is CsInstance)
            {
                // TODO: Must be named parameter node.  Check.
                // throw new IllegalStateException("Instance from plan not in Injector's set of instances?!?");
                return(((CsInstance)plan).instance);
            }
            else if (plan is Constructor)
            {
                Constructor     constructor = (Constructor)plan;
                object[]        args        = new object[constructor.GetArgs().Length];
                InjectionPlan[] argPlans    = constructor.GetArgs();

                for (int i = 0; i < argPlans.Length; i++)
                {
                    args[i] = InjectFromPlan(argPlans[i]);
                }

                try
                {
                    concurrentModificationGuard = true;
                    object ret = null;
                    try
                    {
                        IConstructorDef def = (IConstructorDef)constructor.GetConstructorDef();
                        ConstructorInfo c   = GetConstructor(def);

                        if (aspect != null)
                        {
                            ret = aspect.Inject(def, c, args);
                        }
                        else
                        {
                            ret = c.Invoke(args);
                        }
                    }
                    catch (ArgumentException e)
                    {
                        Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
                        StringBuilder sb = new StringBuilder("Internal Tang error?  Could not call constructor " + constructor.GetConstructorDef() + " with arguments [");
                        foreach (object o in args)
                        {
                            sb.Append("\n\t" + o);
                        }
                        sb.Append("]");
                        Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException(sb.ToString(), e), LOGGER);
                    }
                    if (ret is IExternalConstructor <object> )
                    {
                        ret = ((IExternalConstructor <object>)ret).NewInstance();
                    }
                    instances.Add(constructor.GetNode(), ret);
                    return(ret);
                }
                catch (TargetInvocationException e)
                {
                    Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
                    Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new InjectionException("Could not invoke constructor: " + plan, e), LOGGER);
                }
                finally
                {
                    concurrentModificationGuard = false;
                }
            }
            else if (plan is Subplan)
            {
                Subplan ambiguous = (Subplan)plan;
                return(InjectFromPlan(ambiguous.GetDelegatedPlan()));
            }
            else if (plan is SetInjectionPlan)
            {
                SetInjectionPlan setPlan   = (SetInjectionPlan)plan;
                INode            n         = setPlan.GetNode();
                string           typeOfSet = null;

                // TODO: This doesn't work for sets of generics (e.g., Set<Foo<int>>
                // because GetFullName and GetFullArgName strip generic info).
                if (n is INamedParameterNode)
                {
                    INamedParameterNode np = (INamedParameterNode)n;
                    typeOfSet = np.GetFullArgName();
                }
                else if (n is IClassNode)
                {
                    typeOfSet = n.GetFullName();
                }
                else
                {
                    Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new ApplicationException("Unknown node type :" + n.ToString()), LOGGER);
                }

                Type t = classHierarchy.ClassForName(typeOfSet);

                // MakeGenericType(t = int: MonotonicHashSet<> -> MonotonicHashSet<int>
                // Get constructor: MonotonicHashSet<int> -> public MonotonicHashSet<int>() { ... }
                // Invoke: public MonotonicHashSet<int> -> new MonotonicHashSet<int>()
                object ret = typeof(MonotonicHashSet <>).MakeGenericType(t).GetConstructor(new Type[] { }).Invoke(new object[] { }); // (this, classHierarchy.ClassForName(fut.GetNode().GetFullName()));

                MethodInfo mf = ret.GetType().GetMethod("Add");

                foreach (InjectionPlan subplan in setPlan.GetEntryPlans())
                {
                    // ret.Add(InjectFromPlan(subplan));
                    mf.Invoke(ret, new object[] { InjectFromPlan(subplan) });
                }
                return(ret);
            }
            else if (plan is ListInjectionPlan)
            {
                ListInjectionPlan listPlan   = (ListInjectionPlan)plan;
                INode             n          = listPlan.GetNode();
                string            typeOfList = null;

                if (n is INamedParameterNode)
                {
                    INamedParameterNode np = (INamedParameterNode)n;
                    typeOfList = np.GetFullArgName();
                }
                else if (n is IClassNode)
                {
                    typeOfList = n.GetFullName();
                }
                else
                {
                    Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new ApplicationException("Unknown node type :" + n.ToString()), LOGGER);
                }

                Type   t   = classHierarchy.ClassForName(typeOfList);
                object ret = typeof(List <>).MakeGenericType(t).GetConstructor(new Type[] { }).Invoke(new object[] { });

                MethodInfo mf = ret.GetType().GetMethod("Add");

                foreach (InjectionPlan subplan in listPlan.GetEntryPlans())
                {
                    mf.Invoke(ret, new object[] { InjectFromPlan(subplan) });
                }
                return(ret);
            }
            else
            {
                Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException("Unknown plan type: " + plan), LOGGER);
            }
            return(null); // should never reach here
        }
Exemplo n.º 18
0
 public Futurist(IInjectionFuture <FlyingCar> car)
 {
     this.fcar = car;
 }
 CyclicDependencyClassTwo(IInjectionFuture <CyclicDependencyClassOne> other)
 {
     this.other = other;
 }