• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Fiber类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: HomeWorker

import org.jetlang.fibers.Fiber; //导入依赖的package包/类
public HomeWorker(Fiber fiberThread, int mapId, int homeId, long ownerId) {
    this.fiberThread = fiberThread;
    this.mapId = mapId;
    this.homeId = homeId;
    this.ownerUid = ownerId;

    //回调方法
    Callback<List<NMessage>> callback = new HomeWorkerCallback(this);

    //像消息通道注册消息处理观察者
    BatchSubscriber<NMessage> batchSubscriber = new BatchSubscriber<NMessage>(this.fiberThread, callback, 10, TimeUnit.MILLISECONDS);
    this.messageChannel.subscribe(this.fiberThread, batchSubscriber);

    //改变房间状态为玩家准备中
    this.status = HomeStatusEnum.PLAYER_READY_DOING;
}
 
开发者ID:ninelook,项目名称:wecard-server,代码行数:17,代码来源:HomeWorker.java


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


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


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


示例5: whenTheReplicatorIsInState

import org.jetlang.fibers.Fiber; //导入依赖的package包/类
private void whenTheReplicatorIsInState(Replicator.State state) throws Exception {
  final Fiber replicatorFiber = new ThreadFiber(new RunnableExecutorImpl(batchExecutor),
      "replicatorFiber-Thread", true);

  replicatorInstance = new ReplicatorInstance(replicatorFiber,
      MY_ID,
      QUORUM_ID,
      log,
      clock,
      persistence,
      sendRpcChannel,
      eventChannel,
      commitNotices,
      state);

  sendRpcChannel.subscribe(rpcFiber, (request) -> {
    if (request.getRequest().to == MY_ID) {
      handleLoopBack(request);
    }
  });

  replicatorInstance.start();
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:24,代码来源:ReplicatorElectionTest.java


示例6: addCallback

import org.jetlang.fibers.Fiber; //导入依赖的package包/类
public static <V> void addCallback(@NotNull ListenableFuture<V> future,
                                   @NotNull Consumer<? super V> success,
                                   @NotNull Consumer<Throwable> failure,
                                   @NotNull Fiber fiber) {
  Runnable callbackListener = () -> {
    final V value;
    try {
      value = getUninterruptibly(future);
    } catch (ExecutionException | RuntimeException | Error e) {
      failure.accept(e);
      return;
    }
    success.accept(value);
  };
  future.addListener(callbackListener, fiber);
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:17,代码来源:C5Futures.java


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


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


示例9: SingleReplicatorController

import org.jetlang.fibers.Fiber; //导入依赖的package包/类
public SingleReplicatorController(int port,
                                  long nodeId,
                                  Collection<Long> peerIds,
                                  Path baseTestPath,
                                  Fiber testFiber,
                                  FiberSupplier fiberSupplier,
                                  Consumer<Throwable> exceptionHandler,
                                  EventLoopGroup bossGroup,
                                  EventLoopGroup workerGroup) throws Exception {

  moduleInfo = new SimpleModuleInformationProvider(testFiber, exceptionHandler);

  replicationModule =
      new ReplicatorService(bossGroup, workerGroup, nodeId, port, moduleInfo, fiberSupplier,
          new NioQuorumFileReaderWriter(baseTestPath));
  logModule = new LogService(baseTestPath, fiberSupplier);
  nodeInfoModule = new BeaconService(nodeId, DISCOVERY_PORT, workerGroup, moduleInfo, fiberSupplier);

  startAll();

  service = new C5GeneralizedReplicationService(replicationModule, logModule, fiberSupplier);
  replicator = service.createReplicator(QUORUM_ID, peerIds).get();
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:24,代码来源:C5GeneralizedReplicationServiceTest.java


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


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


示例12: JetlangPonger

import org.jetlang.fibers.Fiber; //导入依赖的package包/类
/** Creates a JetlangPonger. */
public JetlangPonger(final Fiber _fiber) {
    fiber = _fiber;
    channel = new MemoryRequestChannel();
    final Callback<Request> onReq = new Callback<Request>() {
        @Override
        public void onMessage(final Request message) {
            final Object request = message.getRequest();
            if (request instanceof PingRequest) {
                final PingRequest ping = (PingRequest) request;
                message.reply(ping.processRequest(JetlangPonger.this));
            } else {
                throw new IllegalStateException(
                        "Expected PingRequest but got "
                                + request.getClass());
            }
        }
    };
    fiber.start();
    channel.subscribe(fiber, onReq);
}
 
开发者ID:skunkiferous,项目名称:PingPong,代码行数:22,代码来源:JetlangPonger.java


示例13: JATOInstanceActor

import org.jetlang.fibers.Fiber; //导入依赖的package包/类
public JATOInstanceActor(JATOActorFactory actorFactory, T instance, Channel<MethodMessage> mailbox, Fiber fiber) {
    super(actorFactory, mailbox, fiber);
    this.instance = instance;
    this.clazz = (Class<T>) instance.getClass();
    methodAccess = MethodAccess.get(clazz);
    methodNameMap = buildMethodNameMap(methodAccess);
}
 
开发者ID:mySingleLive,项目名称:jato,代码行数:8,代码来源:JATOInstanceActor.java


示例14: JATOAbstractActor

import org.jetlang.fibers.Fiber; //导入依赖的package包/类
public JATOAbstractActor(JATOActorFactory actorFactory, Channel<T> mailbox, Fiber fiber) {
    this.actorFactory = actorFactory;
    this.mailbox = mailbox;
    this.fiber = fiber;
    final JATOAbstractActor<T> self = this;
    this.callback = new Callback<T>() {
        public void onMessage(T t) {
            getActorFactory().addInstanceActorToCache(self, self);
            self.onReceive(t);
        }
    };
    mailbox.subscribe(fiber, callback);
}
 
开发者ID:mySingleLive,项目名称:jato,代码行数:14,代码来源:JATOAbstractActor.java


示例15: startCallbackActor

import org.jetlang.fibers.Fiber; //导入依赖的package包/类
public <T> JATOCallbackActor<T> startCallbackActor(Callback<T> callback) {
    Fiber fiber = startFiber();
    Channel<T> mailbox = new MemoryChannel<T>();
    JATOCallbackActor<T> actor = new JATOCallbackActor<T>(this, mailbox, fiber, callback);
    return actor;

}
 
开发者ID:mySingleLive,项目名称:jato,代码行数:8,代码来源:JATOActorFactory.java


示例16: createReplicatorWithLog

import org.jetlang.fibers.Fiber; //导入依赖的package包/类
private Replicator createReplicatorWithLog(ReplicatorLog log, String quorumId, Collection<Long> peers) {
  if (replicatorInstances.containsKey(quorumId)) {
    LOG.debug("Replicator for quorum {} exists already", quorumId);
    return replicatorInstances.get(quorumId);
  }

  if (!peers.contains(nodeId)) {
    LOG.warn("Creating a replicator instance for quorum {} peers {} but it does not contain me ({})",
        quorumId, peers, nodeId);
  }

  LOG.info("Creating replicator instance for {} peers {}", quorumId, peers);

  MemoryChannel<Throwable> throwableChannel = new MemoryChannel<>();
  Fiber instanceFiber = fiberSupplier.getNewFiber(throwableChannel::publish);
  ReplicatorInstance instance =
      new ReplicatorInstance(
          instanceFiber,
          nodeId,
          quorumId,
          log,
          new DefaultSystemTimeReplicatorClock(),
          persister,
          outgoingRequests,
          replicatorEventChannel,
          indexCommitNotices,
          Replicator.State.FOLLOWER
      );
  if (log.getLastIndex() == 0) {
    instance.bootstrapQuorum(peers);
  }
  throwableChannel.subscribe(fiber, instance::failReplicatorInstance);
  replicatorInstances.put(quorumId, instance);
  instance.start();
  return instance;
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:37,代码来源:ReplicatorService.java


示例17: C5GeneralizedReplicator

import org.jetlang.fibers.Fiber; //导入依赖的package包/类
/**
 * Both the fiber and replicator must be started by the user of this class, and the
 * user takes responsibility for their disposal.
 */
public C5GeneralizedReplicator(Replicator replicator, Fiber fiber) {
  this.nodeId = replicator.getId();
  this.replicator = replicator;
  this.fiber = fiber;

  setupCommitNoticeSubscription();
  setupEventNoticeSubscription();
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:13,代码来源:C5GeneralizedReplicator.java


示例18: createLeaderAndSetupFibersAndChannels

import org.jetlang.fibers.Fiber; //导入依赖的package包/类
@Before
public final void createLeaderAndSetupFibersAndChannels() throws Exception {
  sendRpcChannel.subscribe(rpcFiber, (request) -> System.out.println(request.getRequest()));
  sendRpcChannel.subscribe(rpcFiber, this::routeOutboundRequests);
  sendRpcChannel.subscribe(rpcFiber, requestLog::publish);

  Fiber replicatorFiber = new ThreadFiber(new RunnableExecutorImpl(batchExecutor), "replicatorFiber-Thread", true);
  InRamSim.StoppableClock clock = new InRamSim.StoppableClock(0, 1000);
  clock.startTimeout();

  log.logEntries(
      Lists.newArrayList(
          new LogEntry(CURRENT_TERM, 1, new ArrayList<>(), QuorumConfiguration.of(PEER_ID_LIST).toProtostuff())));
  lastIndex = 1;

  ReplicatorInfoPersistence persister = new InRamSim.Persister();
  persister.writeCurrentTermAndVotedFor(QUORUM_ID, CURRENT_TERM, LEADER_ID);

  replicatorInstance = new ReplicatorInstance(replicatorFiber,
      LEADER_ID,
      QUORUM_ID,
      log,
      clock,
      new InRamSim.Persister(),
      sendRpcChannel,
      new MemoryChannel<>(),
      commitNotices,
      State.LEADER);
  replicatorInstance.start();
  rpcFiber.start();
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:32,代码来源:ReplicatorLeaderTest.java


示例19: QuorumOfReplicatorsController

import org.jetlang.fibers.Fiber; //导入依赖的package包/类
public QuorumOfReplicatorsController(Collection<Long> peerIds,
                                     Path baseTestPath,
                                     Fiber testFiber,
                                     FiberSupplier fiberSupplier,
                                     Consumer<Throwable> exceptionHandler) throws Exception {

  this.peerIds = peerIds;
  this.baseTestPath = baseTestPath;
  this.testFiber = testFiber;
  this.fiberSupplier = fiberSupplier;
  this.exceptionHandler = exceptionHandler;

  createControllersForEachPeerId();
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:15,代码来源:C5GeneralizedReplicationServiceTest.java


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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ToponymSearchCriteria类代码示例发布时间:2022-05-23
下一篇:
Java SequenceWriter类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap