java throwable ca,Java CanalClientException類代碼示例

本文整理匯總了Java中com.alibaba.otter.canal.protocol.exception.CanalClientException類的典型用法代碼示例。如果您正苦於以下問題:Java CanalClientException類的具體用法?Java CanalClientException怎麽用?Java CanalClientException使用的例子?那麽恭喜您, 這裏精選的類代碼示例或許可以為您提供幫助。

CanalClientException類屬於com.alibaba.otter.canal.protocol.exception包,在下文中一共展示了CanalClientException類的30個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: connect

​點讚 3

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

public void connect() throws CanalClientException {

if (connected) {

return;

}

if (runningMonitor != null) {

if (!runningMonitor.isStart()) {

runningMonitor.start();

}

} else {

waitClientRunning();

doConnect();

if (filter != null) { // 如果存在條件,說明是自動切換,基於上一次的條件訂閱一次

subscribe(filter);

}

if (rollbackOnConnect) {

rollback();

}

}

connected = true;

}

開發者ID:alibaba,項目名稱:canal,代碼行數:23,

示例2: subscribe

​點讚 3

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

public void subscribe(String filter) throws CanalClientException {

waitClientRunning();

try {

writeWithHeader(Packet.newBuilder()

.setType(PacketType.SUBSCRIPTION)

.setBody(Sub.newBuilder()

.setDestination(clientIdentity.getDestination())

.setClientId(String.valueOf(clientIdentity.getClientId()))

.setFilter(filter != null ? filter : "")

.build()

.toByteString())

.build()

.toByteArray());

//

Packet p = Packet.parseFrom(readNextPacket());

Ack ack = Ack.parseFrom(p.getBody());

if (ack.getErrorCode() > 0) {

throw new CanalClientException("failed to subscribe with reason: " + ack.getErrorMessage());

}

clientIdentity.setFilter(filter);

} catch (IOException e) {

throw new CanalClientException(e);

}

}

開發者ID:alibaba,項目名稱:canal,代碼行數:26,

示例3: unsubscribe

​點讚 3

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

public void unsubscribe() throws CanalClientException {

waitClientRunning();

try {

writeWithHeader(Packet.newBuilder()

.setType(PacketType.UNSUBSCRIPTION)

.setBody(Unsub.newBuilder()

.setDestination(clientIdentity.getDestination())

.setClientId(String.valueOf(clientIdentity.getClientId()))

.build()

.toByteString())

.build()

.toByteArray());

//

Packet p = Packet.parseFrom(readNextPacket());

Ack ack = Ack.parseFrom(p.getBody());

if (ack.getErrorCode() > 0) {

throw new CanalClientException("failed to unSubscribe with reason: " + ack.getErrorMessage());

}

} catch (IOException e) {

throw new CanalClientException(e);

}

}

開發者ID:alibaba,項目名稱:canal,代碼行數:23,

示例4: receiveMessages

​點讚 3

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

private Message receiveMessages() throws IOException {

Packet p = Packet.parseFrom(readNextPacket());

switch (p.getType()) {

case MESSAGES: {

if (!p.getCompression().equals(Compression.NONE)) {

throw new CanalClientException("compression is not supported in this connector");

}

Messages messages = Messages.parseFrom(p.getBody());

Message result = new Message(messages.getBatchId());

for (ByteString byteString : messages.getMessagesList()) {

result.addEntry(Entry.parseFrom(byteString));

}

return result;

}

case ACK: {

Ack ack = Ack.parseFrom(p.getBody());

throw new CanalClientException("something goes wrong with reason: " + ack.getErrorMessage());

}

default: {

throw new CanalClientException("unexpected packet type: " + p.getType());

}

}

}

開發者ID:alibaba,項目名稱:canal,代碼行數:25,

示例5: ack

​點讚 3

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

