/* © SRSoftware 2025 */
package de.srsoftware.umbrella.messagebus;

import static de.srsoftware.umbrella.messagebus.MessageBus.messageBus;

import de.srsoftware.umbrella.messagebus.events.Event;
import java.net.InetSocketAddress;
import java.util.LinkedList;

public class EventQueue extends LinkedList<Event<?>> implements AutoCloseable, EventListener {

	private final InetSocketAddress addr;
	private final System.Logger log;

	public EventQueue(InetSocketAddress addr){
		this.addr = addr;
		log = System.getLogger(addr.toString());
		messageBus().register(this);
	}



	public void close() {
		messageBus().drop(this);
	}


	@Override
	public int hashCode() {
		return addr.hashCode();
	}

	@Override
	public void onEvent(Event<?> event) {
		log.log(System.Logger.Level.INFO,"adding event to queue of {1}: {0}",event.eventType(),addr);
		add(event);
	}
}
