本文整理汇总了Java中org.springframework.batch.core.JobParametersBuilder.addLong方法的典型用法代码示例。如果您正苦于以下问题:Java JobParametersBuilder.addLong方法的具体用法?Java JobParametersBuilder.addLong怎么用?Java JobParametersBuilder.addLong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.batch.core.JobParametersBuilder
的用法示例。
在下文中一共展示了JobParametersBuilder.addLong方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepareJobParameters
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
/**
* Helper method converting the Camel message headers into the Spring Batch parameters map. Date, Long and Double
* header values are converted to the appropriate types. All the other header values are converted to string
* representation.
*
* @param headers Camel message header to be converted
* @return Camel message headers converted into the Spring Batch parameters map
*/
protected JobParameters prepareJobParameters(Map<String, Object> headers) {
JobParametersBuilder parametersBuilder = new JobParametersBuilder();
for (Map.Entry<String, Object> headerEntry : headers.entrySet()) {
String headerKey = headerEntry.getKey();
Object headerValue = headerEntry.getValue();
if (headerValue instanceof Date) {
parametersBuilder.addDate(headerKey, (Date) headerValue);
} else if (headerValue instanceof Long) {
parametersBuilder.addLong(headerKey, (Long) headerValue);
} else if (headerValue instanceof Double) {
parametersBuilder.addDouble(headerKey, (Double) headerValue);
} else if (headerValue != null) {
parametersBuilder.addString(headerKey, headerValue.toString());
} else {
// if the value is null we just put String with null value here to avoid the NPE
parametersBuilder.addString(headerKey, null);
}
}
JobParameters jobParameters = parametersBuilder.toJobParameters();
log.debug("Prepared parameters for Spring Batch job: {}", jobParameters);
return jobParameters;
}
示例2: unmarshal
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@Override
public JobParameters unmarshal(AdaptedJobParameters params) throws Exception {
JobParametersBuilder jobParametersBuilder = new JobParametersBuilder();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
for (AdaptedJobParameters.AdaptedJobParameter param : params.getParameters()) {
switch (param.type) {
case "STRING":
jobParametersBuilder.addString(param.key, param.value, param.identifier);
break;
case "DATE":
jobParametersBuilder.addDate(param.key, df.parse(param.value), param.identifier);
break;
case "DOUBLE":
jobParametersBuilder.addDouble(param.key, Double.valueOf(param.value), param.identifier);
break;
case "LONG":
jobParametersBuilder.addLong(param.key, Long.valueOf(param.value), param.identifier);
break;
}
}
return jobParametersBuilder.toJobParameters();
}
示例3: getJobParameters
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
public static JobParameters getJobParameters() {
JobParametersBuilder jobParametersBuilder = new JobParametersBuilder();
if (jobParameters.isEmpty()) {
jobParametersBuilder.addLong("id", 1L, true);
jobParametersBuilder.addString("stringTest", "Joe Cool", true);
jobParametersBuilder.addDate("start", new Date(), false);
jobParametersBuilder.addLong("longTest", 1239L, false);
jobParametersBuilder.addDouble("doubleTest", 1.35D, false);
jobParameters = jobParametersBuilder.toJobParameters();
} else {
JobParametersTestUtils utils = new JobParametersTestUtils();
jobParameters = utils.getNext(jobParameters);
}
return jobParameters;
}
示例4: getJobParametersFromJobMap
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
/**
* Copy parameters that are of the correct type over to
* {@link org.springframework.batch.core.launch.JobLauncher JobParameters},
* ignoring jobName.
*
* @return a JobParameters instance
*/
private JobParameters getJobParametersFromJobMap(Map<String, Object> jobDataMap, JobParameters sPreviousJobParameters) {
JobParametersBuilder builder = (sPreviousJobParameters != null) ? new JobParametersBuilder(sPreviousJobParameters) : new JobParametersBuilder();
for (Entry<String, Object> entry : jobDataMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value instanceof String && !key.equals(JOB_NAME)) {
builder.addString(key, (String) value);
} else if (value instanceof Float || value instanceof Double) {
builder.addDouble(key, ((Number) value).doubleValue());
} else if (value instanceof Integer || value instanceof Long) {
builder.addLong(key, ((Number) value).longValue());
} else if (value instanceof Date) {
builder.addDate(key, (Date) value);
} else {
LOGGER.debug("JobDataMap contains values which are not job parameters (ignoring).");
}
}
return builder.toJobParameters();
}
示例5: requestJob3
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@RequestMapping("/job3/{input_file_name}")
@ResponseBody
String requestJob3(@PathVariable("input_file_name") String inputFileName) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException{
JobParametersBuilder jobParametersBuilder = new JobParametersBuilder();
jobParametersBuilder.addString("INPUT_FILE_PATH", inputFileName);
jobParametersBuilder.addLong("TIMESTAMP",new Date().getTime());
jobLauncher.run(job3, jobParametersBuilder.toJobParameters());
return "Job3!";
}
开发者ID:pauldeng,项目名称:aws-elastic-beanstalk-worker-spring-boot-spring-batch-template,代码行数:11,代码来源:RESTController.java
示例6: main
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
public static void main(String[] args)
{
try
{
ServerConfigHelper.initConfig();
ServerConfigHelper.initLog4j("log4j-debug.xml");
ClassPathXmlApplicationContext ctx = Util.initContext("batch/new-context.xml");
JobLauncher launch = ctx.getBean(JobLauncher.class);
JobExplorer epl=ctx.getBean(JobExplorer.class);
JobRegistry reg =ctx.getBean(JobRegistry.class);
JobOperator jop=ctx.getBean(JobOperator.class);
ClassPathXmlApplicationContext ctx2 = Util.initContext(false,"batch/job-context.xml","batch-file-prod.xml");
ctx2.setParent(ctx);
ctx2.refresh();
Job job = ctx2.getBean(Job.class);
JobParametersBuilder build = new JobParametersBuilder();
build.addLong("Id", System.currentTimeMillis());
JobExecution exec= launch.run(job,build.toJobParameters());
System.out.println(reg.getJobNames());
Thread.sleep(Long.MAX_VALUE);
}
catch (Exception e)
{
e.printStackTrace();
}
}
示例7: runJobTwiceTest
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@Test
public void runJobTwiceTest() throws Exception {
JobParametersBuilder jpb = new JobParametersBuilder();
jpb.addString("output_collections", "monster", false);
jpb.addLong("run_id", 1L, true);
JobExecution jobExecution = getJobLauncherTestUtils().launchJob(jpb.toJobParameters());
jpb.addLong("run_id", 2L);
JobExecution jobExecution2 = getJobLauncherTestUtils().launchJob(jpb.toJobParameters());
Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
Assert.assertEquals(BatchStatus.COMPLETED, jobExecution2.getStatus());
}
示例8: convert
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@Override
public JobParameters convert(final JsonNode root) {
final JobParametersBuilder builder = new JobParametersBuilder();
final Iterator<String> it = root.fieldNames();
while (it.hasNext()) {
final String paramName = it.next();
final JsonNode param = root.get(paramName);
final ParameterType type = ParameterType.valueOf(param.get("type").textValue());
final JsonNode value = param.get("value");
final boolean identifying = param.get("identifying").booleanValue();
switch (type) {
case STRING:
builder.addString(paramName, value.textValue(), identifying);
break;
case DATE:
builder.addDate(paramName, new Date(value.longValue()), identifying);
break;
case DOUBLE:
builder.addDouble(paramName, value.doubleValue(), identifying);
break;
case LONG:
builder.addLong(paramName, value.longValue(), identifying);
break;
default:
throw new IllegalArgumentException("Unknown job parameter type: " + type);
}
}
return builder.toJobParameters();
}
示例9: getJobParametersFromJobMap
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
private JobParameters getJobParametersFromJobMap(Map<String, Object> jobDataMap) {
JobParametersBuilder builder = new JobParametersBuilder();
for (Entry<String, Object> entry : jobDataMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value instanceof String && !key.equals(Constants.JOB_NAME)) {
builder.addString(key, (String) value);
} else if (value instanceof Float || value instanceof Double) {
builder.addDouble(key, ((Number) value).doubleValue());
} else if (value instanceof Integer || value instanceof Long) {
builder.addLong(key, ((Number) value).longValue());
} else if (value instanceof Date) {
builder.addDate(key, (Date) value);
} else {
// JobDataMap contains values which are not job parameters
// (ignoring)
}
}
// Needs a unique job parameter to rerun the completed job
builder.addDate(Constants.JOB_RUN_DATE, new Date());
return builder.toJobParameters();
}
示例10: sqsMessageHandler
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@RequestMapping(value="/sqs", method=RequestMethod.POST)
@ResponseBody
public ResponseEntity<Void> sqsMessageHandler(
@RequestHeader(value="User-Agent",required=false) String sqsdMessageUserAgent,
@RequestHeader(value="X-Aws-Sqsd-Msgid",required=false) String sqsdMessageId,
@RequestHeader(value="X-Aws-Sqsd-Queue",required=false) String sqsdMessageQueueName,
@RequestHeader(value="X-Aws-Sqsd-First-Received-At",required=false) String sqsdMessageReceivedTimestamp,
@RequestHeader(value="X-Aws-Sqsd-Receive-Count",required=false) int sqsdMessageCounts,
@RequestHeader(value="Content-Type",required=false) String sqsdMessageContentType,
@RequestHeader(value="X-Aws-Sqsd-Taskname",required=false) String sqsdMessagePeriodicTaskName,
@RequestHeader(value="X-Aws-Sqsd-Attr-(message-attribute-name)",required=false) String sqsdMessageCustomAttribute1,
@RequestHeader(value="X-Aws-Sqsd-Scheduled-At",required=false) String sqsdMessageTaskSchdeuleTime,
@RequestHeader(value="X-Aws-Sqsd-Sender-Id",required=false) String sqsdMessageSenderId,
@RequestBody String sqsdMessageBody) {
try{
File localFile = retrieveS3File(sqsdMessageBody);
if(localFile != null){
System.out.println("File downloaded: " + localFile.getAbsolutePath());
// verify it
File verifiedFile = verify(localFile);
if(verifiedFile != null){
// extract it
File extractedFile = extract(verifiedFile);
if(extractedFile != null){
// process it by launch Spring Batch job. It is a async job and will return immediately.
JobParametersBuilder jobParametersBuilder = new JobParametersBuilder();
jobParametersBuilder.addString("INPUT_FILE_PATH", extractedFile.getAbsolutePath());
jobParametersBuilder.addLong("TIMESTAMP",new Date().getTime());
jobLauncher.run(job3, jobParametersBuilder.toJobParameters());
}
}
}
return new ResponseEntity<Void>(HttpStatus.OK);
}catch(Exception ex){
String errorMessage;
errorMessage = ex + " <== error";
System.out.println("XXXXXXXXX");
System.out.println(errorMessage);
System.out.println("XXXXXXXXX");
return new ResponseEntity<Void>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
开发者ID:pauldeng,项目名称:aws-elastic-beanstalk-worker-spring-boot-spring-batch-template,代码行数:52,代码来源:RESTController.java
示例11: getNext
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@Override
public JobParameters getNext(JobParameters parameters) {
final JobParametersBuilder jobParametersBuilder = new JobParametersBuilder(parameters);
jobParametersBuilder.addLong("time", LocalTime.now().toNanoOfDay());
return jobParametersBuilder.toJobParameters();
}
开发者ID:przodownikR1,项目名称:springBatchBootJavaConfigkata,代码行数:7,代码来源:SimpleJobParametersIncrementer.java
示例12: getNext
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@Override
public JobParameters getNext(JobParameters parameters) {
JobParametersBuilder builder = new JobParametersBuilder(parameters);
builder.addLong("id", parameters.getLong("id") + 1);
return builder.toJobParameters();
}