public void ack(long batchId) throws CanalClientException {

waitClientRunning();

ClientAck ca = ClientAck.newBuilder()

.setDestination(clientIdentity.getDestination())

.setClientId(String.valueOf(clientIdentity.getClientId()))

.setBatchId(batchId)

.build();

try {

writeWithHeader(Packet.newBuilder()

.setType(PacketType.CLIENTACK)

.setBody(ca.toByteString())

.build()

.toByteArray());

} catch (IOException e) {

throw new CanalClientException(e);

}

}

開發者ID:alibaba,項目名稱:canal,代碼行數:18,

示例6: rollback

​點讚 3

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

public void rollback(long batchId) throws CanalClientException {

waitClientRunning();

ClientRollback ca = ClientRollback.newBuilder()

.setDestination(clientIdentity.getDestination())

.setClientId(String.valueOf(clientIdentity.getClientId()))

.setBatchId(batchId)

.build();

try {

writeWithHeader(Packet.newBuilder()

.setType(PacketType.CLIENTROLLBACK)

.setBody(ca.toByteString())

.build()

.toByteArray());

} catch (IOException e) {

throw new CanalClientException(e);

}

}

開發者ID:alibaba,項目名稱:canal,代碼行數:18,

示例7: subscribe

​點讚 3

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

public void subscribe(String filter) throws CanalClientException {

int times = 0;

while (times < retryTimes) {

try {

currentConnector.subscribe(filter);

this.filter = filter;

return;

} catch (Throwable t) {

logger.warn(String.format(

"something goes wrong when subscribing from server: %s",

currentConnector != null ? currentConnector.getAddress() : "null"),

t);

times++;

restart();

logger.info("restart the connector for next round retry.");

}

}

throw new CanalClientException("failed to subscribe after " + times + " times retry.");

}

開發者ID:alibaba,項目名稱:canal,代碼行數:21,

示例8: unsubscribe

​點讚 3

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

public void unsubscribe() throws CanalClientException {

int times = 0;

while (times < retryTimes) {

try {

currentConnector.unsubscribe();

return;

} catch (Throwable t) {

logger.warn(String.format("something goes wrong when unsubscribing from server:%s",

currentConnector != null ? currentConnector.getAddress() : "null"), t);

times++;

restart();

logger.info("restart the connector for next round retry.");

}

}

throw new CanalClientException("failed to unsubscribe after " + times + " times retry.");

}

開發者ID:alibaba,項目名稱:canal,代碼行數:17,

示例9: get

​點讚 3

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

public Message get(int batchSize) throws CanalClientException {

int times = 0;

while (times < retryTimes) {

try {

Message msg = currentConnector.get(batchSize);

return msg;

} catch (Throwable t) {

logger.warn(String.format("something goes wrong when getting data from server:%s",

currentConnector != null ? currentConnector.getAddress() : "null"), t);

times++;

restart();

logger.info("restart the connector for next round retry.");

}

}

throw new CanalClientException("failed to fetch the data after " + times + " times retry");

}

開發者ID:alibaba,項目名稱:canal,代碼行數:17,

示例10: getWithoutAck

​點讚 3

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

public Message getWithoutAck(int batchSize) throws CanalClientException {

int times = 0;

while (times < retryTimes) {

try {

Message msg = currentConnector.getWithoutAck(batchSize);

return msg;

} catch (Throwable t) {

logger.warn(String.format("something goes wrong when getWithoutAck data from server:%s",

currentConnector.getAddress()), t);

times++;

restart();

logger.info("restart the connector for next round retry.");

}

}

throw new CanalClientException("failed to fetch the data after " + times + " times retry");

}

開發者ID:alibaba,項目名稱:canal,代碼行數:17,

示例11: rollback

​點讚 3

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

public void rollback(long batchId) throws CanalClientException {

int times = 0;

while (times < retryTimes) {

try {

currentConnector.rollback(batchId);

return;

} catch (Throwable t) {

logger.warn(String.format("something goes wrong when rollbacking data from server:%s",

currentConnector.getAddress()), t);

times++;

restart();

logger.info("restart the connector for next round retry.");

}

}

throw new CanalClientException("failed to rollback after " + times + " times retry");

}

