-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
INTERNAL: Refactor api using broadcast operation. #646
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,6 @@ | |
import java.util.concurrent.TimeoutException; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.concurrent.locks.ReentrantLock; | ||
import java.util.jar.JarFile; | ||
import java.util.jar.Manifest; | ||
|
@@ -128,6 +127,7 @@ | |
import net.spy.memcached.internal.SMGetFuture; | ||
import net.spy.memcached.internal.PipedCollectionFuture; | ||
import net.spy.memcached.internal.CollectionGetFuture; | ||
import net.spy.memcached.internal.BroadcastFuture; | ||
import net.spy.memcached.ops.BTreeFindPositionOperation; | ||
import net.spy.memcached.ops.BTreeFindPositionWithGetOperation; | ||
import net.spy.memcached.ops.BTreeGetBulkOperation; | ||
|
@@ -1952,96 +1952,29 @@ public OperationFuture<Boolean> flush(final String prefix) { | |
|
||
@Override | ||
public OperationFuture<Boolean> flush(final String prefix, final int delay) { | ||
final AtomicReference<Boolean> flushResult = new AtomicReference<Boolean>(true); | ||
final ConcurrentLinkedQueue<Operation> ops = new ConcurrentLinkedQueue<Operation>(); | ||
|
||
final CountDownLatch blatch = broadcastOp(new BroadcastOpFactory() { | ||
public Operation newOp(final MemcachedNode n, | ||
final CountDownLatch latch) { | ||
Operation op = opFact.flush(prefix, delay, false, | ||
new OperationCallback() { | ||
public void receivedStatus(OperationStatus s) { | ||
if (!s.isSuccess()) { | ||
flushResult.set(false); | ||
} | ||
} | ||
|
||
public void complete() { | ||
latch.countDown(); | ||
} | ||
}); | ||
ops.add(op); | ||
return op; | ||
} | ||
}); | ||
|
||
return new OperationFuture<Boolean>(blatch, flushResult, | ||
operationTimeout) { | ||
@Override | ||
public boolean cancel(boolean ign) { | ||
boolean rv = false; | ||
for (Operation op : ops) { | ||
rv |= op.cancel("by application."); | ||
} | ||
return rv; | ||
} | ||
Collection<MemcachedNode> nodes = getAllNodes(); | ||
final BroadcastFuture<Boolean> rv | ||
= new BroadcastFuture<Boolean>(operationTimeout, Boolean.TRUE, nodes.size()); | ||
|
||
@Override | ||
public boolean isCancelled() { | ||
for (Operation op : ops) { | ||
if (op.isCancelled()) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public Boolean get(long duration, TimeUnit units) | ||
throws InterruptedException, TimeoutException, ExecutionException { | ||
|
||
if (!blatch.await(duration, units)) { | ||
// whenever timeout occurs, continuous timeout counter will increase by 1. | ||
Collection<Operation> timedoutOps = new HashSet<Operation>(); | ||
for (Operation op : ops) { | ||
if (op.getState() != OperationState.COMPLETE) { | ||
MemcachedConnection.opTimedOut(op); | ||
timedoutOps.add(op); | ||
} else { | ||
MemcachedConnection.opSucceeded(op); | ||
} | ||
} | ||
if (timedoutOps.size() > 0) { | ||
throw new CheckedOperationTimeoutException(duration, units, timedoutOps); | ||
} | ||
} else { | ||
// continuous timeout counter will be reset | ||
MemcachedConnection.opsSucceeded(ops); | ||
} | ||
|
||
for (Operation op : ops) { | ||
if (op != null && op.hasErrored()) { | ||
throw new ExecutionException(op.getException()); | ||
} | ||
|
||
if (op != null && op.isCancelled()) { | ||
throw new ExecutionException(new RuntimeException(op.getCancelCause())); | ||
checkState(); | ||
for (MemcachedNode node : nodes) { | ||
Operation op = opFact.flush(prefix, delay, false, new OperationCallback() { | ||
@Override | ||
public void receivedStatus(OperationStatus status) { | ||
if (!status.isSuccess()) { | ||
rv.set(Boolean.FALSE, status); | ||
} | ||
} | ||
|
||
return flushResult.get(); | ||
} | ||
|
||
@Override | ||
public boolean isDone() { | ||
for (Operation op : ops) { | ||
if (!(op.getState() == OperationState.COMPLETE || op.isCancelled())) { | ||
return false; | ||
} | ||
@Override | ||
public void complete() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 메소드 시작 전에 이전 메소드 사이에 1개의 Empty Line을 둡시다. |
||
rv.complete(); | ||
} | ||
return true; | ||
} | ||
}; | ||
}); | ||
rv.addOp(op); | ||
getMemcachedConnection().addOperation(node, op); | ||
} | ||
return rv; | ||
} | ||
|
||
@Override | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import 문이 ABC 순이므로 원래대로라면 이곳에 위치하지 않을 것 같습니다.
프로젝트 루트 디렉토리 우클릭 한 다음
Optimize imports
한 번 실행해주세요.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optimize imports
동작 시 변경되는 파일이 너무 많아별도 PR로 처리하겠습니다.