Usage sharing is enabled by default if using a pipeline builder that is derived from FiftyOnePipelineBuilder. For instance, the DeviceDetectionPipelineBuilder. In this example, we show how to add a ShareUsageElement to a Pipeline using configuration.
As with all ElementBuilders, this can also be handled in code, using the ShareUsageBuilder. The commented section in the example demonstrates this.
The 51d.xml file contains all the configuration options. These are all optional, so each can be omitted if the default for that option is sufficient:
package pipeline.developerexamples.usagesharing;
import fiftyone.pipeline.core.configuration.PipelineOptions;
import fiftyone.pipeline.core.configuration.PipelineOptionsFactory;
import fiftyone.pipeline.core.flowelements.Pipeline;
import fiftyone.pipeline.core.flowelements.PipelineBuilder;
import fiftyone.pipeline.engines.services.HttpClient;
import fiftyone.pipeline.engines.services.HttpClientDefault;
import org.slf4j.ILoggerFactory;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.Objects;
public class Main {
private static final ILoggerFactory loggerFactory =
LoggerFactory.getILoggerFactory();
private static final HttpClient http = new HttpClientDefault();
public static class Example {
public void run() throws Exception {
System.out.println("Constructing pipeline from configuration file.");
System.out.println();
PipelineOptions options = PipelineOptionsFactory.getOptionsFromFile(
new File(Objects.requireNonNull(getClass().getClassLoader().
getResource("51d.xml")).getFile()));
Pipeline pipeline = new PipelineBuilder()
.addService(http)
.buildFromConfiguration(options);
System.out.println(
"Pipeline created with share usage element. Evidence processed " +
"with this pipeline will now be periodically shared with " +
"51Degrees using the specified configuration.");
}
}
public static void main(String[] args) throws Exception {
new Example().run();
}
}