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


Java Subscribers.create方法代码示例

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


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

示例1: start

import rx.observers.Subscribers; //导入方法依赖的package包/类
@Override
public void start() {
  onMemberAddedEventSubscriber = Subscribers.create(remoteMembers::add, this::onError);
  membership.listen().observeOn(scheduler)
      .filter(MembershipEvent::isAdded)
      .map(MembershipEvent::member)
      .subscribe(onMemberAddedEventSubscriber);

  onMemberRemovedEventSubscriber = Subscribers.create(remoteMembers::remove, this::onError);
  membership.listen().observeOn(scheduler)
      .filter(MembershipEvent::isRemoved)
      .map(MembershipEvent::member)
      .subscribe(onMemberRemovedEventSubscriber);

  onGossipRequestSubscriber = Subscribers.create(this::onGossipReq, this::onError);
  transport.listen().observeOn(scheduler)
      .filter(this::isGossipReq)
      .subscribe(onGossipRequestSubscriber);

  spreadGossipTask = executor.scheduleWithFixedDelay(this::doSpreadGossip,
      config.getGossipInterval(), config.getGossipInterval(), TimeUnit.MILLISECONDS);
}
 
开发者ID:scalecube,项目名称:scalecube,代码行数:23,代码来源:GossipProtocolImpl.java

示例2: testSendOrderSingleThreadWithoutPromises

import rx.observers.Subscribers; //导入方法依赖的package包/类
@Test
public void testSendOrderSingleThreadWithoutPromises() throws Exception {
  server = createTransport();

  int iterationNum = 11; // +1 warm up iteration
  int sentPerIteration = 1000;
  long[] iterationTimeSeries = new long[iterationNum - 1];
  for (int i = 0; i < iterationNum; i++) {
    LOGGER.info("####### {} : iteration = {}", testName.getMethodName(), i);

    client = createTransport();
    final List<Message> received = new ArrayList<>();
    final CountDownLatch latch = new CountDownLatch(sentPerIteration);

    Subscriber<Message> serverSubscriber = Subscribers.create(message -> {
      received.add(message);
      latch.countDown();
    });
    server.listen().subscribe(serverSubscriber);

    long startAt = System.currentTimeMillis();
    for (int j = 0; j < sentPerIteration; j++) {
      client.send(server.address(), Message.fromQualifier("q" + j));
    }
    latch.await(20, TimeUnit.SECONDS);
    long iterationTime = System.currentTimeMillis() - startAt;
    if (i > 0) { // exclude warm up iteration
      iterationTimeSeries[i - 1] = iterationTime;
    }
    assertSendOrder(sentPerIteration, received);

    LOGGER.info("Iteration time: {} ms", iterationTime);

    serverSubscriber.unsubscribe();
    destroyTransport(client);
  }

  LongSummaryStatistics iterationTimeStats = LongStream.of(iterationTimeSeries).summaryStatistics();
  LOGGER.info("Iteration time stats (ms): {}", iterationTimeStats);
}
 
开发者ID:scalecube,项目名称:scalecube,代码行数:41,代码来源:TransportSendOrderTest.java

示例3: start

