Remove Buffer redundant strategy judgment code. (#5277)
This commit is contained in:
parent
b0bb7cf3be
commit
b8e5ff516c
|
|
@ -35,22 +35,16 @@ public class Buffer<T> implements QueueBuffer<T> {
|
|||
index = new AtomicRangeInteger(0, bufferSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStrategy(BufferStrategy strategy) {
|
||||
this.strategy = strategy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(T data) {
|
||||
int i = index.getAndIncrement();
|
||||
if (buffer[i] != null) {
|
||||
switch (strategy) {
|
||||
case BLOCKING:
|
||||
while (buffer[i] != null) {
|
||||
try {
|
||||
Thread.sleep(1L);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IF_POSSIBLE:
|
||||
return false;
|
||||
default:
|
||||
|
|
@ -60,10 +54,12 @@ public class Buffer<T> implements QueueBuffer<T> {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBufferSize() {
|
||||
return buffer.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void obtain(List<T> consumeList) {
|
||||
this.obtain(consumeList, 0, buffer.length);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue