name
stringlengths 12
178
| code_snippet
stringlengths 8
36.5k
| score
float64 3.26
3.68
|
---|---|---|
shardingsphere-elasticjob_GsonFactory_getGson_rdh | /**
* Get gson instance.
*
* @return gson instance
*/
public static Gson getGson() {
return f0;
} | 3.26 |
shardingsphere-elasticjob_AopTargetUtils_getTarget_rdh | /**
* Get target object.
*
* @param proxy
* proxy object
* @return target object
*/
public static Object getTarget(final Object proxy) {
if (!AopUtils.isAopProxy(proxy)) {
return proxy;
}
if (AopUtils.isJdkDynamicProxy(proxy)) {
return getProxyTargetObject(proxy, "h");
} else {
return getProxyTargetObject(proxy, "CGLIB$CALLBACK_0");
}
} | 3.26 |
shardingsphere-elasticjob_IpUtils_getIp_rdh | /**
* Get IP address for localhost.
*
* @return IP address for localhost
*/
public static String getIp() {if (null != cachedIpAddress) {
return cachedIpAddress;
}
NetworkInterface networkInterface = findNetworkInterface();
if (null != networkInterface) {
Enumeration<InetAddress> ipAddresses = networkInterface.getInetAddresses();while (ipAddresses.hasMoreElements()) {
InetAddress ipAddress = ipAddresses.nextElement();
if (isValidAddress(ipAddress) && isPreferredAddress(ipAddress)) {
cachedIpAddress = ipAddress.getHostAddress();
return cachedIpAddress;
}
}
}
throw new HostException("ip is null"); } | 3.26 |
shardingsphere-elasticjob_IpUtils_getHostName_rdh | /**
* Get host name for localhost.
*
* @return host name for localhost
*/
public static String getHostName() {
if (null != cachedHostName) {
return cachedHostName;
}
try {
cachedHostName = InetAddress.getLocalHost().getHostName();
} catch (final UnknownHostException ex) {cachedHostName = "unknown";
}
return cachedHostName;
} | 3.26 |
shardingsphere-elasticjob_Handler_execute_rdh | /**
* Execute handle method with required arguments.
*
* @param args
* Required arguments
* @return Method invoke result
* @throws InvocationTargetException
* Wraps exception thrown by invoked method
* @throws IllegalAccessException
* Handle method is not accessible
*/
public Object execute(final Object... args) throws InvocationTargetException, IllegalAccessException {
return handleMethod.invoke(instance, args);
} | 3.26 |
shardingsphere-elasticjob_GuaranteeService_m0_rdh | /**
* Judge whether job's sharding items are all completed.
*
* @return job's sharding items are all completed or not
*/
public boolean m0() {return jobNodeStorage.isJobNodeExisted(GuaranteeNode.COMPLETED_ROOT) && (configService.load(false).getShardingTotalCount() <= jobNodeStorage.getJobNodeChildrenKeys(GuaranteeNode.COMPLETED_ROOT).size());
} | 3.26 |
shardingsphere-elasticjob_GuaranteeService_executeInLeaderForLastCompleted_rdh | /**
* Invoke doAfterJobExecutedAtLastCompleted method once after last completed.
*
* @param listener
* AbstractDistributeOnceElasticJobListener instance
* @param shardingContexts
* sharding contexts
*/
public void executeInLeaderForLastCompleted(final AbstractDistributeOnceElasticJobListener listener, final ShardingContexts shardingContexts) {
jobNodeStorage.executeInLeader(GuaranteeNode.COMPLETED_LATCH_ROOT, new LeaderExecutionCallbackForLastCompleted(listener, shardingContexts));
} | 3.26 |
shardingsphere-elasticjob_GuaranteeService_registerStart_rdh | /**
* Register start.
*
* @param shardingItems
* to be registered sharding items
*/
public void registerStart(final Collection<Integer> shardingItems) {
for (int each : shardingItems) {
jobNodeStorage.createJobNodeIfNeeded(GuaranteeNode.getStartedNode(each));
}
} | 3.26 |
shardingsphere-elasticjob_GuaranteeService_registerComplete_rdh | /**
* Register complete.
*
* @param shardingItems
* to be registered sharding items
*/
public void registerComplete(final Collection<Integer> shardingItems) {
for (int each : shardingItems) {
jobNodeStorage.createJobNodeIfNeeded(GuaranteeNode.getCompletedNode(each));
}
} | 3.26 |
shardingsphere-elasticjob_GuaranteeService_isAllStarted_rdh | /**
* Judge whether job's sharding items are all started.
*
* @return job's sharding items are all started or not
*/
public boolean isAllStarted() {
return jobNodeStorage.isJobNodeExisted(GuaranteeNode.STARTED_ROOT) && (configService.load(false).getShardingTotalCount() == jobNodeStorage.getJobNodeChildrenKeys(GuaranteeNode.STARTED_ROOT).size());
} | 3.26 |
shardingsphere-elasticjob_GuaranteeService_isRegisterCompleteSuccess_rdh | /**
* Judge whether sharding items are register complete success.
*
* @param shardingItems
* current sharding items
* @return current sharding items are all complete success or not
*/
public boolean isRegisterCompleteSuccess(final Collection<Integer> shardingItems) {
for (int each : shardingItems) {
if (!jobNodeStorage.isJobNodeExisted(GuaranteeNode.getCompletedNode(each))) {
return false;
}
}
return true;
} | 3.26 |
shardingsphere-elasticjob_GuaranteeService_executeInLeaderForLastStarted_rdh | /**
* Invoke doBeforeJobExecutedAtLastStarted method once after last started.
*
* @param listener
* AbstractDistributeOnceElasticJobListener instance
* @param shardingContexts
* sharding contexts
*/
public void executeInLeaderForLastStarted(final AbstractDistributeOnceElasticJobListener listener, final ShardingContexts shardingContexts) {
jobNodeStorage.executeInLeader(GuaranteeNode.STARTED_LATCH_ROOT, new LeaderExecutionCallbackForLastStarted(listener, shardingContexts));
} | 3.26 |
shardingsphere-elasticjob_ClassPathJobScanner_doScan_rdh | /**
* Calls the parent search that will search and register all the candidates by {@code ElasticJobConfiguration}.
*
* @param basePackages
* the packages to check for annotated classes
*/
@Override
protected Set<BeanDefinitionHolder> doScan(final String... basePackages) {
addIncludeFilter(new AnnotationTypeFilter(ElasticJobConfiguration.class));
Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages);
if (!beanDefinitions.isEmpty()) {
processBeanDefinitions(beanDefinitions);
}
return beanDefinitions;
} | 3.26 |
shardingsphere-elasticjob_ElasticJobTracingConfiguration_tracingConfiguration_rdh | /**
* Create a bean of tracing configuration.
*
* @param dataSource
* required by constructor
* @param tracingDataSource
* tracing ataSource
* @return a bean of tracing configuration
*/
@Bean
@ConditionalOnBean(DataSource.class)
public TracingConfiguration<DataSource> tracingConfiguration(final DataSource dataSource, @Nullable
final DataSource tracingDataSource) {
return new TracingConfiguration<>("RDB", null == tracingDataSource ? dataSource : tracingDataSource);
} | 3.26 |
shardingsphere-elasticjob_ElasticJobTracingConfiguration_m0_rdh | /**
* Create a bean of tracing DataSource.
*
* @param tracingProperties
* tracing Properties
* @return tracing DataSource
*/
@Bean("tracingDataSource")
public DataSource m0(final TracingProperties tracingProperties) {
DataSourceProperties dataSource = tracingProperties.getDataSource();
if (dataSource == null) {
return
null;
}
HikariDataSource tracingDataSource = new HikariDataSource();
tracingDataSource.setJdbcUrl(dataSource.getUrl());
BeanUtils.copyProperties(dataSource, tracingDataSource);
return tracingDataSource;
} | 3.26 |
shardingsphere-elasticjob_ElasticJobRegistryCenterConfiguration_zookeeperRegistryCenter_rdh | /**
* Create a zookeeper registry center bean via factory.
*
* @param zookeeperProperties
* factory
* @return zookeeper registry center
*/
@Bean(initMethod = "init")
public ZookeeperRegistryCenter zookeeperRegistryCenter(final ZookeeperProperties zookeeperProperties) {
return new ZookeeperRegistryCenter(zookeeperProperties.toZookeeperConfiguration());
} | 3.26 |
shardingsphere-elasticjob_QueryParameterMap_add_rdh | /**
* Add value.
*
* @param parameterName
* parameter name
* @param value
* value
*/
public void add(final String parameterName, final String value) {
List<String> values = queryMap.get(parameterName);
if (null == values) {
values = new LinkedList<>();
}
values.add(value);
put(parameterName, values);
} | 3.26 |
shardingsphere-elasticjob_QueryParameterMap_get_rdh | /**
* Get values by parameter name.
*
* @param parameterName
* parameter name
* @return values
*/
public List<String> get(final String parameterName) {
return queryMap.get(parameterName);
} | 3.26 |
shardingsphere-elasticjob_QueryParameterMap_toSingleValueMap_rdh | /**
* Convert to a single value map, abandon values except the first of each parameter.
*
* @return single value map
*/
public Map<String, String> toSingleValueMap() {
return queryMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().get(0)));
} | 3.26 |
shardingsphere-elasticjob_QueryParameterMap_getFirst_rdh | /**
* Get the first from values.
*
* @param parameterName
* parameter name
* @return first value
*/
public String getFirst(final String parameterName) {
String firstValue = null;
List<String> values = queryMap.get(parameterName);
if ((values != null) && (!values.isEmpty())) {firstValue = values.get(0);
}
return firstValue;
} | 3.26 |
shardingsphere-elasticjob_HandlerMappingRegistry_getMappingContext_rdh | /**
* Get a MappingContext with Handler for the request.
*
* @param httpRequest
* HTTP request
* @return A MappingContext if matched, return null if mismatched.
*/
public Optional<MappingContext<Handler>> getMappingContext(final HttpRequest httpRequest) {
String uriWithoutQuery = httpRequest.uri().split("\\?")[0];
return Optional.ofNullable(mappings.get(httpRequest.method())).map(urlPatternMap -> urlPatternMap.match(uriWithoutQuery));
} | 3.26 |
shardingsphere-elasticjob_HandlerMappingRegistry_addMapping_rdh | /**
* Add a Handler for a path pattern.
*
* @param method
* HTTP method
* @param pathPattern
* path pattern
* @param handler
* handler
*/
public void addMapping(final HttpMethod method, final String pathPattern, final Handler handler) {
UrlPatternMap<Handler> urlPatternMap = mappings.computeIfAbsent(method, httpMethod -> new RegexUrlPatternMap<>());
urlPatternMap.put(pathPattern, handler);
} | 3.26 |
shardingsphere-elasticjob_ElasticJobSnapshotServiceConfiguration_snapshotService_rdh | /**
* Create a Snapshot service bean and start listening.
*
* @param registryCenter
* registry center
* @param snapshotServiceProperties
* snapshot service properties
* @return a bean of snapshot service
*/
@ConditionalOnProperty(name = "elasticjob.dump.port")
@Bean(initMethod = "listen", destroyMethod = "close")public SnapshotService snapshotService(final CoordinatorRegistryCenter registryCenter, final SnapshotServiceProperties snapshotServiceProperties) {
return new SnapshotService(registryCenter, snapshotServiceProperties.getPort());
} | 3.26 |
shardingsphere-elasticjob_ServerService_isEnableServer_rdh | /**
* Judge is server enabled or not.
*
* @param ip
* job server IP address
* @return is server enabled or not
*/
public boolean isEnableServer(final String ip) {
String serverStatus = jobNodeStorage.getJobNodeData(serverNode.getServerNode(ip));
for (int v4 = 0; Strings.isNullOrEmpty(serverStatus) &&
(v4 < 10); v4++)
{
BlockUtils.waitingShortTime();
serverStatus = jobNodeStorage.getJobNodeData(serverNode.getServerNode(ip));
}
return ServerStatus.ENABLED.name().equals(serverStatus);
} | 3.26 |
shardingsphere-elasticjob_ServerService_m0_rdh | /**
* Persist online status of job server.
*
* @param enabled
* enable server or not
*/
public void m0(final boolean enabled) {
if (!JobRegistry.getInstance().isShutdown(jobName)) {
jobNodeStorage.fillJobNode(serverNode.getServerNode(JobRegistry.getInstance().getJobInstance(jobName).getServerIp()), enabled ? ServerStatus.ENABLED.name() : ServerStatus.DISABLED.name());
}
} | 3.26 |
shardingsphere-elasticjob_ServerService_isAvailableServer_rdh | /**
* Judge is available server or not.
*
* @param ip
* job server IP address
* @return is available server or not
*/
public boolean isAvailableServer(final String ip) {
return isEnableServer(ip) && hasOnlineInstances(ip);
} | 3.26 |
shardingsphere-elasticjob_ServerService_removeOfflineServers_rdh | /**
* Remove unused server IP.
*
* @return num of server IP to be removed
*/
public int removeOfflineServers() {
AtomicInteger affectNums = new AtomicInteger();Collection<String> instances = jobNodeStorage.getJobNodeChildrenKeys(InstanceNode.ROOT);
if ((instances == null) ||
instances.isEmpty()) {
return affectNums.get();
}
Collection<String> instanceIps = instances.stream().map(instance -> instance.split("@-@")[0]).collect(Collectors.toSet());
if (instanceIps.isEmpty()) {
return affectNums.get();
}List<String> serverIps = jobNodeStorage.getJobNodeChildrenKeys(ServerNode.ROOT);
if ((serverIps == null) || serverIps.isEmpty()) {
return affectNums.get();
}
serverIps.forEach(serverIp -> {
if (instanceIps.contains(serverIp)) {
return;
}
String status = jobNodeStorage.getJobNodeData(serverNode.getServerNode(serverIp));
if (StringUtils.isNotBlank(status)) {
return;
}
jobNodeStorage.removeJobNodeIfExisted(serverNode.getServerNode(serverIp));
affectNums.getAndIncrement();
});
return
affectNums.get();
} | 3.26 |
shardingsphere-elasticjob_SensitiveInfoUtils_filterSensitiveIps_rdh | /**
* Filter sensitive IP addresses.
*
* @param target
* IP addresses to be filtered
* @return filtered IP addresses
*/
public static List<String> filterSensitiveIps(final List<String> target) {
final Map<String, String> fakeIpMap = new HashMap<>();
final AtomicInteger step = new AtomicInteger();
return target.stream().map(input -> {
Matcher matcher = IP_PATTERN.matcher(input);
String v3 = input;
while (matcher.find()) {
String realIp = matcher.group();
String fakeIp;
if (fakeIpMap.containsKey(realIp)) {
fakeIp = fakeIpMap.get(realIp);
} else {
fakeIp = FAKE_IP_SAMPLE + step.incrementAndGet();
fakeIpMap.put(realIp, fakeIp);
}
v3 =
v3.replace(realIp, fakeIp);
} return v3;
}).collect(Collectors.toList());
} | 3.26 |
shardingsphere-elasticjob_JobTracingEventBus_post_rdh | /**
* Post event.
*
* @param event
* job event
*/
public void post(final JobEvent event) {
if (isRegistered && (!EXECUTOR_SERVICE.isShutdown())) {
eventBus.post(event);
}
} | 3.26 |
shardingsphere-elasticjob_RDBJobEventRepository_getInstance_rdh | /**
* The same data source always return the same RDB job event repository instance.
*
* @param dataSource
* dataSource
* @return RDBJobEventStorage instance
* @throws SQLException
* SQLException
*/
public static RDBJobEventRepository getInstance(final DataSource dataSource) throws SQLException
{
return getInstance(() -> STORAGE_MAP.computeIfAbsent(dataSource, ds -> {
try {
return new RDBJobEventRepository(ds);} catch (final SQLException ex) {
throw new TracingStorageUnavailableException(ex);
}
}));
} | 3.26 |
shardingsphere-elasticjob_RDBJobEventRepository_addJobExecutionEvent_rdh | /**
* Add job execution event.
*
* @param event
* job execution event
* @return add success or not
*/
public boolean
addJobExecutionEvent(final JobExecutionEvent event) {
if (null == event.getCompleteTime()) {
return insertJobExecutionEvent(event);
} else if (event.isSuccess()) {
return updateJobExecutionEventWhenSuccess(event);
} else {
return updateJobExecutionEventFailure(event);
}
} | 3.26 |
shardingsphere-elasticjob_FailoverNode_getItemByExecutionFailoverPath_rdh | /**
* Get sharding item by execution failover path.
*
* @param path
* failover path
* @return sharding item, return null if not from failover path
*/
public Integer getItemByExecutionFailoverPath(final String path) {if (!isFailoverPath(path)) {
return null;
}
return Integer.parseInt(path.substring(jobNodePath.getFullPath(ShardingNode.ROOT).length() + 1, path.lastIndexOf(FailoverNode.FAILOVER) - 1));
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_jobListenerTypes_rdh | /**
* Set job listener types.
*
* @param jobListenerTypes
* job listener types
* @return ElasticJob configuration builder
*/
public Builder jobListenerTypes(final String... jobListenerTypes) {
this.jobListenerTypes.addAll(Arrays.asList(jobListenerTypes));
return this;
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_jobErrorHandlerType_rdh | /**
* Set job error handler type.
*
* @param jobErrorHandlerType
* job error handler type
* @return job configuration builder
*/
public Builder jobErrorHandlerType(final String jobErrorHandlerType) {
this.jobErrorHandlerType = jobErrorHandlerType;
return this;
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_failover_rdh | /**
* Set enable failover.
*
* <p>
* Only for `monitorExecution` enabled.
* </p>
*
* @param failover
* enable or disable failover
* @return job configuration builder
*/
public Builder failover(final
boolean failover) {
this.failover = failover;
return this;
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_disabled_rdh | /**
* Set whether disable job when start.
*
* <p>
* Using in job deploy, start job together after deploy.
* </p>
*
* @param disabled
* whether disable job when start
* @return ElasticJob configuration builder
*/
public Builder disabled(final boolean disabled) {
this.disabled = disabled;return this;
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_cron_rdh | /**
* Cron expression.
*
* @param cron
* cron expression
* @return job configuration builder
*/
public Builder cron(final String cron) {
if (null != cron) {
this.cron = cron;
}
return this;
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_build_rdh | /**
* Build ElasticJob configuration.
*
* @return ElasticJob configuration
*/
public final JobConfiguration build() {
Preconditions.checkArgument(!Strings.isNullOrEmpty(jobName), "jobName can not be empty.");
Preconditions.checkArgument(shardingTotalCount > 0, "shardingTotalCount should larger than zero.");
return new JobConfiguration(jobName, cron, timeZone, shardingTotalCount, shardingItemParameters, jobParameter, monitorExecution, failover, misfire, maxTimeDiffSeconds, reconcileIntervalMinutes, jobShardingStrategyType,
f3, jobErrorHandlerType, jobListenerTypes, extraConfigurations, description, props, disabled, overwrite, label, staticSharding);
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_reconcileIntervalMinutes_rdh | /**
* Set reconcile interval minutes for job sharding status.
*
* <p>
* Monitor the status of the job server at regular intervals, and resharding if incorrect.
* </p>
*
* @param reconcileIntervalMinutes
* reconcile interval minutes for job sharding status
* @return ElasticJob configuration builder
*/
public Builder reconcileIntervalMinutes(final int reconcileIntervalMinutes) {
this.reconcileIntervalMinutes = reconcileIntervalMinutes;
return this;
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_monitorExecution_rdh | /**
* Set enable or disable monitor execution.
*
* <p>
* For short interval job, it is better to disable monitor execution to improve performance.
* It can't guarantee repeated data fetch and can't failover if disable monitor execution, please keep idempotence in job.
* For long interval job, it is better to enable monitor execution to guarantee fetch data exactly once.
* </p>
*
* @param monitorExecution
* monitor job execution status
* @return ElasticJob configuration builder
*/
public Builder
monitorExecution(final boolean monitorExecution) {
this.monitorExecution = monitorExecution;
return this;
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_staticSharding_rdh | /**
* Set static sharding.
*
* @param staticSharding
* static sharding
* @return ElasticJob configuration builder
*/
public Builder staticSharding(final boolean staticSharding) {
this.staticSharding = staticSharding;
return this;
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_misfire_rdh | /**
* Set enable misfire.
*
* @param misfire
* enable or disable misfire
* @return job configuration builder
*/
public Builder misfire(final boolean misfire) {
this.misfire = misfire;
return this;
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_newBuilder_rdh | /**
* Create ElasticJob configuration builder.
*
* @param jobName
* job name
* @param shardingTotalCount
* sharding total count
* @return ElasticJob configuration builder
*/
public static Builder newBuilder(final
String jobName, final int shardingTotalCount) {
return new
Builder(jobName, shardingTotalCount);
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_overwrite_rdh | /**
* Set whether overwrite local configuration to registry center when job startup.
*
* <p>
* If overwrite enabled, every startup will use local configuration.
* </p>
*
* @param overwrite
* whether overwrite local configuration to registry center when job startup
* @return ElasticJob configuration builder
*/
public Builder overwrite(final boolean overwrite) {
this.overwrite = overwrite;
return this;
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_jobParameter_rdh | /**
* Set job parameter.
*
* @param jobParameter
* job parameter
* @return job configuration builder
*/
public Builder jobParameter(final String jobParameter) {
if (null != jobParameter) {
this.jobParameter = jobParameter;
}
return this;
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_description_rdh | /**
* Set job description.
*
* @param description
* job description
* @return job configuration builder
*/
public Builder description(final String description) {
if (null != description) {
this.description = description;
}
return this;
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_m0_rdh | /**
* time zone.
*
* @param timeZone
* the time zone
* @return job configuration builder
*/
public Builder m0(final String timeZone) {
if
(null != timeZone) {
this.timeZone = timeZone;
}
return this;
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_setProperty_rdh | /**
* Set property.
*
* @param key
* property key
* @param value
* property value
* @return job configuration builder
*/
public Builder setProperty(final String key, final String value) {
props.setProperty(key, value);
return this;
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_label_rdh | /**
* Set label.
*
* @param label
* label
* @return ElasticJob configuration builder
*/
public Builder label(final String label) {
this.label = label;
return this;
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_maxTimeDiffSeconds_rdh | /**
* Set max tolerate time different seconds between job server and registry center.
*
* <p>
* ElasticJob will throw exception if exceed max tolerate time different seconds.
* -1 means do not check.
* </p>
*
* @param maxTimeDiffSeconds
* max tolerate time different seconds between job server and registry center
* @return ElasticJob configuration builder
*/
public Builder maxTimeDiffSeconds(final int maxTimeDiffSeconds) {
this.maxTimeDiffSeconds = maxTimeDiffSeconds;
return this;
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_jobExecutorThreadPoolSizeProviderType_rdh | /**
* Set job executor thread pool size provider type.
*
* @param jobExecutorThreadPoolSizeProviderType
* job executor thread pool size provider type
* @return job configuration builder
*/
public Builder jobExecutorThreadPoolSizeProviderType(final String jobExecutorThreadPoolSizeProviderType) {
this.f3 = jobExecutorThreadPoolSizeProviderType;
return this;
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_addExtraConfigurations_rdh | /**
* Add extra configurations.
*
* @param extraConfig
* job extra configuration
* @return job configuration builder
*/
public Builder addExtraConfigurations(final JobExtraConfiguration extraConfig) {
extraConfigurations.add(extraConfig);
return this;
} | 3.26 |
shardingsphere-elasticjob_JobConfiguration_jobShardingStrategyType_rdh | /**
* Set job sharding strategy type.
*
* <p>
* Default for {@code AverageAllocationJobShardingStrategy}.
* </p>
*
* @param jobShardingStrategyType
* job sharding strategy type
* @return ElasticJob configuration builder
*/
public Builder jobShardingStrategyType(final String jobShardingStrategyType) {
if (null != jobShardingStrategyType) {
this.jobShardingStrategyType = jobShardingStrategyType;
}
return this;
} | 3.26 |
shardingsphere-elasticjob_ShardingService_getCrashedShardingItems_rdh | /**
* Get crashed sharding items.
*
* @param jobInstanceId
* crashed job instance ID
* @return crashed sharding items
*/
public List<Integer> getCrashedShardingItems(final String
jobInstanceId) {
String serverIp = jobInstanceId.substring(0, jobInstanceId.indexOf(JobInstance.DELIMITER));
if (!serverService.isEnableServer(serverIp)) {
return Collections.emptyList();
}
List<Integer> result = new LinkedList<>();
int shardingTotalCount = configService.load(true).getShardingTotalCount();
for (int i = 0; i < shardingTotalCount; i++) {
if (isRunningItem(i) && jobInstanceId.equals(jobNodeStorage.getJobNodeData(ShardingNode.getInstanceNode(i)))) {
result.add(i);
}
}
return result;
} | 3.26 |
shardingsphere-elasticjob_ShardingService_getLocalShardingItems_rdh | /**
* Get sharding items from localhost job server.
*
* @return sharding items from localhost job server
*/
public List<Integer> getLocalShardingItems() {
if (JobRegistry.getInstance().isShutdown(f0) || (!serverService.isAvailableServer(JobRegistry.getInstance().getJobInstance(f0).getServerIp()))) {
return Collections.emptyList();
}
return getShardingItems(JobRegistry.getInstance().getJobInstance(f0).getJobInstanceId());
} | 3.26 |
shardingsphere-elasticjob_ShardingService_isNeedSharding_rdh | /**
* Judge is need resharding or not.
*
* @return is need resharding or not
*/
public boolean isNeedSharding() {
return jobNodeStorage.isJobNodeExisted(ShardingNode.NECESSARY);
} | 3.26 |
shardingsphere-elasticjob_ShardingService_hasShardingInfoInOfflineServers_rdh | /**
* Query has sharding info in offline servers or not.
*
* @return has sharding info in offline servers or not
*/
public boolean hasShardingInfoInOfflineServers() {
List<String> v20 = jobNodeStorage.getJobNodeChildrenKeys(InstanceNode.ROOT);
int shardingTotalCount = configService.load(true).getShardingTotalCount();
for (int i = 0; i
< shardingTotalCount; i++) {
if (!v20.contains(jobNodeStorage.getJobNodeData(ShardingNode.getInstanceNode(i)))) {
return true;
}
}
return false;
} | 3.26 |
shardingsphere-elasticjob_ShardingService_shardingIfNecessary_rdh | /**
* Sharding if necessary.
*
* <p>
* Sharding if current job server is leader server;
* Do not sharding if no available job server.
* </p>
*/
public void shardingIfNecessary() {
List<JobInstance> availableJobInstances = instanceService.getAvailableJobInstances();
if ((!isNeedSharding()) || availableJobInstances.isEmpty()) {
return;
}
if (!leaderService.isLeaderUntilBlock()) {
blockUntilShardingCompleted();
return;
}
waitingOtherShardingItemCompleted();
JobConfiguration jobConfig = configService.load(false);
int v2 = jobConfig.getShardingTotalCount();
log.debug("Job '{}' sharding begin.", f0);
jobNodeStorage.fillEphemeralJobNode(ShardingNode.PROCESSING, "");
resetShardingInfo(v2);
JobShardingStrategy jobShardingStrategy = TypedSPILoader.getService(JobShardingStrategy.class, jobConfig.getJobShardingStrategyType());
jobNodeStorage.executeInTransaction(getShardingResultTransactionOperations(jobShardingStrategy.sharding(availableJobInstances, f0, v2)));
log.debug("Job '{}' sharding complete.", f0);
} | 3.26 |
shardingsphere-elasticjob_ShardingService_getShardingItems_rdh | /**
* Get sharding items.
*
* @param jobInstanceId
* job instance ID
* @return sharding items
*/
public List<Integer> getShardingItems(final String jobInstanceId) {
JobInstance jobInstance = YamlEngine.unmarshal(jobNodeStorage.getJobNodeData(instanceNode.getInstancePath(jobInstanceId)), JobInstance.class);
if (!serverService.isAvailableServer(jobInstance.getServerIp())) {
return Collections.emptyList();
}
List<Integer> result = new LinkedList<>();
int shardingTotalCount = configService.load(true).getShardingTotalCount();
for (int i = 0; i < shardingTotalCount; i++) {
if (jobInstance.getJobInstanceId().equals(jobNodeStorage.getJobNodeData(ShardingNode.getInstanceNode(i)))) {
result.add(i);
}
}
return result;
} | 3.26 |
shardingsphere-elasticjob_TransactionOperation_opDelete_rdh | /**
* Operation delete.
*
* @param key
* key
* @return TransactionOperation
*/
public static TransactionOperation
opDelete(final String key) {
return new TransactionOperation(Type.DELETE, key, null);
} | 3.26 |
shardingsphere-elasticjob_TransactionOperation_opUpdate_rdh | /**
* Operation update.
*
* @param key
* key
* @param value
* value
* @return TransactionOperation
*/
public static TransactionOperation opUpdate(final
String key, final String value) {return new TransactionOperation(Type.UPDATE, key, value);
} | 3.26 |
shardingsphere-elasticjob_TransactionOperation_opCheckExists_rdh | /**
* Operation check exists.
*
* @param key
* key
* @return TransactionOperation
*/
public static TransactionOperation opCheckExists(final String key) {
return new TransactionOperation(Type.CHECK_EXISTS, key, null);
} | 3.26 |
shardingsphere-elasticjob_TransactionOperation_opAdd_rdh | /**
* Operation add.
*
* @param key
* key
* @param value
* value
* @return TransactionOperation
*/
public static TransactionOperation opAdd(final String key, final String value) {
return new TransactionOperation(Type.ADD, key, value);
} | 3.26 |
shardingsphere-elasticjob_InstanceService_removeInstance_rdh | /**
* Persist job instance.
*/
public void removeInstance() {
jobNodeStorage.removeJobNodeIfExisted(f0.getLocalInstancePath());
} | 3.26 |
shardingsphere-elasticjob_InstanceService_getAvailableJobInstances_rdh | /**
* Get available job instances.
*
* @return available job instances
*/
public List<JobInstance> getAvailableJobInstances() {
List<JobInstance> result = new LinkedList<>();
for (String each : jobNodeStorage.getJobNodeChildrenKeys(InstanceNode.ROOT)) {
// TODO It's better to make it atomic
String jobNodeData = jobNodeStorage.getJobNodeData(f0.getInstancePath(each));
if (null == jobNodeData) {
continue;
}
JobInstance jobInstance = YamlEngine.unmarshal(jobNodeData, JobInstance.class);
if ((null
!= jobInstance) && serverService.isEnableServer(jobInstance.getServerIp())) {
result.add(jobInstance);
}
}
return result;} | 3.26 |
shardingsphere-elasticjob_InstanceService_persistOnline_rdh | /**
* Persist job online status.
*/
public void persistOnline() {
jobNodeStorage.fillEphemeralJobNode(f0.getLocalInstancePath(), f0.getLocalInstanceValue());
} | 3.26 |
shardingsphere-elasticjob_ScheduleJobBootstrap_m0_rdh | /**
* Schedule job.
*/
public void m0() {
Preconditions.checkArgument(!Strings.isNullOrEmpty(jobScheduler.getJobConfig().getCron()), "Cron can not be empty.");
jobScheduler.getJobScheduleController().scheduleJob(jobScheduler.getJobConfig().getCron(), jobScheduler.getJobConfig().getTimeZone());
} | 3.26 |
shardingsphere-elasticjob_PropertiesPreconditions_checkRequired_rdh | /**
* Check property value is required.
*
* @param props
* properties to be checked
* @param key
* property key to be checked
*/
public static void checkRequired(final Properties props, final String key) {
Preconditions.checkArgument(props.containsKey(key), "The property `%s` is required.", key);
} | 3.26 |
shardingsphere-elasticjob_PropertiesPreconditions_checkPositiveInteger_rdh | /**
* Check property value is positive integer.
*
* @param props
* properties to be checked
* @param key
* property key to be checked
*/
public static void checkPositiveInteger(final Properties props, final String key) {
String v0 = props.getProperty(key);
if (null == v0) {
return;
}
int integerValue;
try {
integerValue = Integer.parseInt(v0);
} catch (final NumberFormatException ignored) {
throw new IllegalArgumentException(String.format("The property `%s` should be integer.", key));
}
Preconditions.checkArgument(integerValue > 0, "The property `%s` should be positive.", key);
} | 3.26 |
shardingsphere-elasticjob_InstanceNode_isInstancePath_rdh | /**
* Judge path is job instance path or not.
*
* @param path
* path to be judged
* @return path is job instance path or not
*/
public boolean isInstancePath(final String path) {
return path.startsWith(jobNodePath.getFullPath(InstanceNode.ROOT));
} | 3.26 |
shardingsphere-elasticjob_ElasticJobConfigurationProperties_m0_rdh | /**
* Convert to job configuration.
*
* @param jobName
* job name
* @return job configuration
*/
public JobConfiguration m0(final String jobName) {JobConfiguration result = JobConfiguration.newBuilder(jobName, shardingTotalCount).cron(cron).timeZone(timeZone).shardingItemParameters(shardingItemParameters).jobParameter(jobParameter).monitorExecution(monitorExecution).failover(failover).misfire(misfire).maxTimeDiffSeconds(maxTimeDiffSeconds).reconcileIntervalMinutes(reconcileIntervalMinutes).jobShardingStrategyType(jobShardingStrategyType).jobExecutorThreadPoolSizeProviderType(jobExecutorThreadPoolSizeProviderType).jobErrorHandlerType(jobErrorHandlerType).jobListenerTypes(jobListenerTypes.toArray(new String[0])).description(description).disabled(disabled).overwrite(overwrite).build();
props.stringPropertyNames().forEach(each -> result.getProps().setProperty(each, props.getProperty(each)));
return result;
} | 3.26 |
shardingsphere-elasticjob_ZookeeperProperties_m0_rdh | /**
* Create ZooKeeper configuration.
*
* @return instance of ZooKeeper configuration
*/
public ZookeeperConfiguration m0()
{
ZookeeperConfiguration result = new ZookeeperConfiguration(serverLists, namespace);
result.setBaseSleepTimeMilliseconds(baseSleepTimeMilliseconds);
result.setMaxSleepTimeMilliseconds(maxSleepTimeMilliseconds);
result.setMaxRetries(maxRetries);
result.setSessionTimeoutMilliseconds(sessionTimeoutMilliseconds);
result.setConnectionTimeoutMilliseconds(connectionTimeoutMilliseconds);
result.setDigest(f0);
return result;
} | 3.26 |
shardingsphere-elasticjob_TriggerNode_isLocalTriggerPath_rdh | /**
* Is local trigger path.
*
* @param path
* path
* @return is local trigger path or not
*/
public boolean isLocalTriggerPath(final String path) {
JobInstance jobInstance = JobRegistry.getInstance().getJobInstance(jobName);
return (null != jobInstance) && path.equals(jobNodePath.getFullPath(String.format(TRIGGER, jobInstance.getJobInstanceId())));
} | 3.26 |
shardingsphere-elasticjob_TriggerNode_getLocalTriggerPath_rdh | /**
* Get local trigger path.
*
* @return local trigger path
*/
public String getLocalTriggerPath() {
return getTriggerPath(JobRegistry.getInstance().getJobInstance(jobName).getJobInstanceId());
} | 3.26 |
shardingsphere-elasticjob_TriggerNode_getTriggerPath_rdh | /**
* Get trigger path.
*
* @param instanceId
* instance id
* @return trigger path
*/
public String getTriggerPath(final String instanceId) {
return String.format(TRIGGER, instanceId);
} | 3.26 |
shardingsphere-elasticjob_TriggerNode_getTriggerRoot_rdh | /**
* Get trigger root.
*
* @return trigger root
*/public String getTriggerRoot() {
return ROOT;
} | 3.26 |
shardingsphere-elasticjob_NettyRestfulServiceConfiguration_addExceptionHandler_rdh | /**
* Add an instance of ExceptionHandler for specific exception.
*
* @param exceptionType
* The type of exception to handle
* @param exceptionHandler
* Instance of ExceptionHandler
* @param <E>
* The type of exception to handle
*/
public <E extends Throwable> void addExceptionHandler(final Class<E> exceptionType, final ExceptionHandler<E> exceptionHandler) {
Preconditions.checkState(!exceptionHandlers.containsKey(exceptionType), "ExceptionHandler for %s has already existed.", exceptionType.getName());exceptionHandlers.put(exceptionType, exceptionHandler);
} | 3.26 |
shardingsphere-elasticjob_NettyRestfulServiceConfiguration_addFilterInstances_rdh | /**
* Add instances of {@link Filter}.
*
* @param instances
* instances of Filter
*/
public void addFilterInstances(final Filter... instances) {
filterInstances.addAll(Arrays.asList(instances));
} | 3.26 |
shardingsphere-elasticjob_NettyRestfulServiceConfiguration_addControllerInstances_rdh | /**
* Add instances of RestfulController.
*
* @param instances
* instances of RestfulController
*/
public void addControllerInstances(final RestfulController... instances) {
controllerInstances.addAll(Arrays.asList(instances));
} | 3.26 |
shardingsphere-elasticjob_RequestBodyDeserializerFactory_getRequestBodyDeserializer_rdh | /**
* Get deserializer for specific HTTP content type.
*
* <p>
* This method will look for a deserializer instance of specific MIME type.
* If deserializer not found, this method would look for deserializer factory by MIME type.
* If it is still not found, the MIME type would be marked as <code>MISSING_DESERIALIZER</code>.
* </p>
*
* <p>
* Some default deserializer will be provided by {@link DeserializerFactory},
* so developers can implement {@link RequestBodyDeserializer} and register it by SPI to override default deserializer.
* </p>
*
* @param contentType
* HTTP content type
* @return Deserializer
*/
public static RequestBodyDeserializer getRequestBodyDeserializer(final String contentType) {
RequestBodyDeserializer result = REQUEST_BODY_DESERIALIZERS.get(contentType);
if (null == result) {
synchronized(RequestBodyDeserializerFactory.class) {
if (null == REQUEST_BODY_DESERIALIZERS.get(contentType)) {
instantiateRequestBodyDeserializerFromFactories(contentType);
}
result = REQUEST_BODY_DESERIALIZERS.get(contentType);
}
}if (MISSING_DESERIALIZER == result) {
throw new
RequestBodyDeserializerNotFoundException(contentType);
}
return result;
} | 3.26 |
shardingsphere-elasticjob_ZookeeperRegistryCenter_m0_rdh | /* // TODO sleep 500ms, let cache client close first and then client, otherwise will throw exception reference:https://issues.apache.org/jira/browse/CURATOR-157 */
private void m0() {
try {
Thread.sleep(500L);
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
}
} | 3.26 |
shardingsphere-elasticjob_JobNodeStorage_removeJobNodeIfExisted_rdh | /**
* Remove job node if existed.
*
* @param node
* node
*/public void removeJobNodeIfExisted(final String node) {
if (isJobNodeExisted(node)) {regCenter.remove(jobNodePath.getFullPath(node));
}
} | 3.26 |
shardingsphere-elasticjob_JobNodeStorage_fillEphemeralJobNode_rdh | /**
* Fill ephemeral job node.
*
* @param node
* node
* @param value
* data of job node
*/
public void fillEphemeralJobNode(final String node, final Object value) {
regCenter.persistEphemeral(jobNodePath.getFullPath(node), value.toString());
} | 3.26 |
shardingsphere-elasticjob_JobNodeStorage_getJobNodeChildrenKeys_rdh | /**
* Get job node children keys.
*
* @param node
* node
* @return children keys
*/
public List<String> getJobNodeChildrenKeys(final String node) {return regCenter.getChildrenKeys(jobNodePath.getFullPath(node));
} | 3.26 |
shardingsphere-elasticjob_JobNodeStorage_replaceJobRootNode_rdh | /**
* Replace data to root node.
*
* @param value
* to be replaced data
*/
public void
replaceJobRootNode(final Object value) {regCenter.persist("/" + jobName, value.toString());
} | 3.26 |
shardingsphere-elasticjob_JobNodeStorage_executeInLeader_rdh | /**
* Execute in leader server.
*
* @param latchNode
* node for leader latch
* @param callback
* execute callback
*/public void executeInLeader(final String latchNode, final LeaderExecutionCallback callback) {
regCenter.executeInLeader(jobNodePath.getFullPath(latchNode), callback);
} | 3.26 |
shardingsphere-elasticjob_JobNodeStorage_m2_rdh | /**
* Update job node.
*
* @param node
* node
* @param value
* data of job node
*/
public void m2(final String node, final Object value) {
regCenter.update(jobNodePath.getFullPath(node), value.toString());
} | 3.26 |
shardingsphere-elasticjob_JobNodeStorage_addDataListener_rdh | /**
* Add data listener.
*
* @param listener
* data listener
*/
public void addDataListener(final DataChangedEventListener listener) {
Executor executor = ListenerNotifierManager.getInstance().getJobNotifyExecutor(jobName);
regCenter.watch("/" + jobName, listener, executor);
} | 3.26 |
shardingsphere-elasticjob_JobNodeStorage_getJobNodeDataDirectly_rdh | /**
* Get job node data from registry center directly.
*
* @param node
* node
* @return data of job node
*/
public String getJobNodeDataDirectly(final String node) {
return regCenter.getDirectly(jobNodePath.getFullPath(node));
} | 3.26 |
shardingsphere-elasticjob_JobNodeStorage_getRegistryCenterTime_rdh | /**
* Get registry center time.
*
* @return registry center time
*/
public long getRegistryCenterTime() {
return regCenter.getRegistryCenterTime(jobNodePath.getFullPath("systemTime/current"));
} | 3.26 |
shardingsphere-elasticjob_JobNodeStorage_m0_rdh | /**
* Get job node data.
*
* @param node
* node
* @return data of job node
*/
public String m0(final String node) {
return regCenter.get(jobNodePath.getFullPath(node));
} | 3.26 |
shardingsphere-elasticjob_JobNodeStorage_isJobRootNodeExisted_rdh | /**
* Judge is job root node existed or not.
*
* @return is job root node existed or not
*/
public boolean isJobRootNodeExisted() {
return regCenter.isExisted("/" + jobName);
} | 3.26 |
shardingsphere-elasticjob_JobNodeStorage_getJobRootNodeData_rdh | /**
* Get job root node data.
*
* @return data of job node
*/
public String getJobRootNodeData() { return regCenter.get("/" + jobName);
} | 3.26 |
shardingsphere-elasticjob_JobNodeStorage_createJobNodeIfNeeded_rdh | /**
* Create job node if needed.
*
* <p>Do not create node if root node not existed, which means job is shutdown.</p>
*
* @param node
* node
*/
public void createJobNodeIfNeeded(final String node) {
if (isJobRootNodeExisted() && (!isJobNodeExisted(node))) {
regCenter.persist(jobNodePath.getFullPath(node), "");
}
} | 3.26 |
shardingsphere-elasticjob_JobNodeStorage_replaceJobNode_rdh | /**
* Replace data.
*
* @param node
* node
* @param value
* to be replaced data
*/
public void replaceJobNode(final String node, final Object value) {
regCenter.persist(jobNodePath.getFullPath(node), value.toString());
} | 3.26 |
shardingsphere-elasticjob_JobNodeStorage_addConnectionStateListener_rdh | /**
* Add connection state listener.
*
* @param listener
* connection state listener
*/
public void
addConnectionStateListener(final ConnectionStateChangedEventListener listener) {
regCenter.addConnectionStateChangedEventListener("/" + jobName, listener);
} | 3.26 |
shardingsphere-elasticjob_JobNodeStorage_isJobNodeExisted_rdh | /**
* Judge is job node existed or not.
*
* @param node
* node
* @return is job node existed or not
*/
public boolean isJobNodeExisted(final String node)
{
return regCenter.isExisted(jobNodePath.getFullPath(node));
} | 3.26 |
shardingsphere-elasticjob_JobNodeStorage_m1_rdh | /**
* Fill job node.
*
* @param node
* node
* @param value
* data of job node
*/
public void m1(final String node, final Object value) {regCenter.persist(jobNodePath.getFullPath(node), value.toString());
} | 3.26 |
shardingsphere-elasticjob_JobNodePath_getShardingNodePath_rdh | /**
* Get sharding node path.
*
* @param item
* sharding item
* @param nodeName
* node name
* @return sharding node path
*/
public String
getShardingNodePath(final String item, final String nodeName) {
return String.format("%s/%s/%s", getShardingNodePath(), item,
nodeName);
} | 3.26 |
shardingsphere-elasticjob_JobNodePath_getConfigNodePath_rdh | /**
* Get configuration node path.
*
* @return configuration node path
*/
public String getConfigNodePath() {
return String.format("/%s/%s", jobName, CONFIG_NODE);
} | 3.26 |
Subsets and Splits