Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.github.automately.java.eventbus;
import com.github.automately.java.Automately;
import io.jsync.Async;
import io.jsync.AsyncFactory;
import io.jsync.buffer.Buffer;
import io.jsync.http.HttpClient;
import io.jsync.http.WebSocket;
import io.jsync.json.JsonObject;
import java.util.*;
/**
* The EventBus class provides a way to connect to the Automately Cluster's underlying
* jsync.io EventBus system. The EventBus provides an interface for authentication, handler
* registering, and more. This class is very important.
*/
public class EventBus {
final public static long CONNECTING = 0;
final public static long OPEN = 1;
final public static long CLOSING = 2;
final public static long CLOSED = 3;
final private String AUTH_IDENTIFIER = "automately.sdk.auth";
public static String DEFAULT_HOST = "sdk.automate.ly";
public static int DEFAULT_PORT = 443;
public static boolean USE_SSL = true;
private Async async;
public EventBus(){
this(AsyncFactory.newAsync());
}
public EventBus(Async async){
this.async = async;
}
private WebSocket socket;
private long state = CONNECTING;
private long pingTimerID;
private Runnable openHandler = null;
private Runnable closeHandler = null;
private HashMap>> handlersMap = new LinkedHashMap<>();
private HashMap> replyHandlers = new LinkedHashMap<>();
private String sessionId = "";
public void connect(){
HttpClient client;
String url;
if(USE_SSL){
client = async.createHttpClient()
.setSSL(true)
.setKeyStorePassword("changeit")
.setKeyStorePath(System.getProperty("java.home") + "/lib/security/cacerts")
.setHost(DEFAULT_HOST).setPort(DEFAULT_PORT);
} else {
client = async.createHttpClient()
.setHost(DEFAULT_HOST).setPort(DEFAULT_PORT);
}
url = "/automately.sdk.eventBus/websocket";
client.setTryUseCompression(true);
client.setKeepAlive(true);
client.connectWebsocket(url, socket1 -> {
socket = socket1;
socket.closeHandler(event -> {
state = CLOSED;
if(closeHandler != null){
closeHandler.run();
}
});
socket.dataHandler(event -> {
JsonObject message = new JsonObject(event.toString());
Object body = message.getValue("body");
String address = message.getString("address");
// TODO Implement this
final String replyAddress = message.getString("replyAddress");
Set> handlers = handlersMap.get(address);
if(handlers != null && handlers.size() > 0){
for(Event