congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
co.paralleluniverse.strands
Code IndexAdd Tabnine to your IDE (free)

How to use co.paralleluniverse.strands

Best Java code snippets using co.paralleluniverse.strands (Showing top 20 results out of 315)

origin: vert-x3/vertx-examples

@Suspendable
@Override
public void start() throws Exception {
 EventBus eb = vertx.eventBus();
 eb.consumer(ADDRESS).handler(msg -> msg.reply("pong"));
 // This runs on an event loop but the event loop is at no time blocked!
 for (int i = 0; i < 10; i++) {
  System.out.println("Thread is " + Thread.currentThread());
  Message<String> reply = awaitResult(h -> eb.send(ADDRESS, "ping", h));
  System.out.println("got reply: " + reply.body());
  // Like Thread.sleep but doesn't block the OS thread
  Strand.sleep(1000);
 }
}
origin: co.paralleluniverse/quasar-core

protected boolean set(V value) {
  if (done)
    return false;
  if (casSetting(0, 1)) {
    this.value = value;
    this.done = true;
    sync.signalAll();
    return true;
  } else
    return false;
}
origin: co.paralleluniverse/quasar-core

@Override
public void signalAll() {
  for (Strand s : waiters) {
    record("signalAll", "%s signalling %s", this, s);
    Strand.unpark(s, owner);
  }
}
origin: co.paralleluniverse/quasar-core

/**
 * Convenience method to interrupt current strand.
 */
static void selfInterrupt() {
  Strand.currentStrand().interrupt();
}
origin: co.paralleluniverse/quasar

protected void maybeSetCurrentStrandAsOwner() {
  if (owner == null)
    setStrand(Strand.currentStrand());
  else
    sync.verifyOwner();
}
origin: co.paralleluniverse/quasar-core

/**
 * Convenience method to park and then check if interrupted
 *
 * @return {@code true} if interrupted
 */
private boolean parkAndCheckInterrupt() throws SuspendExecution {
  Strand.park(this);
  return Strand.interrupted();
}
origin: co.paralleluniverse/quasar-core

  @Override
  public void uncaughtException(Thread t, Throwable e) {
    uncaughtExceptionHandler.uncaughtException(Strand.of(t), e);
  }
});
origin: co.paralleluniverse/quasar-core

@Override
public void signal() {
  final Strand s = waiter;
  record("signal", "%s signalling %s", this, s);
  if (s != null)
    Strand.unpark(s, owner);
}
origin: co.paralleluniverse/quasar-core

public void signalAndWait() throws SuspendExecution {
  final Strand s = waiter;
  if (s != null) {
    record("signal", "%s signalling %s", this, s);
    Strand.yieldAndUnpark(s, owner);
  }
}

origin: co.paralleluniverse/quasar-core

  public static Strand of(Object owner) {
    if (owner instanceof Strand)
      return (Strand) owner;
//        if (owner instanceof Fiber)
//            return (Fiber) owner;
    else
      return of((Thread) owner);
  }

origin: co.paralleluniverse/quasar-core

  @Override
  public void run() throws SuspendExecution {
    try {
      Val.this.set0(f.run());
    } catch (Throwable t) {
      Val.this.setException0(t);
    }
  }
}).start();
origin: co.paralleluniverse/quasar-core

protected QueueChannel(BasicQueue<Message> queue, OverflowPolicy overflowPolicy, boolean singleProducer, boolean singleConsumer) {
  this.queue = queue;
  if (!singleConsumer || queue instanceof CircularBuffer)
    this.sync = new SimpleConditionSynchronizer(this);
  else
    this.sync = new OwnedSynchronizer(this);
  this.overflowPolicy = overflowPolicy;
  this.sendersSync = overflowPolicy == OverflowPolicy.BLOCK ? new SimpleConditionSynchronizer(this) : null;
  this.singleProducer = singleProducer;
  this.singleConsumer = singleConsumer;
}
origin: co.paralleluniverse/quasar-core

@Override
public Object register() {
  for(Condition cond : conditions)
    cond.register();
  return null;
}
origin: co.paralleluniverse/quasar-core

@Override
public void unregister(Object registrationToken) {
  for(Condition cond : conditions)
    cond.unregister(null);
}
origin: co.paralleluniverse/quasar

  @Override
  public Void run() throws SuspendExecution, InterruptedException {
    runnable.run();
    return null;
  }
}
origin: co.paralleluniverse/quasar-core

/**
 * A utility method that converts a {@link SuspendableRunnable} to a {@link Runnable} so that it could run
 * as the target of a thread.
 */
public static Runnable toRunnable(final SuspendableRunnable runnable) {
  return new SuspendableRunnableRunnable(runnable);
}
origin: co.paralleluniverse/quasar

Channel(Object owner, SingleConsumerQueue<Message, ?> queue) {
  this.queue = (SingleConsumerQueue<Message, Object>) queue;
  this.owner = owner;
  this.sync = OwnedSynchronizer.create(owner);
}
origin: co.paralleluniverse/quasar-core

/**
 * Convenience method to interrupt current strand.
 */
static void selfInterrupt() {
  Strand.currentStrand().interrupt();
}
origin: co.paralleluniverse/quasar-core

/**
 * Convenience method to park and then check if interrupted
 *
 * @return {@code true} if interrupted
 */
private final boolean parkAndCheckInterrupt() throws SuspendExecution {
  Strand.park(this);
  return Strand.interrupted();
}
origin: co.paralleluniverse/quasar-core

protected boolean setException(Throwable exception) {
  if (done)
    return false;
  if (casSetting(0, 1)) {
    this.exception = exception;
    this.done = true;
    sync.signalAll();
    return true;
  } else
    return false;
}
co.paralleluniverse.strands

Most used classes

  • Strand
    A Strand is either a Thread or a Fiber
  • Channels
    A utility class for creating and manipulating channels.
  • Channel
    A message-passing channel. Implementations of this interface are encouraged (though not required) to
  • SendPort
    A channel's producer-side functional interface.
  • StrandFactory
    Creates new Strand on demand.
  • Timeout,
  • ReceivePort,
  • ReentrantLock,
  • QueueCapacityExceededException,
  • SingleConsumerArrayObjectQueue,
  • SingleConsumerLinkedArrayObjectQueue,
  • SingleConsumerQueue,
  • Condition,
  • OwnedSynchronizer,
  • Strand$ThreadStrand,
  • Stranded,
  • SuspendableRunnable,
  • IntChannel,
  • SingleConsumerQueueChannel
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now