本文整理汇总了Java中co.paralleluniverse.strands.Strand类的典型用法代码示例。如果您正苦于以下问题:Java Strand类的具体用法?Java Strand怎么用?Java Strand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Strand类属于co.paralleluniverse.strands包,在下文中一共展示了Strand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onFrame
import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
void onFrame(FrameUpdate frameUpdate) {
this.frame = frameUpdate.getFrame();
if (frame >= this.wakeUp) {
if (this.nextCommand != null) {
this.lastCommandReturnValue = this.nextCommand.execute();
if (this.lastCommandReturnValue) { // TODO this is not guaranteed to return the error related to the command
this.wakeUp = frame + this.nextCommand.getDelay();
} else {
BwError error = this.publicBoard.getInteractionHandler().getLastError();
logger.warn("{} failed with error probably being {}", this.nextCommand, error);
}
logger.trace("frame {}: {} executed {} ({})", frame, this.scv, this.nextCommand, this.lastCommandReturnValue ? "success" : "failed");
this.nextCommand = null;
Strand.unpark(this.getStrand());
}
}
this.sendOrInterrupt(frameUpdate);
}
示例2: start
import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
@Suspendable
@Override
public void start() throws Exception {
httpServer = vertx.createHttpServer();
httpServer.requestHandler(
Sync.fiberHandler(req -> {
try {
Strand.sleep(1, TimeUnit.SECONDS); // 1
} catch (SuspendExecution | InterruptedException e) { // 1
e.printStackTrace(); // 1
} // 1
//sleep(); // 2
final String body = FiberHttpServer.class.getName();
req.response()
.putHeader("Content-Length", String.valueOf(body.length()))
.end(body);
})).listen(port);
}
示例3: awaitNanos
import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
@Override
@Suspendable
public long awaitNanos(long nanos) throws InterruptedException {
long left = nanos;
long deadline = System.nanoTime() + left;
try {
Strand.parkNanos(this, left);
} catch (SuspendExecution e) {
throw new AssertionError();
}
if (Strand.interrupted()){
throw new InterruptedException();
}
left = deadline - System.nanoTime();
return left;
}
示例4: reset
import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
public void reset() {
int cnt = 0;
log("Waiting on [" + fibers.size() + "] Fibers....");
for(Fiber<?> f: fibers.values()) {
try {
while(f.getState()==Strand.State.RUNNING) {
SystemClock.sleep(100);
}
log("Testing State: %s : %s", f.getName(), f.getState());
cnt++;
} catch (Exception ex) {
ex.printStackTrace(System.err);
//throw new RuntimeException(ex);
}
}
fiberTask.set(0);
log("Reset Complete. Tasks:" + cnt);
invBuilder.build().send();
log("BulkRequest Dispatched");
}
示例5: sleepImpl
import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
/**
* This method is used by both sleep() methods to implement sleeping
* for the given time even if interrupted
*
* @param millis the number of milliseconds to sleep
* @param closure optional closure called when interrupted
* as long as the closure returns false the sleep continues
*/
private static void sleepImpl(long millis, Closure closure) throws SuspendExecution{
long start = System.currentTimeMillis();
long rest = millis;
long current;
while (rest > 0) {
try {
Strand.sleep(rest);
rest = 0;
} catch (InterruptedException e) {
if (closure != null) {
if (DefaultTypeTransformation.castToBoolean(closure.call(e))) {
return;
}
}
current = System.currentTimeMillis(); // compensate for closure's time
rest = millis + start - current;
}
}
}
示例6: getFiber
import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
private static Fiber getFiber(final long sleep, final String message) {
return new Fiber<String>() {
@Override
protected String run() throws SuspendExecution, InterruptedException {
Strand.sleep(sleep);
return message;
}
};
}
示例7: sleep
import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
@Suspendable
public void sleep() {
try {
Strand.sleep(1, TimeUnit.SECONDS);
} catch (SuspendExecution | InterruptedException e) {
e.printStackTrace();
}
}
示例8: sleepIfOnRetry
import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
private static long sleepIfOnRetry(final String logMethodName, final Name tableName, final int attemptCount, final long currentRetryDelay, final ResourceConnectTolerance rct) {
long nextRetryDelay;
/*
* If this is the first attempt, proceed immediately. Otherwise, delay by the current
* exponential-backoff delay interval, then apply the exponential backoff for the next
* interval (if it becomes necessary)
*/
if (attemptCount == 0) {
nextRetryDelay = rct.getRetryDelayInit();
} else {
LOG.debug(logMethodName,
()->"Table '",
()->tableName,
()->"' connection attempt ",
()->Integer.toString(attemptCount),
()->"/",
()->Integer.toString(rct.getAttemptsMax()),
()->" failed; retrying in ",
()->Long.toString(currentRetryDelay),
()->"ms...");
try {
Strand.sleep(currentRetryDelay);
} catch (InterruptedException iExc) {
// ignore
} catch (SuspendExecution quasarInstrumentationExcNeverThrown) {
throw new AssertionError(quasarInstrumentationExcNeverThrown);
}
nextRetryDelay = currentRetryDelay * rct.getRetryDelayMultiplier();
nextRetryDelay = Math.min(rct.getRetryDelayMax(), nextRetryDelay);
}
return nextRetryDelay;
}
示例9: await
import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
@Override
@Suspendable
public void await() throws InterruptedException {
try{
Strand.park(this);
}catch (SuspendExecution e){
throw new AssertionError();
}
if (Strand.interrupted()){
throw new InterruptedException();
}
}
示例10: register
import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
@Override
public void register() {
final Strand currentStrand = Strand.currentStrand();
if (!casWaiter(null, currentStrand)){
throw new IllegalMonitorStateException("attempt by " + currentStrand + " but owned by " + waiter);
}
}
示例11: signal
import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
@Override
public void signal() {
final Strand t = waiter;
if (t != null){
Strand.unpark(t);
}
}
示例12: unregister
import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
@Override
public void unregister() {
if (waiter != Strand.currentStrand()){
throw new IllegalMonitorStateException("attempt by " + Strand.currentStrand() + " but owned by " + waiter);
}
waiter = null;
}
示例13: linkToEchoService
import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
void linkToEchoService(Actor ax) throws SuspendExecution, InterruptedException{
Message cmsg = new Message();
while (true){
ax.monitor(echoSvcAid);
Message msg = ax.recv(cmsg, AtomCode.EXIT, AtomCode.MONITOR);
if (AtomCode.equals(msg.getType(), AtomCode.MONITOR)){
break;
}
Strand.sleep(10);
}
}
示例14: main
import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
public static void main(final ApplicationContext applicationContext, int tn)
throws SuspendExecution, InterruptedException, ExecutionException {
final AtomicInteger total = new AtomicInteger(0);
long start = System.currentTimeMillis();
System.out.println("==============");
int i = 0;
while (i++ < tn) {
Fiber f = new Fiber<Void>() {
private static final long serialVersionUID = 1L;
@Override
protected Void run() throws SuspendExecution, InterruptedException {
int k = 0;
while (k++ < 10) {
DataSourceProxy phoenixDS = (DataSourceProxy) applicationContext.getBean("phoenixDS");
excuteQuery(phoenixDS, "select count(1) from metric_data_entity_pt1m_2");
}
total.addAndGet(10);
return super.run();
}
};
f.start();
}
while (total.get() < tn * 10) {
Strand.sleep(2);
}
System.out.println("F" + (System.currentTimeMillis() - start));
}
示例15: main
import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
public static void main(final ApplicationContext applicationContext, int tn)
throws SuspendExecution, InterruptedException {
final ThreadPoolExecutor pool = new ThreadPoolExecutor(4, 1000, 0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>());
final AtomicInteger total = new AtomicInteger(0);
long start = System.currentTimeMillis();
System.out.println("==============");
int i = 0;
while (i++ < tn)
pool.submit(new Runnable() {
@Override
public void run() {
int k = 0;
while (k++ < 10) {
DataSourceProxy phoenixDS = (DataSourceProxy) applicationContext.getBean("phoenixDS");
excuteQuery(phoenixDS, "select count(1) from metric_data_entity_pt1m_2");
}
total.addAndGet(10);
}
});
while (total.get() < tn * 10) {
Strand.sleep(2);
}
System.out.println("T" + (System.currentTimeMillis() - start));
pool.shutdown();
}