Skip to content

Commit

Permalink
added fail check for health
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Hightower committed Jul 9, 2015
1 parent 9750f03 commit 9338ae3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
*/
public interface ServiceQueue extends Stoppable, ServiceFlushable, Startable {



boolean failing();

void setFailing();

void recover();



Object service();

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.advantageous.qbit.service.health;

import io.advantageous.qbit.annotation.Service;
import io.advantageous.qbit.queue.QueueCallBackHandler;
import io.advantageous.qbit.service.ServiceContext;
import io.advantageous.qbit.util.Timer;

import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -46,7 +48,14 @@ private void check() {

if (duration > checkInIntervalMS) {
lastCheckTime = now;
healthServiceAsync.checkInOk(serviceName);

boolean failing = ServiceContext.serviceContext().currentService().failing();

if (!failing) {
healthServiceAsync.checkInOk(serviceName);
} else {
healthServiceAsync.checkIn(serviceName, HealthStatus.FAIL);
}
healthServiceAsync.clientProxyFlush();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public class BaseServiceQueueImpl implements ServiceQueue {
private Transformer<Response<Object>, Response> responseObjectTransformer = new NoOpResponseTransformer();
private final CallbackManager callbackManager;
private final QueueCallBackHandler queueCallBackHandler;
private final AtomicBoolean failing = new AtomicBoolean();

public BaseServiceQueueImpl(final String rootAddress,
final String serviceAddress,
Expand Down Expand Up @@ -576,6 +577,22 @@ public void flush() {
manageResponseQueue();
}


@Override
public boolean failing() {
return failing.get();
}

@Override
public void setFailing() {
failing.set(true);
}

@Override
public void recover() {
failing.set(false);
}

public Object service() {
return service;
}
Expand Down

0 comments on commit 9338ae3

Please sign in to comment.