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

space.chensheng.wsmessenger.common.reliable.WaitingInfo Maven / Gradle / Ivy

The newest version!
package space.chensheng.wsmessenger.common.reliable;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

class WaitingInfo implements Delayed {
    private long trigger;
    
    private String receiverId;
    
    private T message;
    
    private WaitingCallback callback;
    
    WaitingInfo(T message, String receiverId, WaitingCallback callback, long timeout) {
    	this.message = message;
    	this.receiverId = receiverId;
    	this.callback = callback;
    	this.trigger = System.currentTimeMillis() + timeout;
    }
    
    public T getMessage() {
    	return message;
    }
    
    public String getReceiverId() {
    	return receiverId;
    }
    
    public WaitingCallback getCallback() {
    	return callback;
    }
    
	@Override
	public int compareTo(Delayed o) {
		WaitingInfo other = (WaitingInfo) o;
		int result = 0;
		if (trigger > other.trigger) {
			result = 1;
		} else if (trigger < other.trigger) {
			result = -1;
		} else {
			result = 0;
		}
		return result;
	}

	@Override
	public long getDelay(TimeUnit unit) {
		return unit.convert(trigger - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy