use of org.opennms.core.tasks.Callback in project opennms by OpenNMS.
the class IpInterfaceScan method servicePersister.
/**
* <p>servicePersister</p>
*
* @param currentPhase a {@link org.opennms.core.tasks.BatchTask} object.
* @param serviceName a {@link java.lang.String} object.
* @return a {@link org.opennms.core.tasks.Callback} object.
*/
public static Callback<Boolean> servicePersister(final BatchTask currentPhase, final ProvisionService service, final PluginConfig detectorConfig, final int nodeId, final InetAddress address) {
return new Callback<Boolean>() {
@Override
public void accept(final Boolean serviceDetected) {
final String hostAddress = str(address);
final String serviceName = detectorConfig.getName();
LOG.info("Attempted to detect service {} on address {}: {}", serviceName, hostAddress, serviceDetected);
if (serviceDetected) {
/*
* TODO: Convert this sequence into a chain of CompletableFutures
*/
currentPhase.getBuilder().addSequence(new RunInBatch() {
@Override
public void run(final BatchTask batch) {
if ("SNMP".equals(serviceName)) {
service.setIsPrimaryFlag(nodeId, hostAddress);
}
}
}, new RunInBatch() {
@Override
public void run(final BatchTask batch) {
service.addMonitoredService(nodeId, hostAddress, serviceName);
}
}, new RunInBatch() {
@Override
public void run(final BatchTask batch) {
// NMS-3906
service.updateMonitoredServiceState(nodeId, hostAddress, serviceName);
}
});
}
}
@Override
public Boolean apply(final Throwable t) {
LOG.info("Exception occurred while trying to detect service {} on address {}", detectorConfig.getName(), str(address), t);
return false;
}
};
}
Aggregations