Search in sources :

Example 6 with Packet

use of com.alibaba.otter.canal.protocol.AdminPacket.Packet in project canal by alibaba.

the class SimpleAdminConnector method doInstanceAdmin.

private String doInstanceAdmin(String destination, String action) {
    try {
        writeWithHeader(Packet.newBuilder().setType(PacketType.INSTANCE).setBody(InstanceAdmin.newBuilder().setDestination(destination).setAction(action).build().toByteString()).build().toByteArray());
        Packet p = Packet.parseFrom(readNextPacket());
        Ack ack = Ack.parseFrom(p.getBody());
        if (ack.getCode() > 0) {
            throw new ServiceException("failed to subscribe with reason: " + ack.getMessage());
        }
        return ack.getMessage();
    } catch (IOException e) {
        throw new ServiceException(e);
    }
}
Also used : Packet(com.alibaba.otter.canal.protocol.AdminPacket.Packet) ServiceException(com.alibaba.otter.canal.admin.common.exception.ServiceException) Ack(com.alibaba.otter.canal.protocol.AdminPacket.Ack) IOException(java.io.IOException)

Aggregations

Packet (com.alibaba.otter.canal.protocol.AdminPacket.Packet)6 ServiceException (com.alibaba.otter.canal.admin.common.exception.ServiceException)4 Ack (com.alibaba.otter.canal.protocol.AdminPacket.Ack)4 IOException (java.io.IOException)4 ClientAuth (com.alibaba.otter.canal.protocol.AdminPacket.ClientAuth)2 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)2 Handshake (com.alibaba.otter.canal.protocol.AdminPacket.Handshake)1 InstanceAdmin (com.alibaba.otter.canal.protocol.AdminPacket.InstanceAdmin)1 LogAdmin (com.alibaba.otter.canal.protocol.AdminPacket.LogAdmin)1 ServerAdmin (com.alibaba.otter.canal.protocol.AdminPacket.ServerAdmin)1 CanalClientException (com.alibaba.otter.canal.protocol.exception.CanalClientException)1 ByteString (com.google.protobuf.ByteString)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ChannelHandlerContext (org.jboss.netty.channel.ChannelHandlerContext)1 IdleStateAwareChannelHandler (org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler)1 IdleStateEvent (org.jboss.netty.handler.timeout.IdleStateEvent)1 IdleStateHandler (org.jboss.netty.handler.timeout.IdleStateHandler)1