Java Code Examples for com.alibaba.otter.canal.store.CanalStoreException

The following examples show how to use com.alibaba.otter.canal.store.CanalStoreException. These examples are extracted from open source projects. 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 Project: canal   Source File: DummyEventStore.java    License: Apache License 2.0 6 votes vote down vote up
public void put(List<Event> datas) throws InterruptedException, CanalStoreException {
    for (Event data : datas) {
        Date date = new Date(data.getExecuteTime());
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
        if (data.getEntryType() == EntryType.TRANSACTIONBEGIN || data.getEntryType() == EntryType.TRANSACTIONEND) {
            // System.out.println(MessageFormat.format(messgae, new Object[]
            // { Thread.currentThread().getName(),
            // header.getLogfilename(), header.getLogfileoffset(),
            // format.format(date),
            // data.getEntry().getEntryType(), "" }));
            System.out.println(data.getEntryType());

        } else {
            System.out.println(MessageFormat.format(messgae,
                new Object[] { Thread.currentThread().getName(), data.getJournalName(),
                        String.valueOf(data.getPosition()), format.format(date) }));
        }
    }
}
 
Example 2
Source Project: canal   Source File: DummyEventStore.java    License: Apache License 2.0 6 votes vote down vote up
public boolean tryPut(List<Event> datas) throws CanalStoreException {
    System.out.println("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
    for (Event data : datas) {

        Date date = new Date(data.getExecuteTime());
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
        if (data.getEntryType() == EntryType.TRANSACTIONBEGIN || data.getEntryType() == EntryType.TRANSACTIONEND) {
            // System.out.println(MessageFormat.format(messgae, new Object[]
            // { Thread.currentThread().getName(),
            // header.getLogfilename(), header.getLogfileoffset(),
            // format.format(date),
            // data.getEntry().getEntryType(), "" }));
            System.out.println(data.getEntryType());

        } else {
            System.out.println(MessageFormat.format(messgae,
                new Object[] { Thread.currentThread().getName(), data.getJournalName(),
                        String.valueOf(data.getPosition()), format.format(date) }));
        }

    }
    System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
    return true;
}
 
Example 3
Source Project: canal   Source File: DummyEventStore.java    License: Apache License 2.0 6 votes vote down vote up
public boolean put(List<Event> datas, long timeout, TimeUnit unit) throws InterruptedException, CanalStoreException {
    for (Event data : datas) {
        Date date = new Date(data.getExecuteTime());
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
        if (data.getEntryType() == EntryType.TRANSACTIONBEGIN || data.getEntryType() == EntryType.TRANSACTIONEND) {
            // System.out.println(MessageFormat.format(messgae, new Object[]
            // { Thread.currentThread().getName(),
            // header.getLogfilename(), header.getLogfileoffset(),
            // format.format(date),
            // data.getEntry().getEntryType(), "" }));
            System.out.println(data.getEntryType());

        } else {
            System.out.println(MessageFormat.format(messgae,
                new Object[] { Thread.currentThread().getName(), data.getJournalName(),
                        String.valueOf(data.getPosition()), format.format(date) }));
        }
    }
    return true;
}
 
Example 4
Source Project: canal-1.1.3   Source File: DummyEventStore.java    License: Apache License 2.0 6 votes vote down vote up
public void put(List<Event> datas) throws InterruptedException, CanalStoreException {
    for (Event data : datas) {
        Date date = new Date(data.getExecuteTime());
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
        if (data.getEntryType() == EntryType.TRANSACTIONBEGIN || data.getEntryType() == EntryType.TRANSACTIONEND) {
            // System.out.println(MessageFormat.format(messgae, new Object[]
            // { Thread.currentThread().getName(),
            // header.getLogfilename(), header.getLogfileoffset(),
            // format.format(date),
            // data.getEntry().getEntryType(), "" }));
            System.out.println(data.getEntryType());

        } else {
            System.out.println(MessageFormat.format(messgae,
                new Object[] { Thread.currentThread().getName(), data.getJournalName(),
                        String.valueOf(data.getPosition()), format.format(date) }));
        }
    }
}
 
Example 5
Source Project: canal-1.1.3   Source File: DummyEventStore.java    License: Apache License 2.0 6 votes vote down vote up
public boolean put(List<Event> datas, long timeout, TimeUnit unit) throws InterruptedException, CanalStoreException {
    for (Event data : datas) {
        Date date = new Date(data.getExecuteTime());
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
        if (data.getEntryType() == EntryType.TRANSACTIONBEGIN || data.getEntryType() == EntryType.TRANSACTIONEND) {
            // System.out.println(MessageFormat.format(messgae, new Object[]
            // { Thread.currentThread().getName(),
            // header.getLogfilename(), header.getLogfileoffset(),
            // format.format(date),
            // data.getEntry().getEntryType(), "" }));
            System.out.println(data.getEntryType());

        } else {
            System.out.println(MessageFormat.format(messgae,
                new Object[] { Thread.currentThread().getName(), data.getJournalName(),
                        String.valueOf(data.getPosition()), format.format(date) }));
        }
    }
    return true;
}
 
Example 6
Source Project: canal-1.1.3   Source File: DummyEventStore.java    License: Apache License 2.0 6 votes vote down vote up
public boolean tryPut(List<Event> datas) throws CanalStoreException {
    System.out.println("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
    for (Event data : datas) {

        Date date = new Date(data.getExecuteTime());
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
        if (data.getEntryType() == EntryType.TRANSACTIONBEGIN || data.getEntryType() == EntryType.TRANSACTIONEND) {
            // System.out.println(MessageFormat.format(messgae, new Object[]
            // { Thread.currentThread().getName(),
            // header.getLogfilename(), header.getLogfileoffset(),
            // format.format(date),
            // data.getEntry().getEntryType(), "" }));
            System.out.println(data.getEntryType());

        } else {
            System.out.println(MessageFormat.format(messgae,
                new Object[] { Thread.currentThread().getName(), data.getJournalName(),
                        String.valueOf(data.getPosition()), format.format(date) }));
        }

    }
    System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
    return true;
}
 
Example 7
Source Project: canal-1.1.3   Source File: MemoryEventStoreWithBuffer.java    License: Apache License 2.0 6 votes vote down vote up
public boolean tryPut(List<Event> data) throws CanalStoreException {
    if (data == null || data.isEmpty()) {
        return true;
    }

    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
        if (!checkFreeSlotAt(putSequence.get() + data.size())) {
            return false;
        } else {
            doPut(data);
            return true;
        }
    } finally {
        lock.unlock();
    }
}
 
Example 8
Source Project: canal   Source File: MemoryEventStoreWithBuffer.java    License: Apache License 2.0 6 votes vote down vote up
public boolean tryPut(List<Event> data) throws CanalStoreException {
    if (data == null || data.isEmpty()) {
        return true;
    }

    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
        if (!checkFreeSlotAt(putSequence.get() + data.size())) {
            return false;
        } else {
            doPut(data);
            return true;
        }
    } finally {
        lock.unlock();
    }
}
 
