Java Code Examples for rx.schedulers.Schedulers#from()

The following examples show how to use rx.schedulers.Schedulers#from() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommonStorageServiceDAOConfig.java    From front50 with Apache License 2.0 6 votes vote down vote up
@Bean
SnapshotDAO snapshotDAO(
    StorageService storageService,
    StorageServiceConfigurationProperties storageServiceConfigurationProperties,
    ObjectKeyLoader objectKeyLoader,
    Registry registry,
    CircuitBreakerRegistry circuitBreakerRegistry) {
  return new DefaultSnapshotDAO(
      storageService,
      Schedulers.from(
          Executors.newFixedThreadPool(
              storageServiceConfigurationProperties.getSnapshot().getThreadPool())),
      objectKeyLoader,
      storageServiceConfigurationProperties.getSnapshot().getRefreshMs(),
      storageServiceConfigurationProperties.getSnapshot().getShouldWarmCache(),
      registry,
      circuitBreakerRegistry);
}
 
Example 2
Source File: CommonStorageServiceDAOConfig.java    From front50 with Apache License 2.0 6 votes vote down vote up
@Bean
PluginVersionPinningRepository pluginVersionPinningRepository(
    StorageService storageService,
    StorageServiceConfigurationProperties storageServiceConfigurationProperties,
    ObjectKeyLoader objectKeyLoader,
    Registry registry,
    CircuitBreakerRegistry circuitBreakerRegistry) {
  return new DefaultPluginVersionPinningRepository(
      storageService,
      Schedulers.from(
          Executors.newFixedThreadPool(
              storageServiceConfigurationProperties.getPluginInfo().getThreadPool())),
      objectKeyLoader,
      storageServiceConfigurationProperties.getPluginInfo().getRefreshMs(),
      storageServiceConfigurationProperties.getPluginInfo().getShouldWarmCache(),
      registry,
      circuitBreakerRegistry);
}
 
Example 3
Source File: ConflictWorker.java    From azure-cosmosdb-java with MIT License 6 votes vote down vote up
public ConflictWorker(String databaseName, String basicCollectionName, String manualCollectionName, String lwwCollectionName, String udpCollectionName) {
    this.clients = new ArrayList<>();
    this.basicCollectionUri = Helpers.createDocumentCollectionUri(databaseName, basicCollectionName);
    this.manualCollectionUri = Helpers.createDocumentCollectionUri(databaseName, manualCollectionName);
    this.lwwCollectionUri = Helpers.createDocumentCollectionUri(databaseName, lwwCollectionName);
    this.udpCollectionUri = Helpers.createDocumentCollectionUri(databaseName, udpCollectionName);

    this.databaseName = databaseName;
    this.basicCollectionName = basicCollectionName;
    this.manualCollectionName = manualCollectionName;
    this.lwwCollectionName = lwwCollectionName;
    this.udpCollectionName = udpCollectionName;

    this.executor = Executors.newFixedThreadPool(100);
    this.schedulerForBlockingWork = Schedulers.from(executor);
}
 
Example 4
Source File: CommonStorageServiceDAOConfig.java    From front50 with Apache License 2.0 6 votes vote down vote up
@Bean
DeliveryRepository deliveryRepository(
    StorageService storageService,
    StorageServiceConfigurationProperties storageServiceConfigurationProperties,
    ObjectKeyLoader objectKeyLoader,
    Registry registry,
    CircuitBreakerRegistry circuitBreakerRegistry) {
  return new DefaultDeliveryRepository(
      storageService,
      Schedulers.from(
          Executors.newFixedThreadPool(
              storageServiceConfigurationProperties.getDeliveryConfig().getThreadPool())),
      objectKeyLoader,
      storageServiceConfigurationProperties.getDeliveryConfig().getRefreshMs(),
      storageServiceConfigurationProperties.getDeliveryConfig().getShouldWarmCache(),
      registry,
      circuitBreakerRegistry);
}
 
Example 5
Source File: CommonStorageServiceDAOConfig.java    From front50 with Apache License 2.0 6 votes vote down vote up
@Bean
PipelineStrategyDAO pipelineStrategyDAO(
    StorageService storageService,
    StorageServiceConfigurationProperties storageServiceConfigurationProperties,
    ObjectKeyLoader objectKeyLoader,
    Registry registry,
    CircuitBreakerRegistry circuitBreakerRegistry) {
  return new DefaultPipelineStrategyDAO(
      storageService,
      Schedulers.from(
          Executors.newFixedThreadPool(
              storageServiceConfigurationProperties.getPipelineStrategy().getThreadPool())),
      objectKeyLoader,
      storageServiceConfigurationProperties.getPipelineStrategy().getRefreshMs(),
      storageServiceConfigurationProperties.getPipelineStrategy().getShouldWarmCache(),
      registry,
      circuitBreakerRegistry);
}
 
Example 6
Source File: CommonStorageServiceDAOConfig.java    From front50 with Apache License 2.0 6 votes vote down vote up
@Bean
ApplicationDAO applicationDAO(
    StorageService storageService,
    StorageServiceConfigurationProperties storageServiceConfigurationProperties,
    ObjectKeyLoader objectKeyLoader,
    Registry registry,
    CircuitBreakerRegistry circuitBreakerRegistry) {
  return new DefaultApplicationDAO(
      storageService,
      Schedulers.from(
          Executors.newFixedThreadPool(
              storageServiceConfigurationProperties.getApplication().getThreadPool())),
      objectKeyLoader,
      storageServiceConfigurationProperties.getApplication().getRefreshMs(),
      storageServiceConfigurationProperties.getApplication().getShouldWarmCache(),
      registry,
      circuitBreakerRegistry);
}
 
Example 7
Source File: GcsConfig.java    From front50 with Apache License 2.0 6 votes vote down vote up
@Override
public ApplicationPermissionDAO applicationPermissionDAO(
    StorageService storageService,
    StorageServiceConfigurationProperties storageServiceConfigurationProperties,
    ObjectKeyLoader objectKeyLoader,
    Registry registry,
    CircuitBreakerRegistry circuitBreakerRegistry) {
  GcsStorageService service =
      googleCloudStorageService(ApplicationPermissionDAO.DEFAULT_DATA_FILENAME, gcsProperties);
  ObjectKeyLoader keyLoader = new DefaultObjectKeyLoader(service);
  return new DefaultApplicationPermissionDAO(
      service,
      Schedulers.from(
          Executors.newFixedThreadPool(
              storageServiceConfigurationProperties.getApplicationPermission().getThreadPool())),
      keyLoader,
      storageServiceConfigurationProperties.getApplicationPermission().getRefreshMs(),
      storageServiceConfigurationProperties.getApplicationPermission().getShouldWarmCache(),
      registry,
      circuitBreakerRegistry);
}
 
Example 8
Source File: WampRouter.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
WampRouter(Map<String, RealmConfig> realms) {
    
    // Populate the realms from the configuration
    this.realms = new HashMap<String, Realm>();
    for (Map.Entry<String, RealmConfig> e : realms.entrySet()) {
        Realm info = new Realm(e.getValue());
        this.realms.put(e.getKey(), info);
    }
    
    // Create an eventloop and the RX scheduler on top of it
    this.eventLoop = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r, "WampRouterEventLoop");
            t.setDaemon(true);
            return t;
        }
    });
    this.scheduler = Schedulers.from(eventLoop);

    idleChannels = new HashSet<IConnectionController>();
}
 
Example 9
Source File: CommonStorageServiceDAOConfig.java    From front50 with Apache License 2.0 6 votes vote down vote up
@Bean
ServiceAccountDAO serviceAccountDAO(
    StorageService storageService,
    StorageServiceConfigurationProperties storageServiceConfigurationProperties,
    ObjectKeyLoader objectKeyLoader,
    Registry registry,
    CircuitBreakerRegistry circuitBreakerRegistry) {
  return new DefaultServiceAccountDAO(
      storageService,
      Schedulers.from(
          Executors.newFixedThreadPool(
              storageServiceConfigurationProperties.getServiceAccount().getThreadPool())),
      objectKeyLoader,
      storageServiceConfigurationProperties.getServiceAccount().getRefreshMs(),
      storageServiceConfigurationProperties.getServiceAccount().getShouldWarmCache(),
      registry,
      circuitBreakerRegistry);
}
 
Example 10
Source File: SimpleUploadDataStoreTest.java    From RxUploader with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    sharedPreferences =
            RuntimeEnvironment.application.getSharedPreferences(SimpleUploadDataStore.JOB_REPO,
                    Context.MODE_PRIVATE);
    final Scheduler worker = Schedulers.from(Executors.newSingleThreadExecutor());
    dataStore = new SimpleUploadDataStore(sharedPreferences, worker);
    gson = new GsonBuilder()
            .registerTypeAdapterFactory(JobTypeAdapterFactory.create())
            .create();
}
 
