Esempio n. 1
0
 /// <summary>
 /// Add or update a key in the session key/value store
 /// </summary>
 public void SetKeyValue(long time, string key, object value, VectorConflictStrategy strategy)
 {
     lock (sync)
     {
         data = (from d      in data.Find(key)
                 from vector in d.ToOption()
                 select data.AddOrUpdate(key, vector.AddValue(time, value, strategy)))
                .IfNone(() => data.AddOrUpdate(key, ValueVector.New(time, value)));
     }
     Touch();
 }
Esempio n. 2
0
        /// <summary>
        /// Get a named process setting
        /// </summary>
        /// <param name="pid">Process</param>
        /// <param name="name">Name of setting</param>
        /// <param name="prop">Name of property within the setting (for complex
        /// types, not value types)</param>
        /// <returns></returns>
        internal T GetProcessSetting <T>(ProcessId pid, string name, string prop, T defaultValue, ProcessFlags flags)
        {
            var empty = HashMap <string, ValueToken>();

            var settingsMaps = Seq(
                processSettings.Find(pid).Map(token => token.Settings).IfNone(empty),
                processSettings.Find(RolePid(pid)).Map(token => token.Settings).IfNone(empty),
                roleSettings,
                Cluster.Map(c => c.Settings).IfNone(empty));

            return(GetSettingGeneral(settingsMaps, ActorInboxCommon.ClusterSettingsKey(pid), name, prop, defaultValue, flags));
        }
Esempio n. 3
0
        /// <summary>
        /// Производит поиск в базе данных клиента, соответствующего входным данным.
        /// </summary>
        /// <param name="client"> Клиент, соответствия которому необходимо найти. </param>
        /// <returns> Результат запроса поиска, содержащий информацию
        /// о количестве сравнений и совпадение, если таковое найдено. </returns>
        public SearchQuery <Client> FindClient(Client client)
        {
            var query = new KeyedSearchQuery <int, Client>(client);

            _clients.Find(query);
            return(query);
        }
Esempio n. 4
0
        /// <summary>
        /// Производит поиск в базе данных банкомата, соответствующего входным данным.
        /// </summary>
        /// <param name="machine"> Банкомат, соответствия которому необходимо найти. </param>
        /// <returns> Результат запроса поиска, содержащий информацию
        /// о количестве сравнений и совпадение, если таковое найдено. </returns>
        public SearchQuery <Machine> FindMachine(Machine machine)
        {
            var query = new KeyedSearchQuery <int, Machine>(machine);

            _machines.Find(query);
            return(query);
        }
Esempio n. 5
0
        public Unit DispatchTerminate(ProcessId terminating)
        {
            watchers.Find(terminating).IfSome(ws =>
            {
                var term = new TerminatedMessage(terminating);
                ws.Iter(w =>
                {
                    try
                    {
                        TellUserControl(w, term);
                    }
                    catch (Exception e)
                    {
                        logErr(e);
                    }
                });
            });

            watchers = watchers.Remove(terminating);

            watchings.Find(terminating).IfSome(ws => ws.Iter(w => GetDispatcher(w).UnWatch(terminating)));
            watchings.Remove(terminating);

            return(unit);
        }
Esempio n. 6
0
        public static Either <string, Req> Create(ClientConnectionId id, ClientMessageId msgId, ProcessId to, ProcessId sender, string msg, HashMap <ClientConnectionId, ClientConnection> clientConnections)
        {
            if (!to.IsValid)
            {
                return("Invalid process-id (To)");
            }
            var conn = clientConnections.Find(id);

            if (conn.IsNone)
            {
                return("Invalid connection-id");
            }

            var msgObj = (from type in validMessageTypes(to)
                          let obj = Deserialise.Object(msg, type)
                                    where obj != null
                                    select obj)
                         .FirstOrDefault();

            if (msgObj == null)
            {
                return("Message incompatible with the inbox message type");
            }

            return(new AskReq(id, msgId, to, sender, msgObj, conn.IfNone(() => null)));
        }
Esempio n. 7
0
 public static R Find <A, B, C, D, T, R>(this HashMap <A, HashMap <B, HashMap <C, HashMap <D, T> > > > self, A aKey, B bKey, C cKey, D dKey, Func <T, R> Some, Func <R> None) =>
 self.Find(aKey,
           b => b.Find(bKey,
                       c => c.Find(cKey,
                                   d => d.Find(dKey, Some, None),
                                   None),
                       None),
           None);
Esempio n. 8
0
 void RemoveLocalRegisteredById(ProcessId pid)
 {
     lock (regsync)
     {
         var names = registeredProcessIds.Find(pid).IfNone(Set <ProcessName>());
         names.Iter(name =>
                    registeredProcessNames = registeredProcessNames.SetItem(name, registeredProcessNames[name].Remove(pid))
                    );
         registeredProcessIds = registeredProcessIds.Remove(pid);
     }
 }
