public static void SetContext(ServerConfiguration serverConfig)
 {
     lock (instanceLock) {
         Conditions.AssertState(instance == null);
         instance = new SimpleGrpcMessageLayer(serverConfig);
     }
 }
 public async Task <(IEnumerable <StoredObjectDto>, IEnumerable <PartitionTimestampDto>)> OnListServer()
 {
     Conditions.AssertState(listServerHandler != null);
     //WaitFreeze();
     //await WaitDelay();
     return(listServerHandler());
 }
        /*
         * Creates a partition with the given name. Also stores all server ids and urls
         * Throws ArgumentException if a partition with the given name already exists or
         *                          if a url for an existing id is diferent from the previous id or
         *                          if partition does not have master id
         * Throws InvalidOperationException if the state of the object is incorrect
         *                                  (should never happen)
         */
        public void JoinPartition(JoinPartitionArguments arguments)
        {
            string partitionId = arguments.PartitionId;
            IEnumerable <Tuple <string, string> > members = arguments.Members;
            string masterId = arguments.MasterId;

            HashSet <string> partition = BuildPartition(members);

            lock (this) {
                Conditions.AssertArgument(!partitions.ContainsKey(partitionId));
                Conditions.AssertArgument(partition.Contains(masterId));

                foreach ((string serverId, string serverUrl) in members)
                {
                    bool alreadyExists = TryGetServer(serverId, out string currentUrl);

                    // Url mapping must not exist or be the same as before
                    Conditions.AssertArgument(
                        !alreadyExists || currentUrl.Equals(serverUrl));
                }

                // The following operations should never raise an error
                Conditions.AssertState(partitions.TryAdd(partitionId, partition));
                Conditions.AssertState(partitionMasters.TryAdd(partitionId, masterId));

                // Insert servers correspondence
                foreach ((string serverId, string serverUrl) in members)
                {
                    Conditions.AssertState(RegisterServer(serverId, serverUrl));
                }
            }
        }
Exemple #4
0
        public async Task OnJoinPartition(JoinPartitionArguments arguments)
        {
            Conditions.AssertState(joinPartitionHandler != null);
            WaitFreeze();
            await WaitDelay();

            joinPartitionHandler(arguments);
        }
 public static void SetContext(NamingService namingService)
 {
     lock (instanceLock) {
         Conditions.AssertArgument(namingService != null);
         Conditions.AssertState(instance == null);
         instance = new SimpleKVSMessageLayer(namingService);
     }
 }
        public async Task OnBroadcastWrite(BroadcastWriteArguments arguments)
        {
            Conditions.AssertState(broadcastWriteHandler != null);
            WaitFreeze();
            await WaitDelay();

            broadcastWriteHandler(arguments);
        }
        public async Task <ImmutableVectorClock> OnWrite(WriteArguments arguments)
        {
            Conditions.AssertState(writeHandler != null);
            WaitFreeze();
            await WaitDelay();

            return(writeHandler(arguments));
        }
        public async Task <(string, ImmutableVectorClock)> OnRead(ReadArguments arguments)
        {
            Conditions.AssertState(readHandler != null);
            WaitFreeze();
            await WaitDelay();

            return(readHandler(arguments));
        }
Exemple #9
0
        public async Task OnWriteObject(WriteObjectArguments arguments)
        {
            Conditions.AssertState(writeObjectHandler != null);
            WaitFreeze();
            await WaitDelay();

            writeObjectHandler(arguments);
        }
Exemple #10
0
        public async Task OnLock(LockArguments arguments)
        {
            Conditions.AssertState(lockHandler != null);
            WaitFreeze();
            await WaitDelay();

            lockHandler(arguments);
        }
Exemple #11
0
        public async Task <IEnumerable <StoredValueDto> > OnListServer()
        {
            Conditions.AssertState(listServerHandler != null);
            WaitFreeze();
            await WaitDelay();

            return(listServerHandler());
        }
Exemple #12
0
        public async Task <string> OnRead(ReadArguments arguments)
        {
            Conditions.AssertState(readHandler != null);
            WaitFreeze();
            await WaitDelay();

            return(readHandler(arguments));
        }
Exemple #13
0
 public void OnStatus()
 {
     Conditions.AssertState(statusHandler != null);
     statusHandler();
     // Add freeze status
     lock (freezeLock) {
         Console.WriteLine(
             "[{0}]  Status: {1}",
             DateTime.Now.ToString("HH:mm:ss"),
             freezed ? "Freezed" : "Unfreezed");
     }
 }