Example 11
Source File: RTree3DTest.java    From rtree-3d with Apache License 2.0 5 votes vote down vote up
private void search(final File dir, boolean useFixes) {
    System.out.println("searching");
    final Scheduler scheduler = Schedulers.from(Executors.newFixedThreadPool(10));
    final RTree<String, Box> tree = readUpper(new File(dir, "top"));
    final Box searchBox = createSearchBox(useFixes, tree.context().bounds().get());
    long t = System.currentTimeMillis();
    int found = search(tree, searchBox, scheduler, dir).count().toBlocking().single();
    System.out.println(
            "search found " + found + " in " + (System.currentTimeMillis() - t) + "ms");
}
 
Example 12
Source File: SchedulerImpl.java    From hawkular-metrics with Apache License 2.0 5 votes vote down vote up
public SchedulerImpl(RxSession session, String hostname, JobsService jobsService) {
    this.session = session;
    jobFactories = new HashMap<>();

    tickExecutor = new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder()
            .setNameFormat("ticker-pool-%d").build(), new ThreadPoolExecutor.DiscardPolicy());
    tickScheduler = Schedulers.from(tickExecutor);

    ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("query-thread-pool-%d").build();
    queryExecutor = new ThreadPoolExecutor(getQueryThreadPoolSize(), getQueryThreadPoolSize(), 0,
            TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), threadFactory,
            new ThreadPoolExecutor.DiscardPolicy());
    queryScheduler = Schedulers.from(queryExecutor);

    lockManager = new LockManager(session);
    this.jobsService = jobsService;

    deleteScheduledJobs = initQuery("DELETE FROM scheduled_jobs_idx WHERE time_slice = ?");
    findFinishedJobs = initQuery("SELECT job_id FROM finished_jobs_idx WHERE time_slice = ?");
    deleteFinishedJobs = initQuery("DELETE FROM finished_jobs_idx WHERE time_slice = ?");
    updateJobToFinished = initQuery("INSERT INTO finished_jobs_idx (time_slice, job_id) VALUES (?, ?)");
    addActiveTimeSlice = initQuery("INSERT INTO active_time_slices (time_slice) VALUES (?)");
    findActiveTimeSlices = initQuery("SELECT DISTINCT time_slice FROM active_time_slices");
    deleteActiveTimeSlice = initQuery("DELETE FROM active_time_slices WHERE time_slice = ?");

    finishedTimeSlices = Optional.empty();
    jobFinished = Optional.empty();

    this.hostname = hostname;
}
 
Example 13
Source File: OutOfOrder.java    From akarnokd-misc with Apache License 2.0 4 votes vote down vote up
@Test
public void test() throws Exception {
    final int total = 1000;
    AtomicInteger mValue = new AtomicInteger(0);
    AtomicInteger mCount = new AtomicInteger(0);
    List<Integer> mEmitValues = new ArrayList<>();
    List<Integer> mReceiveValues = new ArrayList<>();

    ExecutorService ex1 = Executors.newSingleThreadExecutor();
    Scheduler subscribeScheduler = Schedulers.from(ex1);
    ExecutorService ex2 = Executors.newSingleThreadExecutor();
    Scheduler mapScheduler = Schedulers.from(ex2);
    ExecutorService ex3 = Executors.newSingleThreadExecutor();
    Scheduler observeScheduler = Schedulers.from(ex3);

    CountDownLatch cdl = new CountDownLatch(1);

    for (int i = 0; i < total; i++) {
        int j = i;
        Observable.just(null)
                .doOnRequest(v -> System.out.println(j))
                .subscribeOn(subscribeScheduler)
                .observeOn(mapScheduler)
                .map(new Func1<Object, Integer>() {
                    @Override
                    public Integer call(Object obj) {
                        int newValue = mValue.incrementAndGet();
                        mEmitValues.add(newValue);
                        return newValue;
                    }
                })
                .observeOn(observeScheduler)
                .subscribe(new Action1<Integer>() {
                    @Override
                    public void call(Integer value) {
                        mReceiveValues.add(value);
                        if (mCount.incrementAndGet() == total) {
                            try {
                                System.out.println("run complete");
                                for (int i = 0; i < total; i++) {
                                    if (!mEmitValues.get(i).equals(mReceiveValues.get(i))) {
                                        System.out.println(i + ": " + mEmitValues.get(i) + " vs " + mReceiveValues.get(i));
                                    }
                                }
                            } finally {
                                cdl.countDown();
                            }
                        }
                    }
                });
    }

    cdl.await();

    Thread.sleep(100);

    ex1.shutdown();
    ex2.shutdown();
    ex3.shutdown();

    System.out.println(new HashSet<>(mReceiveValues).size());

    Assert.assertEquals(mEmitValues, mReceiveValues);
}
 
Example 14
Source File: StackdriverConfig.java    From kork with Apache License 2.0 4 votes vote down vote up
/**
 * Schedule a thread to flush our registry into stackdriver periodically.
 *
 * <p>This configures our StackdriverWriter as well.
 */
@Bean
public StackdriverWriter defaultStackdriverWriter(
    Environment environment,
    Registry registry,
    SpectatorStackdriverConfigurationProperties spectatorStackdriverConfigurationProperties)
    throws IOException {
  Logger log = LoggerFactory.getLogger("StackdriverConfig");
  log.info("Creating StackdriverWriter.");
  Predicate<Measurement> filterNotSpring =
      new Predicate<Measurement>() {
        public boolean test(Measurement measurement) {
          // Dont store measurements that dont have tags.
          // These are from spring; those of interest were replicated in spectator.
          if (measurement.id().tags().iterator().hasNext()) {
            return true;
          }

          return false;
        }
      };
  Predicate<Measurement> measurementFilter;

  final String prototypeFilterPath =
      spectatorStackdriverConfigurationProperties.getWebEndpoint().getPrototypeFilter().getPath();

  if (!prototypeFilterPath.isEmpty()) {
    log.error("Ignoring prototypeFilterPath because it is not yet supported.");
    measurementFilter = null;
    log.info("Configuring stackdriver filter from {}", prototypeFilterPath);
    measurementFilter =
        PrototypeMeasurementFilter.loadFromPath(prototypeFilterPath).and(filterNotSpring);
  } else {
    measurementFilter = filterNotSpring;
  }

  InetAddress hostaddr = serverProperties.getAddress();
  if (hostaddr.equals(InetAddress.getLoopbackAddress())) {
    hostaddr = InetAddress.getLocalHost();
  }

  String host = hostaddr.getCanonicalHostName();
  String hostPort = host + ":" + serverProperties.getPort();

  ConfigParams params =
      new ConfigParams.Builder()
          .setCounterStartTime(new Date().getTime())
          .setCustomTypeNamespace("spinnaker")
          .setProjectName(
              spectatorStackdriverConfigurationProperties.getStackdriver().getProjectName())
          .setApplicationName(
              spectatorStackdriverConfigurationProperties.getApplicationName(
                  environment.getProperty("spring.application.name")))
          .setCredentialsPath(
              spectatorStackdriverConfigurationProperties.getStackdriver().getCredentialsPath())
          .setMeasurementFilter(measurementFilter)
          .setInstanceId(hostPort)
          .build();

  stackdriver = new StackdriverWriter(params);

  Scheduler scheduler = Schedulers.from(Executors.newFixedThreadPool(1));

  Observable.timer(
          spectatorStackdriverConfigurationProperties.getStackdriver().getPeriod(),
          TimeUnit.SECONDS)
      .repeat()
      .subscribe(
          interval -> {
            stackdriver.writeRegistry(registry);
          });

  return stackdriver;
}
 
Example 15
Source File: OperatorBufferToFileTest.java    From rxjava-extras with Apache License 2.0 4 votes vote down vote up
private static Scheduler createSingleThreadScheduler() {
    return Schedulers.from(Executors.newSingleThreadExecutor());
}
 
Example 16
Source File: StateController.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
public StateController(ClientConfiguration clientConfig) {
    this.clientConfig = clientConfig;
    this.scheduler = clientConfig.connectorProvider.createScheduler();
    this.rxScheduler = Schedulers.from(scheduler);
}
 
Example 17
Source File: ExportApp.java    From usergrid with Apache License 2.0 4 votes vote down vote up
/**
 * Tool entry point.
 */
