Search in sources :

Example 46 with Action0

use of rx.functions.Action0 in project PracticeFilmApplication by FOnlyJack.

the class VideoPlayPresenter method loadFilmVideoListInfo.

@Override
public void loadFilmVideoListInfo(int pageIndex, int movieId) {
    Subscription subscribe = ApiDataManager.getFilmVideoInfo(pageIndex, movieId).doOnSubscribe(new Action0() {

        @Override
        public void call() {
            Logger.d("showLoading");
        }
    }).subscribe(new Subscriber<FilmVideoBean>() {

        @Override
        public void onCompleted() {
            view.onCompleted();
        }

        @Override
        public void onError(Throwable e) {
            view.onError(e);
        }

        @Override
        public void onNext(FilmVideoBean filmVideoBean) {
            datalist.add(filmVideoBean);
            view.displayFilmHitInformation(datalist);
            datalist.clear();
        }
    });
    compositeSubscription.add(subscribe);
}
Also used : Action0(rx.functions.Action0) FilmVideoBean(com.example.changemax.sqhappy.model.network.entity.FilmVideoBean) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription)

Example 47 with Action0

use of rx.functions.Action0 in project PracticeFilmApplication by FOnlyJack.

the class FragmentOnePresenter method loadLocCityInfo.

@Override
public void loadLocCityInfo() {
    Subscription subscription = ApiDataManager.getFilmLocation(ApiConstants.FILM_INFORMATION_BASIS_LOCATIONID_HOST).doOnSubscribe(new Action0() {

        @Override
        public void call() {
            Logger.d("showLoading");
        }
    }).subscribe(new Subscriber<FilmInfoLocationBean>() {

        @Override
        public void onCompleted() {
            view.onCompleted();
        }

        @Override
        public void onError(Throwable e) {
            view.onError(e);
        }

        @Override
        public void onNext(FilmInfoLocationBean filmInfoLocationBean) {
            datalist.addAll(filmInfoLocationBean.getP());
            view.displayLocCityInformation(datalist);
            datalist.clear();
        }
    });
    compositeSubscription.add(subscription);
}
Also used : Action0(rx.functions.Action0) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription) FilmInfoLocationBean(com.example.changemax.sqhappy.model.network.entity.FilmInfoLocationBean)

Example 48 with Action0

use of rx.functions.Action0 in project AndroidStudy by tinggengyan.

the class RXJavaActivity method simpleAction.

// 简单的使用action这个接口
private void simpleAction() {
    // 简单的使用Action1这个接口,来变现单个参数的观察者参数
    // 所有只含有一个参数的回调都可以用这个简单的接口
    Action1 onNextAction = new Action1() {

        @Override
        public void call(Object o) {
            System.out.println("next:" + o.toString());
        }
    };
    Action1 onErrorAction = new Action1() {

        @Override
        public void call(Object o) {
            System.out.println("error:" + o.toString());
        }
    };
    // 对于无参的回调,则可以用Action0这个接口简单的实现
    Action0 onCompletedAction = new Action0() {

        @Override
        public void call() {
            System.out.println("Complete");
        }
    };
    String[] words = { "Hello", "Hi", "Aloha" };
    Observable observable = Observable.from(words);
    observable.subscribe(onNextAction);
    observable.subscribe(onNextAction, onErrorAction);
    observable.subscribe(onNextAction, onErrorAction, onCompletedAction);
}
Also used : Action0(rx.functions.Action0) Action1(rx.functions.Action1) Observable(rx.Observable)

Example 49 with Action0

use of rx.functions.Action0 in project halyard by spinnaker.

the class JobExecutorLocal method startJob.

@Override
public String startJob(JobRequest jobRequest, Map<String, String> env, InputStream stdIn, ByteArrayOutputStream stdOut, ByteArrayOutputStream stdErr) {
    List<String> tokenizedCommand = jobRequest.getTokenizedCommand();
    if (tokenizedCommand == null || tokenizedCommand.isEmpty()) {
        throw new IllegalArgumentException("JobRequest must include a tokenized command to run");
    }
    final long timeoutMillis = jobRequest.getTimeoutMillis() == null ? ExecuteWatchdog.INFINITE_TIMEOUT : jobRequest.getTimeoutMillis();
    String jobId = UUID.randomUUID().toString();
    pendingJobSet.add(jobId);
    log.info("Scheduling job " + jobRequest.getTokenizedCommand() + " with id " + jobId);
    scheduler.createWorker().schedule(new Action0() {

        @Override
        public void call() {
            PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(stdOut, stdErr, stdIn);
            CommandLine commandLine;
            log.info("Executing " + jobId + "with tokenized command: " + tokenizedCommand);
            // Grab the first element as the command.
            commandLine = new CommandLine(jobRequest.getTokenizedCommand().get(0));
            // Treat the rest as arguments.
            String[] arguments = Arrays.copyOfRange(tokenizedCommand.toArray(new String[0]), 1, tokenizedCommand.size());
            commandLine.addArguments(arguments, false);
            DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
            ExecuteWatchdog watchdog = new ExecuteWatchdog(timeoutMillis) {

                @Override
                public void timeoutOccured(Watchdog w) {
                    // the result of calling watchdog.destroyProcess().
                    if (w != null) {
                        log.warn("Job " + jobId + " timed-out after " + timeoutMillis + "ms.");
                        cancelJob(jobId);
                    }
                    super.timeoutOccured(w);
                }
            };
            Executor executor = new DefaultExecutor();
            executor.setStreamHandler(pumpStreamHandler);
            executor.setWatchdog(watchdog);
            try {
                executor.execute(commandLine, env, resultHandler);
            } catch (IOException e) {
                throw new RuntimeException("Execution of " + jobId + " failed ", e);
            }
            // Give the job some time to spin up.
            try {
                Thread.sleep(500);
            } catch (InterruptedException ignored) {
            }
            jobIdToHandlerMap.put(jobId, new ExecutionHandler().setResultHandler(resultHandler).setWatchdog(watchdog).setStdOut(stdOut).setStdErr(stdErr));
            if (pendingJobSet.contains(jobId)) {
                pendingJobSet.remove(jobId);
            } else {
                // If the job was removed from the set of pending jobs by someone else, its deletion was requested
                jobIdToHandlerMap.remove(jobId);
                watchdog.destroyProcess();
            }
        }
    });
    return jobId;
}
Also used : Action0(rx.functions.Action0) IOException(java.io.IOException)

Example 50 with Action0

use of rx.functions.Action0 in project spring-cloud-sleuth by spring-cloud.

the class SleuthRxJavaSchedulersHookTests method should_wrap_delegates_action_in_wrapped_action_when_delegate_is_present_on_schedule.

@Test
public void should_wrap_delegates_action_in_wrapped_action_when_delegate_is_present_on_schedule() {
    RxJavaPlugins.getInstance().registerSchedulersHook(new MyRxJavaSchedulersHook());
    SleuthRxJavaSchedulersHook schedulersHook = new SleuthRxJavaSchedulersHook(this.tracer, this.traceKeys, threadsToIgnore);
    Action0 action = schedulersHook.onSchedule(() -> {
        caller = new StringBuilder("hello");
    });
    action.call();
    then(action).isInstanceOf(SleuthRxJavaSchedulersHook.TraceAction.class);
    then(caller.toString()).isEqualTo("called_from_schedulers_hook");
    then(this.reporter.getSpans()).isNotEmpty();
    then(this.tracer.currentSpan()).isNull();
}
Also used : Action0(rx.functions.Action0) Test(org.junit.Test)

Aggregations

Action0 (rx.functions.Action0)134 Subscription (rx.Subscription)58 Test (org.junit.Test)56 CountDownLatch (java.util.concurrent.CountDownLatch)50 Action1 (rx.functions.Action1)28 AtomicReference (java.util.concurrent.atomic.AtomicReference)23 ArrayList (java.util.ArrayList)16 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)16 List (java.util.List)15 Func1 (rx.functions.Func1)13 HystrixRuntimeException (com.netflix.hystrix.exception.HystrixRuntimeException)12 Observable (rx.Observable)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 OnClick (butterknife.OnClick)10 IOException (java.io.IOException)9 CommandStreamTest (com.netflix.hystrix.metric.CommandStreamTest)8 UiThreadTest (android.support.test.annotation.UiThreadTest)7 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)7 TestCollapserTimer (com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer)7 Method (java.lang.reflect.Method)7