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

com.zipwhip.api.signals.sockets.netty.InterruptThreadIfCancelledObserver Maven / Gradle / Ivy

The newest version!
package com.zipwhip.api.signals.sockets.netty;

import com.zipwhip.api.signals.sockets.ConnectionHandle;
import com.zipwhip.concurrent.ObservableFuture;
import com.zipwhip.events.Observer;

/**
 * Created with IntelliJ IDEA.
 * User: Michael
 * Date: 9/12/12
 * Time: 2:11 PM
 *
 * Interrupt the thread if cancelled.
 */
public class InterruptThreadIfCancelledObserver implements Observer> {

    private final Thread thread;

    public InterruptThreadIfCancelledObserver(Thread thread) {
        this.thread = thread;
    }

    public InterruptThreadIfCancelledObserver() {
        this(Thread.currentThread());
    }

    @Override
    public void notify(Object sender, ObservableFuture future) {
        if (future.isCancelled()) {
            thread.interrupt();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy