= 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:
zavakid
2020-09-17 10:48:15 +08:00
parent df60eda679
commit e7658879bc
133 changed files with 990 additions and 1558 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);

View File

@@ -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;

View File

@@ -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>

View File

@@ -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 {