private void CreateIfNotRegistered(WorkerAddress worker)
 {
     if (!m_workersFullInfoGathering.ContainsKey(worker.GetWorkerId()))
     {
         m_workersFullInfoGathering.Add(worker.GetWorkerId(), new WorkerLinkedData <T>(worker, null));
     }
 }
示例#2
0
 public void FetchStatisticsOf(WorkerAddress worker)
 {
     if (worker == null)
     {
         return;
     }
     Push(new EthMineRequest_WorkersStatistics(worker.GetAddress(), worker.GetWorkerName()));
 }
示例#3
0
 public void FetchHistoryOf(WorkerAddress worker)
 {
     if (worker == null)
     {
         return;
     }
     Push(new  EthMineRequest_WorkersHistory(worker.GetAddress(), worker.GetWorkerName()));
 }
 public void GetStatistics(out WorkerAddress worker, out EtherMineOrgWorkerFrame workerFrame)
 {
     worker      = new DefaultWorkerID(m_addressTarget, m_workerName);
     workerFrame = new EtherMineOrgWorkerFrame();
     workerFrame.SetTime(result.data.time);
     workerFrame.SetTimeLastSeen(result.data.lastSeen);
     workerFrame.SetHashRate(result.data.currentHashrate, result.data.reportedHashrate, result.data.averageHashrate);
     workerFrame.SetShares(result.data.validShares, result.data.invalidShares, result.data.staleShares);
 }
 public void SetWith(WorkerAddress workerAddress)
 {
     if (workerAddress == null)
     {
         return;
     }
     m_workerName  = workerAddress.GetWorkerName();
     m_addressName = workerAddress.GetAddress();
 }
    public void Set(WorkerAddress worker, T info)
    {
        bool found = m_workersFullInfoGathering.ContainsKey(worker.GetWorkerId());

        if (!found)
        {
            CheckThatWorkerExist(worker);
        }
        m_workersFullInfoGathering[worker.GetWorkerId()].SetLinkedData(info);
    }
 public void Get(WorkerAddress workerId, out bool found, out WorkerLinkedData <T> fullInfo)
 {
     found = m_workersFullInfoGathering.ContainsKey(workerId.GetWorkerId());
     if (found)
     {
         fullInfo = m_workersFullInfoGathering[workerId.GetWorkerId()];
     }
     else
     {
         fullInfo = null;
     }
 }
示例#8
0
        public void CountPrimes(long min, long max, WorkerAddress returnAddress)
        {
            long count = 0;

            for (long primeCandidate = min; primeCandidate <= max; primeCandidate++)
            {
                if (IsPrime(primeCandidate))
                {
                    count++;
                }
            }
            Worker.Current.Send(returnAddress, MessageTypes.Result, count);
        }
    public void CheckThatWorkerExist(WorkerAddress worker)
    {
        if (worker == null)
        {
            return;
        }
        string id = worker.GetWorkerId();

        CreateIfNotRegistered(worker);
        WorkerLinkedData <T> info = m_workersFullInfoGathering[id];

        info.SetLinkedData(null);
    }
示例#10
0
 public void GetHistory(out WorkerAddress worker, out EtherMineOrgWorkerFrame[] frames)
 {
     worker = new DefaultWorkerID(m_address, m_workerName);
     frames = new EtherMineOrgWorkerFrame[result.data.Length];
     for (int i = 0; i < result.data.Length; i++)
     {
         frames[i] = new EtherMineOrgWorkerFrame();
         frames[i].SetTime(result.data[i].time);
         frames[i].SetTimeLastSeen(result.data[i].time);
         frames[i].SetHashRate(result.data[i].currentHashrate, result.data[i].reportedHashrate, result.data[i].averageHashrate);
         frames[i].SetShares(result.data[i].validShares, result.data[i].invalidShares, result.data[i].staleShares);
     }
 }
示例#11
0
        public void CountPrimes(long min, long max, WorkerAddress returnAddress)
        {
            long count = 0;

            for (long primeCandidate = min; primeCandidate <= max; primeCandidate++)
            {
                //TODO: keep the info somewhere
                if (IsPrime(primeCandidate))
                {
                    //Log.Info ("Prime number found: {0}", primeCandidate);
                    count++;
                }
            }
            Worker.Current.Send(returnAddress, MessageTypes.Result, count);
        }
 public void CheckThatWorkerExist(WorkerAddress worker)
 {
     m_fullInfoByWorkerRegister.CheckThatWorkerExist(worker);
     m_fullInfoByWorkerRegister.Get(worker, out bool found, out WorkerLinkedData <EthermineOrgWorkerFullInformation> pointer);
     if (pointer.GetLinkedData() == null)
     {
         EthermineOrgWorkerFullInformation full = new EthermineOrgWorkerFullInformation();
         full.SetWorkerRef(worker);
         pointer.SetLinkedData(full);
     }
     if (!found)
     {
         throw new Exception("Humm");
     }
 }
