com.alibaba.otter.canal.store.model.Events Java Examples
The following examples show how to use
com.alibaba.otter.canal.store.model.Events.
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 File: CanalServerWithEmbedded.java From canal with Apache License 2.0 | 6 votes |
/** * 根据不同的参数,选择不同的方式获取数据 */ private Events<Event> getEvents(CanalEventStore eventStore, Position start, int batchSize, Long timeout, TimeUnit unit) { if (timeout == null) { return eventStore.tryGet(start, batchSize); } else { try { if (timeout <= 0) { return eventStore.get(start, batchSize); } else { return eventStore.get(start, batchSize, timeout, unit); } } catch (Exception e) { throw new CanalServerException(e); } } }
Example #2
Source File: MemoryEventStorePutAndGetTest.java From canal with Apache License 2.0 | 6 votes |
@Test public void testOnePutOneGet() { MemoryEventStoreWithBuffer eventStore = new MemoryEventStoreWithBuffer(); eventStore.start(); boolean result = eventStore.tryPut(buildEvent("1", 1L, 1L)); Assert.assertTrue(result); Position position = eventStore.getFirstPosition(); Events<Event> entrys = eventStore.tryGet(position, 1); Assert.assertTrue(entrys.getEvents().size() == 1); Assert.assertEquals(position, entrys.getPositionRange().getStart()); Assert.assertEquals(position, entrys.getPositionRange().getEnd()); eventStore.stop(); }
Example #3
Source File: CanalServerWithEmbedded.java From canal-1.1.3 with Apache License 2.0 | 6 votes |
/** * 根据不同的参数,选择不同的方式获取数据 */ private Events<Event> getEvents(CanalEventStore eventStore, Position start, int batchSize, Long timeout, TimeUnit unit) { if (timeout == null) { return eventStore.tryGet(start, batchSize); } else { try { if (timeout <= 0) { return eventStore.get(start, batchSize); } else { return eventStore.get(start, batchSize, timeout, unit); } } catch (Exception e) { throw new CanalServerException(e); } } }
Example #4
Source File: MemoryEventStoreMemBatchTest.java From canal with Apache License 2.0 | 6 votes |
@Test public void testOnePutOneGet() { MemoryEventStoreWithBuffer eventStore = new MemoryEventStoreWithBuffer(); eventStore.setBatchMode(BatchMode.MEMSIZE); eventStore.start(); boolean result = eventStore.tryPut(buildEvent("1", 1L, 1L)); Assert.assertTrue(result); Position position = eventStore.getFirstPosition(); Events<Event> entrys = eventStore.tryGet(position, 1); Assert.assertTrue(entrys.getEvents().size() == 1); Assert.assertEquals(position, entrys.getPositionRange().getStart()); Assert.assertEquals(position, entrys.getPositionRange().getEnd()); eventStore.stop(); }
Example #5
Source File: MemoryEventStorePutAndGetTest.java From canal-1.1.3 with Apache License 2.0 | 6 votes |
@Test public void testOnePutOneGet() { MemoryEventStoreWithBuffer eventStore = new MemoryEventStoreWithBuffer(); eventStore.start(); boolean result = eventStore.tryPut(buildEvent("1", 1L, 1L)); Assert.assertTrue(result); Position position = eventStore.getFirstPosition(); Events<Event> entrys = eventStore.tryGet(position, 1); Assert.assertTrue(entrys.getEvents().size() == 1); Assert.assertEquals(position, entrys.getPositionRange().getStart()); Assert.assertEquals(position, entrys.getPositionRange().getEnd()); eventStore.stop(); }
Example #6
Source File: MemoryEventStoreWithBuffer.java From canal-1.1.3 with Apache License 2.0 | 6 votes |
public Events<Event> get(Position start, int batchSize) throws InterruptedException, CanalStoreException { final ReentrantLock lock = this.lock; lock.lockInterruptibly(); try { try { while (!checkUnGetSlotAt((LogPosition) start, batchSize)) notEmpty.await(); } catch (InterruptedException ie) { notEmpty.signal(); // propagate to non-interrupted thread throw ie; } return doGet(start, batchSize); } finally { lock.unlock(); } }
Example #7
Source File: MemoryEventStoreMemBatchTest.java From canal-1.1.3 with Apache License 2.0 | 6 votes |
@Test public void testOnePutOneGet() { MemoryEventStoreWithBuffer eventStore = new MemoryEventStoreWithBuffer(); eventStore.setBatchMode(BatchMode.MEMSIZE); eventStore.start(); boolean result = eventStore.tryPut(buildEvent("1", 1L, 1L)); Assert.assertTrue(result); Position position = eventStore.getFirstPosition(); Events<Event> entrys = eventStore.tryGet(position, 1); Assert.assertTrue(entrys.getEvents().size() == 1); Assert.assertEquals(position, entrys.getPositionRange().getStart()); Assert.assertEquals(position, entrys.getPositionRange().getEnd()); eventStore.stop(); }
Example #8
Source File: MemoryEventStoreWithBuffer.java From canal with Apache License 2.0 | 6 votes |
public Events<Event> get(Position start, int batchSize) throws InterruptedException, CanalStoreException { final ReentrantLock lock = this.lock; lock.lockInterruptibly(); try { try { while (!checkUnGetSlotAt((LogPosition) start, batchSize)) notEmpty.await(); } catch (InterruptedException ie) { notEmpty.signal(); // propagate to non-interrupted thread throw ie; } return doGet(start, batchSize); } finally { lock.unlock(); } }
Example #9
Source File: MemoryEventStorePutAndGetTest.java From canal with Apache License 2.0 | 5 votes |
@Test public void testFullPutBatchGet() { int bufferSize = 16; MemoryEventStoreWithBuffer eventStore = new MemoryEventStoreWithBuffer(); eventStore.setBufferSize(bufferSize); eventStore.start(); for (int i = 0; i < bufferSize; i++) { boolean result = eventStore.tryPut(buildEvent("1", 1L, 1L + i)); sleep(100L); Assert.assertTrue(result); } Position first = eventStore.getFirstPosition(); Position lastest = eventStore.getLatestPosition(); Assert.assertEquals(first, CanalEventUtils.createPosition(buildEvent("1", 1L, 1L))); Assert.assertEquals(lastest, CanalEventUtils.createPosition(buildEvent("1", 1L, 1L + bufferSize - 1))); System.out.println("start get"); Events<Event> entrys1 = eventStore.tryGet(first, bufferSize); System.out.println("first get size : " + entrys1.getEvents().size()); Assert.assertTrue(entrys1.getEvents().size() == bufferSize); Assert.assertEquals(first, entrys1.getPositionRange().getStart()); Assert.assertEquals(lastest, entrys1.getPositionRange().getEnd()); Assert.assertEquals(first, CanalEventUtils.createPosition(entrys1.getEvents().get(0))); Assert.assertEquals(lastest, CanalEventUtils.createPosition(entrys1.getEvents().get(bufferSize - 1))); eventStore.stop(); }
Example #10
Source File: MemoryEventStorePutAndGetTest.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
@Test public void testFullPutBatchGet() { int bufferSize = 16; MemoryEventStoreWithBuffer eventStore = new MemoryEventStoreWithBuffer(); eventStore.setBufferSize(bufferSize); eventStore.start(); for (int i = 0; i < bufferSize; i++) { boolean result = eventStore.tryPut(buildEvent("1", 1L, 1L + i)); sleep(100L); Assert.assertTrue(result); } Position first = eventStore.getFirstPosition(); Position lastest = eventStore.getLatestPosition(); Assert.assertEquals(first, CanalEventUtils.createPosition(buildEvent("1", 1L, 1L))); Assert.assertEquals(lastest, CanalEventUtils.createPosition(buildEvent("1", 1L, 1L + bufferSize - 1))); System.out.println("start get"); Events<Event> entrys1 = eventStore.tryGet(first, bufferSize); System.out.println("first get size : " + entrys1.getEvents().size()); Assert.assertTrue(entrys1.getEvents().size() == bufferSize); Assert.assertEquals(first, entrys1.getPositionRange().getStart()); Assert.assertEquals(lastest, entrys1.getPositionRange().getEnd()); Assert.assertEquals(first, CanalEventUtils.createPosition(entrys1.getEvents().get(0))); Assert.assertEquals(lastest, CanalEventUtils.createPosition(entrys1.getEvents().get(bufferSize - 1))); eventStore.stop(); }
Example #11
Source File: MemoryEventStoreMemBatchTest.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
@Test public void testFullPutBatchGet() { int bufferSize = 16; MemoryEventStoreWithBuffer eventStore = new MemoryEventStoreWithBuffer(); eventStore.setBufferSize(bufferSize); eventStore.setBatchMode(BatchMode.MEMSIZE); eventStore.start(); for (int i = 0; i < bufferSize; i++) { boolean result = eventStore.tryPut(buildEvent("1", 1L, 1L + i)); sleep(100L); Assert.assertTrue(result); } Position first = eventStore.getFirstPosition(); Position lastest = eventStore.getLatestPosition(); Assert.assertEquals(first, CanalEventUtils.createPosition(buildEvent("1", 1L, 1L))); Assert.assertEquals(lastest, CanalEventUtils.createPosition(buildEvent("1", 1L, 1L + bufferSize - 1))); System.out.println("start get"); Events<Event> entrys1 = eventStore.tryGet(first, bufferSize); System.out.println("first get size : " + entrys1.getEvents().size()); Assert.assertTrue(entrys1.getEvents().size() == bufferSize); Assert.assertEquals(first, entrys1.getPositionRange().getStart()); Assert.assertEquals(lastest, entrys1.getPositionRange().getEnd()); Assert.assertEquals(first, CanalEventUtils.createPosition(entrys1.getEvents().get(0))); Assert.assertEquals(lastest, CanalEventUtils.createPosition(entrys1.getEvents().get(bufferSize - 1))); eventStore.stop(); }
Example #12
Source File: MemoryEventStoreWithBuffer.java From canal with Apache License 2.0 | 5 votes |
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 #13
Source File: MemoryEventStoreWithBuffer.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
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 #14
Source File: MemoryEventStoreWithBuffer.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
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 #15
Source File: MemoryEventStoreWithBuffer.java From canal with Apache License 2.0 | 5 votes |
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 #16
Source File: MemoryEventStoreMemBatchTest.java From canal with Apache License 2.0 | 5 votes |
@Test public void testFullPutBatchGet() { int bufferSize = 16; MemoryEventStoreWithBuffer eventStore = new MemoryEventStoreWithBuffer(); eventStore.setBufferSize(bufferSize); eventStore.setBatchMode(BatchMode.MEMSIZE); eventStore.start(); for (int i = 0; i < bufferSize; i++) { boolean result = eventStore.tryPut(buildEvent("1", 1L, 1L + i)); sleep(100L); Assert.assertTrue(result); } Position first = eventStore.getFirstPosition(); Position lastest = eventStore.getLatestPosition(); Assert.assertEquals(first, CanalEventUtils.createPosition(buildEvent("1", 1L, 1L))); Assert.assertEquals(lastest, CanalEventUtils.createPosition(buildEvent("1", 1L, 1L + bufferSize - 1))); System.out.println("start get"); Events<Event> entrys1 = eventStore.tryGet(first, bufferSize); System.out.println("first get size : " + entrys1.getEvents().size()); Assert.assertTrue(entrys1.getEvents().size() == bufferSize); Assert.assertEquals(first, entrys1.getPositionRange().getStart()); Assert.assertEquals(lastest, entrys1.getPositionRange().getEnd()); Assert.assertEquals(first, CanalEventUtils.createPosition(entrys1.getEvents().get(0))); Assert.assertEquals(lastest, CanalEventUtils.createPosition(entrys1.getEvents().get(bufferSize - 1))); eventStore.stop(); }
Example #17
Source File: DummyEventStore.java From canal with Apache License 2.0 | 4 votes |
public Events tryGet(Position start, int batchSize) throws CanalStoreException { return null; }
Example #18
Source File: DummyEventStore.java From canal with Apache License 2.0 | 4 votes |
public Events get(Position start, int batchSize, long timeout, TimeUnit unit) throws InterruptedException, CanalStoreException { return null; }
Example #19
Source File: DummyEventStore.java From canal with Apache License 2.0 | 4 votes |
public Events get(Position start, int batchSize) throws InterruptedException, CanalStoreException { return null; }
Example #20
Source File: GatewayEventStore.java From DataLink with Apache License 2.0 | 4 votes |
@Override public Events get(Position start, int batchSize, long timeout, TimeUnit unit) throws InterruptedException, CanalStoreException { throw new UnsupportedOperationException("this method is not support."); }
Example #21
Source File: DummyEventStore.java From canal with Apache License 2.0 | 4 votes |
public Events tryGet(Position start, int batchSize) throws CanalStoreException { return null; }
Example #22
Source File: DummyEventStore.java From canal with Apache License 2.0 | 4 votes |
public Events get(Position start, int batchSize, long timeout, TimeUnit unit) throws InterruptedException, CanalStoreException { return null; }
Example #23
Source File: DummyEventStore.java From canal with Apache License 2.0 | 4 votes |
public Events get(Position start, int batchSize) throws InterruptedException, CanalStoreException { return null; }
Example #24
Source File: GatewayEventStore.java From DataLink with Apache License 2.0 | 4 votes |
@Override public Events tryGet(Position start, int batchSize) throws CanalStoreException { throw new UnsupportedOperationException("this method is not support."); }
Example #25
Source File: DummyEventStore.java From canal-1.1.3 with Apache License 2.0 | 4 votes |
public Events get(Position start, int batchSize) throws InterruptedException, CanalStoreException { return null; }
Example #26
Source File: GatewayEventStore.java From DataLink with Apache License 2.0 | 4 votes |
@Override public Events get(Position start, int batchSize) throws InterruptedException, CanalStoreException { throw new UnsupportedOperationException("this method is not support."); }
Example #27
Source File: DummyEventStore.java From canal-1.1.3 with Apache License 2.0 | 4 votes |
public Events tryGet(Position start, int batchSize) throws CanalStoreException { return null; }
Example #28
Source File: DummyEventStore.java From canal-1.1.3 with Apache License 2.0 | 4 votes |
public Events get(Position start, int batchSize, long timeout, TimeUnit unit) throws InterruptedException, CanalStoreException { return null; }
Example #29
Source File: DummyEventStore.java From canal-1.1.3 with Apache License 2.0 | 4 votes |
public Events get(Position start, int batchSize) throws InterruptedException, CanalStoreException { return null; }
Example #30
Source File: DummyEventStore.java From canal-1.1.3 with Apache License 2.0 | 4 votes |
public Events tryGet(Position start, int batchSize) throws CanalStoreException { return null; }