@Override
public void runTool(CommandLine line) throws Exception {

    applicationName = line.getOptionValue( APPLICATION_NAME );

    if (StringUtils.isNotEmpty( line.getOptionValue( WRITE_THREAD_COUNT ) )) {
        try {
            writeThreadCount = Integer.parseInt( line.getOptionValue( WRITE_THREAD_COUNT ) );
        } catch (NumberFormatException nfe) {
            logger.error( "-" + WRITE_THREAD_COUNT + " must be specified as an integer. Aborting..." );
            return;
        }
    }

    setVerbose( line );

    applyOrgId( line );
    prepareBaseOutputFileName( line );
    outputDir = createOutputParentDir();
    logger.info( "Export directory: " + outputDir.getAbsolutePath() );

    startSpring();

    UUID applicationId = emf.lookupApplication( applicationName );
    if (applicationId == null) {
        throw new RuntimeException( "Cannot find application " + applicationName );
    }
    final EntityManager em = emf.getEntityManager( applicationId );
    organizationName = em.getApplication().getOrganizationName();

    ExecutorService writeThreadPoolExecutor = Executors.newFixedThreadPool( writeThreadCount );
    writeScheduler = Schedulers.from( writeThreadPoolExecutor );

    Observable<String> collectionsObservable = Observable.create( new CollectionsObservable( em ) );

    logger.debug( "Starting export" );

    collectionsObservable.flatMap( collection -> {

        return Observable.create( new EntityObservable( em, collection ) )
                .doOnNext( new EntityWriteAction() ).subscribeOn( writeScheduler );


    } ).flatMap( exportEntity -> {

        return Observable.create( new ConnectionsObservable( em, exportEntity ) )
                .doOnNext( new ConnectionWriteAction() ).subscribeOn( writeScheduler );

    } ).doOnCompleted( new FileWrapUpAction() ).toBlocking().lastOrDefault(null);
}
 
Example 18
Source File: DefaultReconciliationFramework.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
public DefaultReconciliationFramework(List<InternalReconciliationEngine<EVENT>> bootstrapEngines,
                                      Function<EntityHolder, InternalReconciliationEngine<EVENT>> engineFactory,
                                      long idleTimeoutMs,
                                      long activeTimeoutMs,
                                      Map<Object, Comparator<EntityHolder>> indexComparators,
                                      Registry registry,
                                      Optional<Scheduler> optionalScheduler) {
    Preconditions.checkArgument(idleTimeoutMs > 0, "idleTimeout <= 0 (%s)", idleTimeoutMs);
    Preconditions.checkArgument(activeTimeoutMs <= idleTimeoutMs, "activeTimeout(%s) > idleTimeout(%s)", activeTimeoutMs, idleTimeoutMs);

    this.engineFactory = engineFactory;
    this.indexSet = IndexSet.newIndexSet(indexComparators);

    this.idleTimeoutMs = idleTimeoutMs;
    this.activeTimeoutMs = activeTimeoutMs;

    if (optionalScheduler.isPresent()) {
        this.scheduler = optionalScheduler.get();
        this.executor = null;
    } else {
        this.executor = Executors.newSingleThreadExecutor(runnable -> {
            Thread thread = new Thread(runnable, "TitusReconciliationFramework");
            thread.setDaemon(true);
            return thread;
        });
        this.scheduler = Schedulers.from(executor);
    }

    this.worker = scheduler.createWorker();
    this.eventsObservable = Observable.merge(eventsMergeSubject).share();

    // To keep eventsObservable permanently active.
    this.internalEventSubscription = eventsObservable.subscribe(ObservableExt.silentSubscriber());

    this.loopExecutionTime = registry.timer(LOOP_EXECUTION_TIME_METRIC);
    this.lastFullCycleExecutionTimeMs = scheduler.now() - idleTimeoutMs;
    this.lastExecutionTimeMs = scheduler.now();
    PolledMeter.using(registry).withName(LAST_EXECUTION_TIME_METRIC).monitorValue(this, self -> scheduler.now() - self.lastExecutionTimeMs);
    PolledMeter.using(registry).withName(LAST_FULL_CYCLE_EXECUTION_TIME_METRIC).monitorValue(this, self -> scheduler.now() - self.lastFullCycleExecutionTimeMs);

    engines.addAll(bootstrapEngines);
    bootstrapEngines.forEach(engine -> eventsMergeSubject.onNext(engine.events()));

    updateIndexSet();
}
 
Example 19
Source File: JsonRpc2_0Rx.java    From etherscan-explorer with GNU General Public License v3.0 4 votes vote down vote up
public JsonRpc2_0Rx(Web3j web3j, ScheduledExecutorService scheduledExecutorService) {
    this.web3j = web3j;
    this.scheduledExecutorService = scheduledExecutorService;
    this.scheduler = Schedulers.from(scheduledExecutorService);
}
 
Example 20
Source File: RxTaskSchedulerImpl.java    From usergrid with Apache License 2.0 3 votes vote down vote up
@Inject
public RxTaskSchedulerImpl(final ThreadPoolExecutor executor){

    Preconditions.checkNotNull( executor , "executor must not be null");


    this.scheduler = Schedulers.from(executor);


}