org.bdware.doip.cluster.callback.AutoCancelRouteResultCallback Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doip-audit-tool Show documentation
Show all versions of doip-audit-tool Show documentation
doip audit tool developed by bdware
package org.bdware.doip.cluster.callback;
import io.netty.util.Timeout;
import io.netty.util.TimerTask;
import org.bdware.doip.endpoint.client.ResponseWait;
import java.util.concurrent.TimeUnit;
public class AutoCancelRouteResultCallback extends CookieJSResultCallback {
// static Logger LOGGER = LogManager.getLogger(AutoCancelRouteResultCallback.class);
private final AsyncJSResultCallback originalCallback;
Timeout timeout;
public AutoCancelRouteResultCallback(CookieJSResultCallback original, int numOfSeconds) {
super(original.cookie);
this.originalCallback = original;
TimerTask tt = timeout -> {
AutoCancelRouteResultCallback.this.timeout = null;
// LOGGER.info("AutoCancelRouteResultCallback RouteResultCallback wait timeout");
// TODO: 修复潜在的bug
originalCallback.onResult(null);
};
timeout = ResponseWait.HASHED_WHEEL_TIMER.newTimeout(tt, numOfSeconds, TimeUnit.SECONDS);
}
@Override
public void onResult(String[] result) {
// Already timeout is var timeout is null!
if (timeout != null) {
timeout.cancel();
originalCallback.onResult(result);
} //Already timeout!
}
}