package vs;

import jakarta.websocket.OnClose;
import jakarta.websocket.OnOpen;
import jakarta.websocket.Session;
import jakarta.websocket.server.ServerEndpoint;

@ServerEndpoint(value = "/dataService", encoders = DataEncoder.class)
public class MessungsService {

	@OnOpen
	public void open(Session session) {
		SensorSimulator sensor = new SensorSimulator(session);
		session.getUserProperties().put("sensor", sensor);
		sensor.start();
	}

	@SuppressWarnings("deprecation")
	@OnClose
	public void close(Session session) {
		SensorSimulator sensor = (SensorSimulator) session.getUserProperties().get("sensor");
		sensor.stop();
		session.getUserProperties().remove("sensor");
	}
}
