Reputation: 892
currently I'm starting out with observable's, however Currently I'm stuck with something..
At the moment I have a main class these one will call a Observable file watcher, so far so good. That works.
so something like that:
public static void main(String args[]) {
Observable<String> myObservable = observable();
// Buffer on Backpressure since I load every old file/directory, too
Subscription subscription = observable.onBackpressureBuffer()
.subscribe(subscriber -> {
})
... // Code that stop the program from stopping
}
So that's what I have however know I want to have some other Observable's something like
OfficeObservable
or PdfObservable
. Which will be used when the file has a extension of .pdf
it will use the PdfObservable. And if it has something like .docx
it should call the OfficeObservable. However how could I attach that to a bigger program. Especially since that won't be the last observable's I want to use.
Could I just chain them together inside the subscribe method or flatMap over them and let all of them return the same interface? I'm stuck on how to get a bigger Application out of RxJava.
Upvotes: 0
Views: 115
Reputation: 1392
You could expose your specialised (and FileObservable) like this:
Observable<String> fileObservable;
private void init(){ // called from constructor or some other init'ish method
//init your fileObservable
}
public Observable<String> getFileObservable(){
return fileObservable;
}
public Observable<String> getPdfFileObservable(){
return fileObservable.filter(name -> name.endsWith(".pdf"))
}
It strongly depends on what you want to do, if you want to add a cache()
to your fileObservable or put other helpful Observable operators in.
Upvotes: 0