Пример #1
0
        /// <summary>
        /// Performs a function invocation on the desired target method
        /// </summary>
        /// <param name="source">The source of the message</param>
        /// <param name="message">The message object</param>
        /// <returns>True if the method exists, false otherwise</returns>
        public static bool Invoke(IMessageSource source, IMessage message)
        {
            string invocationTarget; if (message.TryGetInvocationTarget(out invocationTarget))

            {
                registryLock.ReadLock();
                try
                {
                    Action <IMessageSource, IMessage> target; if (registry.TryGetValue(invocationTarget, out target))
                    {
                        target(source, message);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                finally
                {
                    registryLock.ReadRelease();
                }
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        /// <summary>Check if node is already in the map.</summary>
        internal virtual bool Contains(DatanodeDescriptor node)
        {
            if (node == null)
            {
                return(false);
            }
            string ipAddr = node.GetIpAddr();

            hostmapLock.ReadLock().Lock();
            try
            {
                DatanodeDescriptor[] nodes = map[ipAddr];
                if (nodes != null)
                {
                    foreach (DatanodeDescriptor containedNode in nodes)
                    {
                        if (node == containedNode)
                        {
                            return(true);
                        }
                    }
                }
            }
            finally
            {
                hostmapLock.ReadLock().Unlock();
            }
            return(false);
        }
Пример #3
0
 public bool Dispatch(ref IMessage message)
 {
     subscriptionLock.ReadLock();
     try
     {
         foreach (IPrioritizedActor actor in subscriptions)
         {
             try
             {
                 if (actor.OnNext(message))
                 {
                     return(true);
                 }
             }
             catch (Exception er)
             {
                 try
                 {
                     actor.OnError(er);
                 }
                 catch { }
             }
         }
     }
     finally
     {
         subscriptionLock.ReadRelease();
     }
     return(false);
 }
Пример #4
0
 public override bool TryGet(ref IMessage message, out IReactiveStream <IMessage, bool> result)
 {
     streamLock.ReadLock();
     try
     {
         return(streams.TryGetValue(message.Id, out result));
     }
     finally
     {
         streamLock.ReadRelease();
     }
 }
Пример #5
0
        public Task <IDictionary <long, WorkChapter> > GetWorkChaptersAsync(IEnumerable <long> works)
        {
            return(Task.Run(() =>
            {
                using (ReadWriteLock.ReadLock())
                {
                    IDictionary <long, WorkChapter> r = new Dictionary <long, WorkChapter>();

                    foreach (long w in works)
                    {
                        if (storage.TryGetValue(w, out Work work))
                        {
                            r[w] = new WorkChapter(work);
                        }
                    }

                    return r;
                }
            }));
        }
Пример #6
0
 /// <summary>Given a string representation of a rack, return its children</summary>
 /// <param name="loc">a path-like string representation of a rack</param>
 /// <returns>a newly allocated list with all the node's children</returns>
 public virtual IList <Node> GetDatanodesInRack(string loc)
 {
     netlock.ReadLock().Lock();
     try
     {
         loc = NodeBase.Normalize(loc);
         if (!NodeBase.Root.Equals(loc))
         {
             loc = Runtime.Substring(loc, 1);
         }
         NetworkTopology.InnerNode rack = (NetworkTopology.InnerNode)clusterMap.GetLoc(loc
                                                                                       );
         if (rack == null)
         {
             return(null);
         }
         return(new AList <Node>(rack.GetChildren()));
     }
     finally
     {
         netlock.ReadLock().Unlock();
     }
 }