Esempio n. 9
0
        /// <summary>
        /// returns a list of lists emulating a left join between two hashmaps
        /// </summary>
        /// <param name="datHM1">the left table represented by a hashmap</param>
        /// <param name="datHM2">the right table represented by the hash map</param>
        /// <returns>the resulting table as a list of string lists after performing a left join</returns>
        public static List <List <string> > LeftJoin(HashMap datHM1, HashMap datHM2)
        {
            // making an assumption that we're allowed to know the keys of a hashmap
            List <string> hMap1Keys = new List <string> {
                "fond", "wrath", "diligent", "outfit", "guide"
            };
            List <string> hMap2Keys = new List <string> {
                "fond", "wrath", "diligent", "guide", "flow"
            };
            List <string> hMap2Values = new List <string>();

            foreach (var key in hMap2Keys)
            {
                hMap2Values.AddRange(datHM2.Find(key));
            }

            for (int i = 0; i < hMap2Keys.Count; i++)
            {
                datHM1.AddJoin(hMap2Keys[i], hMap2Values[i]);
            }

            foreach (var key in hMap1Keys)
            {
                // emulating the .contains method because
                // Collin got jealous that I was using it
                bool isHMap1Key = false;
                foreach (var hMap2Key in hMap2Keys)
                {
                    if (hMap2Key == key)
                    {
                        isHMap1Key = true;
                        break;
                    }
                }

                if (isHMap1Key == false)
                {
                    datHM1.AddJoin(key, null);
                }
            }

            List <List <string> > returnLists = new List <List <string> >();

            foreach (var key in hMap1Keys)
            {
                List <string> tempList = new List <string> {
                    key
                };
                tempList.AddRange(datHM1.Find(key));
                returnLists.Add(tempList);
            }

            return(returnLists);
        }
Esempio n. 10
0
    public static HashMap <A, HashMap <B, V> > TrySetItemT <A, B, V>(this HashMap <A, HashMap <B, V> > map, A aKey, B bKey, V value)
    {
        var a = map.Find(aKey);

        if (a.IsNone)
        {
            return(map);
        }
        var av = a.Value;

        return(map.SetItem(aKey, av.TrySetItem(bKey, value)));
    }
Esempio n. 11
0
    public static HashMap <A, HashMap <B, V> > SetItemT <A, B, V>(this HashMap <A, HashMap <B, V> > map, A aKey, B bKey, V value)
    {
        var a = map.Find(aKey);

        if (a.IsNone)
        {
            throw new ArgumentException("Key not found in Map");
        }
        var av = a.Value;

        return(map.SetItem(aKey, av.SetItem(bKey, value)));
    }
Esempio n. 12
0
    public static HashMap <A, HashMap <B, HashMap <C, HashMap <D, V> > > > SetItemT <A, B, C, D, V>(this HashMap <A, HashMap <B, HashMap <C, HashMap <D, V> > > > map, A aKey, B bKey, C cKey, D dKey, Func <V, V> Some)
    {
        var a = map.Find(aKey);

        if (a.IsNone)
        {
            throw new ArgumentException("Key not found in Map");
        }
        var av = a.Value;

        return(map.SetItem(aKey, av.SetItemT(bKey, cKey, dKey, Some)));
    }
Esempio n. 13
0
    public static HashMap <A, HashMap <B, HashMap <C, HashMap <D, V> > > > TrySetItemT <A, B, C, D, V>(this HashMap <A, HashMap <B, HashMap <C, HashMap <D, V> > > > map, A aKey, B bKey, C cKey, D dKey, Func <V, V> Some)
    {
        var a = map.Find(aKey);

        if (a.IsNone)
        {
            return(map);
        }
        var av = a.Value;

        return(map.SetItem(aKey, av.TrySetItemT(bKey, cKey, dKey, Some)));
    }
Esempio n. 14
0
        public static Either <string, Req> Create(ClientConnectionId id, ProcessId publisher, ProcessId subscriber, HashMap <ClientConnectionId, ClientConnection> clientConnections)
        {
            if (!publisher.IsValid)
            {
                return("Invalid publisher-id");
            }
            if (!subscriber.IsValid)
            {
                return("Invalid subscriber-id");
            }
            var conn = clientConnections.Find(id);

            if (conn.IsNone)
            {
                return("Invalid connection-id");
            }
            return(new UnSubscribeReq(id, publisher, subscriber, conn.IfNone(() => null)));
        }
Esempio n. 15
0
    public static HashMap <A, HashMap <B, T> > Remove <A, B, T>(this HashMap <A, HashMap <B, T> > self, A outerKey, B innerKey)
    {
        var b = self.Find(outerKey);

        if (b.IsSome)
        {
            var bv = b.Value.Remove(innerKey);
            if (bv.Count() == 0)
            {
                return(self.Remove(outerKey));
            }
            else
            {
                return(self.SetItem(outerKey, bv));
            }
        }
        else
        {
            return(self);
        }
    }
