本文整理汇总了Java中co.paralleluniverse.fibers.Fiber类的典型用法代码示例。如果您正苦于以下问题:Java Fiber类的具体用法?Java Fiber怎么用?Java Fiber使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Fiber类属于co.paralleluniverse.fibers包,在下文中一共展示了Fiber类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: submit
import co.paralleluniverse.fibers.Fiber; //导入依赖的package包/类
@Suspendable
public Future<T> submit(Callable<T> callable) {
return new Fiber<T>() {
@Override
protected T run() throws SuspendExecution, InterruptedException {
try {
return callable.call();
} catch (Exception e) {
e.printStackTrace();
} finally {
channel.send(this);
}
return null;
}
}.start();
}
开发者ID:pmohankumar,项目名称:fibers,代码行数:17,代码来源:FiberCompletionService.java
示例2: main
import co.paralleluniverse.fibers.Fiber; //导入依赖的package包/类
/**
* In current state - no where near as good performance as vertx, but syntax is better
*/
public static void main(String[] args) throws Exception {
int count = 9999;
CountDownLatch done = new CountDownLatch(count);
Stopwatch stopwatch = Stopwatch.createStarted();
IntStream.range(0,count).forEach(i ->
new Fiber((SuspendableRunnable) () -> {
try (CloseableHttpResponse response = client.execute(new HttpGet(url))){
response.getStatusLine().getStatusCode();
} catch (Exception e) {
e.printStackTrace();
} finally {
done.countDown();
}
}).start()
);
done.await(15, TimeUnit.SECONDS);
TaskRunner.print(
new TaskRunner.Result(stopwatch.elapsed(TimeUnit.MILLISECONDS), Runtime.getRuntime().totalMemory()),
done.getCount(),
FiberHttpRequest.class.getSimpleName());
}
开发者ID:ChristinGorman,项目名称:javazone2016,代码行数:27,代码来源:FiberHttpRequest.java
示例3: record
import co.paralleluniverse.fibers.Fiber; //导入依赖的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
示例4: main
import co.paralleluniverse.fibers.Fiber; //导入依赖的package包/类
public static void main(String[] args) throws SuspendExecution, InterruptedException {
final IntervalGenerator intervalGen = new ConstantIntervalGenerator(10000000);
final RequestExecutor<EchoRequest, EchoResponse> requestExector = new EchoRequestExecutor();
final Channel<EchoRequest> requestCh = Channels.newChannel(-1);
final Channel<TimingEvent<EchoResponse>> eventCh = Channels.newChannel(-1);
// Requests generator
new Fiber<Void>("req-gen", () -> {
for (int i=0; i < 1000; ++i) {
final EchoRequest req = new EchoRequest();
req.setMessage("foo");
requestCh.send(req);
}
requestCh.close();
}).start();
final Histogram histogram = new Histogram(3600000000L, 3);
// Event recording, both HistHDR and logging
record(eventCh, new HdrHistogramRecorder(histogram, 1000000), new LoggingRecorder(LOG));
JBender.loadTestThroughput(intervalGen, 0, requestCh, requestExector, eventCh);
histogram.outputPercentileDistribution(System.out, 1000.0);
}
开发者ID:pinterest,项目名称:jbender,代码行数:27,代码来源:Main.java
示例5: spawn
import co.paralleluniverse.fibers.Fiber; //导入依赖的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
示例6: reset
import co.paralleluniverse.fibers.Fiber; //导入依赖的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
示例7: testQuasar
import co.paralleluniverse.fibers.Fiber; //导入依赖的package包/类
@Test
public void testQuasar() throws ExecutionException, InterruptedException {
AsyncApi async = new AsyncApiImpl();
SyncApi sync = new SyncApiImpl(async);
new Fiber<Void>(() -> {
int a = new Random().nextInt(1000);
System.out.println("a is " + a);
int b = new Random().nextInt(1000);
System.out.println("b is " + b);
System.out.println(a + " + " + b + " = " + sync.sum(a, b));
}).start().join();
}
开发者ID:ufoscout,项目名称:jporm,代码行数:17,代码来源:QuasarTest.java
示例8: testDefaultSleep
import co.paralleluniverse.fibers.Fiber; //导入依赖的package包/类
@Test
public void testDefaultSleep() throws Exception {
final Script script = createScript("sleep(1000);", new HashMap<String, Object>());
final AtomicInteger counter = new AtomicInteger(0);
Fiber fiber = new Fiber(scheduler, new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
counter.incrementAndGet();
script.run();
counter.incrementAndGet();
}
});
fiber.start();
fiber.join();
Assert.assertEquals(counter.intValue(), 2);
}
开发者ID:dinix2008,项目名称:quasar-groovy,代码行数:17,代码来源:FiberTest.java
示例9: testClosuresSleep
import co.paralleluniverse.fibers.Fiber; //导入依赖的package包/类
@Test
public void testClosuresSleep() throws Exception {
final SleepMethodSupport sleepMethodSupport = new SleepMethodSupport();
HashMap<String, Object> args = new HashMap<String, Object>() {
{
put("sleepMethodSupport", sleepMethodSupport);
put("_sleep", new MethodClosure(sleepMethodSupport, "_sleep"));
}
};
final Script script = createScript("sleep(1000);_sleep(1000);sleepMethodSupport._sleep(1000)", args);
final AtomicInteger counter = new AtomicInteger(0);
Fiber fiber = new Fiber(scheduler, new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
counter.incrementAndGet();
script.run();
counter.incrementAndGet();
}
});
fiber.start();
fiber.join();
Assert.assertEquals(counter.intValue(), 2);
}
开发者ID:dinix2008,项目名称:quasar-groovy,代码行数:24,代码来源:FiberTest.java
示例10: testInFiber
import co.paralleluniverse.fibers.Fiber; //导入依赖的package包/类
private static void testInFiber() throws ExecutionException, InterruptedException {
final HystrixFiber hystrixFiber = new HystrixFiber();
// System.out.println(hystrixFiber.execute());
Fiber fiber = new Fiber<String>() {
@Override
@Suspendable
protected String run() throws SuspendExecution, InterruptedException {
System.out.println(Thread.currentThread().getName());
return hystrixFiber.execute();
}
}.start();
System.out.println(fiber.get());
}
开发者ID:pmohankumar,项目名称:fibers,代码行数:14,代码来源:HystrixFiberTest.java
示例11: execute
import co.paralleluniverse.fibers.Fiber; //导入依赖的package包/类
@Override
@Suspendable
public void execute(Runnable command) {
new Fiber<Void>() {
@Override
protected Void run() throws SuspendExecution, InterruptedException {
command.run();
return null;
}
}.start();
}
开发者ID:pmohankumar,项目名称:fibers,代码行数:12,代码来源:FiberThreadPoolExecutor.java
示例12: getFiber
import co.paralleluniverse.fibers.Fiber; //导入依赖的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
示例13: startFiber
import co.paralleluniverse.fibers.Fiber; //导入依赖的package包/类
private static void startFiber(FiberCompletionService completionService, String message, long sleep) {
new Fiber<Void>() {
@Override
protected Void run() throws SuspendExecution, InterruptedException {
completionService.submit(new FiberCallable(message, sleep));
return null;
}
}.start();
}
开发者ID:pmohankumar,项目名称:fibers,代码行数:10,代码来源:FiberCompletionServiceTest.java
示例14: fiberSleep
import co.paralleluniverse.fibers.Fiber; //导入依赖的package包/类
@Suspendable
public static Long fiberSleep() {
try {
Fiber.sleep(1000);
return 1000l;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
开发者ID:ChristinGorman,项目名称:javazone2016,代码行数:10,代码来源:Sleeper.java
示例15: main
import co.paralleluniverse.fibers.Fiber; //导入依赖的package包/类
/**
* Simple syntax, but no performance gain
*/
public static void main(String[] args) throws Exception {
TaskRunner taskRunner = new TaskRunner(1000);
taskRunner.runTask(() -> new Fiber((SuspendableRunnable) () -> {
Big.task();
taskRunner.countDown();
}).start());
}
开发者ID:ChristinGorman,项目名称:javazone2016,代码行数:12,代码来源:CpuBlockingFibers.java
示例16: loadtestThroughput
import co.paralleluniverse.fibers.Fiber; //导入依赖的package包/类
public Histogram loadtestThroughput() throws SuspendExecution, InterruptedException, ExecutionException {
final IntervalGenerator intervalGenerator = new ConstantIntervalGenerator(1000);
final RequestExecutor<String, Void> requestExecutor = new NoopRequestExecutor<>();
final Channel<String> requestCh = Channels.newChannel(10000);
final Channel<TimingEvent<Void>> eventCh = Channels.newChannel(10000);
// Requests generator
new Fiber<Void>("req-gen", () -> {
// Bench handling 10k reqs
for (int i = 0; i < 10000; ++i) {
requestCh.send("message");
}
requestCh.close();
}).start();
final Histogram histogram = new Histogram(3600000000L, 3);
// Event recording, both HistHDR and logging
record(eventCh, new HdrHistogramRecorder(histogram, 1000000));
// Main
new Fiber<Void>("jbender", () -> {
JBender.loadTestThroughput(intervalGenerator, 0, requestCh, requestExecutor, eventCh);
eventCh.close();
}).start().join();
// Avoid code elimination
return histogram;
}
开发者ID:pinterest,项目名称:jbender,代码行数:32,代码来源:JBenderBenchmark.java
示例17: requests
import co.paralleluniverse.fibers.Fiber; //导入依赖的package包/类
private void requests(Channel<Integer> requestCh, int count) {
new Fiber<Void>(() -> {
for (int i = 0; i < count; ++i) {
requestCh.send(i);
}
requestCh.close();
}).start();
}
开发者ID:pinterest,项目名称:jbender,代码行数:9,代码来源:JBenderTest.java
示例18: main
import co.paralleluniverse.fibers.Fiber; //导入依赖的package包/类
public static void main(final String[] args) throws SuspendExecution, InterruptedException, ExecutionException, IOReactorException, IOException {
final IntervalGenerator intervalGenerator = new ConstantIntervalGenerator(10000000);
try (final FiberApacheHttpClientRequestExecutor requestExecutor =
new FiberApacheHttpClientRequestExecutor<>((res) -> {
if (res == null) {
throw new AssertionError("Response is null");
}
final int status = res.getStatusLine().getStatusCode();
if (status != 200) {
throw new AssertionError("Status is " + status);
}
}, 1000000)) {
final Channel<HttpGet> requestCh = Channels.newChannel(1000);
final Channel<TimingEvent<CloseableHttpResponse>> eventCh = Channels.newChannel(1000);
// Requests generator
new Fiber<Void>("req-gen", () -> {
// Bench handling 1k reqs
for (int i = 0; i < 1000; ++i) {
requestCh.send(new HttpGet("http://localhost:8080/hello-world"));
}
requestCh.close();
}).start();
final Histogram histogram = new Histogram(3600000000L, 3);
// Event recording, both HistHDR and logging
record(eventCh, new HdrHistogramRecorder(histogram, 1000000), new LoggingRecorder(LOG));
// Main
new Fiber<Void>("jbender", () -> {
JBender.loadTestThroughput(intervalGenerator, 0, requestCh, requestExecutor, eventCh);
}).start().join();
histogram.outputPercentileDistribution(System.out, 1000.0);
}
}
开发者ID:pinterest,项目名称:jbender,代码行数:40,代码来源:LoadTest.java
示例19: fountainFibers
import co.paralleluniverse.fibers.Fiber; //导入依赖的package包/类
public void fountainFibers() {
List<Fiber<Void>> fibers = new ArrayList<>();
for (int count = 0; count < SERVER_COUNT; count++) {
fibers.add(new Fiber<Void>(serverRunnableFiber(BYTE_COUNT_LIMIT, NUM_CLIENTS)).start());
}
fibers.forEach((f)->{
try {
f.join();
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
});
}
开发者ID:arienkock,项目名称:parallelism-benchmarks,代码行数:14,代码来源:FountainSocketBenchmark.java
示例20: startClientsFiber
import co.paralleluniverse.fibers.Fiber; //导入依赖的package包/类
public List<Fiber<Void>> startClientsFiber(SocketAddress localAddress, int numClients) {
List<Fiber<Void>> fibers = new ArrayList<Fiber<Void>>();
for (int count = 0; count < numClients; count++) {
fibers.add(new Fiber<Void>(clientRunnableFiber(localAddress)).start());
}
return fibers;
}
开发者ID:arienkock,项目名称:parallelism-benchmarks,代码行数:8,代码来源:FountainSocketBenchmark.java
注:本文中的co.paralleluniverse.fibers.Fiber类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论