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);
}
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);
}
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);
}
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;
}
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();
}
Aggregations