Example 9
Source Project: canal   Source File: MemoryEventStoreWithBuffer.java    License: Apache License 2.0 6 votes vote down vote up
public void cleanAll() throws CanalStoreException {
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
        putSequence.set(INIT_SEQUENCE);
        getSequence.set(INIT_SEQUENCE);
        ackSequence.set(INIT_SEQUENCE);

        putMemSize.set(0);
        getMemSize.set(0);
        ackMemSize.set(0);
        entries = null;
        // for (int i = 0; i < entries.length; i++) {
        // entries[i] = null;
        // }
    } finally {
        lock.unlock();
    }
}
 
Example 10
Source Project: canal-1.1.3   Source File: EventTransactionBuffer.java    License: Apache License 2.0 5 votes vote down vote up
public void start() throws CanalStoreException {
    super.start();
    if (Integer.bitCount(bufferSize) != 1) {
        throw new IllegalArgumentException("bufferSize must be a power of 2");
    }

    Assert.notNull(flushCallback, "flush callback is null!");
    indexMask = bufferSize - 1;
    entries = new CanalEntry.Entry[bufferSize];
}
 
Example 11
Source Project: canal-1.1.3   Source File: EventTransactionBuffer.java    License: Apache License 2.0 5 votes vote down vote up
public void stop() throws CanalStoreException {
    putSequence.set(INIT_SQEUENCE);
    flushSequence.set(INIT_SQEUENCE);

    entries = null;
    super.stop();
}
 
Example 12
Source Project: canal-1.1.3   Source File: MemoryEventStoreWithBuffer.java    License: Apache License 2.0 5 votes vote down vote up
public void start() throws CanalStoreException {
    super.start();
    if (Integer.bitCount(bufferSize) != 1) {
        throw new IllegalArgumentException("bufferSize must be a power of 2");
    }

    indexMask = bufferSize - 1;
    entries = new Event[bufferSize];
}
 
Example 13
Source Project: canal   Source File: EventTransactionBuffer.java    License: Apache License 2.0 5 votes vote down vote up
public void stop() throws CanalStoreException {
    putSequence.set(INIT_SQEUENCE);
    flushSequence.set(INIT_SQEUENCE);

    entries = null;
    super.stop();
}
 
Example 14
Source Project: canal   Source File: MemoryEventStoreWithBuffer.java    License: Apache License 2.0 5 votes vote down vote up
public Events<Event> tryGet(Position start, int batchSize) throws CanalStoreException {
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
        return doGet(start, batchSize);
    } finally {
        lock.unlock();
    }
}
 
Example 15
Source Project: canal   Source File: MemoryEventStoreWithBuffer.java    License: Apache License 2.0 5 votes vote down vote up
public void start() throws CanalStoreException {
    super.start();
    if (Integer.bitCount(bufferSize) != 1) {
        throw new IllegalArgumentException("bufferSize must be a power of 2");
    }

    indexMask = bufferSize - 1;
    entries = new Event[bufferSize];
}
 
Example 16
Source Project: canal-1.1.3   Source File: MemoryEventStoreWithBuffer.java    License: Apache License 2.0 5 votes vote down vote up
public Events<Event> get(Position start, int batchSize, long timeout, TimeUnit unit) throws InterruptedException,
                                                                                    CanalStoreException {
    long nanos = unit.toNanos(timeout);
    final ReentrantLock lock = this.lock;
    lock.lockInterruptibly();
    try {
        for (;;) {
            if (checkUnGetSlotAt((LogPosition) start, batchSize)) {
                return doGet(start, batchSize);
            }

            if (nanos <= 0) {
                // 如果时间到了,有多少取多少
                return doGet(start, batchSize);
            }

            try {
                nanos = notEmpty.awaitNanos(nanos);
            } catch (InterruptedException ie) {
                notEmpty.signal(); // propagate to non-interrupted thread
                throw ie;
            }

        }
    } finally {
        lock.unlock();
    }
}
 
Example 17
Source Project: DataLink   Source File: GatewayEventStore.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean tryPut(List data) throws CanalStoreException {
    /*
     * 对类加一个全局锁,以避免上一轮的instanc和本轮的instance,同时执行tryput方法,而出现线程安全问题
     * 为什么会出现此种情况呢?因为上一轮的instance关闭时,只是把running的状态置为了false,tryput方法不一定立刻退出,而下一轮的
     * instance此时可能已经启动起来了,这样就可能出现同一个EnpointInstance的CanalEventStore被两个GatewayEventStore持有的情况。
     */
    synchronized (GatewayEventStore.class) {
        return doPut(data);
    }
}
 
Example 18
Source Project: DataLink   Source File: GatewayEventStore.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 必须所有store都put成功之后再返回,避免外部重试导致单个store一直重复put
 */
@SuppressWarnings("unchecked")
private boolean doPut(List data) throws CanalStoreException {
    succeededStores.clear();
    isSuspend = false;
    startTime = System.currentTimeMillis();

    while (running && !interrupted) {
        if (!isSuspend) {
            Map<String, CanalEventStore> stores = Maps.newHashMap(attachedEventStores);
            if (stores.isEmpty()) {
                return false;
            }

            boolean result = true;
            for (String key : stores.keySet()) {
                if (!succeededStores.containsKey(key)) {
                    boolean putResult = stores.get(key).tryPut(data);
                    if (putResult) {
                        succeededStores.put(key, stores.get(key));
                    }
                    result &= putResult;
                }
            }
            if (result) {
                return true;
            }
            if (System.currentTimeMillis() - startTime > 1000 * 60 * 1) {
                isSuspend = true;
            }
        }

        //100ms
        LockSupport.parkNanos(1000 * 1000L * 100);
    }

    return false;
}
 
Example 19
Source Project: canal   Source File: MemoryEventStoreWithBuffer.java    License: Apache License 2.0 5 votes vote down vote up
public Events<Event> get(Position start, int batchSize, long timeout, TimeUnit unit) throws InterruptedException,
                                                                                    CanalStoreException {
    long nanos = unit.toNanos(timeout);
    final ReentrantLock lock = this.lock;
    lock.lockInterruptibly();
    try {
        for (;;) {
            if (checkUnGetSlotAt((LogPosition) start, batchSize)) {
                return doGet(start, batchSize);
            }

            if (nanos <= 0) {
                // 如果时间到了,有多少取多少
                return doGet(start, batchSize);
            }

            try {
                nanos = notEmpty.awaitNanos(nanos);
            } catch (InterruptedException ie) {
                notEmpty.signal(); // propagate to non-interrupted thread
                throw ie;
            }

        }
    } finally {
        lock.unlock();
    }
}
 
Example 20
Source Project: canal   Source File: MemoryEventStoreWithBuffer.java    License: Apache License 2.0 5 votes vote down vote up
public boolean put(List<Event> data, long timeout, TimeUnit unit) throws InterruptedException, CanalStoreException {
    if (data == null || data.isEmpty()) {
        return true;
    }

    long nanos = unit.toNanos(timeout);
    final ReentrantLock lock = this.lock;
    lock.lockInterruptibly();
    try {
        for (;;) {
            if (checkFreeSlotAt(putSequence.get() + data.size())) {
                doPut(data);
                return true;
            }
            if (nanos <= 0) {
                return false;
            }

            try {
                nanos = notFull.awaitNanos(nanos);
            } catch (InterruptedException ie) {
                notFull.signal(); // propagate to non-interrupted thread
                throw ie;
            }
        }
    } finally {
        lock.unlock();
    }
}
 
Example 21
Source Project: canal   Source File: MemoryEventStoreWithBuffer.java    License: Apache License 2.0 5 votes vote down vote up
public void rollback() throws CanalStoreException {
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
        getSequence.set(ackSequence.get());
        getMemSize.set(ackMemSize.get());
    } finally {
        lock.unlock();
    }
}
 
Example 22
Source Project: canal   Source File: EventTransactionBuffer.java    License: Apache License 2.0 5 votes vote down vote up
public void start() throws CanalStoreException {
    super.start();
    if (Integer.bitCount(bufferSize) != 1) {
        throw new IllegalArgumentException("bufferSize must be a power of 2");
    }

    Assert.notNull(flushCallback, "flush callback is null!");
    indexMask = bufferSize - 1;
    entries = new CanalEntry.Entry[bufferSize];
}
 
Example 23
Source Project: canal-1.1.3   Source File: DummyEventStore.java    License: Apache License 2.0 4 votes vote down vote up
public Events get(Position start, int batchSize) throws InterruptedException, CanalStoreException {
    return null;
}
 
Example 24
Source Project: canal-1.1.3   Source File: DummyEventStore.java    License: Apache License 2.0 4 votes vote down vote up
public Events get(Position start, int batchSize, long timeout, TimeUnit unit) throws InterruptedException,
                                                                             CanalStoreException {
    return null;
}
 
Example 25
Source Project: canal-1.1.3   Source File: DummyEventStore.java    License: Apache License 2.0 4 votes vote down vote up
public Position getFirstPosition() throws CanalStoreException {
    return null;
}
 
Example 26
Source Project: canal-1.1.3   Source File: DummyEventStore.java    License: Apache License 2.0 4 votes vote down vote up
public Position getLatestPosition() throws CanalStoreException {
    return null;
}
 
Example 27
Source Project: canal   Source File: DummyEventStore.java    License: Apache License 2.0 4 votes vote down vote up
public boolean tryPut(Event data) throws CanalStoreException {
    return tryPut(Arrays.asList(data));
}
 
Example 28
Source Project: canal-1.1.3   Source File: DummyEventStore.java    License: Apache License 2.0 4 votes vote down vote up
public Events tryGet(Position start, int batchSize) throws CanalStoreException {
    return null;
}
 
Example 29
Source Project: canal-1.1.3   Source File: DummyEventStore.java    License: Apache License 2.0 4 votes vote down vote up
public void cleanAll() throws CanalStoreException {
}
 
Example 30
Source Project: canal   Source File: MemoryEventStoreWithBuffer.java    License: Apache License 2.0 4 votes vote down vote up
public void ack(Position position) throws CanalStoreException {
    cleanUntil(position, -1L);
}