in qa/src/main/java/org/apache/brooklyn/qa/load/SimulatedNginxControllerImpl.java [64:122]
public void connectSensors() {
boolean simulateEntity = getConfig(SIMULATE_ENTITY);
boolean simulateExternalMonitoring = getConfig(SIMULATE_EXTERNAL_MONITORING);
if (!simulateEntity && !simulateExternalMonitoring) {
super.connectSensors();
return;
}
// From AbstractController.connectSensors
if (getUrl()==null) {
sensors().set(MAIN_URI, URI.create(inferUrl()));
sensors().set(ROOT_URL, inferUrl());
}
addServerPoolMemberTrackingPolicy();
// From NginxController.connectSensors
ConfigToAttributes.apply(this);
if (!simulateExternalMonitoring) {
// if simulating entity, then simulate work of periodic HTTP request; TODO but not parsing JSON response
String uriToPoll = (simulateEntity) ? "http://localhost:8081" : getAttribute(MAIN_URI).toString();
httpFeed = HttpFeed.builder()
.entity(this)
.period(getConfig(HTTP_POLL_PERIOD))
.baseUri(uriToPoll)
.poll(new HttpPollConfig<Boolean>(SERVICE_UP)
.onSuccess(Functions.constant(true))
.onFailureOrException(Functions.constant(true)))
.build();
}
functionFeed = FunctionFeed.builder()
.entity(this)
.period(getConfig(HTTP_POLL_PERIOD))
.poll(new FunctionPollConfig<Boolean,Boolean>(SERVICE_UP)
.callable(new Callable<Boolean>() {
@Override
public Boolean call() {
return true;
}}))
.build(false);
// Can guarantee that parent/managementContext has been set
Group urlMappings = getConfig(URL_MAPPINGS);
if (urlMappings != null) {
// Listen to the targets of each url-mapping changing
subscriptions().subscribeToMembers(urlMappings, UrlMapping.TARGET_ADDRESSES, new SensorEventListener<Collection<String>>() {
@Override public void onEvent(SensorEvent<Collection<String>> event) {
updateNeeded();
}
});
// Listen to url-mappings being added and removed
urlMappingsMemberTrackerPolicy = policies().add(PolicySpec.create(UrlMappingsMemberTrackerPolicy.class)
.configure("group", urlMappings));
}
}