開發者ID:alibaba,項目名稱:canal,代碼行數:17,

示例12: ack

​點讚 3

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

public void ack(long batchId) throws CanalClientException {

int times = 0;

while (times < retryTimes) {

try {

currentConnector.ack(batchId);

return;

} catch (Throwable t) {

logger.warn(String.format("something goes wrong when acking data from server:%s",

currentConnector.getAddress()), t);

times++;

restart();

logger.info("restart the connector for next round retry.");

}

}

throw new CanalClientException("failed to ack after " + times + " times retry");

}

開發者ID:alibaba,項目名稱:canal,代碼行數:18,

示例13: disConnect

​點讚 2

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

@Override

public void disConnect() {

log.info("canal instance: " + instanceName + " start disConnect");

try {

canalConnector.unsubscribe();

} finally {

try {

canalConnector.disconnect();

log.info("canal instance: " + instanceName + " disConnect succeed");

} catch (CanalClientException e) {

log.error("canal instance: " + instanceName + " disConnect failed", e);

}

}

}

開發者ID:wxingyl,項目名稱:search-commons,代碼行數:15,

示例14: disconnect

​點讚 2

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

public void disconnect() throws CanalClientException {

if (rollbackOnDisConnect && channel.isConnected()) {

rollback();

}

connected = false;

if (runningMonitor != null) {

if (runningMonitor.isStart()) {

runningMonitor.stop();

}

} else {

doDisconnnect();

}

}

開發者ID:alibaba,項目名稱:canal,代碼行數:15,

示例15: doDisconnnect

​點讚 2

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

private void doDisconnnect() throws CanalClientException {

if (readableChannel != null) {

quietlyClose(readableChannel);

readableChannel = null;

}

if (writableChannel != null) {

quietlyClose(writableChannel);

writableChannel = null;

}

if (channel != null) {

quietlyClose(channel);

channel = null;

}

}

開發者ID:alibaba,項目名稱:canal,代碼行數:15,

示例16: getWithoutAck

​點讚 2

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

public Message getWithoutAck(int batchSize, Long timeout, TimeUnit unit) throws CanalClientException {

waitClientRunning();

try {

int size = (batchSize <= 0) ? 1000 : batchSize;

long time = (timeout == null || timeout < 0) ? -1 : timeout; // -1代表不做timeout控製

if (unit == null) {

unit = TimeUnit.MILLISECONDS;

}

writeWithHeader(Packet.newBuilder()

.setType(PacketType.GET)

.setBody(Get.newBuilder()

.setAutoAck(false)

.setDestination(clientIdentity.getDestination())

.setClientId(String.valueOf(clientIdentity.getClientId()))

.setFetchSize(size)

.setTimeout(time)

.setUnit(unit.ordinal())

.build()

.toByteString())

.build()

.toByteArray());

return receiveMessages();

} catch (IOException e) {

throw new CanalClientException(e);

}

}

開發者ID:alibaba,項目名稱:canal,代碼行數:28,

示例17: waitClientRunning

​點讚 2

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

private void waitClientRunning() {

try {

if (zkClientx != null) {

if (!connected) {// 未調用connect

throw new CanalClientException("should connect first");

}

mutex.get();// 阻塞等待

}

} catch (InterruptedException e) {

Thread.currentThread().interrupt();

throw new CanalClientException(e);

}

}

開發者ID:alibaba,項目名稱:canal,代碼行數:15,

示例18: restart

​點讚 2

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

private void restart() throws CanalClientException {

disconnect();

try {

Thread.sleep(retryInterval);

} catch (InterruptedException e) {

throw new CanalClientException(e);

}

connect();

}

開發者ID:alibaba,項目名稱:canal,代碼行數:10,

示例19: nextNode

​點讚 2

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

public SocketAddress nextNode() {

if (runningAddress != null) {// 如果服務已經啟動,直接選擇當前正在工作的節點

return runningAddress;

} else if (!currentAddress.isEmpty()) { // 如果不存在已經啟動的服務,可能服務是一種lazy啟動,隨機選擇一台觸發服務器進行啟動

return currentAddress.get(0);// 默認返回第一個節點,之前已經做過shuffle

} else {

throw new CanalClientException("no alive canal server");

}

}

開發者ID:alibaba,項目名稱:canal,代碼行數:10,

示例20: doConnect

​點讚 2

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

private InetSocketAddress doConnect() throws CanalClientException {

try {

channel = SocketChannel.open();

channel.socket().setSoTimeout(soTimeout);

SocketAddress address = getAddress();

if (address == null) {

address = getNextAddress();

}

channel.connect(address);

readableChannel = Channels.newChannel(channel.socket().getInputStream());

writableChannel = Channels.newChannel(channel.socket().getOutputStream());

Packet p = Packet.parseFrom(readNextPacket());

if (p.getVersion() != 1) {

throw new CanalClientException("unsupported version at this client.");

}

if (p.getType() != PacketType.HANDSHAKE) {

throw new CanalClientException("expect handshake but found other type.");

}

//

Handshake handshake = Handshake.parseFrom(p.getBody());

supportedCompressions.addAll(handshake.getSupportedCompressionsList());

//

ClientAuth ca = ClientAuth.newBuilder()

.setUsername(username != null ? username : "")

.setPassword(ByteString.copyFromUtf8(password != null ? password : ""))

.setNetReadTimeout(soTimeout)

.setNetWriteTimeout(soTimeout)

.build();

writeWithHeader(Packet.newBuilder()

.setType(PacketType.CLIENTAUTHENTICATION)

.setBody(ca.toByteString())

.build()

.toByteArray());

//

Packet ack = Packet.parseFrom(readNextPacket());

if (ack.getType() != PacketType.ACK) {

throw new CanalClientException("unexpected packet type when ack is expected");

}

Ack ackBody = Ack.parseFrom(ack.getBody());

if (ackBody.getErrorCode() > 0) {

throw new CanalClientException("something goes wrong when doing authentication: "

+ ackBody.getErrorMessage());

}

connected = true;

return new InetSocketAddress(channel.socket().getLocalAddress(), channel.socket().getLocalPort());

} catch (IOException e) {

throw new CanalClientException(e);

}

}

開發者ID:alibaba,項目名稱:canal,代碼行數:53,

示例21: get

​點讚 2

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

public Message get(int batchSize) throws CanalClientException {

return get(batchSize, null, null);

}

開發者ID:alibaba,項目名稱:canal,代碼行數:4,

示例22: connect

​點讚 2

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

public void connect() throws CanalClientException {

while (currentConnector == null) {

int times = 0;

while (true) {

try {

currentConnector = new SimpleCanalConnector(null, username, password, destination) {

@Override

public SocketAddress getNextAddress() {

return accessStrategy.nextNode();

}

};

currentConnector.setSoTimeout(soTimeout);

if (filter != null) {

currentConnector.setFilter(filter);

}

if (accessStrategy instanceof ClusterNodeAccessStrategy) {

currentConnector.setZkClientx(((ClusterNodeAccessStrategy) accessStrategy).getZkClient());

}

currentConnector.connect();

break;

} catch (Exception e) {

logger.warn("failed to connect to:{} after retry {} times", accessStrategy.currentNode(), times);

currentConnector.disconnect();

currentConnector = null;

// retry for #retryTimes for each node when trying to

// connect to it.

times = times + 1;

if (times >= retryTimes) {

throw new CanalClientException(e);

} else {

// fixed issue #55,增加sleep控製,避免重試connect時cpu使用過高

try {

Thread.sleep(retryInterval);

} catch (InterruptedException e1) {

throw new CanalClientException(e1);

}

}

}

}

}

}