import rx.observers.Subscribers; //导入方法依赖的package包/类
@Override
public void start() {
  onMemberAddedSubscriber = Subscribers.create(this::onMemberAdded, this::onError);
  membership.listen().observeOn(scheduler)
      .filter(MembershipEvent::isAdded)
      .map(MembershipEvent::member)
      .subscribe(onMemberAddedSubscriber);

  onMemberRemovedSubscriber = Subscribers.create(this::onMemberRemoved, this::onError);
  membership.listen().observeOn(scheduler)
      .filter(MembershipEvent::isRemoved)
      .map(MembershipEvent::member)
      .subscribe(onMemberRemovedSubscriber);

  onMemberUpdatedSubscriber = Subscribers.create(this::onMemberUpdated, this::onError);
  membership.listen().observeOn(scheduler)
      .filter(MembershipEvent::isUpdated)
      .subscribe(onMemberUpdatedSubscriber);

  onPingRequestSubscriber = Subscribers.create(this::onPing, this::onError);
  transport.listen().observeOn(scheduler)
      .filter(this::isPing)
      .subscribe(onPingRequestSubscriber);

  onAskToPingRequestSubscriber = Subscribers.create(this::onPingReq, this::onError);
  transport.listen().observeOn(scheduler)
      .filter(this::isPingReq)
      .subscribe(onAskToPingRequestSubscriber);

  onTransitPingAckRequestSubscriber = Subscribers.create(this::onTransitPingAck, this::onError);
  transport.listen().observeOn(scheduler)
      .filter(this::isTransitPingAck)
      .subscribe(onTransitPingAckRequestSubscriber);

  pingTask = executor.scheduleWithFixedDelay(
      this::doPing, config.getPingInterval(), config.getPingInterval(), TimeUnit.MILLISECONDS);
}
 
开发者ID:scalecube,项目名称:scalecube,代码行数:38,代码来源:FailureDetectorImpl.java

示例4: start

import rx.observers.Subscribers; //导入方法依赖的package包/类
/**
 * Starts running cluster membership protocol. After started it begins to receive and send cluster membership messages
 */
public CompletableFuture<Void> start() {
  // Init membership table with local member record
  Member member = memberRef.get();
  MembershipRecord localMemberRecord = new MembershipRecord(member, ALIVE, 0);
  membershipTable.put(member.id(), localMemberRecord);

  // Listen to incoming SYNC requests from other members
  onSyncRequestSubscriber = Subscribers.create(this::onSync, this::onError);
  transport.listen().observeOn(scheduler)
      .filter(msg -> SYNC.equals(msg.qualifier()))
      .filter(this::checkSyncGroup)
      .subscribe(onSyncRequestSubscriber);

  // Listen to incoming SYNC ACK responses from other members
  onSyncAckResponseSubscriber = Subscribers.create(this::onSyncAck, this::onError);
  transport.listen().observeOn(scheduler)
      .filter(msg -> SYNC_ACK.equals(msg.qualifier()))
      .filter(msg -> msg.correlationId() == null) // filter out initial sync
      .filter(this::checkSyncGroup)
      .subscribe(onSyncAckResponseSubscriber);

  // Listen to events from failure detector
  onFdEventSubscriber = Subscribers.create(this::onFailureDetectorEvent, this::onError);
  failureDetector.listen().observeOn(scheduler)
      .subscribe(onFdEventSubscriber);

  // Listen to membership gossips
  onGossipRequestSubscriber = Subscribers.create(this::onMembershipGossip, this::onError);
  gossipProtocol.listen().observeOn(scheduler)
      .filter(msg -> MEMBERSHIP_GOSSIP.equals(msg.qualifier()))
      .subscribe(onGossipRequestSubscriber);

  // Make initial sync with all seed members
  return doInitialSync();
}
 
开发者ID:scalecube,项目名称:scalecube,代码行数:39,代码来源:MembershipProtocolImpl.java

示例5: _dispose

import rx.observers.Subscribers; //导入方法依赖的package包/类
private void _dispose(Action1<T> disposedElementsProcessor) {
    Subscriber<T> noOpSub = new PassThruObserver<>(Subscribers.create(disposedElementsProcessor,
            new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {

                }
            }),
            state); // Any buffering post buffer draining must not be lying in the buffer
    state.buffer.sendAllNotifications(noOpSub); // It is important to empty the buffer before setting the observer.
    // If not done, there can be two threads draining the buffer
    // (PassThroughObserver on any notification) and this thread.
    state.setObserverRef(noOpSub); // All future notifications are not sent anywhere.
}
 
开发者ID:Netflix,项目名称:Prana,代码行数:15,代码来源:UnicastDisposableCachingSubject.java

示例6: onNextOnComplete

