Example #1
0
        /// <summary>
        /// Handles a PushIndexRequest sent through this ClientThread's TcpCLient
        /// </summary>
        /// <param name="pir">The PushIndexRequest we need to process</param>
        private void processMyPushIndexRequest(PushIndexRequest pir)
        {
            Logger.Debug("ClientThread:processMyPushIndexRequest");
            int             ret      = sendMessage(tcpClient, pir);
            NetworkResponse response = (NetworkResponse)receiveMessage(tcpClient);

            if (response.Type == Backend.ResponseType.Yes)
            {
                ret = writeFileToNetwork(pir.Path);
                lock (_lock)
                {
                    eventQueue.Enqueue(response);
                }
            }
            else
            {
                Logger.Warn("ClientThread:processMyPushIndexRequest Remote node refused to store index file: " + response.Type + ' ' + response.Reason);
                //other node said 'no' (willnot, cannot, or notimplemented)
                //add result to event queue
                lock (_lock)
                {
                    eventQueue.Enqueue(response);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Handles a PushIndexRequest received from this ClientThread's TcpClient
        /// </summary>
        /// <param name="pir">The PushIndexRequest we need to process</param>
        private void processRemotePushIndexRequest(PushIndexRequest pir)
        {
            Logger.Debug("ClientThread:processRemotePushIndexRequest");
            sendMessage(tcpClient, new NetworkResponse(ResponseType.Yes, "", guid, pir.SequenceNumber));
            //pir.Path should be modified to be the local path where we want to store the received database
            readFileToDisk(pir.DBSize, pir.Path);
            IndexDistribution idd = new IndexDistribution();

            idd.processIndexes(pir.Path);
        }
Example #3
0
        // Send indexes to all trusted nodes that are online
        // For use after a backup and associated index insertion have occurred
        public void sendIndexes()
        {
            IndexDatabase idd = new IndexDatabase();

            if (!idd.TablesEmpty()) //if there are indexes to send
            {
                DistributionDatabase ddb      = new DistributionDatabase();
                List <string>        guidList = new List <string>();
                NodeDatabase         ndb      = new NodeDatabase();

                string online      = "online";
                string indexDBCopy = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\indexes_" + (Properties.Settings.Default.guid).ToString() + ".s3db";

                if (System.IO.File.Exists(idd.GetPathFileName()))
                {
                    try
                    {
                        System.IO.File.Copy(idd.GetPathFileName(), indexDBCopy, true);
                    }
                    catch (System.IO.IOException e)
                    {
                        Debug.Print(e.Message);
                    }
                }

                guidList = ndb.SelectGUID();

                foreach (string currentGUID in guidList)
                {
                    if (Node.GetGuid() != Guid.Parse(currentGUID) && ddb.GetStatus(currentGUID) == online && ndb.SelectNodeTrusted(Guid.Parse(currentGUID)) == "yes")
                    {
                        Guid             myGuid    = Node.GetGuid();
                        TcpClient        tcpClient = new TcpClient((ndb.SelectNodeIp(Guid.Parse(currentGUID))).ToString(), 7890);
                        ClientThread     ct        = new ClientThread(tcpClient, false, myGuid);
                        PushIndexRequest pir       = new PushIndexRequest(indexDBCopy, new FileInfo(indexDBCopy).Length);
                        ct.EnqueueWork(pir);
                        NetworkResponse response = (NetworkResponse)ct.DequeueEvent();
                        while (ct.IsWorking())
                        {
                            Thread.Sleep(1000);
                        }
                        ct.RequestStop();
                        while (ct.IsAlive())
                        {
                            Thread.Sleep(1000);
                        }
                    }
                }
            }
        }
Example #4
0
        // Send indexes to a specific node
        // Use after a node comes online
        public void sendIndexes(string guid)
        {
            NodeDatabase  ndb = new NodeDatabase();
            IndexDatabase idd = new IndexDatabase();

            if (!idd.TablesEmpty()) //if there are indexes to send
            {
                string indexDBCopy = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\indexes_" + (Properties.Settings.Default.guid).ToString() + ".s3db";

                if (System.IO.File.Exists(idd.GetPathFileName()))
                {
                    try
                    {
                        System.IO.File.Copy(idd.GetPathFileName(), indexDBCopy, true);
                    }
                    catch (System.IO.IOException e)
                    {
                        Debug.Print(e.Message);
                    }
                }

                Guid             myGuid    = Node.GetGuid();
                TcpClient        tcpClient = new TcpClient((ndb.SelectNodeIp(Guid.Parse(guid))).ToString(), 7890);
                ClientThread     ct        = new ClientThread(tcpClient, false, myGuid);
                PushIndexRequest pir       = new PushIndexRequest(indexDBCopy, new FileInfo(indexDBCopy).Length);
                ct.EnqueueWork(pir);
                NetworkResponse response = (NetworkResponse)ct.DequeueEvent();
                while (ct.IsWorking())
                {
                    Thread.Sleep(1000);
                }
                ct.RequestStop();
                while (ct.IsAlive())
                {
                    Thread.Sleep(1000);
                }
            }
        }
Example #5
0
        // Send indexes to a specific node
        // Use after a node comes online
        public void sendIndexes(string guid)
        {
            NodeDatabase ndb = new NodeDatabase();
            IndexDatabase idd = new IndexDatabase();
            if (!idd.TablesEmpty()) //if there are indexes to send
            {
                string indexDBCopy = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\indexes_" + (Properties.Settings.Default.guid).ToString() + ".s3db";

                if (System.IO.File.Exists(idd.GetPathFileName()))
                {
                    try
                    {
                        System.IO.File.Copy(idd.GetPathFileName(), indexDBCopy, true);
                    }
                    catch (System.IO.IOException e)
                    {
                        Debug.Print(e.Message);
                    }
                }

                Guid myGuid = Node.GetGuid();
                TcpClient tcpClient = new TcpClient((ndb.SelectNodeIp(Guid.Parse(guid))).ToString(), 7890);
                ClientThread ct = new ClientThread(tcpClient, false, myGuid);
                PushIndexRequest pir = new PushIndexRequest(indexDBCopy, new FileInfo(indexDBCopy).Length);
                ct.EnqueueWork(pir);
                NetworkResponse response = (NetworkResponse)ct.DequeueEvent();
                while (ct.IsWorking())
                {
                    Thread.Sleep(1000);
                }
                ct.RequestStop();
                while (ct.IsAlive())
                {
                    Thread.Sleep(1000);
                }
            }
        }
Example #6
0
        // Send indexes to all trusted nodes that are online
        // For use after a backup and associated index insertion have occurred
        public void sendIndexes()
        {
            IndexDatabase idd = new IndexDatabase();
            if (!idd.TablesEmpty()) //if there are indexes to send
            {
                DistributionDatabase ddb = new DistributionDatabase();
                List<string> guidList = new List<string>();
                NodeDatabase ndb = new NodeDatabase();

                string online = "online";
                string indexDBCopy = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\indexes_" + (Properties.Settings.Default.guid).ToString() + ".s3db";

                if (System.IO.File.Exists(idd.GetPathFileName()))
                {
                    try
                    {
                        System.IO.File.Copy(idd.GetPathFileName(), indexDBCopy, true);
                    }
                    catch (System.IO.IOException e)
                    {
                        Debug.Print(e.Message);
                    }
                }

                guidList = ndb.SelectGUID();

                foreach (string currentGUID in guidList)
                {
                    if (Node.GetGuid() != Guid.Parse(currentGUID) && ddb.GetStatus(currentGUID) == online && ndb.SelectNodeTrusted(Guid.Parse(currentGUID)) == "yes")
                    {
                        Guid myGuid = Node.GetGuid();
                        TcpClient tcpClient = new TcpClient((ndb.SelectNodeIp(Guid.Parse(currentGUID))).ToString(), 7890);
                        ClientThread ct = new ClientThread(tcpClient, false, myGuid);
                        PushIndexRequest pir = new PushIndexRequest(indexDBCopy, new FileInfo(indexDBCopy).Length);
                        ct.EnqueueWork(pir);
                        NetworkResponse response = (NetworkResponse)ct.DequeueEvent();
                        while (ct.IsWorking())
                        {
                            Thread.Sleep(1000);
                        }
                        ct.RequestStop();
                        while (ct.IsAlive())
                        {
                            Thread.Sleep(1000);
                        }
                    }
                }
            }
        }
Example #7
0
 protected void processPushIndexRequest(ClientThread ct, PushIndexRequest request)
 {
     Logger.Debug("EchoBackupService:processPushIndexRequest");
     //there probably ought to be some processing here but oh well
     ct.EnqueueWork((NetworkRequest)request);
 }
Example #8
0
 /// <summary>
 /// Handles a PushIndexRequest received from this ClientThread's TcpClient
 /// </summary>
 /// <param name="pir">The PushIndexRequest we need to process</param>
 private void processRemotePushIndexRequest(PushIndexRequest pir)
 {
     Logger.Debug("ClientThread:processRemotePushIndexRequest");
     sendMessage(tcpClient, new NetworkResponse(ResponseType.Yes, "", guid, pir.SequenceNumber));
     //pir.Path should be modified to be the local path where we want to store the received database
     readFileToDisk(pir.DBSize, pir.Path);
     IndexDistribution idd = new IndexDistribution();
     idd.processIndexes(pir.Path);
 }
Example #9
0
 /// <summary>
 /// Handles a PushIndexRequest sent through this ClientThread's TcpCLient
 /// </summary>
 /// <param name="pir">The PushIndexRequest we need to process</param>
 private void processMyPushIndexRequest(PushIndexRequest pir)
 {
     Logger.Debug("ClientThread:processMyPushIndexRequest");
     int ret = sendMessage(tcpClient, pir);
     NetworkResponse response = (NetworkResponse)receiveMessage(tcpClient);
     if (response.Type == Backend.ResponseType.Yes)
     {
         ret = writeFileToNetwork(pir.Path);
         lock (_lock)
         {
             eventQueue.Enqueue(response);
         }
     }
     else
     {
         Logger.Warn("ClientThread:processMyPushIndexRequest Remote node refused to store index file: " + response.Type + ' ' + response.Reason);
         //other node said 'no' (willnot, cannot, or notimplemented)
         //add result to event queue
         lock (_lock)
         {
             eventQueue.Enqueue(response);
         }
     }
 }
Example #10
0
 protected void processPushIndexRequest(ClientThread ct, PushIndexRequest request)
 {
     Logger.Debug("EchoBackupService:processPushIndexRequest");
     //there probably ought to be some processing here but oh well
     ct.EnqueueWork((NetworkRequest)request);
 }