|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package io.opentelemetry.javaagent.instrumentation.apacheelasticjob.v3_0; |
| 7 | + |
| 8 | +import org.apache.shardingsphere.elasticjob.api.ShardingContext; |
| 9 | + |
| 10 | +public final class ElasticJobProcessRequest { |
| 11 | + private final String jobName; |
| 12 | + private final String taskId; |
| 13 | + private final int shardingItemIndex; |
| 14 | + private final int shardingTotalCount; |
| 15 | + private final String shardingItemParameter; |
| 16 | + private final ElasticJobType jobType; |
| 17 | + private final Class<?> userJobClass; |
| 18 | + private final String userMethodName; |
| 19 | + |
| 20 | + private ElasticJobProcessRequest( |
| 21 | + ShardingContext shardingContext, |
| 22 | + ElasticJobType jobType, |
| 23 | + Class<?> userJobClass, |
| 24 | + String userMethodNam) { |
| 25 | + this.jobName = shardingContext.getJobName(); |
| 26 | + this.taskId = shardingContext.getTaskId(); |
| 27 | + this.shardingItemIndex = shardingContext.getShardingItem(); |
| 28 | + this.shardingTotalCount = shardingContext.getShardingTotalCount(); |
| 29 | + this.shardingItemParameter = emptyToNull(shardingContext.getShardingParameter()); |
| 30 | + this.jobType = jobType; |
| 31 | + this.userJobClass = userJobClass; |
| 32 | + this.userMethodName = userMethodNam; |
| 33 | + } |
| 34 | + |
| 35 | + private static String emptyToNull(String string) { |
| 36 | + return string == null || string.isEmpty() ? null : string; |
| 37 | + } |
| 38 | + |
| 39 | + public static ElasticJobProcessRequest create( |
| 40 | + ShardingContext shardingContext, |
| 41 | + ElasticJobType jobType, |
| 42 | + Class<?> userJobClass, |
| 43 | + String userMethodName) { |
| 44 | + return new ElasticJobProcessRequest(shardingContext, jobType, userJobClass, userMethodName); |
| 45 | + } |
| 46 | + |
| 47 | + public String getJobName() { |
| 48 | + return this.jobName; |
| 49 | + } |
| 50 | + |
| 51 | + public String getTaskId() { |
| 52 | + return this.taskId; |
| 53 | + } |
| 54 | + |
| 55 | + public int getShardingItemIndex() { |
| 56 | + return this.shardingItemIndex; |
| 57 | + } |
| 58 | + |
| 59 | + public int getShardingTotalCount() { |
| 60 | + return this.shardingTotalCount; |
| 61 | + } |
| 62 | + |
| 63 | + public String getShardingItemParameter() { |
| 64 | + return this.shardingItemParameter; |
| 65 | + } |
| 66 | + |
| 67 | + public ElasticJobType getJobType() { |
| 68 | + return this.jobType; |
| 69 | + } |
| 70 | + |
| 71 | + public Class<?> getUserJobClass() { |
| 72 | + return this.userJobClass; |
| 73 | + } |
| 74 | + |
| 75 | + public String getUserMethodName() { |
| 76 | + return this.userMethodName; |
| 77 | + } |
| 78 | +} |
0 commit comments