Package com.alibaba.otter.canal.protocol

Examples of com.alibaba.otter.canal.protocol.ClientIdentity


                                int soTimeout){
        this.address = address;
        this.username = username;
        this.password = password;
        this.soTimeout = soTimeout;
        this.clientIdentity = new ClientIdentity(destination, (short) 1001);
    }
View Full Code Here


        MetaLogPositionManager logPositionManager = new MetaLogPositionManager();
        logPositionManager.setMetaManager(metaManager);
        logPositionManager.start();
        // 构建meta信息
        ClientIdentity client1 = new ClientIdentity(destination, (short) 1);
        metaManager.subscribe(client1);

        PositionRange range1 = buildRange(1);
        metaManager.updateCursor(client1, range1.getEnd());

        PositionRange range2 = buildRange(2);
        metaManager.updateCursor(client1, range2.getEnd());

        ClientIdentity client2 = new ClientIdentity(destination, (short) 2);
        metaManager.subscribe(client2);

        PositionRange range3 = buildRange(3);
        metaManager.updateCursor(client2, range3.getEnd());
View Full Code Here

                                int soTimeout){
        this.address = address;
        this.username = username;
        this.password = password;
        this.soTimeout = soTimeout;
        this.clientIdentity = new ClientIdentity(destination, (short) 1001);
    }
View Full Code Here

    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
        logger.info("message receives in session handler...");
        ChannelBuffer buffer = (ChannelBuffer) e.getMessage();
        Packet packet = Packet.parseFrom(buffer.readBytes(buffer.readableBytes()).array());
        ClientIdentity clientIdentity = null;
        try {
            switch (packet.getType()) {
                case SUBSCRIPTION:
                    Sub sub = Sub.parseFrom(packet.getBody());
                    if (StringUtils.isNotEmpty(sub.getDestination()) && StringUtils.isNotEmpty(sub.getClientId())) {
                        clientIdentity = new ClientIdentity(sub.getDestination(), Short.valueOf(sub.getClientId()),
                                                            sub.getFilter());
                        MDC.put("destination", clientIdentity.getDestination());
                        embededServer.subscribe(clientIdentity);

                        // 尝试启动,如果已经启动,忽略
                        if (!embededServer.isStart(clientIdentity.getDestination())) {
                            ServerRunningMonitor runningMonitor = ServerRunningMonitors.getRunningMonitor(clientIdentity.getDestination());
                            if (!runningMonitor.isStart()) {
                                runningMonitor.start();
                            }
                        }

                        ctx.setAttachment(clientIdentity);// 设置状态数据
                        NettyUtils.ack(ctx.getChannel(), null);
                    } else {
                        NettyUtils.error(401,
                                         MessageFormatter.format("destination or clientId is null", sub.toString()).getMessage(),
                                         ctx.getChannel(), null);
                    }
                    break;
                case UNSUBSCRIPTION:
                    Unsub unsub = Unsub.parseFrom(packet.getBody());
                    if (StringUtils.isNotEmpty(unsub.getDestination()) && StringUtils.isNotEmpty(unsub.getClientId())) {
                        clientIdentity = new ClientIdentity(unsub.getDestination(), Short.valueOf(unsub.getClientId()),
                                                            unsub.getFilter());
                        MDC.put("destination", clientIdentity.getDestination());
                        embededServer.unsubscribe(clientIdentity);
                        stopCanalInstanceIfNecessary(clientIdentity);// 尝试关闭
                        NettyUtils.ack(ctx.getChannel(), null);
                    } else {
                        NettyUtils.error(401,
                                         MessageFormatter.format("destination or clientId is null", unsub.toString()).getMessage(),
                                         ctx.getChannel(), null);
                    }
                    break;
                case GET:
                    Get get = CanalPacket.Get.parseFrom(packet.getBody());
                    if (StringUtils.isNotEmpty(get.getDestination()) && StringUtils.isNotEmpty(get.getClientId())) {
                        clientIdentity = new ClientIdentity(get.getDestination(), Short.valueOf(get.getClientId()));
                        MDC.put("destination", clientIdentity.getDestination());
                        Message message = null;

                        //                        if (get.getAutoAck()) {
                        //                            if (get.getTimeout() == -1) {//是否是初始值
                        //                                message = embededServer.get(clientIdentity, get.getFetchSize());
                        //                            } else {
                        //                                TimeUnit unit = convertTimeUnit(get.getUnit());
                        //                                message = embededServer.get(clientIdentity, get.getFetchSize(), get.getTimeout(), unit);
                        //                            }
                        //                        } else {
                        if (get.getTimeout() == -1) {//是否是初始值
                            message = embededServer.getWithoutAck(clientIdentity, get.getFetchSize());
                        } else {
                            TimeUnit unit = convertTimeUnit(get.getUnit());
                            message = embededServer.getWithoutAck(clientIdentity, get.getFetchSize(), get.getTimeout(),
                                                                  unit);
                        }
                        //                        }

                        Packet.Builder packetBuilder = CanalPacket.Packet.newBuilder();
                        packetBuilder.setType(PacketType.MESSAGES);

                        Messages.Builder messageBuilder = CanalPacket.Messages.newBuilder();
                        messageBuilder.setBatchId(message.getId());
                        if (message.getId() != -1 && !CollectionUtils.isEmpty(message.getEntries())) {
                            for (Entry entry : message.getEntries()) {
                                messageBuilder.addMessages(entry.toByteString());
                            }
                        }
                        packetBuilder.setBody(messageBuilder.build().toByteString());
                        NettyUtils.write(ctx.getChannel(), packetBuilder.build().toByteArray(), null);// 输出数据
                    } else {
                        NettyUtils.error(401,
                                         MessageFormatter.format("destination or clientId is null", get.toString()).getMessage(),
                                         ctx.getChannel(), null);
                    }
                    break;
                case CLIENTACK:
                    ClientAck ack = CanalPacket.ClientAck.parseFrom(packet.getBody());
                    MDC.put("destination", ack.getDestination());
                    if (StringUtils.isNotEmpty(ack.getDestination()) && StringUtils.isNotEmpty(ack.getClientId())) {
                        if (ack.getBatchId() == 0L) {
                            NettyUtils.error(402,
                                             MessageFormatter.format("batchId should assign value", ack.toString()).getMessage(),
                                             ctx.getChannel(), null);
                        } else if (ack.getBatchId() == -1L) { // -1代表上一次get没有数据,直接忽略之
                            // donothing
                        } else {
                            clientIdentity = new ClientIdentity(ack.getDestination(), Short.valueOf(ack.getClientId()));
                            embededServer.ack(clientIdentity, ack.getBatchId());
                        }
                    } else {
                        NettyUtils.error(401,
                                         MessageFormatter.format("destination or clientId is null", ack.toString()).getMessage(),
                                         ctx.getChannel(), null);
                    }
                    break;
                case CLIENTROLLBACK:
                    ClientRollback rollback = CanalPacket.ClientRollback.parseFrom(packet.getBody());
                    MDC.put("destination", rollback.getDestination());
                    if (StringUtils.isNotEmpty(rollback.getDestination())
                        && StringUtils.isNotEmpty(rollback.getClientId())) {
                        clientIdentity = new ClientIdentity(rollback.getDestination(),
                                                            Short.valueOf(rollback.getClientId()));
                        if (rollback.getBatchId() == 0L) {
                            embededServer.rollback(clientIdentity);// 回滚所有批次
                        } else {
                            embededServer.rollback(clientIdentity, rollback.getBatchId()); // 只回滚单个批次
View Full Code Here

    private static final String MYSQL_ADDRESS  = "127.0.0.1";
    protected ClientIdentity    clientIdentity = new ClientIdentity(destination, (short) 1); ;

    public void doSubscribeTest(CanalMetaManager metaManager) {
        ClientIdentity client1 = new ClientIdentity(destination, (short) 1);
        metaManager.subscribe(client1);
        metaManager.subscribe(client1); // 重复调用
        ClientIdentity client2 = new ClientIdentity(destination, (short) 2);
        metaManager.subscribe(client2);

        List<ClientIdentity> clients = metaManager.listAllSubscribeInfo(destination);
        Assert.assertEquals(Arrays.asList(client1, client2), clients);

        metaManager.unsubscribe(client2);
        ClientIdentity client3 = new ClientIdentity(destination, (short) 3);
        metaManager.subscribe(client3);

        clients = metaManager.listAllSubscribeInfo(destination);
        Assert.assertEquals(Arrays.asList(client1, client3), clients);
View Full Code Here

            default:
                final ClientAuth clientAuth = ClientAuth.parseFrom(packet.getBody());
                // 如果存在订阅信息
                if (StringUtils.isNotEmpty(clientAuth.getDestination())
                    && StringUtils.isNotEmpty(clientAuth.getClientId())) {
                    ClientIdentity clientIdentity = new ClientIdentity(clientAuth.getDestination(),
                        Short.valueOf(clientAuth.getClientId()),
                        clientAuth.getFilter());
                    try {
                        MDC.put("destination", clientIdentity.getDestination());
                        embededServer.subscribe(clientIdentity);
                        ctx.setAttachment(clientIdentity);// 设置状态数据
                        // 尝试启动,如果已经启动,忽略
                        if (!embededServer.isStart(clientIdentity.getDestination())) {
                            ServerRunningMonitor runningMonitor = ServerRunningMonitors.getRunningMonitor(clientIdentity.getDestination());
                            if (!runningMonitor.isStart()) {
                                runningMonitor.start();
                            }
                        }
                    } finally {
View Full Code Here

                    filter = new String(bytes, ENCODE);
                } catch (UnsupportedEncodingException e) {
                    throw new CanalMetaManagerException(e);
                }
            }
            clientIdentities.add(new ClientIdentity(destination, clientId, filter));
        }

        return clientIdentities;
    }
View Full Code Here

                                int soTimeout){
        this.address = address;
        this.username = username;
        this.password = password;
        this.soTimeout = soTimeout;
        this.clientIdentity = new ClientIdentity(destination, (short) 1001);
    }
View Full Code Here

            }
        });
        canalServer.start();

        canalServer.start(destination);
        this.clientIdentity = new ClientIdentity(destination, pipeline.getParameters().getMainstemClientId(), filter);
        canalServer.subscribe(clientIdentity);// 发起一次订阅

        running = true;
    }
View Full Code Here

            }
        });
        canalServer.start();

        canalServer.start(destination);
        this.clientIdentity = new ClientIdentity(destination, pipeline.getParameters().getMainstemClientId(), filter);
        canalServer.subscribe(clientIdentity);// 发起一次订阅

        running = true;
    }
View Full Code Here

TOP

Related Classes of com.alibaba.otter.canal.protocol.ClientIdentity

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.