-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileDataHandler.java
More file actions
51 lines (41 loc) · 1.37 KB
/
FileDataHandler.java
File metadata and controls
51 lines (41 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package Task_4;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
public class FileDataHandler implements Observer<FileData> {
private final int PERIOD_MULTIPLIER;
private final String TYPE_FILE;
public FileDataHandler(int PERIOD_MULTIPLIER, String TYPE_FILE) {
this.PERIOD_MULTIPLIER = PERIOD_MULTIPLIER;
this.TYPE_FILE = TYPE_FILE;
}
@Override
public void onSubscribe(@NonNull Disposable d) {
System.out.println("onSubscribe " + this.getClass());
}
@Override
public void onNext(@NonNull FileData fileData) {
if (!fileData.getType().equals(this.TYPE_FILE)) {
return;
}
Thread thread = new Thread(() -> {
try {
long sleepTime = (long) fileData.getSize() * this.PERIOD_MULTIPLIER;
System.out.println("sleep: " + sleepTime);
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(fileData);
});
thread.start();
}
@Override
public void onError(@NonNull Throwable e) {
e.printStackTrace();
}
@Override
public void onComplete() {
System.out.println("onComplete " + this.getClass());
}
}