Package org.hive2hive.core.network.data

Source Code of org.hive2hive.core.network.data.PutQueueEntry

package org.hive2hive.core.network.data;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;

import org.hive2hive.core.exceptions.PutFailedException;

class PutQueueEntry extends QueueEntry {

  private final AtomicBoolean readyToPut = new AtomicBoolean(false);
  private final AtomicBoolean abort = new AtomicBoolean(false);
  private final CountDownLatch putWaiter = new CountDownLatch(1);

  private PutFailedException putFailedException;

  public PutQueueEntry(String pid) {
    super(pid);
  }

  public boolean isReadyToPut() {
    return readyToPut.get();
  }

  public void readyToPut() {
    readyToPut.set(true);
  }

  public boolean isAborted() {
    return abort.get();
  }

  public void abort() {
    abort.set(true);
  }

  public void notifyPut() {
    putWaiter.countDown();
  }

  public void waitForPut() throws PutFailedException {
    if (putFailedException != null) {
      throw putFailedException;
    }

    try {
      putWaiter.await();
    } catch (InterruptedException e) {
      putFailedException = new PutFailedException("Could not wait to put the user profile");
    }

    if (putFailedException != null) {
      throw putFailedException;
    }
  }

  public void setPutError(PutFailedException error) {
    this.putFailedException = error;
  }
}
TOP

Related Classes of org.hive2hive.core.network.data.PutQueueEntry

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.