// create java thread pool. ExecutorService pool = Executors.newCachedThreadPool(); //initialize factory with backing pool PoolFiberFactory fiberFactory = new PoolFiberFactory(pool); Fiber fiber = fiberFactory.create(); fiber.start(); //use fiber for normal publishing and subscribing.
/** * Starts the execution of this fiber asynchronously. * <p/> * <p/> * This method works like {@link Thread#start()}. * * @param tubeline The first tube of the tubeline that will act on the packet. * @param request The request packet to be passed to {@code startPoint.processRequest()}. * @param completionCallback The callback to be invoked when the processing is finished and the * final response packet is available. * @see #runSync(Tube, Packet) */ public void start(@NotNull Tube tubeline, @NotNull Packet request, @Nullable CompletionCallback completionCallback) { start(tubeline, request, completionCallback, false); }
/** * Starts the execution of this fiber asynchronously. * <p/> * <p/> * This method works like {@link Thread#start()}. * * @param tubeline The first tube of the tubeline that will act on the packet. * @param request The request packet to be passed to {@code startPoint.processRequest()}. * @param completionCallback The callback to be invoked when the processing is finished and the * final response packet is available. * @see #runSync(Tube, Packet) */ public void start(@NotNull Tube tubeline, @NotNull Packet request, @Nullable CompletionCallback completionCallback) { start(tubeline, request, completionCallback, false); }
/** * Starts the execution of this fiber asynchronously. * <p/> * <p/> * This method works like {@link Thread#start()}. * * @param tubeline The first tube of the tubeline that will act on the packet. * @param request The request packet to be passed to {@code startPoint.processRequest()}. * @param completionCallback The callback to be invoked when the processing is finished and the * final response packet is available. * @see #runSync(Tube, Packet) */ public void start(@NotNull Tube tubeline, @NotNull Packet request, @Nullable CompletionCallback completionCallback) { start(tubeline, request, completionCallback, false); }
@Test public void simpleRequestResponse() throws InterruptedException { Fiber req = new ThreadFiber(); Fiber reply = new ThreadFiber(); req.start(); reply.start(); RequestChannel<String, Integer> channel = new MemoryRequestChannel<String, Integer>(); Callback<Request<String, Integer>> onReq = new Callback<Request<String, Integer>>() { public void onMessage(Request<String, Integer> message) { assertEquals("hello", message.getRequest()); message.reply(1); } }; channel.subscribe(reply, onReq); final CountDownLatch done = new CountDownLatch(1); Callback<Integer> onReply = new Callback<Integer>() { public void onMessage(Integer message) { assertEquals(1, message.intValue()); done.countDown(); } }; AsyncRequest.withOneReply(req, channel, "hello", onReply); assertTrue(done.await(10, TimeUnit.SECONDS)); req.dispose(); reply.dispose(); }
((BindingImpl) binding).createCodec(), null, null)); Fiber fiber = endpoint.getEngine().createFiber(); fiber.start(transport, packet, fiberCallback);
((BindingImpl) binding).createCodec(), null, null)); Fiber fiber = endpoint.getEngine().createFiber(); fiber.start(transport, packet, fiberCallback);
((BindingImpl) binding).createCodec(), null, null)); Fiber fiber = endpoint.getEngine().createFiber(); fiber.start(transport, packet, fiberCallback);
fiber.start(tube, request, cbak, binding.isFeatureEnabled(SyncStartForAsyncFeature.class) || !schedule);
fiber.start(tube, request, cbak, binding.isFeatureEnabled(SyncStartForAsyncFeature.class) || !schedule);
fiber.start(tube, request, cbak, binding.isFeatureEnabled(SyncStartForAsyncFeature.class) || !schedule);
fiber.start(tube, request, fiberCallback, getBinding().isFeatureEnabled(SyncStartForAsyncFeature.class) && !requestContext.containsKey(PREVENT_SYNC_START_FOR_ASYNC_INVOKE));
fiber.start(tube, request, fiberCallback, getBinding().isFeatureEnabled(SyncStartForAsyncFeature.class) && !requestContext.containsKey(PREVENT_SYNC_START_FOR_ASYNC_INVOKE));
fiber.start(tube, request, fiberCallback, getBinding().isFeatureEnabled(SyncStartForAsyncFeature.class) && !requestContext.containsKey(PREVENT_SYNC_START_FOR_ASYNC_INVOKE));