Komplettes G-Earth Paket inkl. JRE, Extensions und Tools. Extensions: - G-BuildTools, G-Click Ultimate, G-Loader, G-Manipulate - G-Presets, G-Translator, G-Trigger, G-itemViewer - Market Utils, Packet Info Explorer, Plants - RandomRoomVisitor, RoomLogger, Sanbovir Photo Inspector - SpyFriends, WallAligner, XabboScripter, xabbo
93 lines
2.4 KiB
Java
93 lines
2.4 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*/
|
|
package okio;
|
|
|
|
import java.io.IOException;
|
|
import java.io.InterruptedIOException;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
public class Timeout {
|
|
public static final Timeout NONE = new Timeout(){
|
|
|
|
@Override
|
|
public Timeout timeout(long timeout, TimeUnit unit) {
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
public Timeout deadlineNanoTime(long deadlineNanoTime) {
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
public void throwIfReached() throws IOException {
|
|
}
|
|
};
|
|
private boolean hasDeadline;
|
|
private long deadlineNanoTime;
|
|
private long timeoutNanos;
|
|
|
|
public Timeout timeout(long timeout, TimeUnit unit) {
|
|
if (timeout < 0L) {
|
|
throw new IllegalArgumentException("timeout < 0: " + timeout);
|
|
}
|
|
if (unit == null) {
|
|
throw new IllegalArgumentException("unit == null");
|
|
}
|
|
this.timeoutNanos = unit.toNanos(timeout);
|
|
return this;
|
|
}
|
|
|
|
public long timeoutNanos() {
|
|
return this.timeoutNanos;
|
|
}
|
|
|
|
public boolean hasDeadline() {
|
|
return this.hasDeadline;
|
|
}
|
|
|
|
public long deadlineNanoTime() {
|
|
if (!this.hasDeadline) {
|
|
throw new IllegalStateException("No deadline");
|
|
}
|
|
return this.deadlineNanoTime;
|
|
}
|
|
|
|
public Timeout deadlineNanoTime(long deadlineNanoTime) {
|
|
this.hasDeadline = true;
|
|
this.deadlineNanoTime = deadlineNanoTime;
|
|
return this;
|
|
}
|
|
|
|
public final Timeout deadline(long duration, TimeUnit unit) {
|
|
if (duration <= 0L) {
|
|
throw new IllegalArgumentException("duration <= 0: " + duration);
|
|
}
|
|
if (unit == null) {
|
|
throw new IllegalArgumentException("unit == null");
|
|
}
|
|
return this.deadlineNanoTime(System.nanoTime() + unit.toNanos(duration));
|
|
}
|
|
|
|
public Timeout clearTimeout() {
|
|
this.timeoutNanos = 0L;
|
|
return this;
|
|
}
|
|
|
|
public Timeout clearDeadline() {
|
|
this.hasDeadline = false;
|
|
return this;
|
|
}
|
|
|
|
public void throwIfReached() throws IOException {
|
|
if (Thread.interrupted()) {
|
|
throw new InterruptedIOException("thread interrupted");
|
|
}
|
|
if (this.hasDeadline && this.deadlineNanoTime - System.nanoTime() <= 0L) {
|
|
throw new InterruptedIOException("deadline reached");
|
|
}
|
|
}
|
|
}
|
|
|