Esempio n. 16
0
        static MethodInfo DeserialiseFunc(Type type)
        {
            var name   = type.FullName;
            var result = funcs.Find(name);

            if (result.IsSome)
            {
                return(result.IfNoneUnsafe(Ignore));
            }

            var func = typeof(JsonConvert).GetTypeInfo()
                       .GetDeclaredMethods("DeserializeObject")
                       .Filter(m => m.IsGenericMethod)
                       .Filter(m => m.GetParameters().Length == 2)
                       .Filter(m => m.GetParameters().ElementAt(1).ParameterType.Equals(typeof(JsonSerializerSettings)))
                       .Head()
                       .MakeGenericMethod(type);

            // No locks because we don't really care if it's done
            // more than once, but we do care about locking unnecessarily.
            funcs = funcs.AddOrUpdate(name, func);
            return(func);
        }
Esempio n. 17
0
    public static HashMap <A, HashMap <B, HashMap <C, T> > > Remove <A, B, C, T>(this HashMap <A, HashMap <B, HashMap <C, T> > > self, A aKey, B bKey, C cKey)
    {
        var b = self.Find(aKey);

        if (b.IsSome)
        {
            var c = b.Value.Find(bKey);
            if (c.IsSome)
            {
                var cv = c.Value.Remove(cKey);
                if (cv.Count() == 0)
                {
                    var bv = b.Value.Remove(bKey);
                    if (b.Value.Count() == 0)
                    {
                        return(self.Remove(aKey));
                    }
                    else
                    {
                        return(self.SetItem(aKey, bv));
                    }
                }
                else
                {
                    return(self.SetItem(aKey, b.Value.SetItem(bKey, cv)));
                }
            }
            else
            {
                return(self);
            }
        }
        else
        {
            return(self);
        }
    }
Esempio n. 18
0
 public static Either <string, Req> Create(ClientConnectionId id, HashMap <ClientConnectionId, ClientConnection> clientConnections) =>
 clientConnections.Find(id).Map(x => new DisconnectReq(id, x) as Req)
 .ToEither("Invalid connection-id");
Esempio n. 19
0
 /// <summary>
 /// Returns a named strategy
 /// </summary>
 internal Option <State <StrategyContext, Unit> > GetStrategy(string name) =>
 stratSettings.Find(name);
Esempio n. 20
0
 /// <summary>
 /// Gets a supplementary session id from sessionId
 /// </summary>
 /// <param name="sessionId"></param>
 /// <returns></returns>
 internal Option <SupplementarySessionId> GetSupplementarySessionId(SessionId sessionId) => sessionToSupp.Find(sessionId);
Esempio n. 21
0
 /// <summary>
 /// Gets session id from supplementary sessionId
 /// </summary>
 /// <param name="sessionId"></param>
 /// <returns></returns>
 internal Option <SessionId> GetSessionId(SupplementarySessionId sessionId) => suppToSession.Find(sessionId);
Esempio n. 22
0
 public Option <ValueToken> Local(string name) =>
 Locals.Find(name);
Esempio n. 23
0
 public static Option <T> Find <A, B, T>(this HashMap <A, HashMap <B, T> > self, A outerKey, B innerKey) =>
 self.Find(outerKey, b => b.Find(innerKey), () => None);
Esempio n. 24
0
 public static R Find <A, B, T, R>(this HashMap <A, HashMap <B, T> > self, A outerKey, B innerKey, Func <T, R> Some, Func <R> None) =>
 self.Find(outerKey, b => b.Find(innerKey, Some, None), None);
Esempio n. 25
0
 Option <T> GetValue <T>(string name) =>
 Settings.Find(name).Map(tok => tok.Cast <T>());
Esempio n. 26
0
 public Set <ProcessId> GetLocalRegistered(ProcessName name) =>
 registeredProcessNames
 .Find(name)
 .IfNone(Set <ProcessId>());
Esempio n. 27
0
 internal Option <HashMap <string, object> > GetProcessSettingsOverrides(ProcessId pid) =>
 settingOverrides.Find(pid.Path);
Esempio n. 28
0
 public Unit RemoveSubscription(ProcessId pid)
 {
     subs.Find(pid.Path).IfSome(x => x.Dispose());
     subs = subs.Remove(pid.Path);
     return(unit);
 }
Esempio n. 29
0
 public static Option <T> Find <A, B, C, T>(this HashMap <A, HashMap <B, HashMap <C, T> > > self, A aKey, B bKey, C cKey) =>
 self.Find(aKey, b => b.Find(bKey, c => c.Find(cKey), () => None), () => None);