Exemple #1
0
        /*
         * The Handler Function which handles the User Meta Data Change
         */
        public bool handleUserMetaData(UserMetaDataSync request)
        {
            try {
                Logger.Debug("handleFileUserMetaData - Begin");

                if (request.initiatedSystemId.Equals(IsisSystem.GetMyAddress()))
                {
                    TryReleaseLock(request.initiatedSystemId, request.transactionID);
                    Logger.Debug("handleFileUserMetaData - End");
                    return(true);
                }

                UserMetaData userdata = new UserMetaData(request.clientId, request.password, request.versionNumber, 0);

                try {
                    filesystem.updateMetadataSynchronized(userdata);
                    TryReleaseLock(request.initiatedSystemId, request.transactionID);
                    Logger.Debug("handleFileUserMetaData - End");
                } catch (UserNotLoadedInMemoryException e) {
                    Logger.Debug("Exception: " + e.ToString());
                    filesystem.addUserSynchronized(request.clientId, request.password);
                    TryReleaseLock(request.initiatedSystemId, request.transactionID);
                    Logger.Debug("handleFileUserMetaData - End");
                }
                return(true);
            } catch (Exception e) {
                Logger.Debug("handleUserMetaData Encountered an exception " + e.ToString());
                return(false);
            }
        }
