• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Strand类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中co.paralleluniverse.strands.Strand的典型用法代码示例。如果您正苦于以下问题:Java Strand类的具体用法?Java Strand怎么用?Java Strand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Strand类属于co.paralleluniverse.strands包,在下文中一共展示了Strand类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
 
开发者ID:OpenBW,项目名称:TSBW4J,代码行数:24,代码来源:WorkerActor.java


示例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);
}
 
开发者ID:pesia,项目名称:vertx-sync-examples,代码行数:23,代码来源:FiberHttpServer.java


示例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;
}
 
开发者ID:nousxiong,项目名称:actorx4j,代码行数:19,代码来源:StrandSynchronizer.java


示例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");
}
 
开发者ID:nickman,项目名称:JMXMPAgent,代码行数:22,代码来源:SuspendableMBeanServerConnection.java


示例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;
		}
	}
}
 
开发者ID:dinix2008,项目名称:quasar-groovy,代码行数:28,代码来源:DefaultGroovyStaticMethods.java


示例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;
        }
    };
}
 
开发者ID:pmohankumar,项目名称:fibers,代码行数:10,代码来源:FiberTest.java


示例7: sleep

import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
@Suspendable
public void sleep() {
    try {
        Strand.sleep(1, TimeUnit.SECONDS);
    } catch (SuspendExecution | InterruptedException e) {
        e.printStackTrace();
    }
}
 
开发者ID:pesia,项目名称:vertx-sync-examples,代码行数:9,代码来源:FiberHttpServer.java


示例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;
}
 
开发者ID:LiaisonTechnologies,项目名称:shachi,代码行数:34,代码来源:HBaseUtil.java


示例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();
	}
}
 
开发者ID:nousxiong,项目名称:actorx4j,代码行数:14,代码来源:StrandSynchronizer.java


示例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);
	}
}
 
开发者ID:nousxiong,项目名称:actorx4j,代码行数:8,代码来源:StrandSynchronizer.java


示例11: signal

import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
@Override
public void signal() {
	final Strand t = waiter;
	if (t != null){
		Strand.unpark(t);
	}
}
 
开发者ID:nousxiong,项目名称:actorx4j,代码行数:8,代码来源:StrandSynchronizer.java


示例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;
}
 
开发者ID:nousxiong,项目名称:actorx4j,代码行数:8,代码来源:StrandSynchronizer.java


示例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);
	}
}
 
开发者ID:nousxiong,项目名称:actorx4j,代码行数:12,代码来源:ServiceExit.java


示例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));
}
 
开发者ID:peiliping,项目名称:excalibur,代码行数:30,代码来源:Quasar.java


示例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();
}
 
开发者ID:peiliping,项目名称:excalibur,代码行数:30,代码来源:Quasar2.java


示例16: parkAndUnpark

import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
public static void parkAndUnpark(Strand other, Object blocker) {
    try {
        Strand.parkAndUnpark(other, blocker);
    } catch (SuspendExecution e) {
        throw RuntimeSuspendExecution.of(e);
    }
}
 
开发者ID:icode,项目名称:ameba,代码行数:8,代码来源:Strands.java


示例17: yieldAndUnpark

import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
public static void yieldAndUnpark(Strand other, Object blocker) {
    try {
        Strand.yieldAndUnpark(other, blocker);
    } catch (SuspendExecution e) {
        throw RuntimeSuspendExecution.of(e);
    }
}
 
开发者ID:icode,项目名称:ameba,代码行数:8,代码来源:Strands.java


示例18: spawnActor

import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
private <Message, V> Actor<Message, V> spawnActor(Actor<Message, V> actor) {
    Fiber fiber = new Fiber("actor", scheduler, actor);
    fiber.setUncaughtExceptionHandler(new Strand.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Strand s, Throwable e) {
            e.printStackTrace();
            throw Exceptions.rethrow(e);
        }
    });
    fiber.start();
    return actor;
}
 
开发者ID:bacta,项目名称:pre-cu,代码行数:13,代码来源:ActorTest.java


示例19: execute

import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
private boolean execute(Command command) throws InterruptedException, SuspendExecution {
	
	this.nextCommand = command;
	Strand.park();
	return this.lastCommandReturnValue;
}
 
开发者ID:OpenBW,项目名称:TSBW4J,代码行数:7,代码来源:WorkerActor.java


示例20: call

import co.paralleluniverse.strands.Strand; //导入依赖的package包/类
@Override
@Suspendable
public String call() throws Exception {
    Strand.sleep(sleep);
    return message;
}
 
开发者ID:pmohankumar,项目名称:fibers,代码行数:7,代码来源:FiberCallable.java



注:本文中的co.paralleluniverse.strands.Strand类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NodeStatusUpdater类代码示例发布时间:2022-05-22
下一篇:
Java StackProfiler类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap