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


Java Fiber.execute方法代码示例

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


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

示例1: 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

示例2: 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

示例3: ReplicatorInstance

import org.jetlang.fibers.Fiber; //导入方法依赖的package包/类
public ReplicatorInstance(final Fiber fiber,
                          final long myId,
                          final String quorumId,
                          ReplicatorLog log,
                          ReplicatorClock clock,
                          ReplicatorInfoPersistence persister,
                          RequestChannel<RpcRequest, RpcWireReply> sendRpcChannel,
                          final Channel<ReplicatorInstanceEvent> eventChannel,
                          final Channel<IndexCommitNotice> commitNoticeChannel,
                          State initialState) {
  this.fiber = fiber;
  this.myId = myId;
  this.quorumId = quorumId;
  this.logger = getNewLogger();
  this.sendRpcChannel = sendRpcChannel;
  this.log = log;
  this.clock = clock;
  this.persister = persister;
  this.eventChannel = eventChannel;
  this.commitNoticeChannel = commitNoticeChannel;
  this.myElectionTimeout = clock.electionTimeout();
  this.lastRPC = clock.currentTimeMillis();

  commitNoticeChannel.subscribe(
      new ChannelSubscription<>(fiber, this::onCommit,
          (notice) ->
              notice.nodeId == myId
                  && notice.quorumId.equals(quorumId)));

  incomingChannel.subscribe(fiber, this::onIncomingMessage);
  fiber.scheduleWithFixedDelay(this::checkOnElection, clock.electionCheckInterval(),
      clock.electionCheckInterval(), TimeUnit.MILLISECONDS);

  this.myState = initialState;

  fiber.execute(() -> {
    try {
      refreshQuorumConfigurationFromLog();

      readPersistentData();
      // indicate we are running!
      eventChannel.publish(
          new ReplicatorInstanceEvent(
              ReplicatorInstanceEvent.EventType.QUORUM_START,
              ReplicatorInstance.this,
              0,
              0,
              clock.currentTimeMillis(),
              null, null)
      );

      if (initialState == State.LEADER) {
        becomeLeader();
      }
    } catch (IOException e) {
      logger.error("error during persistent data init", e);
      failReplicatorInstance(e);
    }
  });
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:61,代码来源:ReplicatorInstance.java

示例4: 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


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