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


Java Fiber类代码示例

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


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


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