mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
= cold cleanup
* using lambda if possible (we are already building in Java8) * using diamond when new generic instance * remove used improt
This commit is contained in:
@@ -12,7 +12,7 @@ import com.alibaba.otter.canal.filter.CanalEventFilter;
|
||||
public abstract class AbstractCanalEventSink<T> extends AbstractCanalLifeCycle implements CanalEventSink<T> {
|
||||
|
||||
protected CanalEventFilter filter;
|
||||
protected List<CanalEventDownStreamHandler> handlers = new ArrayList<CanalEventDownStreamHandler>();
|
||||
protected List<CanalEventDownStreamHandler> handlers = new ArrayList<>();
|
||||
|
||||
public void setFilter(CanalEventFilter filter) {
|
||||
this.filter = filter;
|
||||
|
||||
@@ -90,7 +90,7 @@ public class EntryEventSink extends AbstractCanalEventSink<List<CanalEntry.Entry
|
||||
throws InterruptedException {
|
||||
boolean hasRowData = false;
|
||||
boolean hasHeartBeat = false;
|
||||
List<Event> events = new ArrayList<Event>();
|
||||
List<Event> events = new ArrayList<>();
|
||||
for (CanalEntry.Entry entry : entrys) {
|
||||
if (!doFilter(entry)) {
|
||||
continue;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class HeartBeatEntryEventHandler extends AbstractCanalEventDownStreamHand
|
||||
return events;
|
||||
} else {
|
||||
// 目前heartbeat和其他事件是分离的,保险一点还是做一下检查处理
|
||||
List<Event> result = new ArrayList<Event>();
|
||||
List<Event> result = new ArrayList<>();
|
||||
for (Event event : events) {
|
||||
if (event.getEntryType() != EntryType.HEARTBEAT) {
|
||||
result.add(event);
|
||||
|
||||
@@ -32,7 +32,7 @@ public class TimelineBarrier implements GroupBarrier<Event> {
|
||||
protected ReentrantLock lock = new ReentrantLock();
|
||||
protected Condition condition = lock.newCondition();
|
||||
protected volatile long threshold;
|
||||
protected BlockingQueue<Long> lastTimestamps = new PriorityBlockingQueue<Long>(); // 当前通道最后一次single的时间戳
|
||||
protected BlockingQueue<Long> lastTimestamps = new PriorityBlockingQueue<>(); // 当前通道最后一次single的时间戳
|
||||
|
||||
public TimelineBarrier(int groupSize){
|
||||
this.groupSize = groupSize;
|
||||
|
||||
@@ -16,12 +16,7 @@ import com.alibaba.otter.canal.store.model.Event;
|
||||
*/
|
||||
public class TimelineTransactionBarrier extends TimelineBarrier {
|
||||
|
||||
private ThreadLocal<Boolean> inTransaction = new ThreadLocal() {
|
||||
|
||||
protected Object initialValue() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
private ThreadLocal<Boolean> inTransaction = ThreadLocal.withInitial(() -> false);
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
|
||||
@@ -28,71 +28,62 @@ public class GroupEventSinkTest {
|
||||
|
||||
ExecutorService executor = Executors.newFixedThreadPool(3);
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
executor.submit(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
for (int i = 0; i < 50; i++) {
|
||||
try {
|
||||
eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 1L + i)), address, "ljhtest1");
|
||||
Thread.sleep(50L + RandomUtils.nextInt(50));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
executor.submit(() -> {
|
||||
for (int i = 0; i < 50; i++) {
|
||||
try {
|
||||
eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 1L + i)), address, "ljhtest1");
|
||||
Thread.sleep(50L + RandomUtils.nextInt(50));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 50; i++) {
|
||||
try {
|
||||
eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 30L + i)), address, "ljhtest1");
|
||||
Thread.sleep(50L + RandomUtils.nextInt(50));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("one sink finished!");
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 50; i++) {
|
||||
try {
|
||||
eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 30L + i)), address, "ljhtest1");
|
||||
Thread.sleep(50L + RandomUtils.nextInt(50));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("one sink finished!");
|
||||
latch.countDown();
|
||||
});
|
||||
|
||||
executor.submit(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
for (int i = 0; i < 50; i++) {
|
||||
try {
|
||||
eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 10L + i)), address, "ljhtest2");
|
||||
Thread.sleep(50L + RandomUtils.nextInt(50));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
executor.submit(() -> {
|
||||
for (int i = 0; i < 50; i++) {
|
||||
try {
|
||||
eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 10L + i)), address, "ljhtest2");
|
||||
Thread.sleep(50L + RandomUtils.nextInt(50));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 50; i++) {
|
||||
try {
|
||||
eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 40L + i)), address, "ljhtest2");
|
||||
Thread.sleep(50L + RandomUtils.nextInt(50));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.out.println("tow sink finished!");
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 50; i++) {
|
||||
try {
|
||||
eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 40L + i)), address, "ljhtest2");
|
||||
Thread.sleep(50L + RandomUtils.nextInt(50));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.out.println("tow sink finished!");
|
||||
latch.countDown();
|
||||
});
|
||||
|
||||
executor.submit(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
try {
|
||||
eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 30L + i)), address, "ljhtest3");
|
||||
Thread.sleep(50L + RandomUtils.nextInt(50));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
executor.submit(() -> {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
try {
|
||||
eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 30L + i)), address, "ljhtest3");
|
||||
Thread.sleep(50L + RandomUtils.nextInt(50));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("tow sink finished!");
|
||||
latch.countDown();
|
||||
}
|
||||
System.out.println("tow sink finished!");
|
||||
latch.countDown();
|
||||
});
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user