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

io.firebus.information.KnownAddressInformation Maven / Gradle / Ivy

There is a newer version: 1.3.3
Show newest version
package io.firebus.information;

import io.firebus.Address;

public class KnownAddressInformation {
	protected Address address;
	protected long lastTry;
	protected long nextTry;
	protected int failedCount;
	
	public KnownAddressInformation(Address a) {
		address = a;
		lastTry = 0;
		nextTry = 0;
		failedCount = 0;
	}
	
	public Address getAddress() {
		return address;
	}
	
	public boolean isDueToTry() {
		long now = System.currentTimeMillis();
		return now > nextTry;
	}
	
	public void connectionFailed() {
		failedCount++;
		long now = System.currentTimeMillis();
		if(failedCount <= 3) {
			nextTry = now + 2000;
		} else if(failedCount <= 15) {
			nextTry = now + (2000 * (failedCount - 3));
		} else {
			nextTry = now + 30000;
		}
	}
	
	public void connectionSucceeded() {
		failedCount = 0;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy