当前位置: 首页>>代码示例>>Java>>正文


Java Fiber.start方法代码示例

本文整理汇总了Java中org.jetlang.fibers.Fiber.start方法的典型用法代码示例。如果您正苦于以下问题:Java Fiber.start方法的具体用法?Java Fiber.start怎么用?Java Fiber.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jetlang.fibers.Fiber的用法示例。


在下文中一共展示了Fiber.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Service

import org.jetlang.fibers.Fiber; //导入方法依赖的package包/类
public Service(String name) {
	serviceName = name;
	Fiber fiber = Kernel.getInstance().getScheduler().newFiber();
	fiber.start();
	Callback<Packet> sysCtrlCallback = new Callback<Packet>() {
		public void onMessage(Packet pkt) {
			if(pkt instanceof ControlPacket){
				processSysCtrl((ControlPacket) pkt);
			}
		}
	};
	subscription = new Subscription(CoreChannel.SYSCTRL, fiber, sysCtrlCallback);
	
	try {
		Kernel.getInstance().getStream().subscribe(subscription);
	} catch (CommunicationException e) {
		System.err.println(e.getMessage());
	}
	
	taskRegistry = new FastMap<String, Taskable>();
}
 
开发者ID:drpjm,项目名称:pancakes,代码行数:22,代码来源:Service.java

示例2: Log4jService

import org.jetlang.fibers.Fiber; //导入方法依赖的package包/类
public Log4jService() {
	super(Log4jService.class.getSimpleName());
	PropertyConfigurator.configure(CFG_FILE);
	Fiber fiber = Kernel.getInstance().getScheduler().newFiber();
	fiber.start();
	Callback<Packet> callback = new Callback<Packet>() {
		public void onMessage(Packet packet) {
			LogPacket p = (LogPacket) packet;
			Logger.getLogger(p.getSource()).log(Level.toLevel(p.getLevel()), p.getMessage());
		}
	};
	
	subscription = new Subscription(CoreChannel.LOG, fiber, callback);
	
	try {
		Kernel.getInstance().getStream().subscribe(subscription);
	} catch (CommunicationException e) {
		e.printStackTrace();
	}
}
 
开发者ID:drpjm,项目名称:pancakes,代码行数:21,代码来源:Log4jService.java

示例3: TwitterService

import org.jetlang.fibers.Fiber; //导入方法依赖的package包/类
public TwitterService(Properties properties) {
	super(TwitterService.class.getSimpleName());
	tweeter = new Tweeter(properties);
	Fiber fiber = Kernel.getInstance().getScheduler().newFiber();
	fiber.start();
	
	Callback<Packet> callback = new Callback<Packet>() {
		public void onMessage(Packet pkt) {
			LogPacket l = (LogPacket) pkt;
			if(l.getSource().equals("twitter")) {
				tweeter.tweet(l.getMessage());
			}
		}
	};
	
	subscription = new Subscription(CoreChannel.LOG, fiber, callback);
	
	try {
		Kernel.getInstance().getStream().subscribe(subscription);
	} catch (CommunicationException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:drpjm,项目名称:pancakes,代码行数:25,代码来源:TwitterService.java

示例4: waitForReply

import org.jetlang.fibers.Fiber; //导入方法依赖的package包/类
public static <S, R> ChannelListener<S> waitForReply(RequestChannel<S, R> channel) {
  List<Throwable> throwables = new ArrayList<>();
  BatchExecutor exceptionHandlingBatchExecutor = new ExceptionHandlingBatchExecutor(throwables::add);
  RunnableExecutor runnableExecutor = new RunnableExecutorImpl(exceptionHandlingBatchExecutor);
  Fiber channelSubscriberFiber = new ThreadFiber(runnableExecutor, null, true);
  ArrayBlockingQueue<S> messages = new ArrayBlockingQueue<>(1);
  channel.subscribe(channelSubscriberFiber, m -> {
    try {
      messages.put(m.getRequest());
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    }
  });
  channelSubscriberFiber.start();
  return new ChannelListener<>(channelSubscriberFiber, messages, throwables);
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:17,代码来源:AsyncChannelAsserts.java

示例5: listenTo

import org.jetlang.fibers.Fiber; //导入方法依赖的package包/类
public static <T> ChannelListener<T> listenTo(Subscriber<T> channel) {
  List<Throwable> throwables = new ArrayList<>();
  BatchExecutor exceptionHandlingBatchExecutor = new ExceptionHandlingBatchExecutor(throwables::add);
  RunnableExecutor runnableExecutor = new RunnableExecutorImpl(exceptionHandlingBatchExecutor);
  Fiber channelSubscriberFiber = new ThreadFiber(runnableExecutor, null, true);
  ArrayBlockingQueue<T> messages = new ArrayBlockingQueue<>(1);
  channel.subscribe(channelSubscriberFiber, m -> {
    try {
      messages.put(m);
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    }
  });
  channelSubscriberFiber.start();
  return new ChannelListener<>(channelSubscriberFiber, messages, throwables);
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:17,代码来源:AsyncChannelAsserts.java

示例6: writeOutAsynchronously

import org.jetlang.fibers.Fiber; //导入方法依赖的package包/类
@Test
public void writeOutAsynchronously() throws ExecutionException, InterruptedException, TimeoutException {
  RegionSpecifier regionSpecifier = new RegionSpecifier(RegionSpecifier.RegionSpecifierType.REGION_NAME,
      ByteBuffer.wrap(Bytes.toBytes("c5:writeOutAsynchronously")));
  ByteBuffer cq = ByteBuffer.wrap(Bytes.toBytes("cq"));
  ByteBuffer cf = ByteBuffer.wrap(Bytes.toBytes("cf"));
  ByteBuffer value = ByteBuffer.wrap(new byte[512]);
  MutationProto.ColumnValue.QualifierValue qualifierValue = new MutationProto.ColumnValue.QualifierValue(cq,
      value,
      0l,
      null);

  SingleNodeTableInterface singleNodeTable = new SingleNodeTableInterface("localhost", getRegionServerPort());

  Fiber flusher = new ThreadFiber();
  flusher.start();
  flusher.scheduleAtFixedRate(singleNodeTable::flushHandler, 50, 50, MILLISECONDS);

  for (int i = 0; i != TO_SEND; i++) {
    sendProto(regionSpecifier, cf, Arrays.asList(qualifierValue), singleNodeTable, i);
  }
  System.out.println("buffered");
  countDownLatch.await();
}
 
开发者ID:cloud-software-foundation,项目名称:c5,代码行数:25,代码来源:ITAsyncWrite.java

示例7: scan

import org.jetlang.fibers.Fiber; //导入方法依赖的package包/类
private void scan(ChannelHandlerContext ctx, Call call) throws IOException,
    RegionNotFoundException {
  final ScanRequest scanIn = call.getScan();
  if (scanIn == null) {
    throw new IOException("Poorly specified scan. There is no actual get data in the RPC");
  }

  final long scannerId;
  scannerId = getScannerId(scanIn);
  final Integer numberOfRowsToSend = scanIn.getNumberOfRows();
  Channel<Integer> channel = scanManager.getChannel(scannerId);
  // New Scanner
  if (null == channel) {
    final Fiber fiber = new ThreadFiber();
    fiber.start();
    channel = new MemoryChannel<>();
    Region region = regionServerService.getOnlineRegion(call.getScan().getRegion());
    final ScanRunnable scanRunnable = new ScanRunnable(ctx, call, scannerId, region);
    channel.subscribe(fiber, scanRunnable);
    scanManager.addChannel(scannerId, channel);
  }
  channel.publish(numberOfRowsToSend);
}
 
开发者ID:cloud-software-foundation,项目名称:c5,代码行数:24,代码来源:RegionServerHandler.java

示例8: beforeClass

import org.jetlang.fibers.Fiber; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() throws Exception {
  if (dirty) {
    System.setProperty(C5ServerConstants.C5_CFG_PATH, ClusterOrPseudoCluster.testFolder.getRoot().getAbsolutePath());
    System.setProperty("clusterName", C5ServerConstants.LOCALHOST);

    server = Main.startC5Server(new String[]{});
    metaOnNode = server.getNodeId();
    TabletModule tabletServer = (TabletModule) server.getModule(ModuleType.Tablet).get();
    RegionServerModule regionServer = (RegionServerModule) server.getModule(ModuleType.RegionServer).get();
    stateChanges = tabletServer.getTabletStateChanges();

    Fiber receiver = new ThreadFiber(new RunnableExecutorImpl(), "cluster-receiver-static-fiber", false);
    receiver.start();

    // create java.util.concurrent.CountDownLatch to notify when message arrives
    final CountDownLatch latch = new CountDownLatch(1);
    Fiber fiber = new ThreadFiber(new RunnableExecutorImpl(), "cluster-tablet-state-change-fiber", false);
    fiber.start();
    tabletServer.getTabletStateChanges().subscribe(fiber, tabletStateChange -> {
      if (tabletStateChange.state.equals(Tablet.State.Leader)) {
        if (tabletStateChange.tablet.getRegionInfo().getRegionNameAsString().startsWith("hbase:meta")) {
          metaOnPort = regionServer.port();
          metaOnNode = server.getNodeId();

          latch.countDown();
          fiber.dispose();
        }
      }
    });

    latch.await();
    receiver.dispose();
  }
  dirty = false;
}
 
开发者ID:cloud-software-foundation,项目名称:c5,代码行数:37,代码来源:ClusterOrPseudoCluster.java

示例9: before

import org.jetlang.fibers.Fiber; //导入方法依赖的package包/类
@Before
public void before() throws InterruptedException, ExecutionException, TimeoutException {
  Fiber receiver = new ThreadFiber(new RunnableExecutorImpl(), "cluster-receiver-fiber", false);
  receiver.start();

  final CountDownLatch latch = new CountDownLatch(1);
  Callback<TabletStateChange> onMsg = message -> {
    if (message.state.equals(Tablet.State.Leader)) {
      latch.countDown();
    }
  };
  stateChanges.subscribe(receiver, onMsg);

  TableName clientTableName = TabletNameHelpers.getClientTableName("c5", name.getMethodName());
  org.apache.hadoop.hbase.TableName tableName = TabletNameHelpers.getHBaseTableName(clientTableName);
  Channel<CommandRpcRequest<?>> commandChannel = server.getCommandChannel();

  ModuleSubCommand createTableSubCommand = new ModuleSubCommand(ModuleType.Tablet,
      TestHelpers.getCreateTabletSubCommand(tableName, splitkeys, Arrays.asList(server)));
  CommandRpcRequest<ModuleSubCommand> createTableCommand = new CommandRpcRequest<>(server.getNodeId(),
      createTableSubCommand);

  commandChannel.publish(createTableCommand);
  latch.await();

  table = new FakeHTable(C5TestServerConstants.LOCALHOST, getRegionServerPort(),
      TabletNameHelpers.toByteString(clientTableName));
  row = Bytes.toBytes(name.getMethodName());
  receiver.dispose();
}
 
开发者ID:cloud-software-foundation,项目名称:c5,代码行数:31,代码来源:ClusterOrPseudoCluster.java

示例10: requestFox

import org.jetlang.fibers.Fiber; //导入方法依赖的package包/类
protected String requestFox(final Map<String, String> parameter) {
  String output = "";
  // get a fox instance
  IFox fox = Server.pool.get(parameter.get(FoxParameter.Parameter.LANG.toString())).poll();

  // init. thread
  final Fiber fiber = new ThreadFiber();
  fiber.start();
  final CountDownLatch latch = new CountDownLatch(1);

  // set up fox
  fox.setCountDownLatch(latch);
  fox.setParameter(parameter);

  // run fox
  fiber.execute(fox);

  // wait 5min or till the fox instance is finished
  try {
    latch.await(Integer.parseInt(FoxCfg.get(FoxHttpHandler.CFG_KEY_FOX_LIFETIME)),
        TimeUnit.MINUTES);
  } catch (final InterruptedException e) {
    LOG.error("Fox timeout after " + FoxCfg.get(FoxHttpHandler.CFG_KEY_FOX_LIFETIME) + "min.");
    LOG.error("\n", e);
    LOG.error("input: " + parameter.get(FoxParameter.Parameter.INPUT.toString()));
  }

  // shutdown thread
  fiber.dispose();

  if (latch.getCount() == 0) {
    output = fox.getResultsAndClean();
    Server.pool.get(parameter.get(FoxParameter.Parameter.LANG.toString())).push(fox);
  } else {
    fox = null;
    Server.pool.get(parameter.get(FoxParameter.Parameter.LANG.toString())).add();
  }
  return output;
}
 
开发者ID:dice-group,项目名称:FOX,代码行数:40,代码来源:ApiResource.java

示例11: callFox

import org.jetlang.fibers.Fiber; //导入方法依赖的package包/类
protected boolean callFox(final IFox fox, final Map<String, String> parameter) {
  boolean done = false;

  if (fox != null) {
    LOG.info("start");

    // init. thread
    final Fiber fiber = new ThreadFiber();
    fiber.start();
    final CountDownLatch latch = new CountDownLatch(1);
    fox.setCountDownLatch(latch);
    fox.setParameter(parameter);
    fiber.execute(fox);

    // wait
    try {

      latch.await(CFG.getInt(CFG_KEY_FOX_LIFETIME), TimeUnit.MINUTES);
    } catch (final InterruptedException e) {
      LOG.error("Fox timeout after " + CFG.getInt(CFG_KEY_FOX_LIFETIME) + "min.");
      LOG.error("\n", e);
      LOG.error("input: " + parameter.get(FoxParameter.Parameter.INPUT.toString()));
    }

    // shutdown thread
    fiber.dispose();

    if (latch.getCount() == 0) {
      done = true;
    }
  }
  return done;
}
 
开发者ID:dice-group,项目名称:FOX,代码行数:34,代码来源:FoxServer.java

示例12: startFiber

import org.jetlang.fibers.Fiber; //导入方法依赖的package包/类
private Fiber startFiber() {
    Fiber fiber = fiberFactory.create();
    fiber.start();
    return fiber;
}
 
开发者ID:mySingleLive,项目名称:jato,代码行数:6,代码来源:JATOActorFactory.java

示例13: createAndStartFiber

import org.jetlang.fibers.Fiber; //导入方法依赖的package包/类
private Fiber createAndStartFiber(Consumer<Throwable> throwableConsumer) {
  Fiber newFiber = fiberSupplier.getNewFiber(throwableConsumer);
  fiber.execute(() -> disposables.add(newFiber));
  newFiber.start();
  return newFiber;
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:7,代码来源:C5GeneralizedReplicationService.java

示例14: setURIs

import org.jetlang.fibers.Fiber; //导入方法依赖的package包/类
protected void setURIs(Set<Entity> entities) {
  if ((entities != null) && !entities.isEmpty()) {
    infoLog("Start NE linking ...");

    final CountDownLatch latch = new CountDownLatch(1);
    final ToolsGenerator toolsGenerator = new ToolsGenerator();
    if (linking == null) {
      try {
        linking = toolsGenerator.getDisambiguationTool(lang);
      } catch (UnsupportedLangException | LoadingNotPossibleException e1) {
        infoLog(e1.getLocalizedMessage());
        linking = new NoLinking();
      }
    }
    linking.setCountDownLatch(latch);
    linking.setInput(entities, parameter.get(FoxParameter.Parameter.INPUT.toString()));

    final Fiber fiber = new ThreadFiber();
    fiber.start();
    fiber.execute(linking);

    // use another time for the uri lookup?
    final int min = Integer.parseInt(FoxCfg.get(Tools.CFG_KEY_LIFETIME));
    try {
      latch.await(min, TimeUnit.MINUTES);
    } catch (final InterruptedException e) {
      LOG.error("Timeout after " + min + "min.");
      LOG.error("\n", e);
    }

    // shutdown threads
    fiber.dispose();
    // get results
    if (latch.getCount() == 0) {
      entities = new HashSet<Entity>(linking.getResults());
    } else {
      infoLog("Timeout after " + min + " min (" + linking.getClass().getName() + ").");
      // use dev lookup after timeout
      new NoLinking().setUris(entities, parameter.get(FoxParameter.Parameter.INPUT.toString()));
    }
    linking = null;
  }
  infoLog("Start NE linking done.");
}
 
开发者ID:dice-group,项目名称:FOX,代码行数:45,代码来源:Fox.java

示例15: configure

import org.jetlang.fibers.Fiber; //导入方法依赖的package包/类
@Override
protected void configure() {
  install(new StateModule(timeout));

  PoolFiberFactory fiberFactory = new PoolFiberFactory(executor);

  Fiber raftFiber = fiberFactory.create(new BatchExecutor());
  raftFiber.start();
  bind(Fiber.class).annotatedWith(RaftExecutor.class).toInstance(raftFiber);

  Fiber stateMachineFiber = fiberFactory.create(new BatchExecutor());
  stateMachineFiber.start();

  install(new LogModule(logDir, stateMachine, stateMachineFiber));

  bind(ClusterConfig.class).toInstance(config);

  bind(Client.class).asEagerSingleton();

  expose(Raft.class);
  expose(ClusterConfig.class);
}
 
开发者ID:mgodave,项目名称:barge,代码行数:23,代码来源:RaftCoreModule.java


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