package org.kne.cloud.network.ipv6;

import java.util.concurrent.CopyOnWriteArraySet;
import java.util.function.BiConsumer;
import java.util.function.Supplier;

import org.kne.cloud.network.srv6.SRv6Router;

public abstract class AbstractIPv6NetworkLink implements IPv6NetworkLink {
	private CopyOnWriteArraySet<IPv6LinkStateListener> listeners = new CopyOnWriteArraySet<>();

	private SRv6Router srv6Router;
	
	
	public SRv6Router getSrv6Router() {
		return srv6Router;
	}

	public void setSRv6Router(SRv6Router srv6Router) {
		this.srv6Router = srv6Router;
	}

	@Override
	public void addIPv6LinkStateListener(IPv6LinkStateListener listener) {
		listeners.add(listener);
	}

	@Override
	public void removeIPv6LinkStateListener(IPv6LinkStateListener listener) {
		listeners.remove(listener);

	}
	
	public void onOnlineStateUpdate() {
		listeners.forEach((v) -> {
			v.onOnlineStateUpdate(this);
		});
	}
	public void onLocatorUpdate() {
		listeners.forEach((v) -> {
			v.onLocatorUpdate(this);
		});
	}
	
	public void onAddressUpdate() {
		listeners.forEach((v) -> {
			v.onAddressUpdate(this);
		});
	}
	
	public BiConsumer<IPv6NetworkLink, Supplier<IPv6Packet>> getReceiveConsumer() {
		return receiveConsumer;
	}

	private BiConsumer<IPv6NetworkLink, Supplier<IPv6Packet>> receiveConsumer;
	@Override
	public void setReceiveConsumer(BiConsumer<IPv6NetworkLink,Supplier< IPv6Packet>> receiveConsumer) {
		this.receiveConsumer = receiveConsumer;
	}
}
