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;
import com.github.automately.java.data.EventBus;
import io.jsync.Async;
import io.jsync.AsyncFactory;
import io.jsync.Handler;
import io.jsync.VoidHandler;
import io.jsync.json.JsonObject;
import io.jsync.logging.Logger;
import io.jsync.logging.impl.LoggerFactory;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.concurrent.TimeUnit;
/**
* The MessageBus is a pretty powerful feature that Automately offers.
* It is basically a clustered messaging system that allows your code to
* communicate at scale.
*/
public class MessageBus {
private static long DEFAULT_TIMEOUT = TimeUnit.SECONDS.toMillis(25);
private final Async async = AsyncFactory.newAsync();
private final Logger logger = LoggerFactory.getLogger(MessageBus.class);
private boolean stopping = false;
private boolean initialized = false;
private EventBus eventBus = null;
public boolean stopping() {
return stopping;
}
public boolean initialized() {
return initialized && !stopping;
}
public MessageBus initialize(String publicKey, final Handler callback) {
return initialize(publicKey, null, callback);
}
public MessageBus initialize(String publicKey, String key, final Handler callback) {
if (publicKey == null || publicKey.isEmpty()) {
throw new RuntimeException("Your public api key cannot be empty.");
}
eventBus = new EventBus(async);
eventBus.onOpen(event -> authorize(event1 -> {
if (!event1) {
// We want to wait at least 30 seconds in case the connection is slow
final long loginFailTimer = async.setTimer(DEFAULT_TIMEOUT, event2 -> callback.handle(false));
Handler