5 // The Registry provides a 'threadsafe' interface to various global
8 // The registry dispatch thread is forbidden from performing any work
9 // that is likely to block. Result channels must be buffered with
10 // enough space for the full set of results.
21 type registryRequest struct {
25 responseChannel chan *registryResponse
28 type registryResponse struct {
33 var chanRequest = make(chan *registryRequest, requestQueueSize)
35 // bake a minimal request structure together.
36 func newRequest(wants_response bool) (r *registryRequest) {
37 r = new(registryRequest)
39 r.responseChannel = make(chan *registryResponse, 1)
45 // Add a Task to the registry. Return true if successful, returns
46 // false if the task is lacking critical information (such as a Job Id)
47 // and can't be registered.
48 func TaskAdd(task *TaskRequest) bool {
49 rr := newRequest(true)
50 rr.operation = requestAddTask
54 resp := <- rr.responseChannel
58 // Get a Task from the registry. Returns the task if successful,
59 // returns nil if the task couldn't be found.
60 func TaskGet(id uint64) *TaskRequest {
61 rr := newRequest(true)
62 rr.operation = requestGetTask
66 resp := <- rr.responseChannel
70 func manageRegistry() {
71 taskRegister := make(map[uint64]*TaskRequest)
75 resp := new (registryResponse)
76 switch (req.operation) {
79 // and register the job
80 taskRegister[req.task.Id] = req.task
86 task, exists := taskRegister[req.id]
92 if req.responseChannel != nil {
93 req.responseChannel <- resp