@Override public void insert(Task task, TaskStatus status) throws EntryExistsException { giant.lock(); try { Preconditions.checkNotNull(task, "task"); Preconditions.checkNotNull(status, "status"); Preconditions.checkArgument( task.getId().equals(status.getId()), "Task/Status ID mismatch[%s/%s]", task.getId(), status.getId() ); if (tasks.containsKey(task.getId())) { throw new EntryExistsException(task.getId()); } log.info("Inserting task %s with status: %s", task.getId(), status); tasks.put(task.getId(), new TaskStuff(task, status, DateTimes.nowUtc(), task.getDataSource())); } finally { giant.unlock(); } }
/** * Adds some work to the queue and the underlying task storage facility with a generic "running" status. * * @param task task to add * * @return true * * @throws EntryExistsException if the task already exists */ public boolean add(final Task task) throws EntryExistsException { if (taskStorage.getTask(task.getId()).isPresent()) { throw new EntryExistsException(StringUtils.format("Task %s is already exists", task.getId())); } giant.lock(); try { Preconditions.checkState(active, "Queue is not active!"); Preconditions.checkNotNull(task, "task"); Preconditions.checkState(tasks.size() < config.getMaxSize(), "Too many tasks (max = %,d)", config.getMaxSize()); // If this throws with any sort of exception, including TaskExistsException, we don't want to // insert the task into our queue. So don't catch it. taskStorage.insert(task, TaskStatus.running(task.getId())); addTaskInternal(task); managementMayBeNecessary.signalAll(); return true; } finally { giant.unlock(); } }
throw new EntryExistsException(id, e); } else { throw new RuntimeException(e);
@Override public void insert(Task task, TaskStatus status) throws EntryExistsException { giant.lock(); try { Preconditions.checkNotNull(task, "task"); Preconditions.checkNotNull(status, "status"); Preconditions.checkArgument( task.getId().equals(status.getId()), "Task/Status ID mismatch[%s/%s]", task.getId(), status.getId() ); if (tasks.containsKey(task.getId())) { throw new EntryExistsException(task.getId()); } log.info("Inserting task %s with status: %s", task.getId(), status); tasks.put(task.getId(), new TaskStuff(task, status, DateTimes.nowUtc(), task.getDataSource())); } finally { giant.unlock(); } }
/** * Adds some work to the queue and the underlying task storage facility with a generic "running" status. * * @param task task to add * * @return true * * @throws EntryExistsException if the task already exists */ public boolean add(final Task task) throws EntryExistsException { if (taskStorage.getTask(task.getId()).isPresent()) { throw new EntryExistsException(StringUtils.format("Task %s is already exists", task.getId())); } giant.lock(); try { Preconditions.checkState(active, "Queue is not active!"); Preconditions.checkNotNull(task, "task"); Preconditions.checkState(tasks.size() < config.getMaxSize(), "Too many tasks (max = %,d)", config.getMaxSize()); // If this throws with any sort of exception, including TaskExistsException, we don't want to // insert the task into our queue. So don't catch it. taskStorage.insert(task, TaskStatus.running(task.getId())); addTaskInternal(task); managementMayBeNecessary.signalAll(); return true; } finally { giant.unlock(); } }
throw new EntryExistsException(id, e); } else { throw new RuntimeException(e);