import rx.observers.Subscribers; //导入方法依赖的package包/类
public static <T> Subscriber<T> onNextOnComplete(Action1<T> onNext, Action0 onComplete) {
    return Subscribers.create(wrap(onNext), onError(), onComplete);
}
 
开发者ID:paramsen,项目名称:currency-android-reactive,代码行数:4,代码来源:SubscriberUtils.java

示例7: onNextOnError

import rx.observers.Subscribers; //导入方法依赖的package包/类
public static <T> Subscriber<T> onNextOnError(Action1<T> onNext, Action1<Throwable> onError) {
    return Subscribers.create(wrap(onNext), wrap(onError), () -> {});
}
 
开发者ID:paramsen,项目名称:currency-android-reactive,代码行数:4,代码来源:SubscriberUtils.java

示例8: testSendOrderSingleThread

import rx.observers.Subscribers; //导入方法依赖的package包/类
@Test
public void testSendOrderSingleThread() throws Exception {
  server = createTransport();

  int iterationNum = 11; // +1 warm up iteration
  int sentPerIteration = 1000;
  long[] iterationTimeSeries = new long[iterationNum - 1];
  List<Long> totalSentTimeSeries = new ArrayList<>(sentPerIteration * (iterationNum - 1));
  for (int i = 0; i < iterationNum; i++) {
    LOGGER.info("####### {} : iteration = {}", testName.getMethodName(), i);
    List<Long> iterSentTimeSeries = new ArrayList<>(sentPerIteration);

    client = createTransport();
    final List<Message> received = new ArrayList<>();
    final CountDownLatch latch = new CountDownLatch(sentPerIteration);

    Subscriber<Message> serverSubscriber = Subscribers.create(message -> {
      received.add(message);
      latch.countDown();
    });
    server.listen().subscribe(serverSubscriber);

    long startAt = System.currentTimeMillis();
    for (int j = 0; j < sentPerIteration; j++) {
      CompletableFuture<Void> sendPromise = new CompletableFuture<>();
      long sentAt = System.currentTimeMillis();
      client.send(server.address(), Message.fromQualifier("q" + j), sendPromise);
      sendPromise.whenComplete((aVoid, exception) -> {
        if (exception == null) {
          long sentTime = System.currentTimeMillis() - sentAt;
          iterSentTimeSeries.add(sentTime);
        } else {
          LOGGER.error("Failed to send message in {} ms", System.currentTimeMillis() - sentAt, exception);
        }
      });
    }

    latch.await(20, TimeUnit.SECONDS);
    long iterationTime = System.currentTimeMillis() - startAt;
    if (i > 0) { // exclude warm up iteration
      iterationTimeSeries[i - 1] = iterationTime;
    }
    assertSendOrder(sentPerIteration, received);

    Thread.sleep(10); // await a bit for last msg confirmation

    LongSummaryStatistics iterSentTimeStats = iterSentTimeSeries.stream().mapToLong(v -> v).summaryStatistics();
    if (i == 0) { // warm up iteration
      LOGGER.info("Warm up iteration time: {} ms", iterationTime);
      LOGGER.info("Sent time stats warm up iter (ms): {}", iterSentTimeStats);
    } else {
      totalSentTimeSeries.addAll(iterSentTimeSeries);
      LongSummaryStatistics totalSentTimeStats = totalSentTimeSeries.stream().mapToLong(v -> v).summaryStatistics();
      LOGGER.info("Iteration time: {} ms", iterationTime);
      LOGGER.info("Sent time stats iter  (ms): {}", iterSentTimeStats);
      LOGGER.info("Sent time stats total (ms): {}", totalSentTimeStats);
    }

    serverSubscriber.unsubscribe();
    destroyTransport(client);
  }

  LongSummaryStatistics iterationTimeStats = LongStream.of(iterationTimeSeries).summaryStatistics();
  LOGGER.info("Iteration time stats (ms): {}", iterationTimeStats);
}
 
开发者ID:scalecube,项目名称:scalecube,代码行数:66,代码来源:TransportSendOrderTest.java


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