Package com.taobao.tdhs.client.packet

Examples of com.taobao.tdhs.client.packet.BasePacket


                sb.append(" ");
            }
            sb.append("]");
            logger.debug(sb.toString());
        }
        return new BasePacket(TDHSResponseEnum.ClientStatus.valueOf((int) response), seqId, reserved, data);
    }
View Full Code Here


    }

    @Override
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {

        BasePacket packet = (BasePacket) e.getMessage();
        ArrayBlockingQueue<BasePacket> blockingQueue = responses.get(packet.getSeqId());
        if (blockingQueue != null) {
            blockingQueue.put(packet);
        }
    }
View Full Code Here

        if (StringUtils.isBlank(request.getCharsetName())) {
            //use default charsetName
            request.setCharsetName(this.charsetName);
        }
        byte data[] = version.getTdhsProtocol().encode(request);
        BasePacket packet = new BasePacket(type, id.getAndIncrement(), hash, data);
        ArrayBlockingQueue<BasePacket> queue = new ArrayBlockingQueue<BasePacket>(1);
        long seqId = packet.getSeqId();
        responses.put(seqId, queue);
        try {
            tdhsNet.write(packet);
            return do_response(queue, metaData, request.getCharsetName());
        } finally {
View Full Code Here

                                       String charsetName)
            throws TDHSException {
        ByteArrayOutputStream retData = new ByteArrayOutputStream();
        try {
            while (true) {
                BasePacket ret = null;
                ret = queue.poll(timeOut, TimeUnit.MILLISECONDS);
                if (ret == null) {
                    throw new TDHSTimeoutException("TimeOut");
                } else {
                    if (TDHSResponseEnum.ClientStatus.ACCEPT.equals(ret.getClientStatus())) {
                        retData.write(ret.getData());
                    } else if (TDHSResponseEnum.ClientStatus.OK.equals(ret.getClientStatus())) {
                        retData.write(ret.getData());
                        return new TDHSResponse(ret.getClientStatus(), metaData, retData.toByteArray(),
                                charsetName);
                    } else if (ret.getClientStatus() != null && ret.getClientStatus().getStatus() >= 400 &&
                            ret.getClientStatus().getStatus() < 600) {
                        return new TDHSResponse(ret.getClientStatus(), metaData, ret.getData(), charsetName);
                    } else {
                        throw new TDHSException("unknown response code! [" + (ret.getClientStatus() != null ?
                                String.valueOf(ret.getClientStatus().getStatus()) : "") + "]");
                    }
                }
            }
        } catch (InterruptedException e) {
            throw new TDHSException(e);
View Full Code Here

                    responses.put(is.getPacket().getSeqId(), new ArrayBlockingQueue<BasePacket>(1));
                }
            } catch (IOException e) {
                throw new TDHSException(e);
            }
            BasePacket headerPacket =
                    new BasePacket(TDHSCommon.RequestType.BATCH, headerId, batchRequest.size(),
                            retData.toByteArray());
            ArrayBlockingQueue<BasePacket> queue = new ArrayBlockingQueue<BasePacket>(1);
            responses.put(headerId, queue);
            tdhsNet.write(headerPacket);
            return do_real_response(queue);
View Full Code Here

            return this.timeOut;
        }
    }

    private TDHSResponse[] do_real_response(ArrayBlockingQueue<BasePacket> queue) throws TDHSException {
        BasePacket ret = null;
        try {
            ret = queue.poll(getTimeOut(), TimeUnit.MILLISECONDS);
            if (ret == null) {
                throw new TDHSTimeoutException("TimeOut");
            }
            if (!TDHSResponseEnum.ClientStatus.MULTI_STATUS.equals(ret.getClientStatus())) {
                if (ret.getClientStatus() != null && ret.getClientStatus().getStatus() >= 400 &&
                        ret.getClientStatus().getStatus() < 600) {
                    throw new TDHSBatchException(
                            new TDHSResponse(ret.getClientStatus(), null, ret.getData(), charsetName));
                } else {
                    throw new TDHSException("unknown response code! [" + (ret.getClientStatus() != null ?
                            String.valueOf(ret.getClientStatus().getStatus()) : "") + "]");
                }
            }
            if (ret.getBatchNumber() != batchRequest.size()) {
                throw new TDHSException(
                        "unmatch batch size! request is[" + String.valueOf(batchRequest.size()) + "], response is [" +
                                String.valueOf(ret.getBatchNumber()) + "]");
            }

            TDHSResponse result[] = new TDHSResponse[batchRequest.size()];
            int i = 0;
            for (internal_struct is : batchRequest) {
View Full Code Here

        if (StringUtils.isBlank(request.getCharsetName())) {
            //use default charsetName
            request.setCharsetName(this.charsetName);
        }
        byte data[] = version.getTdhsProtocol().encode(request);
        BasePacket packet = new BasePacket(type, id.getAndIncrement(), data);
        batchRequest.add(new internal_struct(packet, metaData, request.getCharsetName()));
        return null;
    }
View Full Code Here

            out.write("TDHS".getBytes());
            writeInt32ToStream(2, out);//版本号
            writeInt32ToStream(timeOut, out);//超时时间
            writeToStream(readCode, out, null); //read code
            writeToStream(writeCode, out, null);//write code
            return new BasePacket(TDHSCommon.RequestType.SHAKE_HAND, 0, out.toByteArray());
        } catch (IOException e) {
            assert false; //不应该发生
            logger.error("shakeHandPacket failed!", e);
            return null;
        }
View Full Code Here

            out.write("TDHS".getBytes());
            writeInt32ToStream(1, out);//版本号
            writeInt32ToStream(timeOut, out);//超时时间
            writeToStream(readCode, out, null); //read code
            writeToStream(writeCode, out, null);//write code
            return new BasePacket(TDHSCommon.RequestType.SHAKE_HAND, 0, out.toByteArray());
        } catch (IOException e) {
            assert false; //不应该发生
            logger.error("shakeHandPacket failed!", e);
            return null;
        }
View Full Code Here

TOP

Related Classes of com.taobao.tdhs.client.packet.BasePacket

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.