/** * hmily initialization. * * @param hmilyConfig {@linkplain HmilyConfig} */ @Override public void initialization(final HmilyConfig hmilyConfig) { Runtime.getRuntime().addShutdownHook(new Thread(() -> LOGGER.info("hmily shutdown now"))); try { loadSpiSupport(hmilyConfig); hmilyCoordinatorService.start(hmilyConfig); } catch (Exception ex) { LogUtil.error(LOGGER, " hmily init exception:{}", ex::getMessage); System.exit(1); } new HmilyLogo().logo(); }
@Override public void init(final String modelName, final HmilyConfig hmilyConfig) { rootPathPrefix = RepositoryPathUtils.buildZookeeperPathPrefix(modelName); try { connect(hmilyConfig.getHmilyZookeeperConfig()); } catch (Exception e) { LogUtil.error(LOGGER, "zookeeper init error please check you config:{}", e::getMessage); throw new HmilyRuntimeException(e.getMessage()); } }
@Override public void init(final String modelName, final HmilyConfig hmilyConfig) { keyPrefix = RepositoryPathUtils.buildRedisKeyPrefix(modelName); final HmilyRedisConfig hmilyRedisConfig = hmilyConfig.getHmilyRedisConfig(); try { buildJedisPool(hmilyRedisConfig); } catch (Exception e) { LogUtil.error(LOGGER, "redis init error please check you config:{}", e::getMessage); throw new HmilyRuntimeException(e); } }
@Override public void init(final String modelName, final HmilyConfig hmilyConfig) { collectionName = RepositoryPathUtils.buildMongoTableName(modelName); final HmilyMongoConfig hmilyMongoConfig = hmilyConfig.getHmilyMongoConfig(); MongoClientFactoryBean clientFactoryBean = buildMongoClientFactoryBean(hmilyMongoConfig); try { clientFactoryBean.afterPropertiesSet(); template = new MongoTemplate(Objects.requireNonNull(clientFactoryBean.getObject()), hmilyMongoConfig.getMongoDbName()); } catch (Exception e) { LogUtil.error(LOGGER, "mongo init error please check you config:{}", e::getMessage); throw new HmilyRuntimeException(e); } }
/** * Cancel. * * @param hmilyTransaction the hmily transaction */ public void cancel(final HmilyTransaction hmilyTransaction) { final List<HmilyParticipant> hmilyParticipants = hmilyTransaction.getHmilyParticipants(); List<HmilyParticipant> failList = Lists.newArrayListWithCapacity(hmilyParticipants.size()); boolean success = true; if (CollectionUtils.isNotEmpty(hmilyParticipants)) { for (HmilyParticipant hmilyParticipant : hmilyParticipants) { try { HmilyTransactionContext context = new HmilyTransactionContext(); context.setAction(HmilyActionEnum.CANCELING.getCode()); context.setTransId(hmilyTransaction.getTransId()); context.setRole(HmilyRoleEnum.START.getCode()); HmilyTransactionContextLocal.getInstance().set(context); executeCoordinator(hmilyParticipant.getCancelHmilyInvocation()); } catch (Exception e) { LogUtil.error(LOGGER, "execute cancel exception:{}", () -> e); success = false; failList.add(hmilyParticipant); } finally { HmilyTransactionContextLocal.getInstance().remove(); } } executeHandler(success, hmilyTransaction, failList); } }
/** * Confirm. * * @param hmilyTransaction the hmily transaction */ public void confirm(final HmilyTransaction hmilyTransaction) { final List<HmilyParticipant> hmilyParticipants = hmilyTransaction.getHmilyParticipants(); List<HmilyParticipant> failList = Lists.newArrayListWithCapacity(hmilyParticipants.size()); boolean success = true; if (CollectionUtils.isNotEmpty(hmilyParticipants)) { for (HmilyParticipant hmilyParticipant : hmilyParticipants) { try { HmilyTransactionContext context = new HmilyTransactionContext(); context.setAction(HmilyActionEnum.CONFIRMING.getCode()); context.setRole(HmilyRoleEnum.START.getCode()); context.setTransId(hmilyTransaction.getTransId()); HmilyTransactionContextLocal.getInstance().set(context); executeCoordinator(hmilyParticipant.getConfirmHmilyInvocation()); } catch (Exception e) { LogUtil.error(LOGGER, "execute confirm exception:{}", () -> e); success = false; failList.add(hmilyParticipant); } finally { HmilyTransactionContextLocal.getInstance().remove(); } } executeHandler(success, hmilyTransaction, failList); } }
executeParticipantMethod(hmilyParticipant.getConfirmHmilyInvocation()); } catch (Exception e) { LogUtil.error(LOGGER, "execute confirm :{}", () -> e); success = false; failList.add(hmilyParticipant);
executeParticipantMethod(hmilyParticipant.getCancelHmilyInvocation()); } catch (Throwable e) { LogUtil.error(LOGGER, "execute cancel ex:{}", () -> e); success = false; failList.add(hmilyParticipant);
} catch (Exception ex) { ex.printStackTrace(); LogUtil.error(LOGGER, "hmily find method error {} ", ex::getMessage);
executeUpdate(SqlHelper.buildCreateTableSql(hmilyDbConfig.getDriverClassName(), tableName)); } catch (Exception e) { LogUtil.error(LOGGER, "hmily jdbc log init exception please check config:{}", e::getMessage); throw new HmilyRuntimeException(e);
@SuppressWarnings("unchecked") private HmilyTransaction buildByCache(final MongoAdapter cache) { try { HmilyTransaction hmilyTransaction = new HmilyTransaction(); hmilyTransaction.setTransId(cache.getTransId()); hmilyTransaction.setCreateTime(cache.getCreateTime()); hmilyTransaction.setLastTime(cache.getLastTime()); hmilyTransaction.setRetriedCount(cache.getRetriedCount()); hmilyTransaction.setVersion(cache.getVersion()); hmilyTransaction.setStatus(cache.getStatus()); hmilyTransaction.setRole(cache.getRole()); hmilyTransaction.setPattern(cache.getPattern()); hmilyTransaction.setTargetClass(cache.getTargetClass()); hmilyTransaction.setTargetMethod(cache.getTargetMethod()); List<HmilyParticipant> hmilyParticipants = (List<HmilyParticipant>) objectSerializer.deSerialize(cache.getContents(), CopyOnWriteArrayList.class); hmilyTransaction.setHmilyParticipants(hmilyParticipants); return hmilyTransaction; } catch (HmilyException e) { LogUtil.error(LOGGER, "mongodb deSerialize exception:{}", e::getLocalizedMessage); return null; } }