Calling methods on the MasterWorker

Oct 10, 2011 at 4:38 PM

Please correct me if I missed something. Also, I am using this on Mono.

The examples given don't reflect how a master worker would likely be used within a context of a larger program. The problem is, there is no way to set parameters or call methods on the MasterWorker. This makes the framework fairly useless. Consider using this framework as a web service... how could this be done with the current design?

OpenDistributed<TRootWorker(...) returns the specified worker, but when I called methods on it from within Program I would get the error "Node.PutMessage : Cannot dispatch message" 

Secondly, as far as I can tell, there is no need to launch the MasterWorker in a separate thread. This is overkill, as generally one would want to run the MasterWorker in the main thread. If not, one could always run it in a different thread manually.

I was never able to diagnose the exact cause of the error, but I was able to make a new public method within the Node class which fixes the problem. This method returns the worker and adds the node to the worker. One can then call the methods from the main thread (such as Main() or DoThisOperation() or RunWithParamaters(paramaters)) etc...


		public TMainWorker SetMainWorker<TMainWorker>(string registrationServerNameOrAddress, int registrationServerPort, int listenerPort)
			where TMainWorker : Worker
			OpenAndConnectToRegistrationServer(registrationServerNameOrAddress, registrationServerPort, listenerPort);
			    ushort workerId = 0;
                while (_localWorkers.ContainsKey(workerId))
                    if (workerId == ushort.MaxValue)
                        Log.Error("Unable to spawn more workers. There are already {0} workers running", _localWorkers.Count);
                        return null;
				TMainWorker worker = Activator.CreateInstance<TMainWorker>();
                worker.Id = workerId;
                _localWorkers.Add(workerId, worker);

                if (_localWorkers.Count >= WorkerCountWarningLimit)
                    Log.Warning("There are now {0} workers on this node.", _localWorkers.Count);

			return worker;

Just add that method to Node class and call a MasterWorker as follows:

worker = node.SetMainWorker<MainWorker>(regServerAddress, regServerPort, port);

Please advise if I misunderstood something. Or have anything to add.