org.bdware.doip.cluster.callback.AutoCancelReconnectCallback 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
The newest version!
package org.bdware.doip.cluster.callback;
import io.netty.util.Timeout;
import io.netty.util.TimerTask;
import org.bdware.doip.audit.client.AuditDoipClient;
import org.bdware.doip.endpoint.client.ResponseWait;
import java.util.concurrent.TimeUnit;
public class AutoCancelReconnectCallback implements ClientReadyCallback {
// static Logger LOGGER = LogManager.getLogger(AutoCancelReconnectCallback.class);
private final ClientReadyCallback originalCallback;
Timeout timeout;
public AutoCancelReconnectCallback(AuditDoipClient doipClient, ClientReadyCallback original, int numOfSeconds) {
this.originalCallback = original;
TimerTask tt = timeout -> {
AutoCancelReconnectCallback.this.timeout = null;
if (doipClient.rwLock.availablePermits() <= 0)
doipClient.rwLock.release();
if (originalCallback != null)
originalCallback.onReady(doipClient);
};
timeout = ResponseWait.HASHED_WHEEL_TIMER.newTimeout(tt, numOfSeconds, TimeUnit.SECONDS);
}
@Override
public void onReady(AuditDoipClient result) {
// Already timeout is var timeout is null!
if (timeout != null) {
timeout.cancel();
if (originalCallback != null)
originalCallback.onReady(result);
}
}
}