com.lorne.core.framework.utils.KidUtils Java Examples

The following examples show how to use com.lorne.core.framework.utils.KidUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TxManagerServiceImpl.java    From tx-lcn with Apache License 2.0 5 votes vote down vote up
@Override
public TxGroup createTransactionGroup() {
    String groupId = KidUtils.generateShortUuid();
    TxGroup txGroup = new TxGroup();
    txGroup.setStartTime(System.currentTimeMillis());
    txGroup.setGroupId(groupId);
    String key = key_prefix + groupId;
    ValueOperations<String, String> value = redisTemplate.opsForValue();
    value.set(key, txGroup.toJsonString(), redis_save_max_time, TimeUnit.SECONDS);
    return txGroup;
}
 
Example #2
Source File: UploadServiceImpl.java    From fileServer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean cutImage(String fileName, String cutSize) throws ServiceException {

    if(StringUtils.isEmpty(fileName)){
        throw new ParamException("fileName is null");
    }

    List<ImageWH> whs =loadCutSize(cutSize);


    StorePath path = StorePath.praseFromUrl(fileName);

    String ext = FilenameUtils.getExtension(fileName);

    InputStream sourceStream =storageClient.downloadFile(path.getGroup(), path.getPath(), new DownloadCallback<InputStream>() {

        @Override
        public InputStream recv(InputStream inputStream) throws IOException {
            return inputStream;
        }
    });

    if(sourceStream==null){
        throw new ServiceException("download error");
    }

    File file = new File(KidUtils.getUUID());
    try {
        FileUtils.copyInputStreamToFile(sourceStream,file);
        uploadCutImages(whs,file,path,ext);

    } catch (IOException e) {
        throw new ServiceException(e);
    }finally {
        file.delete();
    }

    return true;
}
 
Example #3
Source File: Request.java    From tx-lcn with Apache License 2.0 4 votes vote down vote up
public Request(String action, String params) {
    this.action = action;
    this.params = params;
    this.key = KidUtils.generateShortUuid();
}
 
Example #4
Source File: TxRunningTransactionServerImpl.java    From tx-lcn with Apache License 2.0 4 votes vote down vote up
@Override
public Object execute(final ProceedingJoinPoint point, final TxTransactionInfo info) throws Throwable {

    String kid = KidUtils.generateShortUuid();
    String txGroupId = info.getTxGroupId();
    logger.info("tx-running-start->" + txGroupId);
    long t1 = System.currentTimeMillis();

    boolean isHasIsGroup =  group.hasGroup(txGroupId);

    TransactionRecover recover = new TransactionRecover();
    recover.setId(KidUtils.generateShortUuid());
    recover.setInvocation(info.getInvocation());
    recover.setTaskId(kid);
    recover.setGroupId(txGroupId);

    TxTransactionLocal txTransactionLocal = new TxTransactionLocal();
    txTransactionLocal.setGroupId(txGroupId);
    txTransactionLocal.setHasStart(false);
    txTransactionLocal.setRecover(recover);
    txTransactionLocal.setKid(kid);
    txTransactionLocal.setTransactional(info.getTransactional());
    txTransactionLocal.setMaxTimeOut(info.getMaxTimeOut());
    TxTransactionLocal.setCurrent(txTransactionLocal);


    try {

        Object res = point.proceed();

        //写操作 处理
        if(!txTransactionLocal.isReadOnly()) {

            TxGroup resTxGroup = txManagerService.addTransactionGroup(txGroupId, kid, isHasIsGroup);

            //已经进入过该模块的
            if(!isHasIsGroup) {
                String type = txTransactionLocal.getType();

                TxTask waitTask = TaskGroupManager.getInstance().getTask(kid, type);

                //lcn 连接已经开始等待时.
                while (waitTask != null && !waitTask.isAwait()) {
                    TimeUnit.MILLISECONDS.sleep(1);
                }

                if (resTxGroup == null) {

                    //通知业务回滚事务
                    if (waitTask != null) {
                        //修改事务组状态异常
                        waitTask.setState(-1);
                        waitTask.signalTask();
                        throw new ServiceException("修改事务组状态异常." + txGroupId);
                    }
                }
            }
        }

        return res;
    } catch (Throwable e) {
        throw e;
    } finally {
        TxTransactionLocal.setCurrent(null);
        long t2 = System.currentTimeMillis();
        logger.info("tx-running-end->" + txGroupId+",time->"+(t2-t1));
    }
}
 
Example #5
Source File: TxManagerServiceImpl.java    From tx-lcn with Apache License 2.0 4 votes vote down vote up
@Override
public void clearNotifyData(int time) {
    Set<String> keys =  redisTemplate.keys(key_prefix_notify+"*");

    ValueOperations<String, String> value = redisTemplate.opsForValue();
    for(String key:keys){
        String json =  value.get(key);
        TxGroup txGroup = TxGroup.parser(json);
        if(txGroup==null) {
            continue;
        }

        long nowTime = System.currentTimeMillis();
        if((nowTime - txGroup.getStartTime())>time*1000*60){
            if(txGroup.getList()!=null&&txGroup.getList().size()>0){
                for(TxInfo txInfo:txGroup.getList()){

                    String modelName = txInfo.getModelName();

                    Channel channel = SocketManager.getInstance().getChannelByModelName(modelName);

                    if(channel==null||!channel.isActive()){
                        //查找在线的有无同模块的
                        String uniqueKey = txInfo.getUniqueKey();

                        channel = SocketManager.getInstance().getChannelByUniqueKey(uniqueKey);

                        if(channel==null||!channel.isActive()){
                            continue;
                        }

                    }


                    final JSONObject jsonObject = new JSONObject();
                    jsonObject.put("a", "c");
                    jsonObject.put("g", txInfo.getKid());
                    String k = KidUtils.generateShortUuid();
                    jsonObject.put("k", k);
                    final Task task = ConditionUtils.getInstance().createTask(k);


                    ScheduledFuture future =  executorService.schedule(new TimerTask() {
                        @Override
                        public void run() {
                            task.setBack(new IBack() {
                                @Override
                                public Object doing(Object... objs) throws Throwable {
                                    return "0";
                                }
                            });
                            task.signalTask();
                        }
                    },getDelayTime(),TimeUnit.SECONDS);

                    final Channel sender = channel;

                    threadPool.execute(new Runnable() {
                        @Override
                        public void run() {
                            awaitSend(task, sender, jsonObject.toJSONString());
                        }
                    });

                    task.awaitTask();

                    if(!future.isDone()){
                        future.cancel(false);
                    }

                    try {
                        String data = (String) task.getBack().doing();
                        // 1 tx数据已经删除
                        boolean res = "1".equals(data);
                        if (res) {
                            txInfo.setNotify(1);
                        }

                    } catch (Throwable throwable) {
                        throwable.printStackTrace();
                    } finally {
                        task.remove();
                    }

                }

                boolean isOver = true;
                for (TxInfo info : txGroup.getList()) {
                    if (info.getIsGroup()==0&&info.getNotify() == 0) {
                        isOver = false;
                        break;
                    }
                }

                if (isOver) {
                    redisTemplate.delete(key);
                }
            }
        }
    }
}
 
Example #6
Source File: TestServiceImpl.java    From pay with Apache License 2.0 4 votes vote down vote up
@Override
public boolean refundOrder(String subMchId,String outTradeNo, int money) {
    return creditCardPay.refundOrder(subMchId,outTradeNo, KidUtils.getKid(),money,money);
}
 
Example #7
Source File: TestServiceImpl.java    From pay with Apache License 2.0 4 votes vote down vote up
@Override
public boolean refundOrder(String outTradeNo, int money) {
    return creditCardPay.refundOrder(outTradeNo, KidUtils.getKid(),money,money);
}
 
Example #8
Source File: TestServiceImpl.java    From pay with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, Object> transfers(String openid, int amount) {
    String partner_trade_no = KidUtils.getKid();
    return creditCardPay.transfers(partner_trade_no,openid,"NO_CHECK","",amount,"奖金","192.168.2.1");
}
 
Example #9
Source File: TestServiceImpl.java    From pay with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, Object> accountPay(int amount, String openId) {
    String tradeNo = KidUtils.getKid();
    return accountPay.createPay(tradeNo,"小走","契约金",amount,openId);
}
 
Example #10
Source File: UploadServiceImpl.java    From fileServer with Apache License 2.0 3 votes vote down vote up
@Override
public String uploadImage(String groupName, String cutSize, MultipartFile file) throws ServiceException {

    if (file.getSize() <= 0) {
        throw new ParamException("file is null.");
    }

    if(StringUtils.isEmpty(groupName)){
        throw new ParamException("groupName is null");
    }

    List<ImageWH> whs =loadCutSize(cutSize);

    fileValidateService.validateFile(file);

    try {

        String ext = FilenameUtils.getExtension(file.getOriginalFilename());
        StorePath path = storageClient.uploadFile(groupName, file.getInputStream(), file.getSize(), ext);
        if(path==null) {
            throw new ServiceException("upload error.");
        }


        File sourceFile = new File(KidUtils.getUUID());
        FileUtils.copyInputStreamToFile(file.getInputStream(),sourceFile);

        uploadCutImages(whs,sourceFile,path,ext);

        sourceFile.delete();

        return path.getFullPath();
    } catch (Exception e) {
        throw new ServiceException(e);
    }

}