use of ddf.catalog.source.SourceMonitor in project ddf by codice.
the class ConfluenceSource method isAvailable.
@Override
public boolean isAvailable() {
boolean isAvailable = false;
if (!lastAvailable || (lastAvailableDate.before(new Date(System.currentTimeMillis() - availabilityPollInterval)))) {
Response response = null;
try {
response = getClientFactory().getWebClient().head();
} catch (Exception e) {
LOGGER.debug("Web Client was unable to connect to endpoint.", e);
}
if (response != null && !(response.getStatus() >= HttpStatus.SC_NOT_FOUND || response.getStatus() == HttpStatus.SC_BAD_REQUEST || response.getStatus() == HttpStatus.SC_PAYMENT_REQUIRED)) {
isAvailable = true;
lastAvailableDate = new Date();
}
} else {
isAvailable = lastAvailable;
}
if (lastAvailable != isAvailable) {
for (SourceMonitor monitor : this.sourceMonitors) {
if (isAvailable) {
monitor.setAvailable();
} else {
monitor.setUnavailable();
}
}
}
lastAvailable = isAvailable;
return isAvailable;
}
use of ddf.catalog.source.SourceMonitor in project ddf by codice.
the class ConfluenceSourceTest method testAvaliabilitySourceMonitor.
@Test
public void testAvaliabilitySourceMonitor() throws Exception {
SourceMonitor monitor = mock(SourceMonitor.class);
WebClient mockClient = mock(WebClient.class);
when(factory.getWebClient()).thenReturn(mockClient);
Response mockResponse = mock(Response.class);
when(mockClient.head()).thenReturn(mockResponse);
when(mockResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
assertThat(confluence.isAvailable(monitor), is(true));
verify(monitor).setAvailable();
Thread.sleep(10);
assertThat(confluence.isAvailable(monitor), is(false));
verify(monitor).setUnavailable();
}
use of ddf.catalog.source.SourceMonitor in project ddf by codice.
the class RegistryStoreImpl method init.
public void init() {
SourceMonitor registrySourceMonitor = new SourceMonitor() {
@Override
public void setAvailable() {
try {
registryInfoQuery();
} catch (UnsupportedQueryException e) {
LOGGER.debug("Unable to query registry configurations, ", e);
}
}
@Override
public void setUnavailable() {
}
};
addSourceMonitor(registrySourceMonitor);
super.init();
}
use of ddf.catalog.source.SourceMonitor in project ddf by codice.
the class AbstractCswSource method availabilityChanged.
private void availabilityChanged(boolean isAvailable) {
if (isAvailable) {
LOGGER.debug("CSW source {} is available.", cswSourceConfiguration.getId());
} else {
LOGGER.debug("CSW source {} is unavailable.", cswSourceConfiguration.getId());
}
for (SourceMonitor monitor : this.sourceMonitors) {
if (isAvailable) {
LOGGER.debug("Notifying source monitor that CSW source {} is available.", cswSourceConfiguration.getId());
monitor.setAvailable();
} else {
LOGGER.debug("Notifying source monitor that CSW source {} is unavailable.", cswSourceConfiguration.getId());
monitor.setUnavailable();
}
}
}
use of ddf.catalog.source.SourceMonitor in project ddf by codice.
the class WfsSource method availabilityChanged.
private void availabilityChanged(boolean isAvailable) {
if (isAvailable) {
LOGGER.info("WFS source {} is available.", getId());
} else {
LOGGER.info("WFS source {} is unavailable.", getId());
}
for (SourceMonitor monitor : this.sourceMonitors) {
if (isAvailable) {
LOGGER.debug("Notifying source monitor that WFS source {} is available.", getId());
monitor.setAvailable();
} else {
LOGGER.debug("Notifying source monitor that WFS source {} is unavailable.", getId());
monitor.setUnavailable();
}
}
}
Aggregations