![JAR search and dependency download from the Maven repository](/logo.png)
com.github.ltsopensource.jobclient.JobClientBuilder Maven / Gradle / Ivy
package com.github.ltsopensource.jobclient;
import com.github.ltsopensource.autoconfigure.PropertiesConfigurationFactory;
import com.github.ltsopensource.core.cluster.AbstractNodeBuilder;
import com.github.ltsopensource.core.commons.utils.CollectionUtils;
import com.github.ltsopensource.core.commons.utils.StringUtils;
import com.github.ltsopensource.core.properties.JobClientProperties;
import com.github.ltsopensource.jobclient.support.JobCompletedHandler;
import java.util.Map;
/**
* @author Robert HG ([email protected]) on 4/21/16.
*/
public class JobClientBuilder extends AbstractNodeBuilder {
private JobCompletedHandler jobCompletedHandler;
public JobClientBuilder setJobCompletedHandler(JobCompletedHandler jobCompletedHandler) {
this.jobCompletedHandler = jobCompletedHandler;
return this;
}
@Override
protected JobClient build0() {
JobClientProperties properties = PropertiesConfigurationFactory
.createPropertiesConfiguration(JobClientProperties.class, locations);
JobClient jobClient = buildByProperties(properties);
if (jobCompletedHandler != null) {
jobClient.setJobCompletedHandler(jobCompletedHandler);
}
return jobClient;
}
public static JobClient buildByProperties(JobClientProperties properties) {
properties.checkProperties();
JobClient jobClient;
if (properties.isUseRetryClient()) {
jobClient = new RetryJobClient();
} else {
jobClient = new JobClient();
}
jobClient.setRegistryAddress(properties.getRegistryAddress());
if (StringUtils.isNotEmpty(properties.getClusterName())) {
jobClient.setClusterName(properties.getClusterName());
}
if (StringUtils.isNotEmpty(properties.getIdentity())) {
jobClient.setIdentity(properties.getIdentity());
}
if (StringUtils.isNotEmpty(properties.getNodeGroup())) {
jobClient.setNodeGroup(properties.getNodeGroup());
}
if (StringUtils.isNotEmpty(properties.getDataPath())) {
jobClient.setDataPath(properties.getDataPath());
}
if (StringUtils.isNotEmpty(properties.getBindIp())) {
jobClient.setBindIp(properties.getBindIp());
}
if (CollectionUtils.isNotEmpty(properties.getConfigs())) {
for (Map.Entry entry : properties.getConfigs().entrySet()) {
jobClient.addConfig(entry.getKey(), entry.getValue());
}
}
return jobClient;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy