Package cl.niclabs.skandium.gcm

Source Code of cl.niclabs.skandium.gcm.DelegationRegistry

package cl.niclabs.skandium.gcm;

import java.util.concurrent.ConcurrentHashMap;

import cl.niclabs.skandium.system.Task;

public class DelegationRegistry {

  private ConcurrentHashMap<Long, Task> transmitted;
  private ConcurrentHashMap<Long, TaskHead> received;
 
  DelegationRegistry() {
    transmitted = new ConcurrentHashMap<Long, Task>();
    received = new ConcurrentHashMap<Long, TaskHead>();
  }
 
 
  TaskHead registerTransmittedTask(Task task) {
   
    TaskHead head = new TaskHead(task.id, task.getP(), task.getStack());
   
    transmitted.put(task.id, task);
    return head;
  }
 
  Task registerReceivedTask(TaskHead head, SCTaskExecutor executor) {
   
    Task task = new Task(head.getData(), head.getStack(), executor);
    received.put(task.id, head);
    return task;
  }
 
  Task eraseTransmittedTask(TaskHead head) {
   
    Task task =  transmitted.remove(head.getOriginId());
    if(task != null) {
      task.setP(head.getData());
    }
   
    return task;
  }
 
  TaskHead eraseReceivedTask(Task task) {
   
    return received.remove(task.id);   
  }
}
TOP

Related Classes of cl.niclabs.skandium.gcm.DelegationRegistry

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.