未验证 提交 b8e5ff51 编写于 作者: 李文广 提交者: GitHub

Remove Buffer redundant strategy judgment code. (#5277)

上级 b0bb7cf3
...@@ -35,22 +35,16 @@ public class Buffer<T> implements QueueBuffer<T> { ...@@ -35,22 +35,16 @@ public class Buffer<T> implements QueueBuffer<T> {
index = new AtomicRangeInteger(0, bufferSize); index = new AtomicRangeInteger(0, bufferSize);
} }
@Override
public void setStrategy(BufferStrategy strategy) { public void setStrategy(BufferStrategy strategy) {
this.strategy = strategy; this.strategy = strategy;
} }
@Override
public boolean save(T data) { public boolean save(T data) {
int i = index.getAndIncrement(); int i = index.getAndIncrement();
if (buffer[i] != null) { if (buffer[i] != null) {
switch (strategy) { switch (strategy) {
case BLOCKING:
while (buffer[i] != null) {
try {
Thread.sleep(1L);
} catch (InterruptedException e) {
}
}
break;
case IF_POSSIBLE: case IF_POSSIBLE:
return false; return false;
default: default:
...@@ -60,10 +54,12 @@ public class Buffer<T> implements QueueBuffer<T> { ...@@ -60,10 +54,12 @@ public class Buffer<T> implements QueueBuffer<T> {
return true; return true;
} }
@Override
public int getBufferSize() { public int getBufferSize() {
return buffer.length; return buffer.length;
} }
@Override
public void obtain(List<T> consumeList) { public void obtain(List<T> consumeList) {
this.obtain(consumeList, 0, buffer.length); this.obtain(consumeList, 0, buffer.length);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册