Exemple #2
0
        void handleBootStrappingContinue(BootStrappingCheckPoint request, Group group, OOBHandler oobhandle)
        {
            Logger.Debug("handleBootStrappingContinue , Response received from " + request.nodeAddress.ToStringVerboseFormat());
            int bootStrapStatus    = SUCCESS;
            int numberOfUsersAdded = 0;

            if (null != state.selectedNode && request.nodeAddress.Equals(state.selectedNode))
            {
                Logger.Debug("handleBootStrapping Continue :)");

                state.currState = eBootStrapState.ReceivingData;
                MemoryMappedFile transferredFile = group.OOBFetch(request.fileName);

                if (transferredFile != null)
                {
                    Logger.Debug("File" + request.fileName + "request Transfer Successfull!");
                    try
                    {
                        int index = 0;
                        InMemoryFileSystem tempFileSystem = null;
                        tempFileSystem = oobhandle.deserializeFromMemoryMappedFile(transferredFile, ref index, request.dataLength) as InMemoryFileSystem;

                        List <string> users = tempFileSystem.GetInMemoryUserList();
                        numberOfUsersAdded = users.Count;

                        foreach (string user in users)
                        {
                            UserFileSystem userfilesys = tempFileSystem.GetClonedInMemoryUserFileSystem(user);
                            if (null != userfilesys)
                            {
                                fileSystem.addFSToMapSynchronized(userfilesys, user);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Debug("Exception Encountered : " + e.ToString());
                        bootStrapStatus = FAILURE;
                    }
                }
                else
                {
                    Logger.Debug("File" + request.fileName + "was Deleted!");
                    bootStrapStatus = FAILURE;
                }

                Logger.Debug("handleBootStrapping Added :)" + numberOfUsersAdded + " Users");
                group.OOBDelete(request.fileName);

                BootStrappingResponse response = null;
                response = new BootStrappingResponse(request.fileName, IsisSystem.GetMyAddress(), bootStrapStatus);

                group.P2PSend(request.nodeAddress, FileServerComm.BootStrapResponse, response);
            }
            else
            {
                Logger.Debug("handleBootStrappingContinue, Receieved from Another Node, Some Problem. Ignore this Plz :)");
            }
        }
Exemple #3
0
 public void TryReleaseLock(Address addr, string transactionID)
 {
     if (addr.Equals(IsisSystem.GetMyAddress()))
     {
         Transaction trans = FileServerComm.getInstance().transManager.removeAndGetTransaction(transactionID);
         if (null != trans)
         {
             trans.signalTransactionEnd();
         }
     }
 }
Exemple #4
0
        /*
         *      This Function is called when a New File Needs to be Added into the memory
         */
        public bool sendsynchaddFileToMemory(string UserName, UserFile file, OOBHandler oobhandle, Group group, List <Address> where)
        {
            try {
                Logger.Debug("File Operations Synch - sendsynchaddFileToMemory >> BEGIN");
                bool             operationResult = false;
                MemoryMappedFile transferFile    = null;

                string      fileName = FileServerComm.getInstance().transManager.generateTransactionId(UserName + "_" + file.filemetadata.filepath);
                Transaction trans    = new Transaction(fileName);

                if (true == FileServerComm.getInstance().transManager.insertTransaction(trans))
                {
                    try {
                        int writtenBytesLength = 0;
                        transferFile = oobhandle.serializeIntoMemoryMappedFile(fileName, file, ref writtenBytesLength);

                        oobhandle.sendOOBData(group, transferFile, fileName, where);

                        trans.waitTillSignalled();
                        Logger.Debug("File Operations Synch - sendsynchaddFileToMemory >> OOB Transfer of Data Complete for : "
                                     + file.filemetadata.filepath);

                        operationResult = !trans.isTimedOut;

                        OOBTransaction oobtrabs = new OOBTransaction(fileName, IsisSystem.GetMyAddress(), writtenBytesLength);

                        if (operationResult)
                        {
                            group.OrderedSend(FileServerComm.SaveFileToMemory, oobtrabs);
                            trans.waitTillSignalled();
                            Logger.Debug("File Operations Synch - sendsynchaddFileToMemory >> Ordered Send Complete Complete for : "
                                         + file.filemetadata.filepath);
                            operationResult = !trans.isTimedOut;
                        }
                        FileServerComm.getInstance().transManager.removeAndGetTransaction(fileName);
                        operationResult = !trans.isTimedOut;
                    } catch (Exception e) {
                        Logger.Debug("Exception during File Operations Synch - sendsynchaddFileToMemory" + e.ToString());
                        FileServerComm.getInstance().transManager.removeAndGetTransaction(fileName);
                        operationResult = false;
                    }
                }
                else
                {
                    Logger.Debug("File Operations Synch - sendsynchaddFileToMemory >> Generation of Transaction ID Failed: " + fileName);
                }
                return(operationResult);
            } catch (Exception e) {
                Logger.Debug("Caught Exception " + e.ToString());
            }
            return(false);
        }
        public string generateTransactionId()
        {
            string transactionID;

            lock (this.privateLock) {
                Address addr = IsisSystem.GetMyAddress();
                transactionID  = addr.ToString();
                transactionID += "_" + this.sequenceNumber;
                transactionID += "_" + DateTime.Now.ToFileTimeUtc();
                this.sequenceNumber++;
            }
            return(transactionID);
        }
Exemple #6
0
        public void sendBootStrappingRequest(Group group, Address lastSelectedNode)
        {
            Address [] liveMembers = group.getLiveMembers();
            Address    myAddress   = IsisSystem.GetMyAddress();

            if (liveMembers.Length > 1)
            {
                Random rnd = new Random();

                int sendNodeIndex = 0;
                int numTries      = 0;

                do
                {
                    sendNodeIndex = rnd.Next(0, liveMembers.Length);
                    if (liveMembers [sendNodeIndex].Equals(myAddress))
                    {
                        continue;
                    }
                    Logger.Debug("Stuck in a Infinite Loop : Length: " + liveMembers.Length);
                    numTries = numTries + 1;
                    break;
                } while(true);

                if (numTries != liveMembers.Length)
                {
                    Logger.Debug("sendBootStrappingRequest Succeeded :). Sending to Address " + liveMembers [sendNodeIndex].ToStringVerboseFormat());
                    Logger.Debug("My Address is :) " + IsisSystem.GetMyAddress().ToStringVerboseFormat());

                    BootStrappingRequest request = new BootStrappingRequest(IsisSystem.GetMyAddress(),
                                                                            FileServerComm.getInstance().transManager.generateTransactionId());
                    state.selectedNode = liveMembers [sendNodeIndex];
                    state.currState    = eBootStrapState.SentBootStrappingBeginRequest;

                    group.RawP2PSend(liveMembers [sendNodeIndex], FileServerComm.BootStrapRequest, request);
                }
                else
                {
                    Logger.Debug("sendBootStrappingRequest Failed :) Try After Backup");
                    state.selectedNode = lastSelectedNode;
                    state.currState    = eBootStrapState.Initialized;
                    state.setBootStrappingTimer(group, this);
                }
            }
            else
            {
                Logger.Debug("There are No Live Members Available, Just Continue :  " + liveMembers.Length);
                state.currState = eBootStrapState.BootStrappingComplete;
                waitBootStrap.Release();
            }
        }
Exemple #7
0
 public bool handleUnshareRequest(SyncUnSharedUser request)
 {
     Logger.Debug("handleUnshareRequest - Begin");
     if (request.initiatedSystemId.Equals(IsisSystem.GetMyAddress()))
     {
         TryReleaseLock(request.initiatedSystemId, request.transactionID);
         Logger.Debug("handleUnshareRequest - End");
         return(true);
     }
     try {
         filesystem.unShareFileWithUser(request.clientId, request.filename, request.sharedWithUser);
     } catch (Exception e) {
         Logger.Debug("Exception : " + e.ToString());
     }
     Logger.Debug("handleUnshareRequest - End");
     return(true);
 }
Exemple #8
0
        public bool sendSynchShareRequest(ShareFileWithUser request, OOBHandler handler, Group group, bool waitToFinish = true)
        {
            try {
                Logger.Debug("File Operations Synch - sendSynchShareRequest >> BEGIN");
                bool operationResult = false;

                if (waitToFinish)
                {
                    string      transactionId = FileServerComm.getInstance().transManager.generateTransactionId(request.filename);
                    Transaction trans         = new Transaction(transactionId);
                    if (true == FileServerComm.getInstance().transManager.insertTransaction(trans))
                    {
                        SyncSharedUser sync = new SyncSharedUser(transactionId, IsisSystem.GetMyAddress(),
                                                                 request.clientId,
                                                                 request.password,
                                                                 request.filename, request.sharedWithUser);
                        group.OrderedSend(FileServerComm.ShareWithUser, sync);
                        trans.waitTillSignalled();
                        FileServerComm.getInstance().transManager.removeAndGetTransaction(transactionId);
                        operationResult = !trans.isTimedOut;
                    }
                    else
                    {
                        Logger.Debug("File Operations Synch - sendsynchdeleteFile >> Generation of Transaction ID Failed: " + transactionId);
                    }
                }
                else
                {
                    SyncSharedUser sync = new SyncSharedUser("", IsisSystem.GetMyAddress(), request.clientId,
                                                             request.password, request.filename, request.sharedWithUser);
                    group.OrderedSend(FileServerComm.ShareWithUser, sync);
                    operationResult = true;
                }


                Logger.Debug("File Operations Synch - sendsynchdeleteFileFromMemory >> END Operation Status " + operationResult);
                return(operationResult);
            } catch (Exception e) {
                Logger.Debug("File Server Creation Failed");
                return(false);
            }
        }
Exemple #9
0
        /*
         * This Function is to be Called when a Entire User Needs to be Moved
         */
        public bool sendsynchUser(UserFileSystem file, OOBHandler oobhandle, Group group, List <Address> where)
        {
            try {
                Logger.Debug("File Operations Synch - sendsynchUser >> BEGIN");
                bool   operationResult = false;
                string fileName        = FileServerComm.getInstance().transManager.generateTransactionId(file.metadata.clientId);

                Transaction trans = new Transaction(fileName);

                if (true == FileServerComm.getInstance().transManager.insertTransaction(trans))
                {
                    try {
                        MemoryMappedFile transferFile = null;
                        int writtenBytesLength        = 0;
                        transferFile = oobhandle.serializeIntoMemoryMappedFile(fileName, file, ref writtenBytesLength);

                        OOBTransaction oobtrabs = new OOBTransaction(fileName, IsisSystem.GetMyAddress(), writtenBytesLength);
                        oobhandle.sendOOBData(group, transferFile, fileName, where);

                        trans.waitTillSignalled();
                        operationResult = !trans.isTimedOut;

                        if (operationResult)
                        {
                            group.OrderedSend(FileServerComm.UpdateUser, oobtrabs);
                            trans.waitTillSignalled();
                            operationResult = !trans.isTimedOut;
                        }
                        FileServerComm.getInstance().transManager.removeAndGetTransaction(fileName);
                        operationResult = !trans.isTimedOut;
                    } catch (Exception e) {
                        Logger.Debug("Exception during File Operations Synch - sendsynchUser" + e.ToString());
                    }
                }

                return(operationResult);
            } catch (Exception e) {
                Logger.Debug("File Operations Synch - sendsynchUser >> Encountered Exception : " + e.ToString());
                return(false);
            }
        }
Exemple #10
0
        /*
         * Handler Function which Deletes a File and Marks it for Deletion if Required
         */
        public bool handleDeleteFile(FileMetaDataSync request)
        {
            try {
                Logger.Debug("handleDeleteFile - Begin");
                TryReleaseLock(request.initiatedSystemId, request.transactionID);

                if (!request.initiatedSystemId.Equals(IsisSystem.GetMyAddress()))
                {
                    bool delete = filesystem.deleteFileSynchronized(request.owner, request.filepath);

                    if (!delete)
                    {
                        Logger.Debug("The file : " + request.filepath + " was already marked for deletion, skipping");
                    }
                }
                Logger.Debug("handleDeleteFile - End");
                return(true);
            } catch (Exception e) {
                Logger.Debug("handleDeleteFile Encountered an Exception " + e.ToString());
                return(false);
            }
        }
Exemple #11
0
        /*
         * This Function is to be called when the File is Deleted from the Users List
         */
        public bool sendsynchdeleteFile(FileMetaData filemetadata, OOBHandler handler, Group group, bool waitToFinish = true)
        {
            try {
                Logger.Debug("File Operations Synch - sendsynchdeleteFile >> BEGIN");
                bool operationResult = false;

                if (waitToFinish)
                {
                    string      transactionId = FileServerComm.getInstance().transManager.generateTransactionId(filemetadata.filepath);
                    Transaction trans         = new Transaction(transactionId);
                    if (true == FileServerComm.getInstance().transManager.insertTransaction(trans))
                    {
                        FileMetaDataSync sync = new FileMetaDataSync(transactionId, IsisSystem.GetMyAddress(), filemetadata);
                        group.OrderedSend(FileServerComm.DeleteFile, sync);
                        trans.waitTillSignalled();
                        FileServerComm.getInstance().transManager.removeAndGetTransaction(transactionId);
                        operationResult = !trans.isTimedOut;
                    }
                    else
                    {
                        Logger.Debug("File Operations Synch - sendsynchdeleteFile >> Generation of Transaction ID Failed: " + transactionId);
                    }
                }
                else
                {
                    FileMetaDataSync sync = new FileMetaDataSync("", IsisSystem.GetMyAddress(), filemetadata);
                    group.OrderedSend(FileServerComm.DeleteFile, sync);
                    operationResult = true;
                }


                Logger.Debug("File Operations Synch - sendsynchdeleteFileFromMemory >> END Operation Status " + operationResult);
                return(operationResult);
            } catch (Exception e) {
                Logger.Debug("File Operations Synch - sendsynchdeleteFile encountered a Excetpion: " + e.ToString());
                return(false);
            }
        }
Exemple #12
0
        /*
         * This Function is called when a New User Is Added or the Meta Data of the User Needs to be Changed and Synched
         */
        public bool sendsynchUserMetaData(UserMetaData data, OOBHandler handler, Group group, bool waitToFinish = true)
        {
            try {
                Logger.Debug("File Operations Synch - sendsynchUserMetaData >> BEGIN");
                bool operationResult = false;

                if (waitToFinish)
                {
                    string      transactionId = FileServerComm.getInstance().transManager.generateTransactionId(data.clientId);
                    Transaction trans         = new Transaction(transactionId);
                    if (true == FileServerComm.getInstance().transManager.insertTransaction(trans))
                    {
                        UserMetaDataSync sync = new UserMetaDataSync(transactionId, IsisSystem.GetMyAddress(), data);
                        group.OrderedSend(FileServerComm.UpdateUserMetaData, sync);
                        Logger.Debug("File Operations Synch - Making a Ordered Send");
                        trans.waitTillSignalled();
                        FileServerComm.getInstance().transManager.removeAndGetTransaction(transactionId);
                        operationResult = !trans.isTimedOut;
                    }
                    else
                    {
                        Logger.Debug("File Operations Synch - sendsynchUserMetaData >> Generation of Transaction ID Failed: " + transactionId);
                    }
                }
                else
                {
                    UserMetaDataSync sync = new UserMetaDataSync("", IsisSystem.GetMyAddress(), data);
                    group.OrderedSend(FileServerComm.UpdateUserMetaData, sync);
                    operationResult = true;
                }
                Logger.Debug("File Operations Synch - sendsynchUserMetaData >> END Operation Status " + operationResult);
                return(operationResult);
            } catch (Exception e) {
                Logger.Debug("File Operations Synch - sendsynchUserMetaData threw an Exception " + e.ToString());
                return(false);
            }
        }
        static void MonitorStart()
        {
            if (monitor == null)
            {
                monitor = new Thread(delegate()
                {
                    while (true)
                    {
                        if (!sending)
                        {
                            string state = IsisSystem.GetMyAddress().ToString() + " " + IsisSystem.NOW();
                            Console.WriteLine("Get time " + state);
                            Byte[] tosend = Encoding.ASCII.GetBytes(state);
                            try
                            {
                                sender.BeginSend(tosend, tosend.Length, web, new AsyncCallback(OnSend), ss);
                                sending = true;
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.Message);
                            }
                        }
                        Thread.Sleep(5 * 1000);
                    }
                });
                monitor.Name = "Monitor Thread";
                monitor.Start();
            }
            else
            {
                monitor.Resume();
            }

            Console.WriteLine("Monitor Thread running");
        }
Exemple #14
0
        /*
         * Handler Function which Adds a File into Memory
         */
        public void handleAddFileToMemory(object arg)
        {
            try {
                OOBTransaction request     = (OOBTransaction)arg;
                UserFile       userfilesys = null;
                Logger.Debug("Update addFileToMemory Data Synchronized - Begin");

                Group      group     = FileServerComm.getInstance().getFileServerGroup();
                OOBHandler oobhandle = FileServerComm.getInstance().getOOBHandler();

                MemoryMappedFile transferredFile = group.OOBFetch(request.transactionID);

                if (null != transferredFile)
                {
                    Logger.Debug("getUserFileInfo OOB Fetch Success :)");
                    int index = 0;
                    userfilesys = oobhandle.deserializeFromMemoryMappedFile(transferredFile, ref index, request.fileLength) as UserFile;
                }
                else
                {
                    Logger.Debug("getUserFileInfo Failed Reason: OOB Fetch Failed:)");
                }

                if (!request.initiatedSystemId.Equals(IsisSystem.GetMyAddress()) &&
                    null != userfilesys)
                {
                    filesystem.addFileSynchronized(userfilesys.filemetadata.owner, userfilesys);
                }
                group.OOBDelete(request.transactionID);

                TryReleaseLock(request.initiatedSystemId, request.transactionID);
                Logger.Debug("Update addFileToMemory Data Synchronized - End");
            } catch (Exception e) {
                Logger.Debug("Update addFileToMemory Data Synchronized encountered an exception " + e.ToString());
            }
        }
        private Message OnConnectRequest(Message msg)
        {
            Contract.Requires(msg is ConnectRequest);
            var connectMsg = msg as ConnectRequest;

            Log.Info("Received OnConnectRequest with {0}", connectMsg.Info);

            var isisAddr = _lastIsisView.GetLiveMembers().FirstOrDefault(x => (ulong)x.GetHashCode() == connectMsg.Info.NodeId);

            if (isisAddr != null)
            {
                if (isisAddr.Equals(IsisSystem.GetMyAddress()))
                {
                    return(new ConnectReply {
                        Info = _node.Info
                    });
                }
                else
                {
                    _nodesByIsisAddress.Add(isisAddr, connectMsg.Info);
                    _onClusterViewChanged.OnNext(new ClusterView(_lastIsisView.viewid,
                                                                 (ulong)_lastIsisView.members.First().GetHashCode(),
                                                                 _nodesByIsisAddress.Values.ToImmutableList(),
                                                                 ImmutableList <NodeRemoteInfo> .Empty.Add(connectMsg.Info),
                                                                 ImmutableList <NodeRemoteInfo> .Empty));
                    return(new ConnectReply {
                        Info = _node.Info
                    });
                }
            }
            else
            {
                Log.Warn("Received connect from non group member " + connectMsg.Info);
                return(new InvalidOperation((ushort)BasicErrorCode.NonAuthorized, "Received connect from non group member"));
            }
        }
Exemple #16
0
        void handleBootStrappingRequest(Group group, OOBHandler oobhandle, InMemoryFileSystem fileSystem, string requestName, Address recvdFrom)
        {
            if (state.currState == eBootStrapState.BootStrappingComplete)
            {
                Logger.Debug("handleBootStrappingRequest , Received from " + recvdFrom.ToStringVerboseFormat());

                BootStrappingCheckPoint initialStage = null;
                initialStage = new BootStrappingCheckPoint("Boot Strapping Begin", FileServerComm.BootStrapBegin,
                                                           IsisSystem.GetMyAddress(), SUCCESS,
                                                           0);

                Logger.Debug("Sending a BootStrapping Begin , Response to " + recvdFrom.ToStringVerboseFormat());
                group.RawP2PSend(recvdFrom, FileServerComm.BootStrapBegin, initialStage);

                MemoryMappedFile transferFile = null;
                int currentUserIndex          = 0;
                int numberOfUsersCurrentBatch = 0;

                List <string>      users          = fileSystem.GetInMemoryUserList();
                InMemoryFileSystem tempFileSystem = new InMemoryFileSystem(false);

                //Yayy Lets Begin Doing Some Boot Strapping
                try {
                    Logger.Debug("Number of Users to BootStrap and Send " + users.Count);
                    while (currentUserIndex < users.Count)
                    {
                        UserFileSystem userfilesys = fileSystem.GetClonedInMemoryUserFileSystem(users [currentUserIndex]);
                        numberOfUsersCurrentBatch++;

                        Logger.Debug("Adding User to the BootStrap : " + users[currentUserIndex]);

                        tempFileSystem.addFSToMapSynchronized(userfilesys, users [currentUserIndex]);
                        currentUserIndex++;

                        if (numberOfUsersCurrentBatch == BatchSize)
                        {
                            //Let's Make a OOB File and Transfer the Data
                            string currentFileName = FileServerComm.getInstance().transManager.generateTransactionId();

                            bool operationResult = false;

                            numberOfUsersCurrentBatch = 0;

                            Transaction trans = new Transaction(currentFileName);

                            FileServerComm.getInstance().transManager.insertTransaction(trans);

                            int writtenBytesLength = 0;
                            transferFile = oobhandle.serializeIntoMemoryMappedFile(currentFileName, tempFileSystem, ref writtenBytesLength);

                            BootStrappingCheckPoint continueBootStrap = null;
                            continueBootStrap = new BootStrappingCheckPoint(currentFileName, FileServerComm.BootStrapContinue,
                                                                            IsisSystem.GetMyAddress(), SUCCESS,
                                                                            writtenBytesLength);
                            List <Address> where = new List <Address>();
                            where.Add(recvdFrom);
                            where.Add(IsisSystem.GetMyAddress());
                            oobhandle.sendOOBData(group, transferFile, currentFileName, where);

                            trans.waitTillSignalled();
                            operationResult = !trans.isTimedOut;

                            if (operationResult)
                            {
                                group.RawP2PSend(recvdFrom, FileServerComm.BootStrapContinue, continueBootStrap);
                                trans.waitTillSignalled();
                                operationResult = !trans.isTimedOut;
                            }
                            else
                            {
                                Logger.Debug("Sending BootStraping Request Timed Out, Quit Out of BootStrapping partcicipation");
                                return;
                            }
                            tempFileSystem = new InMemoryFileSystem();
                        }
                    }

                    //Lets Throw out the Remaining Users
                    if (numberOfUsersCurrentBatch != 0)
                    {
                        string currentFileName = FileServerComm.getInstance().transManager.generateTransactionId();

                        Transaction trans = new Transaction(currentFileName);
                        FileServerComm.getInstance().transManager.insertTransaction(trans);

                        bool currentOperationResult = false;

                        int writtenBytesLength = 0;
                        transferFile = oobhandle.serializeIntoMemoryMappedFile(currentFileName, tempFileSystem, ref writtenBytesLength);
                        BootStrappingCheckPoint _continue = null;
                        _continue = new BootStrappingCheckPoint(currentFileName, FileServerComm.BootStrapContinue,
                                                                IsisSystem.GetMyAddress(), SUCCESS,
                                                                writtenBytesLength);

                        List <Address> where = new List <Address>();
                        where.Add(recvdFrom);
                        where.Add(IsisSystem.GetMyAddress());

                        oobhandle.sendOOBData(group, transferFile, currentFileName, where);

                        trans.waitTillSignalled();
                        currentOperationResult = !trans.isTimedOut;

                        if (currentOperationResult)
                        {
                            group.RawP2PSend(recvdFrom, FileServerComm.BootStrapContinue, _continue);

                            trans.waitTillSignalled();
                            currentOperationResult = !trans.isTimedOut;
                        }
                        else
                        {
                            Logger.Debug("Sending BootStraping Request Timed Out, Quit Out of BootStrapping partcicipation");
                            return;
                        }

                        tempFileSystem            = new InMemoryFileSystem();
                        numberOfUsersCurrentBatch = 0;
                    }

                    Logger.Debug("Sending a Boot Strap End Response to " + recvdFrom.ToString());

                    BootStrappingCheckPoint finalStage = null;
                    finalStage = new BootStrappingCheckPoint("Yayyy Finally Done", FileServerComm.BootStrapEnd,
                                                             IsisSystem.GetMyAddress(), SUCCESS,
                                                             0);

                    group.RawP2PSend(recvdFrom, FileServerComm.BootStrapEnd, finalStage);

                    return;
                } catch (Exception e) {
                    Logger.Debug("Caught an Exception : " + e.ToString());
                    BootStrappingCheckPoint _exception = null;
                    _exception = new BootStrappingCheckPoint(e.ToString(), FileServerComm.BootStrapException,
                                                             IsisSystem.GetMyAddress(), FAILURE,
                                                             0);
                    group.P2PSend(recvdFrom, FileServerComm.BootStrapException, _exception);
                    return;
                }
            }
            else
            {
                Logger.Debug("Node is Not in the State of Boot Strapping, Ignore this Request and Keep Calm");
            }
        }
        static void OnReceive(IAsyncResult ar)
        {
            Byte[] receiveBytes  = receiver.EndReceive(ar, ref web_);
            string receiveString = Encoding.ASCII.GetString(receiveBytes);

            Console.WriteLine("Received: {0}", receiveString);

            switch (receiveString.ToLower())
            {
            case "monitor":
                if (!monitoring)
                {
                    MonitorStart();
                    monitoring = true;
                }
                break;

            case "stop":
                if (monitoring)
                {
                    monitor.Suspend();
                    monitoring = false;
                }
                break;

            case "address":
            {
                string address = IsisSystem.GetMyAddress().ToStringVerboseFormat();
                Byte[] tosend  = Encoding.ASCII.GetBytes(address);
                sender.BeginSend(tosend, tosend.Length, web, new AsyncCallback(OnSend), ss);
                sending = true;
            }
            break;

            case "members":
            {
                Address[] mems    = smallGroup.GetView().members;
                string    members = "Members: ";
                foreach (Address mem in mems)
                {
                    members += mem.ToStringVerboseFormat() + "|";
                }
                Byte[] tosend = Encoding.ASCII.GetBytes(members);
                sender.BeginSend(tosend, tosend.Length, web, new AsyncCallback(OnSend), ss);
                sending = true;
            }
            break;

            case "query":
            {
                rankList.Clear();
                int    nr     = smallGroup.Query(Group.ALL, SmallGroup.myTO, SmallGroup.COUNT, 1, "Query", SmallGroup.myEOL, rankList);
                string result = nr.ToString() + " returns: ";
                int    total  = 0;
                foreach (int count in rankList)
                {
                    result += "| " + count;
                    total  += count;
                }
                result += "| Total processors: " + total;
                Console.WriteLine(result);
                Byte[] tosend = Encoding.ASCII.GetBytes(result);
                sender.BeginSend(tosend, tosend.Length, web, new AsyncCallback(OnSend), ss);
                sending = true;
            }
            break;

            default:
            {
                Byte[] tosend = Encoding.ASCII.GetBytes("Wrong command, Isis cannot handle");
                sender.BeginSend(tosend, tosend.Length, web, new AsyncCallback(OnSend), ss);
                sending = true;
            }
            break;
            }

            receiver.BeginReceive(new AsyncCallback(OnReceive), rs);
        }
Exemple #18
0
 public void handleBootStarppingResponse(BootStrappingResponse response)
 {
     FileServerComm.getInstance().getFileHandler().TryReleaseLock(IsisSystem.GetMyAddress(), response.fileName);
 }
 public ulong GenerateNodeId()
 {
     return((ulong)IsisSystem.GetMyAddress().GetHashCode());
 }