Exemplo n.º 1
0
 /// <summary>
 /// Proceeds a lookup into current AppDomain to detect functions marked as exported
 /// and available to be remote executed
 /// </summary>
 public static void Register()
 {
     #if NET_FRAMEWORK
     foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
     #else
     foreach (Assembly assembly in AssemblyLoadContext.Default.Assemblies)
     #endif
     {
         foreach (Type type in assembly.GetTypes())
         {
             foreach (MethodInfo remoteProcedure in type.GetMethods <ExportEndPointAttribute>(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static))
             {
                 string remoteId = string.Concat(type.FullName, ".", remoteProcedure.Name);
                 registryLock.WriteLock();
                 try
                 {
                     if (!registry.ContainsKey(remoteId))
                     {
                         ParameterInfo[] parameter = remoteProcedure.GetParameters();
                         bool            extend; if (parameter.Length > 0)
                         {
                             extend = (parameter[0].ParameterType.IsAssignableFrom(PeerInterfaceType));
                         }
                         else
                         {
                             extend = false;
                         }
                         Func <object[], object>           target = remoteProcedure.CreateDelegate().DynamicInvoke;
                         Action <IMessageSource, IMessage> action; if (TaskType.IsAssignableFrom(remoteProcedure.ReturnType))
                         {
                             action = (remoteHost, message) =>
                             {
                                 CallAsync(remoteHost, message, target, extend);
                             };
                         }
                         else
                         {
                             action = (remoteHost, message) =>
                             {
                                 Call(remoteHost, message, target, extend);
                             }
                         };
                         registry.Add(remoteId, action);
                     }
                     else
                     {
                         Application.Warning(SeverityFlags.Full, "End point '{0}' already defined", remoteId);
                     }
                 }
                 finally
                 {
                     registryLock.WriteRelease();
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        public override bool TryGet(object[] parameter, out IReactiveStream <IMessage, bool> result)
        {
            if (parameter.Length == 0)
            {
                throw new IndexOutOfRangeException();
            }
            if (!(parameter[0] is UInt32))
            {
                throw new ArgumentOutOfRangeException("parameter");
            }
            UInt32 id = (UInt32)parameter[0];

            streamLock.WriteLock();
            try
            {
                if (!streams.TryGetValue(id, out result))
                {
                    result = new MessageStream <IMessage>
                             (
                        new PriorityDispatcher()
                             );
                    streams.Add(id, result);
                }
                return(true);
            }
            finally
            {
                streamLock.WriteRelease();
            }
        }
Exemplo n.º 3
0
        public void Register(IReceiver <IMessage, bool> observer)
        {
            IPrioritizedActor actor = observer as IPrioritizedActor;

            if (actor == null)
            {
                throw new ArgumentException();
            }
            subscriptionLock.WriteLock();
            try
            {
                subscriptions.Add(actor);

                Sort();

                actor.Attach(this);
            }
            finally
            {
                subscriptionLock.WriteRelease();
            }
        }