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

org.bimserver.client.notifications.WebSocketHeartbeat Maven / Gradle / Ivy

Go to download

A client library for BIMserver, can communicate via JSON, SOAP and ProtocolBuffers

There is a newer version: 2.0.0
Show newest version
package org.bimserver.client.notifications;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

public class WebSocketHeartbeat extends Thread {
	private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketHeartbeat.class);
	private WebSocketImpl webSocketImpl;
	private volatile boolean running = true;

	public WebSocketHeartbeat(WebSocketImpl webSocketImpl) {
		this.webSocketImpl = webSocketImpl;
	}

	public void shutdown() {
		this.running = false;
		this.interrupt();
	}
	
	@Override
	public void run() {
		ObjectNode message = new ObjectMapper().createObjectNode();
		message.put("hb", true);
		while (running) {
			webSocketImpl.send(message);
			try {
				Thread.sleep(1000 * 30);
			} catch (InterruptedException e) {
				if (running) {
					LOGGER.error("", e);
				}
			}
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy