All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bdware.doip.cluster.callback.AutoCancelRouteResultCallback Maven / Gradle / Ivy

There is a newer version: 1.5.4
Show newest version
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!

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy