本文整理汇总了Java中co.paralleluniverse.fibers.FiberScheduler类的典型用法代码示例。如果您正苦于以下问题:Java FiberScheduler类的具体用法?Java FiberScheduler怎么用?Java FiberScheduler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FiberScheduler类属于co.paralleluniverse.fibers包,在下文中一共展示了FiberScheduler类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: record
import co.paralleluniverse.fibers.FiberScheduler; //导入依赖的package包/类
/**
* Record events in a separate Fiber using one or more Recorders.
*
* This method returns immediately after starting the Fiber for recording events.
*
* @param fiberName the name of the fiber that records events.
* @param fe an optional scheduler for the spawned recording fiber, null to use the default.
* @param rp a channel on which to receive TimingEvents, which are passed to the underlying
* Recorders.
* @param rs zero or more Recorders, each of which receives every event (after the delay period)
* in the order they are passed to this method.
* @param <T> the type of the Response object in each TimingEvent.
*/
@SafeVarargs
static <T> Fiber<Void> record(final String fiberName,
final FiberScheduler fe,
final ReceivePort<TimingEvent<T>> rp,
final Recorder<T>... rs)
{
return new Fiber<Void>(fiberName, fe != null ? fe : DefaultFiberScheduler.getInstance(), () -> {
while (true) {
final TimingEvent<T> event = rp.receive();
if (event == null) {
break;
}
for (final Recorder<T> r : rs) {
r.record(event);
}
}
return null;
}).start();
}
开发者ID:pinterest,项目名称:jbender,代码行数:35,代码来源:Recorder.java
示例2: spawn
import co.paralleluniverse.fibers.FiberScheduler; //导入依赖的package包/类
/**
* 产生一个纤程actor,并且使用指定的Handler来放入指定的调度器执行
* @param fibSche 调度器
* @param ah 可运行单元
* @return 新Actor的Id
*/
@Suspendable
public ActorId spawn(FiberScheduler fibSche, final IFiberActorHandler ah){
if (fibSche == null){
throw new NullPointerException();
}
final Actor actor = makeActor(fibSche);
ActorId aid = actor.getActorId();
new Fiber<Void>(fibSche) {
private static final long serialVersionUID = 2841359941298581576L;
@Override
protected Void run() throws SuspendExecution, InterruptedException {
Actor.runOnFiber(actor, ah);
return null;
}
}.start();
return aid;
}
开发者ID:nousxiong,项目名称:actorx4j,代码行数:25,代码来源:ActorSystem.java
示例3: makeActor
import co.paralleluniverse.fibers.FiberScheduler; //导入依赖的package包/类
@Suspendable
private Actor makeActor(FiberScheduler fibSche){
ActorId aid = generateActorId();
Actor actor = new Actor(this, aid, fibSche);
actorMap.put(aid, actor);
return actor;
}
开发者ID:nousxiong,项目名称:actorx4j,代码行数:8,代码来源:ActorSystem.java
示例4: loadTestThroughput
import co.paralleluniverse.fibers.FiberScheduler; //导入依赖的package包/类
private static <Req, Res> void loadTestThroughput(final IntervalGenerator intervalGen,
int warmupRequests,
final ReceivePort<Req> requests,
final RequestExecutor<Req, Res> executor,
final SendPort<TimingEvent<Res>> eventChannel,
final FiberScheduler fiberScheduler,
final StrandFactory strandFactory)
throws SuspendExecution, InterruptedException
{
final long startNanos = System.nanoTime();
try {
long overageNanos = 0;
long overageStart = System.nanoTime();
final WaitGroup waitGroup = new WaitGroup();
while (true) {
final long receiveNanosStart = System.nanoTime();
final Req request = requests.receive();
LOG.trace("Receive request time: {}", System.nanoTime() - receiveNanosStart);
if (request == null) {
break;
}
// Wait before dispatching request as much as generated, minus the remaining dispatching overhead
// to be compensated for (up to having 0 waiting time of course, not negative)
long waitNanos = intervalGen.nextInterval(System.nanoTime() - startNanos);
final long adjust = Math.min(waitNanos, overageNanos);
waitNanos -= adjust;
overageNanos -= adjust;
// Sleep in the accepting fiber
long sleepNanosStart = System.nanoTime();
Strand.sleep(waitNanos, TimeUnit.NANOSECONDS);
LOG.trace("Sleep time: {}", System.nanoTime() - sleepNanosStart);
// Increment wait group count for new request handler
waitGroup.add();
final long curWaitNanos = waitNanos;
final long curWarmupRequests = warmupRequests;
final long curOverageNanos = overageNanos;
final SuspendableCallable<Void> sc = () -> {
try {
final RequestExecOutcome<Res> outcome = executeRequest(request, executor);
if (curWarmupRequests <= 0) {
report(curWaitNanos, curOverageNanos, outcome, eventChannel);
}
} finally {
// Complete, decrementing wait group count
waitGroup.done();
}
return null;
};
if (fiberScheduler != null) {
new Fiber<>(fiberScheduler, sc).start();
} else if (strandFactory != null) {
strandFactory.newStrand(sc).start();
} else {
new Fiber<>(sc).start();
}
final long nowNanos = System.nanoTime();
overageNanos += nowNanos - overageStart - waitNanos;
overageStart = nowNanos;
warmupRequests = Math.max(warmupRequests - 1, 0);
}
// Wait for all outstanding requests
waitGroup.await();
} finally {
eventChannel.close();
}
}
开发者ID:pinterest,项目名称:jbender,代码行数:75,代码来源:JBender.java
示例5: loadTestConcurrency
import co.paralleluniverse.fibers.FiberScheduler; //导入依赖的package包/类
private static <Req, Res> void loadTestConcurrency(final int concurrency,
int warmupRequests,
final ReceivePort<Req> requests,
final RequestExecutor<Req, Res> executor,
final SendPort<TimingEvent<Res>> eventChannel,
final FiberScheduler fiberScheduler,
final StrandFactory strandFactory)
throws SuspendExecution, InterruptedException
{
try {
final WaitGroup waitGroup = new WaitGroup();
final Semaphore running = new Semaphore(concurrency);
while (true) {
final Req request = requests.receive();
if (request == null) {
break;
}
running.acquire();
waitGroup.add();
final long curWarmupRequests = warmupRequests;
final SuspendableCallable<Void> sc = () -> {
try {
final RequestExecOutcome<Res> outcome = executeRequest(request, executor);
if (curWarmupRequests <= 0) {
report(0, 0, outcome, eventChannel);
}
} finally {
running.release();
waitGroup.done();
}
return null;
};
if (fiberScheduler != null) {
new Fiber<>(fiberScheduler, sc).start();
} else if (strandFactory != null) {
strandFactory.newStrand(sc).start();
} else {
new Fiber<>(sc).start();
}
warmupRequests = Math.max(warmupRequests - 1, 0);
}
waitGroup.await();
} finally {
eventChannel.close();
}
}
开发者ID:pinterest,项目名称:jbender,代码行数:51,代码来源:JBender.java
示例6: Actor
import co.paralleluniverse.fibers.FiberScheduler; //导入依赖的package包/类
/**
* 创建基于纤程的Actor
* @param axs
* @param aid
*/
public Actor(ActorSystem axs, ActorId aid, FiberScheduler fibSche){
this.axs = axs;
this.selfAid = aid;
this.fibSche = fibSche;
}
开发者ID:nousxiong,项目名称:actorx4j,代码行数:11,代码来源:Actor.java
示例7: getFiberScheduler
import co.paralleluniverse.fibers.FiberScheduler; //导入依赖的package包/类
/**
* 返回纤程调度器,如果使用纤程创建的Actor,则返回不为空
* @return
*/
public FiberScheduler getFiberScheduler() {
return fibSche;
}
开发者ID:nousxiong,项目名称:actorx4j,代码行数:8,代码来源:Actor.java
示例8: scheduler
import co.paralleluniverse.fibers.FiberScheduler; //导入依赖的package包/类
/**
* Returns the The default {@link FiberScheduler} scheduler.
*
* @return the default {@link FiberScheduler} scheduler.
*/
public static FiberScheduler scheduler() {
return scheduler;
}
开发者ID:icode,项目名称:ameba-container-grizzly,代码行数:9,代码来源:HttpFiber.java
注:本文中的co.paralleluniverse.fibers.FiberScheduler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论