Add routine to check ws connection to zeppelinhub is open, if not open it (keep trying)

This commit is contained in:
Anthony Corbacho 2016-05-11 16:42:07 +09:00 committed by Khalid Huseynov
parent 27a4042e12
commit 8ad482d2c3
2 changed files with 28 additions and 27 deletions

View file

@ -32,6 +32,7 @@ import org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.Zeppelin
import org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.ZeppelinhubMessage;
import org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.scheduler.SchedulerService;
import org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.scheduler.ZeppelinHubHeartbeat;
import org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.scheduler.ZeppelinhubConnection;
import org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.session.ZeppelinhubSession;
import org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.utils.ZeppelinhubUtils;
import org.apache.zeppelin.notebook.socket.Message;
@ -112,6 +113,15 @@ public class ZeppelinhubClient {
}
}
public void reconnectIfConectionLost() {
if (!isConnectedToZeppelinhub()) {
LOG.info("Zeppelinhub connection is not open, opening it");
zeppelinhubSession = connect();
} else {
LOG.debug("Connection to Zeppelinhub is still open");
}
}
public String getToken() {
return this.zeppelinhubToken;
}
@ -158,6 +168,7 @@ public class ZeppelinhubClient {
private void addRoutines() {
schedulerService.add(ZeppelinHubHeartbeat.newInstance(this), 10, 23);
schedulerService.add(ZeppelinhubConnection.newInstance(this), 5, 10);
}
public void handleMsgFromZeppelinHub(String message) {

View file

@ -16,41 +16,31 @@
*/
package org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.scheduler;
import org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.ZeppelinhubClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Check and test if zeppelinhub connection is still open.
*
* @author anthonyc
*
*
public class ZeppelinhubConntection extends Retryable implements Runnable {
private static final Logger LOG = LoggerFactory.getLogger(ZeppelinhubConntection.class);
private long delay;
private long interval;
private long timeout;
private final TimeUnit timeUnit = TimeUnit.MILLISECONDS;
*/
public class ZeppelinhubConnection implements Runnable {
private static final Logger LOG = LoggerFactory.getLogger(ZeppelinhubConnection.class);
private ZeppelinhubClient client;
private ZeppelinhubConntection(Session session, long delay, long interval, long timeout) {
ZeppelinhubSession = session;
this.delay = delay;
this.interval = interval;
this.timeout = timeout;
public static ZeppelinhubConnection newInstance(ZeppelinhubClient client) {
return new ZeppelinhubConnection(client);
}
private ZeppelinhubConnection(ZeppelinhubClient client) {
this.client = client;
}
@Override
public void run() {
try {
execute(delay, interval, timeout);
} catch (Exception e) {
LOG.error(
"Failed to execute retryable ZeppelinHub connection task with interval {} after {} ms {}",
interval, timeout, e);
}
}
@Override
protected void attempt() throws Exception {
LOG.info("Connecting to ZeppelinHub");
LOG.debug("Checking if Zeppelinbhub connection is open");
client.reconnectIfConectionLost();
}
}
*/