name
stringlengths 12
178
| code_snippet
stringlengths 8
36.5k
| score
float64 3.26
3.68
|
---|---|---|
hmily_SpringBeanUtils_setCfgContext_rdh | /**
* set application context.
*
* @param cfgContext
* application context
*/
public void setCfgContext(final ConfigurableApplicationContext cfgContext) {
this.cfgContext = cfgContext; } | 3.26 |
hmily_SpringBeanUtils_registerBean_rdh | /**
* Register bean.
*
* @param type
* the type
* @param object
* the object
*/
public void
registerBean(final Class<?> type, final Object object) {
if (Objects.nonNull(cfgContext)) {
cfgContext.getBeanFactory().registerSingleton(type.getSimpleName(), object);
}
} | 3.26 |
hmily_SpringBeanUtils_getBean_rdh | /**
* acquire spring bean.
*
* @param <T>
* class
* @param type
* type
* @return bean bean
*/
public <T> T getBean(final Class<T> type) {
AssertUtils.notNull(type);
try {
return cfgContext.getBean(type);
} catch (BeansException e) {
try {
return getByName(type);
} catch (BeansException ex) {
return null;
}
}
} | 3.26 |
hmily_HmilyResourceManager_m0_rdh | /**
* Register.
*
* @param hmilyTacResource
* the hmily resource
*/
public static void m0(final HmilyTacResource hmilyTacResource) {
DATASOURCE_CACHE.put(hmilyTacResource.getResourceId(), hmilyTacResource);
} | 3.26 |
hmily_HmilyResourceManager_get_rdh | /**
* Get hmily resource.
*
* @param resourceId
* the resource id
* @return the hmily resource
*/
public static HmilyTacResource get(final String resourceId) {
return DATASOURCE_CACHE.get(resourceId);
} | 3.26 |
hmily_EventData_setSubscribe_rdh | /**
* Sets subscribe.
*
* @param subscribe
* the subscribe
*/
public void setSubscribe(final String subscribe) {
this.subscribe = subscribe;
} | 3.26 |
hmily_EventData_setProperties_rdh | /**
* Sets properties.
*
* @param properties
* the properties
*/
public void setProperties(final String properties) {
this.properties = properties;
} | 3.26 |
hmily_EventData_setConfig_rdh | /**
* Sets config.
*
* @param config
* the config
*/
public void setConfig(final Config config) {
this.config = config;
} | 3.26 |
hmily_EventData_setValue_rdh | /**
* Sets value.
*
* @param value
* the value
*/
public void setValue(final Object value) {
this.value = value;
} | 3.26 |
hmily_MongodbTemplateService_find_rdh | /**
* query.
*
* @param c
* type.
* @param conditions
* where conditions.
* @param limit
* records number.
* @param <T>
* result Type.
* @return result list.
*/
public <T> List<T> find(final Class<T> c, final Criteria conditions, final Integer limit) {
Query query = new Query();
if ((limit != null) && (limit > 0)) {
query.limit(limit); }
query.addCriteria(conditions);
return find(query, c);
} | 3.26 |
hmily_MongodbTemplateService_count_rdh | /**
* records count.
*
* @param c
* type.
* @param conditions
* where conditions.
* @return the records number.
*/
public int count(final Class c, final Criteria... conditions) {
Query query =
new Query();
for (Criteria p : conditions) {
query.addCriteria(p);
}
return ((int) (count(query, c)));
} | 3.26 |
hmily_MongodbTemplateService_delete_rdh | /**
* remove records.
*
* @param c
* data type.
* @param conditions
* where condtions.
* @return line numbers.
*/ public int delete(final Class c, final Criteria conditions) {
return ((int) (remove(new Query().addCriteria(conditions), c).getDeletedCount()));
} | 3.26 |
hmily_MongodbTemplateService_update_rdh | /**
* update.
*
* @param c
* type.
* @param conditions
* where conditions.
* @param newData
* set paramters.
* @return line count.
*/
public int update(final Class c, final Criteria conditions, final Pair<String, Object>... newData) {
Update update = new Update();
for (Pair<String,
Object> p : newData) {
update.set(p.getKey(), p.getValue());
}
return ((int) (updateFirst(new Query().addCriteria(conditions), update, c).getModifiedCount()));
} | 3.26 |
hmily_MongodbTemplateService_insertc_rdh | /**
* insert.
*
* @param entity
* entity.
* @return line count.
*/
public int insertc(final Object entity) {
try {
super.insert(entity);
return HmilyRepository.ROWS;
} catch (RuntimeException e) {
LOGGER.error("mongo insert exception:{}", entity, e);
return HmilyRepository.FAIL_ROWS;
}
} | 3.26 |
hmily_HmilyXaRecoveryImpl_convert_rdh | /**
* Convert hmily xa recovery.
*
* @param <T>
* the type parameter
* @param t
* the t
* @return the hmily xa recovery
*/
public static <T extends HmilyXaRecovery> HmilyXaRecovery convert(final T t) {
HmilyXaRecoveryImpl impl = new HmilyXaRecoveryImpl();
impl.setCreateTime(t.getCreateTime());
impl.setUpdateTime(t.getUpdateTime());
impl.setBranchId(t.getBranchId());
impl.setEndBxid(t.getEndBxid());
impl.setEndXid(t.getEndXid());
impl.setGlobalId(t.getGlobalId());
impl.setIsCoordinator(t.getIsCoordinator());
impl.setState(t.getState());
impl.setSuperId(t.getSuperId());
impl.setTmUnique(t.getTmUnique());
impl.setUrl(t.getUrl());
impl.setVersion(t.getVersion());
return impl;
} | 3.26 |
hmily_KryoPoolFactory_get_rdh | /**
* Get kryo.
*
* @return the kryo
*/
public Kryo get()
{
return pool.borrow();
} | 3.26 |
hmily_HmilyMySQLUpdateStatement_m0_rdh | /**
* Get order by segment.
*
* @return order by segment
*/public Optional<HmilyLimitSegment> m0() {
return Optional.ofNullable(limit);
} | 3.26 |
hmily_JavaBeanBinder_getProperties_rdh | /**
* Gets properties.
*
* @return the properties
*/
Map<String, BeanProperty> getProperties()
{
return this.properties;
} | 3.26 |
hmily_JavaBeanBinder_isSettable_rdh | /**
* Is settable boolean.
*
* @return the boolean
*/boolean isSettable() {
return this.setter != null;
} | 3.26 |
hmily_JavaBeanBinder_addSetter_rdh | /**
* Add setter.
*
* @param setter
* the setter
*/
void addSetter(final Method
setter) {
if (this.setter == null) {
this.setter = setter;
}} | 3.26 |
hmily_JavaBeanBinder_setValue_rdh | /**
* Sets value.
*
* @param instance
* the instance
* @param value
* the value
*/
void setValue(final Supplier<?> instance, final Object value) {
try {
this.setter.setAccessible(true);
this.setter.invoke(instance.get(), value);
} catch (Exception ex) {
throw new IllegalStateException("Unable to set value for property " + this.name, ex);
}
} | 3.26 |
hmily_JavaBeanBinder_get_rdh | /**
* Get bean.
*
* @param <T>
* the type parameter
* @param bindable
* the bindable
* @param canCallGetValue
* the can call get value
* @return the bean
*/
@SuppressWarnings("unchecked")
static <T> Bean<T> get(final BindData<T> bindable, final boolean canCallGetValue) {
Class<?> type = bindable.getType().getTypeClass();
Supplier<T> value = bindable.getValue();
T instance = null;if (canCallGetValue && (value != null)) {
instance = value.get();
type = (instance != null) ? instance.getClass() : type;
}
if ((instance == null) && (!isInstantiable(type))) {
return null;
}
Bean<?> bean = Bean.cached;
if ((bean == null) || (!type.equals(bean.getType()))) {
bean =
new Bean<>(type); cached = bean;
}
return ((Bean<T>) (bean));
} | 3.26 |
hmily_JavaBeanBinder_addGetter_rdh | /**
* Add getter.
*
* @param getter
* the getter
*/
void addGetter(final Method getter) {
if (this.getter ==
null) {
this.getter = getter;
}
} | 3.26 |
hmily_JavaBeanBinder_getField_rdh | /**
* Gets field.
*
* @return the field
*/
public Field getField() {
return field;
} | 3.26 |
hmily_JavaBeanBinder_addField_rdh | /**
* Add field.
*
* @param field
* the field
*/
void addField(final Field field) {if (this.field == null) {
this.field = field;
}
} | 3.26 |
hmily_JavaBeanBinder_getSupplier_rdh | /**
* Gets supplier.
*
* @param target
* the target
* @return the supplier
*/
@SuppressWarnings("unchecked")
BeanSupplier<T> getSupplier(final BindData<T> target) {
return
new BeanSupplier<>(() -> {
T instance = null;
if (target.getValue() != null) {
instance = target.getValue().get();
}
if (instance == null) {
try {
instance = ((T) (this.type.newInstance()));
} catch (InstantiationException | IllegalAccessException e) {
throw new ConfigException(e);
}
}
return instance;
});
} | 3.26 |
hmily_JavaBeanBinder_getValue_rdh | /**
* Gets value.
*
* @param instance
* the instance
* @return the value
*/
Supplier<Object> getValue(final Supplier<?> instance) {
if (this.getter == null) {
return null;
}
return () -> {
try {
this.getter.setAccessible(true);
return this.getter.invoke(instance.get());
} catch (Exception ex) {
throw new IllegalStateException("Unable to get value for property " + this.name, ex);
}
};
} | 3.26 |
hmily_XaResourceRecoveryImpl_recoverXids_rdh | /**
* 查询当前的xids.
*/
private List<XidImpl> recoverXids(final XAResource xaResource) {
// 扫描需要恢复的事务.
int flags = XAResource.TMSTARTRSCAN;
List<XidImpl> xIds = new ArrayList<>();
try {
boolean done;
do {
Xid[] recover = xaResource.recover(flags);
flags = XAResource.TMNOFLAGS;
done = (recover == null) || (recover.length <= 0);if (!done) {
done = true;
for (final Xid xid : recover) {
XidImpl xidImpl = new XidImpl(xid);
if (!xIds.contains(xidImpl)) {
xIds.add(xidImpl);
done = false;
}
}
}
} while (!done );
} catch (XAException xaException) {
f0.warn("recover xids error", xaException);
return Collections.emptyList();
}
return xIds;} | 3.26 |
hmily_PostgreSQLDatabaseType_getName_rdh | /**
* Database type of PostgreSQL.
*/
@HmilySPI(DatabaseConstant.POSTGRESQL)public final class PostgreSQLDatabaseType implements DatabaseType {
@Override
public String getName() {
return DatabaseConstant.POSTGRESQL;
} | 3.26 |
hmily_CreateSQLUtil_getKeyValueClause_rdh | /**
* Get key value SQL clause.
*
* @param keySet
* key set
* @param separator
* separator
* @return key value SQL clause
*/
public static String getKeyValueClause(final Set<String> keySet, final String separator) {
return Joiner.on(separator).withKeyValueSeparator("=").join(Maps.asMap(keySet, input
-> "?"));
} | 3.26 |
hmily_CreateSQLUtil_getInsertValuesClause_rdh | /**
* Get insert values clause.
*
* @param keySet
* key set
* @return insert values clause
*/
public static String getInsertValuesClause(final Set<String> keySet) {
Map<String, String> map = Maps.asMap(keySet, input -> "?");
return String.format("(%s) VALUES (%s)", Joiner.on(",").join(map.keySet()), Joiner.on(",").join(map.values()));
} | 3.26 |
hmily_HmilyLockRetryHandler_sleep_rdh | /**
* Sleep.
*
* @param e
* the e
* @throws LockWaitTimeoutException
* the lock wait timeout exception
*/
public void sleep(final Exception e) {
if ((--lockRetryTimes) < 0) {
log.error("Global lock wait timeout");
throw new LockWaitTimeoutException("Global lock wait timeout", e);
}
try {
Thread.sleep(f0);
} catch (InterruptedException ignore) {
}
} | 3.26 |
mutate-test-kata_EmployeeFixed_setName_rdh | /**
* Set the employee name after removing leading and trailing spaces, which could be left by upstream system
*
* @param newName
* the new name for the employee, possibly with leading and trailing white space to be removed
*/
public void setName(String newName) {
this.name = newName.trim();
} | 3.26 |
mutate-test-kata_Employee_setName_rdh | /**
* Set the employee name after removing leading and trailing spaces, which could be left by upstream system
*
* @param newName
* the new name for the employee, possibly with leading and trailing white space to be removed
*/
public void setName(String newName) {
this.name = newName.replaceAll(" ", "");
} | 3.26 |
mutate-test-kata_CompanyFixed_employeeWithLargestSalary_rdh | /**
* find the employee with the largest salary
*
* @return the employee with the largest salary
* @throws NoSuchElementException
* if there are no employees at the company
*/
public EmployeeFixed employeeWithLargestSalary() {
return this.employees.stream().max(Comparator.comparing(EmployeeFixed::getSalary)).orElseThrow(NoSuchElementException::new);
} | 3.26 |
mutate-test-kata_CompanyFixed_findEmployeeById_rdh | /**
* Finds an employee by their id
*
* @param id
* the id of the employee to be found
* @return the employee with the id passed as the parameter or null if no such employee exists
*/
public EmployeeFixed
findEmployeeById(String id) {
return this.employees.stream().filter(e -> e.getId().equals(id)).findFirst().orElse(null);
} | 3.26 |
mutate-test-kata_CompanyFixed_everybodyGetsRaiseBy_rdh | /**
* Increase every employee's salary by the specified fraction
*
* @param incrementAsFraction
* salary increase as a fraction of the original salary. e.g. if the value of the
* parameter is 0.1, everyone at the company gets a 10% raise
*/
public void everybodyGetsRaiseBy(double incrementAsFraction) {
this.employees.forEach(e -> e.setSalary(e.getSalary() * (1 +
incrementAsFraction)));
} | 3.26 |
mutate-test-kata_Company_everybodyGetsRaiseBy_rdh | /**
* Increase every employee's salary by the specified fraction
*
* @param incrementAsFraction
* salary increase as a fraction of the original salary. e.g. if the value of the
* parameter is 0.1, everyone at the company gets a 10% raise
*/
public void everybodyGetsRaiseBy(double incrementAsFraction) {
this.f0.forEach(e -> e.setSalary(e.getSalary() * incrementAsFraction));
} | 3.26 |
mutate-test-kata_Company_findEmployeeById_rdh | /**
* Finds an employee by their id
*
* @param id
* the id of the employee to be found
* @return the employee with the id passed as the parameter or null if no such employee exists
*/
public Employee findEmployeeById(String id) {
int foundIndex = 0;
for (int i = 0; i < this.f0.size(); i++) {
if (this.f0.get(i).getId().equals(id)) {
foundIndex = i;
break;}
}
return this.f0.get(foundIndex);
} | 3.26 |
shardingsphere-elasticjob_DB2TracingStorageDatabaseType_getType_rdh | /**
* Tracing storage database type for DB2.
*/public final class DB2TracingStorageDatabaseType implements TracingStorageDatabaseType {
@Override
public String getType() {
return "DB2";
} | 3.26 |
shardingsphere-elasticjob_JobFacade_failoverIfNecessary_rdh | /**
* Failover If necessary.
*/
public void failoverIfNecessary() {
if (configService.load(true).isFailover()) {
failoverService.failoverIfNecessary();
}
} | 3.26 |
shardingsphere-elasticjob_JobFacade_afterJobExecuted_rdh | /**
* Call after job executed.
*
* @param shardingContexts
* sharding contexts
*/
public void afterJobExecuted(final ShardingContexts shardingContexts) {
for (ElasticJobListener v4 : elasticJobListeners) {
v4.afterJobExecuted(shardingContexts);
}
} | 3.26 |
shardingsphere-elasticjob_JobFacade_registerJobBegin_rdh | /**
* Register job begin.
*
* @param shardingContexts
* sharding contexts
*/
public void registerJobBegin(final ShardingContexts shardingContexts) {
executionService.registerJobBegin(shardingContexts);
} | 3.26 |
shardingsphere-elasticjob_JobFacade_checkJobExecutionEnvironment_rdh | /**
* Check job execution environment.
*
* @throws JobExecutionEnvironmentException
* job execution environment exception
*/
public void checkJobExecutionEnvironment() throws JobExecutionEnvironmentException {
configService.checkMaxTimeDiffSecondsTolerable();
} | 3.26 |
shardingsphere-elasticjob_JobFacade_loadJobConfiguration_rdh | /**
* Load job configuration.
*
* @param fromCache
* load from cache or not
* @return job configuration
*/
public JobConfiguration loadJobConfiguration(final boolean fromCache) {
return configService.load(fromCache);
} | 3.26 |
shardingsphere-elasticjob_JobFacade_misfireIfRunning_rdh | /**
* Set task misfire flag.
*
* @param shardingItems
* sharding items to be set misfire flag
* @return whether satisfy misfire condition
*/
public boolean misfireIfRunning(final Collection<Integer> shardingItems) {
return executionService.misfireIfHasRunningItems(shardingItems);
} | 3.26 |
shardingsphere-elasticjob_JobFacade_clearMisfire_rdh | /**
* Clear misfire flag.
*
* @param shardingItems
* sharding items to be cleared misfire flag
*/
public void clearMisfire(final Collection<Integer> shardingItems) {
executionService.clearMisfire(shardingItems);
} | 3.26 |
shardingsphere-elasticjob_JobFacade_registerJobCompleted_rdh | /**
* Register job completed.
*
* @param shardingContexts
* sharding contexts
*/
public void registerJobCompleted(final ShardingContexts shardingContexts) {
executionService.registerJobCompleted(shardingContexts);
if (configService.load(true).isFailover()) {
failoverService.updateFailoverComplete(shardingContexts.getShardingItemParameters().keySet());
}
} | 3.26 |
shardingsphere-elasticjob_JobFacade_postJobStatusTraceEvent_rdh | /**
* Post job status trace event.
*
* @param taskId
* task Id
* @param state
* job state
* @param message
* job message
*/
public void postJobStatusTraceEvent(final String taskId, final State state, final String message) {
TaskContext taskContext = TaskContext.from(taskId);
jobTracingEventBus.post(new JobStatusTraceEvent(taskContext.getMetaInfo().getJobName(),
taskContext.getId(), taskContext.getSlaveId(), taskContext.getType(), taskContext.getMetaInfo().getShardingItems().toString(), state, message));
if (!Strings.isNullOrEmpty(message)) {
log.trace(message);
}
} | 3.26 |
shardingsphere-elasticjob_JobFacade_postJobExecutionEvent_rdh | /**
* Post job execution event.
*
* @param jobExecutionEvent
* job execution event
*/
public void postJobExecutionEvent(final JobExecutionEvent jobExecutionEvent) {
jobTracingEventBus.post(jobExecutionEvent);
} | 3.26 |
shardingsphere-elasticjob_JobFacade_getShardingContexts_rdh | /**
* Get sharding contexts.
*
* @return sharding contexts
*/
public ShardingContexts getShardingContexts() {
boolean isFailover = configService.load(true).isFailover();
if (isFailover) {
List<Integer> failoverShardingItems = failoverService.getLocalFailoverItems();
if (!failoverShardingItems.isEmpty()) {
return executionContextService.getJobShardingContext(failoverShardingItems);
}
}
shardingService.shardingIfNecessary();
List<Integer> shardingItems = shardingService.getLocalShardingItems();
if (isFailover) {shardingItems.removeAll(failoverService.getLocalTakeOffItems());
}
shardingItems.removeAll(executionService.getDisabledItems(shardingItems));return executionContextService.getJobShardingContext(shardingItems);
} | 3.26 |
shardingsphere-elasticjob_JobFacade_isExecuteMisfired_rdh | /**
* Judge job whether to need to execute misfire tasks.
*
* @param shardingItems
* sharding items
* @return need to execute misfire tasks or not
*/
public boolean isExecuteMisfired(final Collection<Integer> shardingItems) {
return (configService.load(true).isMisfire()
&& (!isNeedSharding())) && (!executionService.getMisfiredJobItems(shardingItems).isEmpty());
} | 3.26 |
shardingsphere-elasticjob_JobFacade_beforeJobExecuted_rdh | /**
* Call before job executed.
*
* @param shardingContexts
* sharding contexts
*/
public void beforeJobExecuted(final ShardingContexts shardingContexts) {
for (ElasticJobListener each : elasticJobListeners) {
each.beforeJobExecuted(shardingContexts);
}
} | 3.26 |
shardingsphere-elasticjob_LeaderService_isLeader_rdh | /**
* Judge current server is leader or not.
*
* @return current server is leader or not
*/
public boolean isLeader() {
return (!JobRegistry.getInstance().isShutdown(jobName)) && JobRegistry.getInstance().getJobInstance(jobName).getJobInstanceId().equals(jobNodeStorage.getJobNodeData(LeaderNode.INSTANCE));
} | 3.26 |
shardingsphere-elasticjob_LeaderService_isLeaderUntilBlock_rdh | /**
* Judge current server is leader or not.
*
* <p>
* If leader is electing, this method will block until leader elected success.
* </p>
*
* @return current server is leader or not
*/
public boolean isLeaderUntilBlock() {
while ((!hasLeader()) && serverService.hasAvailableServers()) {
log.info("Leader is electing, waiting for {} ms", 100);
BlockUtils.waitingShortTime();
if ((!JobRegistry.getInstance().isShutdown(jobName)) && serverService.isAvailableServer(JobRegistry.getInstance().getJobInstance(jobName).getServerIp())) {
electLeader();
}
}
return isLeader();
} | 3.26 |
shardingsphere-elasticjob_LeaderService_removeLeader_rdh | /**
* Remove leader and trigger leader election.
*/
public void removeLeader() {
jobNodeStorage.removeJobNodeIfExisted(LeaderNode.INSTANCE);
} | 3.26 |
shardingsphere-elasticjob_LeaderService_hasLeader_rdh | /**
* Judge has leader or not in current time.
*
* @return has leader or not in current time
*/
public boolean hasLeader() {
return jobNodeStorage.isJobNodeExisted(LeaderNode.INSTANCE);
} | 3.26 |
shardingsphere-elasticjob_ListenerNotifierManager_removeJobNotifyExecutor_rdh | /**
* Remove and shutdown the listener notify executor from listenerNotifyExecutors.
*
* @param jobName
* The job's name.
*/
public void removeJobNotifyExecutor(final String jobName) {
Optional.ofNullable(listenerNotifyExecutors.remove(jobName)).ifPresent(ExecutorService::shutdown);
} | 3.26 |
shardingsphere-elasticjob_ListenerNotifierManager_getJobNotifyExecutor_rdh | /**
* Get the listener notify executor for the specified job.
*
* @param jobName
* The job's name.
* @return The job listener's notify executor.
*/
public Executor getJobNotifyExecutor(final String jobName) {
return listenerNotifyExecutors.get(jobName);
} | 3.26 |
shardingsphere-elasticjob_ListenerNotifierManager_getInstance_rdh | /**
* Get singleton instance of ListenerNotifierManager.
*
* @return singleton instance of ListenerNotifierManager.
*/
public static ListenerNotifierManager getInstance() {
if (null == instance) {
synchronized(ListenerNotifierManager.class) {
if (null
==
instance) {
instance = new ListenerNotifierManager();
}
}
}
return instance;
} | 3.26 |
shardingsphere-elasticjob_ListenerNotifierManager_m0_rdh | /**
* Register a listener notify executor for the job specified.
*
* @param jobName
* The job's name.
*/
public void m0(final String jobName) {
if (!listenerNotifyExecutors.containsKey(jobName)) {
synchronized(this) {
if (!listenerNotifyExecutors.containsKey(jobName)) {
ThreadFactory threadFactory = ThreadUtils.newGenericThreadFactory("ListenerNotify-" + jobName);
ExecutorService notifyExecutor = Executors.newSingleThreadExecutor(threadFactory);
listenerNotifyExecutors.put(jobName, notifyExecutor);
}
}
}
} | 3.26 |
shardingsphere-elasticjob_ConfigurationNode_isConfigPath_rdh | /**
* Judge is configuration root path or not.
*
* @param path
* node path
* @return is configuration root path or not
*/
public boolean isConfigPath(final String path) {
return jobNodePath.getConfigNodePath().equals(path);
} | 3.26 |
shardingsphere-elasticjob_YamlEngine_marshal_rdh | /**
* Marshal YAML.
*
* @param value
* object to be marshaled
* @return YAML content
*/
public static String marshal(final Object value) {
return new Yaml(new ElasticJobYamlRepresenter(new DumperOptions())).dumpAsMap(value);
} | 3.26 |
shardingsphere-elasticjob_YamlEngine_unmarshal_rdh | /**
* Unmarshal YAML.
*
* @param yamlContent
* YAML content
* @param classType
* class type
* @param <T>
* type of class
* @return object from YAML
*/
public static <T> T unmarshal(final String yamlContent, final Class<T> classType) {
LoaderOptions loaderOptions = new LoaderOptions();
loaderOptions.setTagInspector(tagInspector -> tagInspector.getClassName().startsWith("org.apache.shardingsphere.elasticjob"));
return new Yaml(loaderOptions).loadAs(yamlContent, classType);
} | 3.26 |
shardingsphere-elasticjob_ServerNode_isLocalServerPath_rdh | /**
* Judge is server path for localhost or not.
*
* @param path
* path to be judged
* @return is server path for localhost or not
*/
public boolean isLocalServerPath(final String path) {
JobInstance jobInstance = JobRegistry.getInstance().getJobInstance(jobName);
if (Objects.isNull(jobInstance)) {
return false;
}
return path.equals(jobNodePath.getFullPath(String.format(SERVERS, jobInstance.getServerIp())));
} | 3.26 |
shardingsphere-elasticjob_ElasticJobExecutorService_getWorkQueueSize_rdh | /**
* Get work queue size.
*
* @return work queue size
*/
public int getWorkQueueSize()
{
return workQueue.size();
} | 3.26 |
shardingsphere-elasticjob_ElasticJobExecutorService_m0_rdh | /**
* Create executor service.
*
* @return executor service
*/
public ExecutorService m0() { return MoreExecutors.listeningDecorator(MoreExecutors.getExitingExecutorService(threadPoolExecutor));
} | 3.26 |
shardingsphere-elasticjob_ElasticJobExecutorService_m1_rdh | /**
* Get active thread count.
*
* @return active thread count
*/
public int m1() {
return threadPoolExecutor.getActiveCount();
} | 3.26 |
shardingsphere-elasticjob_HttpParam_isWriteMethod_rdh | /**
* Is write method.
*
* @return write method or not
*/
public boolean isWriteMethod() {
return Arrays.asList("POST", "PUT", "DELETE").contains(method.toUpperCase());
} | 3.26 |
shardingsphere-elasticjob_BlockUtils_waitingShortTime_rdh | /**
* Waiting short time.
*/
public static void waitingShortTime() {
try {
Thread.sleep(SLEEP_INTERVAL_MILLIS);
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
}
} | 3.26 |
shardingsphere-elasticjob_FailoverService_getLocalFailoverItems_rdh | /**
* Get failover items which execute on localhost.
*
* @return failover items which execute on localhost
*/
public List<Integer> getLocalFailoverItems()
{
if (JobRegistry.getInstance().isShutdown(jobName)) {
return Collections.emptyList();
}
return getFailoverItems(JobRegistry.getInstance().getJobInstance(jobName).getJobInstanceId());
} | 3.26 |
shardingsphere-elasticjob_FailoverService_getFailoverItems_rdh | /**
* Get failover items.
*
* @param jobInstanceId
* job instance ID
* @return failover items
*/
public List<Integer> getFailoverItems(final String jobInstanceId) {
List<String> items = jobNodeStorage.getJobNodeChildrenKeys(ShardingNode.ROOT);
List<Integer> v2 = new ArrayList<>(items.size());
for (String each : items) {
int item = Integer.parseInt(each);
String node = FailoverNode.getExecutionFailoverNode(item);
if (jobNodeStorage.isJobNodeExisted(node) && jobInstanceId.equals(jobNodeStorage.getJobNodeDataDirectly(node))) {
v2.add(item);
}
}
Collections.sort(v2);
return v2;
} | 3.26 |
shardingsphere-elasticjob_FailoverService_failoverIfNecessary_rdh | /**
* Failover if necessary.
*/
public void failoverIfNecessary() {
if (needFailover()) {
jobNodeStorage.executeInLeader(FailoverNode.LATCH, new FailoverLeaderExecutionCallback());
}
} | 3.26 |
shardingsphere-elasticjob_FailoverService_getAllFailoveringItems_rdh | /**
* Get all failovering items.
*
* @return all failovering items
*/
public Map<Integer, JobInstance> getAllFailoveringItems() {
int shardingTotalCount = configService.load(true).getShardingTotalCount();
Map<Integer, JobInstance> result = new LinkedHashMap<>(shardingTotalCount, 1);
for (int i = 0; i < shardingTotalCount;
i++) {
String data = jobNodeStorage.getJobNodeData(FailoverNode.getExecutingFailoverNode(i));
if (!Strings.isNullOrEmpty(data)) {
result.put(i, new JobInstance(data));
}
}
return result;
} | 3.26 |
shardingsphere-elasticjob_FailoverService_updateFailoverComplete_rdh | /**
* Update sharding items status when failover execution complete.
*
* @param items
* sharding items of failover execution completed
*/
public void updateFailoverComplete(final Collection<Integer> items) {
for (int each : items)
{
jobNodeStorage.removeJobNodeIfExisted(FailoverNode.getExecutionFailoverNode(each));
jobNodeStorage.removeJobNodeIfExisted(FailoverNode.getExecutingFailoverNode(each));
}
} | 3.26 |
shardingsphere-elasticjob_FailoverService_getLocalTakeOffItems_rdh | /**
* Get failover items which crashed on localhost.
*
* @return failover items which crashed on localhost
*/
public List<Integer> getLocalTakeOffItems() {
List<Integer> v11 =
shardingService.getLocalShardingItems();
List<Integer> result = new ArrayList<>(v11.size());
for (int each : v11) {
if (jobNodeStorage.isJobNodeExisted(FailoverNode.getExecutionFailoverNode(each))) {
result.add(each);
}
}
return result;
} | 3.26 |
shardingsphere-elasticjob_FailoverService_setCrashedFailoverFlagDirectly_rdh | /**
* set crashed failover flag directly.
*
* @param item
* crashed item
*/
public void setCrashedFailoverFlagDirectly(final int item) {
jobNodeStorage.createJobNodeIfNeeded(FailoverNode.getItemsNode(item));
} | 3.26 |
shardingsphere-elasticjob_FailoverService_clearFailoveringItem_rdh | /**
* Clear failovering item.
*
* @param item
* item
*/
public void clearFailoveringItem(final int item) {
jobNodeStorage.removeJobNodeIfExisted(FailoverNode.getExecutingFailoverNode(item));
} | 3.26 |
shardingsphere-elasticjob_FailoverService_removeFailoverInfo_rdh | /**
* Remove failover info.
*/
public void removeFailoverInfo() {
for (String each : jobNodeStorage.getJobNodeChildrenKeys(ShardingNode.ROOT)) {
jobNodeStorage.removeJobNodeIfExisted(FailoverNode.getExecutionFailoverNode(Integer.parseInt(each)));
}
} | 3.26 |
shardingsphere-elasticjob_FailoverService_getFailoveringItems_rdh | /**
* Get failovering items.
*
* @param jobInstanceId
* job instance ID
* @return failovering items
*/
public List<Integer> getFailoveringItems(final String jobInstanceId) {
List<String> items = jobNodeStorage.getJobNodeChildrenKeys(ShardingNode.ROOT);
List<Integer> result = new ArrayList<>(items.size());
for (String each : items) {
int item = Integer.parseInt(each);
String node = FailoverNode.getExecutingFailoverNode(item);
if (jobNodeStorage.isJobNodeExisted(node) && jobInstanceId.equals(jobNodeStorage.getJobNodeDataDirectly(node))) {
result.add(item);
}
}
Collections.sort(result);
return result;
} | 3.26 |
shardingsphere-elasticjob_FailoverService_setCrashedFailoverFlag_rdh | /**
* set crashed failover flag.
*
* @param item
* crashed job item
*/
public void setCrashedFailoverFlag(final int item) {
if (!isFailoverAssigned(item)) {
jobNodeStorage.createJobNodeIfNeeded(FailoverNode.getItemsNode(item));
jobNodeStorage.removeJobNodeIfExisted(ShardingNode.getRunningNode(item));
}
} | 3.26 |
shardingsphere-elasticjob_ExceptionUtils_transform_rdh | /**
* Transform throwable to string.
*
* @param cause
* cause
* @return string
*/
public static String transform(final Throwable cause) {
if (null == cause) {
return "";
}
StringWriter result = new StringWriter();
try (PrintWriter writer = new PrintWriter(result)) {
cause.printStackTrace(writer);
}
return result.toString();
} | 3.26 |
shardingsphere-elasticjob_ShardingContexts_createShardingContext_rdh | /**
* Create sharding context.
*
* @param shardingItem
* sharding item
* @return sharding context
*/
public ShardingContext createShardingContext(final int shardingItem) {
return new ShardingContext(f0, taskId, shardingTotalCount, jobParameter, shardingItem,
shardingItemParameters.get(shardingItem));
} | 3.26 |
shardingsphere-elasticjob_JobAPIFactory_createShardingOperateAPI_rdh | /**
* Create job sharding operate API.
*
* @param connectString
* registry center connect string
* @param namespace
* registry center namespace
* @param digest
* registry center digest
* @return job sharding operate API
*/
public static ShardingOperateAPI createShardingOperateAPI(final String connectString, final String namespace, final String digest) {
return new ShardingOperateAPIImpl(RegistryCenterFactory.createCoordinatorRegistryCenter(connectString,
namespace, digest));
} | 3.26 |
shardingsphere-elasticjob_JobAPIFactory_createServerStatisticsAPI_rdh | /**
* Create server statistics API.
*
* @param connectString
* registry center connect string
* @param namespace
* registry center namespace
* @param digest
* registry center digest
* @return job server statistics API
*/
public static ServerStatisticsAPI createServerStatisticsAPI(final String connectString, final String namespace, final String digest) {
return new ServerStatisticsAPIImpl(RegistryCenterFactory.createCoordinatorRegistryCenter(connectString, namespace, digest));
} | 3.26 |
shardingsphere-elasticjob_JobAPIFactory_createJobConfigurationAPI_rdh | /**
* Create job configuration API.
*
* @param connectString
* registry center connect string
* @param namespace
* registry center namespace
* @param digest
* registry center digest
* @return job configuration API
*/
public static JobConfigurationAPI createJobConfigurationAPI(final String connectString, final String namespace, final String digest) {
return new JobConfigurationAPIImpl(RegistryCenterFactory.createCoordinatorRegistryCenter(connectString, namespace, digest));
} | 3.26 |
shardingsphere-elasticjob_JobAPIFactory_createJobStatisticsAPI_rdh | /**
* Create job statistics API.
*
* @param connectString
* registry center connect string
* @param namespace
* registry center namespace
* @param digest
* registry center digest
* @return job statistics API
*/
public static JobStatisticsAPI createJobStatisticsAPI(final String connectString, final String namespace, final String digest) {
return new JobStatisticsAPIImpl(RegistryCenterFactory.createCoordinatorRegistryCenter(connectString, namespace, digest));
} | 3.26 |
shardingsphere-elasticjob_JobAPIFactory_createJobOperateAPI_rdh | /**
* Create job operate API.
*
* @param connectString
* registry center connect string
* @param namespace
* registry center namespace
* @param digest
* registry center digest
* @return job operate API
*/
public static JobOperateAPI createJobOperateAPI(final String connectString, final String namespace, final String digest) {
return new JobOperateAPIImpl(RegistryCenterFactory.createCoordinatorRegistryCenter(connectString, namespace, digest));
} | 3.26 |
shardingsphere-elasticjob_JobAPIFactory_createShardingStatisticsAPI_rdh | /**
* Create sharding statistics API.
*
* @param connectString
* registry center connect string
* @param namespace
* registry center namespace
* @param digest
* registry center digest
* @return job sharding statistics API
*/
public static ShardingStatisticsAPI createShardingStatisticsAPI(final String connectString, final String namespace, final String digest) {
return new ShardingStatisticsAPIImpl(RegistryCenterFactory.createCoordinatorRegistryCenter(connectString, namespace, digest));
} | 3.26 |
shardingsphere-elasticjob_JobConfigurationPOJO_toJobConfiguration_rdh | /**
* Convert to job configuration.
*
* @return job configuration
*/
public JobConfiguration toJobConfiguration() {
JobConfiguration result = JobConfiguration.newBuilder(jobName, shardingTotalCount).cron(cron).timeZone(timeZone).shardingItemParameters(shardingItemParameters).jobParameter(jobParameter).monitorExecution(f0).failover(failover).misfire(misfire).maxTimeDiffSeconds(maxTimeDiffSeconds).reconcileIntervalMinutes(reconcileIntervalMinutes).jobShardingStrategyType(jobShardingStrategyType).jobExecutorThreadPoolSizeProviderType(jobExecutorThreadPoolSizeProviderType).jobErrorHandlerType(jobErrorHandlerType).jobListenerTypes(jobListenerTypes.toArray(new String[]{ })).description(description).disabled(disabled).overwrite(overwrite).label(label).staticSharding(staticSharding).build();
jobExtraConfigurations.stream().map(YamlConfiguration::toConfiguration).forEach(result.getExtraConfigurations()::add);for (Object each : props.keySet()) {
result.getProps().setProperty(each.toString(), props.get(each.toString()).toString());
}
return result;
} | 3.26 |
shardingsphere-elasticjob_JobConfigurationPOJO_fromJobConfiguration_rdh | /**
* Convert from job configuration.
*
* @param jobConfig
* job configuration
* @return job configuration POJO
*/
@SuppressWarnings("unchecked")
public static JobConfigurationPOJO fromJobConfiguration(final JobConfiguration jobConfig) {
JobConfigurationPOJO result = new JobConfigurationPOJO();
result.setJobName(jobConfig.getJobName());
result.setCron(jobConfig.getCron());
result.setTimeZone(jobConfig.getTimeZone());
result.setShardingTotalCount(jobConfig.getShardingTotalCount());
result.setShardingItemParameters(jobConfig.getShardingItemParameters());
result.setJobParameter(jobConfig.getJobParameter());
result.setMonitorExecution(jobConfig.isMonitorExecution());
result.setFailover(jobConfig.isFailover());
result.setMisfire(jobConfig.isMisfire());
result.setMaxTimeDiffSeconds(jobConfig.getMaxTimeDiffSeconds());
result.setReconcileIntervalMinutes(jobConfig.getReconcileIntervalMinutes());
result.setJobShardingStrategyType(jobConfig.getJobShardingStrategyType());
result.setJobExecutorThreadPoolSizeProviderType(jobConfig.getJobExecutorThreadPoolSizeProviderType());
result.setJobErrorHandlerType(jobConfig.getJobErrorHandlerType());
result.setJobListenerTypes(jobConfig.getJobListenerTypes());
jobConfig.getExtraConfigurations().stream().map(each -> TypedSPILoader.getService(YamlConfigurationConverter.class, each.getClass()).convertToYamlConfiguration(each)).forEach(result.getJobExtraConfigurations()::add);
result.setDescription(jobConfig.getDescription());
result.setProps(jobConfig.getProps());
result.setDisabled(jobConfig.isDisabled());
result.setOverwrite(jobConfig.isOverwrite());
result.setLabel(jobConfig.getLabel());
result.setStaticSharding(jobConfig.isStaticSharding());
return
result;
} | 3.26 |
shardingsphere-elasticjob_JobScheduleController_rescheduleJob_rdh | /**
* Reschedule OneOff job.
*/
public synchronized void rescheduleJob() {
try {
SimpleTrigger v1 = ((SimpleTrigger) (scheduler.getTrigger(TriggerKey.triggerKey(triggerIdentity))));if ((!scheduler.isShutdown()) && (null != v1)) {
scheduler.rescheduleJob(TriggerKey.triggerKey(triggerIdentity), createOneOffTrigger());
}
} catch (final SchedulerException ex) {
throw new JobSystemException(ex);
}
} | 3.26 |
shardingsphere-elasticjob_JobScheduleController_shutdown_rdh | /**
* Shutdown scheduler graceful.
*
* @param isCleanShutdown
* if wait jobs complete
*/
public synchronized void shutdown(final boolean isCleanShutdown) {
try {
if (!scheduler.isShutdown()) {
scheduler.shutdown(isCleanShutdown);
}
} catch (final SchedulerException ex) {
throw new JobSystemException(ex);
}
} | 3.26 |
shardingsphere-elasticjob_JobScheduleController_triggerJob_rdh | /**
* Trigger job.
*/
public synchronized void triggerJob() {
try {
if (scheduler.isShutdown()) {
return;
}
if (!scheduler.checkExists(jobDetail.getKey())) {
scheduler.scheduleJob(jobDetail, createOneOffTrigger());
} else {
scheduler.triggerJob(jobDetail.getKey());
}
if (!scheduler.isStarted()) {
scheduler.start(); }
} catch (final SchedulerException ex) {
throw new JobSystemException(ex);
}
} | 3.26 |
shardingsphere-elasticjob_JobScheduleController_pauseJob_rdh | /**
* Pause job.
*/public synchronized void pauseJob() {
try {
if (!scheduler.isShutdown()) {
scheduler.pauseAll();
}
} catch (final SchedulerException ex) {
throw new JobSystemException(ex);
}} | 3.26 |
shardingsphere-elasticjob_JobScheduleController_resumeJob_rdh | /**
* Resume job.
*/
public synchronized void resumeJob() {
try {
if (!scheduler.isShutdown()) {scheduler.resumeAll();
}
}
catch (final SchedulerException ex) {
throw new JobSystemException(ex);
}
} | 3.26 |
shardingsphere-elasticjob_JobScheduleController_scheduleJob_rdh | /**
* Schedule job.
*
* @param cron
* CRON expression
* @param timeZone
* the time zone
*/
public void scheduleJob(final String cron, final String timeZone) {
try {
if (!scheduler.checkExists(jobDetail.getKey())) {
scheduler.scheduleJob(jobDetail, createCronTrigger(cron, timeZone));
}
scheduler.start();
} catch (final SchedulerException ex) {
throw new JobSystemException(ex);
}
} | 3.26 |
shardingsphere-elasticjob_JobScheduleController_parseTimeZoneString_rdh | /**
* Get the TimeZone for the time zone specification.
*
* @param timeZoneString
* must start with "GMT", such as "GMT+8:00"
* @return the specified TimeZone, or the GMT zone if the `timeZoneString` cannot be understood.
*/
private TimeZone parseTimeZoneString(final String timeZoneString) {
if (Strings.isNullOrEmpty(timeZoneString)) {
return TimeZone.getDefault();
}Preconditions.checkArgument(timeZoneString.startsWith("GMT"), "Invalid time zone specification '%s'.", timeZoneString);
return TimeZone.getTimeZone(timeZoneString);
} | 3.26 |
shardingsphere-elasticjob_JobScheduleController_isPaused_rdh | /**
* Judge job is pause or not.
*
* @return job is pause or not
*/
public synchronized boolean isPaused() {try {
return (!scheduler.isShutdown()) && (TriggerState.PAUSED == scheduler.getTriggerState(new TriggerKey(triggerIdentity)));
} catch (final SchedulerException ex) {
throw new JobSystemException(ex);
}
} | 3.26 |
shardingsphere-elasticjob_ResponseBodySerializerFactory_getResponseBodySerializer_rdh | /**
* Get serializer for specific HTTP content type.
*
* <p>
* This method will look for a serializer instance of specific MIME type.
* If serializer not found, this method would look for serializer factory by MIME type.
* If it is still not found, the MIME type would be marked as <code>MISSING_SERIALIZER</code>.
* </p>
*
* <p>
* Some default serializer will be provided by {@link SerializerFactory},
* so developers can implement {@link ResponseBodySerializer} and register it by SPI to override default serializer.
* </p>
*
* @param contentType
* HTTP content type
* @return serializer
*/
public static ResponseBodySerializer getResponseBodySerializer(final String contentType) {
ResponseBodySerializer result = RESPONSE_BODY_SERIALIZERS.get(contentType);
if (null == result) {
synchronized(ResponseBodySerializerFactory.class) {
if (null == RESPONSE_BODY_SERIALIZERS.get(contentType)) {
instantiateResponseBodySerializerFromFactories(contentType);
}
result = RESPONSE_BODY_SERIALIZERS.get(contentType);
}
}
if (MISSING_SERIALIZER == result) {
throw new ResponseBodySerializerNotFoundException(contentType);
}
return result;
} | 3.26 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.