開發者ID:alibaba,項目名稱:canal,代碼行數:45,

示例23: disconnect

​點讚 2

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

public void disconnect() throws CanalClientException {

if (currentConnector != null) {

currentConnector.disconnect();

currentConnector = null;

}

}

開發者ID:alibaba,項目名稱:canal,代碼行數:7,

示例24: connect

​點讚 1

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

/**

* 鏈接對應的canal server

*

* @throws CanalClientException

*/

void connect() throws CanalClientException;

開發者ID:alibaba,項目名稱:canal,代碼行數:7,

示例25: disconnect

​點讚 1

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

/**

* 釋放鏈接

*

* @throws CanalClientException

*/

void disconnect() throws CanalClientException;

開發者ID:alibaba,項目名稱:canal,代碼行數:7,

示例26: checkValid

​點讚 1

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

/**

* 檢查下鏈接是否合法

*

*

 
 

* 幾種case下鏈接不合法:

* 1. 鏈接canal server失敗,一直沒有一個可用的鏈接,返回false

* 2. 當前客戶端在進行running搶占的時候,做為備份節點存在,非處於工作節點,返回false

*

* 說明:

* a. 當前客戶端一旦做為備份節點存在,當前所有的對{@linkplain CanalConnector}的操作都會處於阻塞狀態,直到轉為工作節點

* b. 所以業務方最好定時調用checkValid()方法用,比如調用CanalConnector所在線程的interrupt,直接退出CanalConnector,並根據自己的需要退出自己的資源

*

*

* @throws CanalClientException

*/

boolean checkValid() throws CanalClientException;

開發者ID:alibaba,項目名稱:canal,代碼行數:17,

示例27: subscribe

​點讚 1

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

/**

* 客戶端訂閱,重複訂閱時會更新對應的filter信息

*

*

 
 

* 說明:

* a. 如果本次訂閱中filter信息為空,則直接使用canal server服務端配置的filter信息

* b. 如果本次訂閱中filter信息不為空,目前會直接替換canal server服務端配置的filter信息,以本次提交的為準

*

* TODO: 後續可以考慮,如果本次提交的filter不為空,在執行過濾時,是對canal server filter + 本次filter的交集處理,達到隻取1份binlog數據,多個客戶端消費不同的表

*

*

* @throws CanalClientException

*/

void subscribe(String filter) throws CanalClientException;

開發者ID:alibaba,項目名稱:canal,代碼行數:15,

示例28: unsubscribe

​點讚 1

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

/**

* 取消訂閱

*

* @throws CanalClientException

*/

void unsubscribe() throws CanalClientException;

開發者ID:alibaba,項目名稱:canal,代碼行數:7,

示例29: get

​點讚 1

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

/**

* 獲取數據,自動進行確認,該方法返回的條件:嘗試拿batchSize條記錄,有多少取多少,不會阻塞等待

*

* @param batchSize

* @return

* @throws CanalClientException

*/

Message get(int batchSize) throws CanalClientException;

開發者ID:alibaba,項目名稱:canal,代碼行數:9,

示例30: getWithoutAck

​點讚 1

import com.alibaba.otter.canal.protocol.exception.CanalClientException; //導入依賴的package包/類

/**

* 不指定 position 獲取事件,該方法返回的條件: 嘗試拿batchSize條記錄,有多少取多少,不會阻塞等待

* canal 會記住此 client 最新的position。

* 如果是第一次 fetch,則會從 canal 中保存的最老一條數據開始輸出。

*

* @param batchSize

* @throws CanalClientException

*/

Message getWithoutAck(int batchSize) throws CanalClientException;

開發者ID:alibaba,項目名稱:canal,代碼行數:10,

注:本文中的com.alibaba.otter.canal.protocol.exception.CanalClientException類示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值