示例#13
0
    private void RecovertListOfWorkers(EthMineRequest_Workers received)
    {
        if (!received.HasError())
        {
            WorkerLinkedData <EtherMineOrgWorkerFrame>[] m_workersLoadedDebug = received.GetAllWorkersLastReceivedInformation();
            for (int i = 0; i < m_workersLoadedDebug.Length; i++)
            {
                WorkerAddress worker = m_workersLoadedDebug[i].GetWorker();
                CheckThatWorkerToExist(worker);

                m_register.GetWorkerInformation(worker, out bool found, out EthermineOrgWorkerFullInformation info);
                if (found)
                {
                    info.SetWorkerRef(worker);
                    info.SetCurrentFrame(m_workersLoadedDebug[i].GetLinkedData());
                }
            }
        }
    }
 public void Write(TProtocol oprot)
 {
     oprot.IncrementRecursionDepth();
     try
     {
         TStruct struc = new TStruct("BlockLocation");
         oprot.WriteStructBegin(struc);
         TField field = new TField();
         if (__isset.workerId)
         {
             field.Name = "workerId";
             field.Type = TType.I64;
             field.ID   = 1;
             oprot.WriteFieldBegin(field);
             oprot.WriteI64(WorkerId);
             oprot.WriteFieldEnd();
         }
         if (WorkerAddress != null && __isset.workerAddress)
         {
             field.Name = "workerAddress";
             field.Type = TType.Struct;
             field.ID   = 2;
             oprot.WriteFieldBegin(field);
             WorkerAddress.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (TierAlias != null && __isset.tierAlias)
         {
             field.Name = "tierAlias";
             field.Type = TType.String;
             field.ID   = 3;
             oprot.WriteFieldBegin(field);
             oprot.WriteString(TierAlias);
             oprot.WriteFieldEnd();
         }
         oprot.WriteFieldStop();
         oprot.WriteStructEnd();
     }
     finally
     {
         oprot.DecrementRecursionDepth();
     }
 }
示例#15
0
 public EhterMineWorkerRef(WorkerAddress ethermineOrgWorker)
 {
     this.m_workerTargeted = ethermineOrgWorker;
 }
 public void GetWorkerInformation(WorkerAddress worker, out bool found, out EthermineOrgWorkerFullInformation workerInfo)
 {
     m_fullInfoByWorkerRegister.Get(worker, out found, out WorkerLinkedData <EthermineOrgWorkerFullInformation> fullinfo);
     workerInfo = fullinfo.GetLinkedData();
 }
 // Not inehritable, different signature
 public void AddAdress(WorkerAddress address)
 {
     _customerAddresList.Add(address);
 }
示例#18
0
 public void CheckThatWorkerToExist(WorkerAddress worker)
 {
     m_register.CheckThatWorkerExist(worker);
 }
 public bool Has(WorkerAddress workerId)
 {
     return(m_workersFullInfoGathering.ContainsKey(workerId.GetWorkerId()));
 }
示例#20
0
 public void SetWorkerRef(WorkerAddress workerAddress)
 {
     m_worker.SetWith(workerAddress);
 }
示例#21
0
        public override void Main()
        {
            Log.Info("Main worker online");

            //set up some preconditions
            long max            = 99999999;
            long batchSize      = 50000; //the number of numbers to test in each batch
            long currentMinimum = 2;
            long primeCount     = 0;

            // Spawn the prime workers. Spawn one for each processor/processing
            // core in the machine.
            List <WorkerAddress> workers = new List <WorkerAddress>();
            int processorCount           = Node.GetProcessorCount();

            for (int i = 0; i < processorCount; i++)
            {
                WorkerAddress worker = Spawn <PrimeWorker>();
                workers.Add(worker);
                Monitor(worker); //receive messages when the worker terminates
            }

            //start timing the operation
            DateTime dtStart = DateTime.Now;

            //Initialize all workers
            Broadcast(MessageTypes.Start, null);

            //start listening for requests and results
            Message msg;

            do
            {
                msg = Receive();
                switch (msg.MessageType)
                {
                case MessageTypes.RequestBatch:
                    //a worker has requested the next batch
                    //check if there are any left to process
                    if (currentMinimum <= max)
                    {
                        long currentMax = currentMinimum + batchSize;
                        currentMax = currentMax > max ? max : currentMax;
                        Send(msg.SenderAddress, MessageTypes.ReplyBatch, new Batch(currentMinimum, currentMax));
                        currentMinimum = currentMax + 1;
                    }
                    else
                    {
                        Send(msg.SenderAddress, MessageTypes.Terminate, null);
                    }
                    break;

                case MessageTypes.Result:
                    primeCount += (long)msg.Content;
                    break;

                case SystemMessages.WorkerTerminated:
                    //a worker terminated - remove it from the list
                    workers.Remove(msg.SenderAddress);
                    break;

                case SystemMessages.WorkerTerminatedAbnormally:
                    //a worker terminated abnormally - remove it from the list
                    workers.Remove(msg.SenderAddress);
                    Log.Error("Worker {0} terminated abnormally", msg.SenderAddress);
                    break;

                default:
                    break;
                }
            }while (workers.Count > 0); //keep listening until all workers are terminated
            TimeSpan tsTotal = DateTime.Now - dtStart;

            Log.Info("Found {0} primes between 2 and {1}", primeCount, max);
            Log.Info("Computation took {0} seconds", tsTotal.TotalSeconds);
            Log.Info("Main worker terminating");
        }
示例#22
0
 public WorkerLinkedData(WorkerAddress linkedWorker, T linkedData)
 {
     m_linkedWorker = linkedWorker;
     m_linkedData   = linkedData;
 }