本文整理汇总了Java中java.util.concurrent.ConcurrentLinkedQueue.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java ConcurrentLinkedQueue.iterator方法的具体用法?Java ConcurrentLinkedQueue.iterator怎么用?Java ConcurrentLinkedQueue.iterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ConcurrentLinkedQueue
的用法示例。
在下文中一共展示了ConcurrentLinkedQueue.iterator方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkIfNeedHeartBeat
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
private void checkIfNeedHeartBeat(
LinkedList<BackendConnection> heartBeatCons, ConQueue queue,
ConcurrentLinkedQueue<BackendConnection> checkLis,
long hearBeatTime, long hearBeatTime2) {
int maxConsInOneCheck = 10;
Iterator<BackendConnection> checkListItor = checkLis.iterator();
while (checkListItor.hasNext()) {
BackendConnection con = checkListItor.next();
if (con.isClosedOrQuit()) {
checkListItor.remove();
continue;
}
if (validSchema(con.getSchema())) {
if (con.getLastTime() < hearBeatTime
&& heartBeatCons.size() < maxConsInOneCheck) {
checkListItor.remove();
// Heart beat check
con.setBorrowed(true);
heartBeatCons.add(con);
}
} else if (con.getLastTime() < hearBeatTime2) {
// not valid schema conntion should close for idle
// exceed 2*conHeartBeatPeriod
checkListItor.remove();
con.close(" heart beate idle ");
}
}
}
示例2: requestLimit
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
@Before("@annotation(limit)")
public void requestLimit(JoinPoint joinPoint, RequestLimit limit) throws Exception {
DefaultRequestLimitKey key = new DefaultRequestLimitKey(joinPoint);
if (isForbidden(key, limit.period())) {
return;
}
// 时间
Long now = System.currentTimeMillis();
Long before = now - limit.time();
ConcurrentLinkedQueue<Long> queue = limitAccessTime.get(key);
int count = 1;
if (queue != null) {
Iterator<Long> itr = queue.iterator();
while (itr.hasNext()) {
long accessTime = itr.next();
if (accessTime < before) {
itr.remove();
} else {
count++;
}
}
} else {
queue = new ConcurrentLinkedQueue<>();
}
if (count > limit.count()) {
logger.info(key+ " 超过了次数限制" + limit.count());
throw new RequestLimitException(key+ " 超过了次数限制" + limit.count());
}
queue.add(now);
limitAccessTime.put(key, queue);
}
示例3: removeExpiredRequests
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
public Collection<ClientRequest> removeExpiredRequests(long now, long unsentExpiryMs) {
List<ClientRequest> expiredRequests = new ArrayList<>();
for (ConcurrentLinkedQueue<ClientRequest> requests : unsent.values()) {
Iterator<ClientRequest> requestIterator = requests.iterator();
while (requestIterator.hasNext()) {
ClientRequest request = requestIterator.next();
if (request.createdTimeMs() < now - unsentExpiryMs) {
expiredRequests.add(request);
requestIterator.remove();
} else
break;
}
}
return expiredRequests;
}
示例4: testIterator
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
/**
* iterator iterates through all elements
*/
public void testIterator() {
ConcurrentLinkedQueue q = populatedQueue(SIZE);
Iterator it = q.iterator();
int i;
for (i = 0; it.hasNext(); i++)
assertTrue(q.contains(it.next()));
assertEquals(i, SIZE);
assertIteratorExhausted(it);
}
示例5: testIteratorOrdering
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
/**
* iterator ordering is FIFO
*/
public void testIteratorOrdering() {
final ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
q.add(one);
q.add(two);
q.add(three);
int k = 0;
for (Iterator it = q.iterator(); it.hasNext();) {
assertEquals(++k, it.next());
}
assertEquals(3, k);
}
示例6: testWeaklyConsistentIteration
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
/**
* Modifications do not cause iterators to fail
*/
public void testWeaklyConsistentIteration() {
final ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
q.add(one);
q.add(two);
q.add(three);
for (Iterator it = q.iterator(); it.hasNext();) {
q.remove();
it.next();
}
assertEquals("queue should be empty again", 0, q.size());
}
示例7: testIteratorRemove
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
/**
* iterator.remove removes current element
*/
public void testIteratorRemove() {
final ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
q.add(one);
q.add(two);
q.add(three);
Iterator it = q.iterator();
it.next();
it.remove();
it = q.iterator();
assertSame(it.next(), two);
assertSame(it.next(), three);
assertFalse(it.hasNext());
}
示例8: traversalOperationsCollapseNodes
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
@Test(dataProvider = "traversalActions")
public void traversalOperationsCollapseNodes(
Consumer<ConcurrentLinkedQueue> traversalAction) {
ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
Object oldHead;
int n = 1 + rnd.nextInt(5);
for (int i = 0; i < n; i++) q.add(i);
assertInvariants(q);
assertEquals(nodeCount(q), n + 1);
oldHead = head(q);
traversalAction.accept(q); // collapses head node
assertIsSelfLinked(oldHead);
assertInvariants(q);
assertEquals(nodeCount(q), n);
// Iterator.remove does not currently try to collapse dead nodes
for (Iterator it = q.iterator(); it.hasNext(); ) {
it.next();
it.remove();
}
assertEquals(nodeCount(q), n);
assertInvariants(q);
oldHead = head(q);
traversalAction.accept(q); // collapses all nodes
if (n > 1) assertIsSelfLinked(oldHead);
assertEquals(nodeCount(q), 1);
assertInvariants(q);
for (int i = 0; i < n + 1; i++) q.add(i);
assertEquals(nodeCount(q), n + 2);
oldHead = head(q);
assertEquals(0, q.poll()); // 2 leading nodes collapsed
assertIsSelfLinked(oldHead);
assertEquals(nodeCount(q), n);
assertTrue(q.remove(n));
assertEquals(nodeCount(q), n);
traversalAction.accept(q); // trailing node is never collapsed
}
示例9: getNeedHeartbeatCons
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
protected LinkedList<RedisBackendConnection> getNeedHeartbeatCons(
ConcurrentLinkedQueue<RedisBackendConnection> checkLis, long heartbeatTime, long closeTime) {
int maxConsInOneCheck = 10;
LinkedList<RedisBackendConnection> heartbeatCons = new LinkedList<RedisBackendConnection>();
Iterator<RedisBackendConnection> checkListItor = checkLis.iterator();
while (checkListItor.hasNext()) {
RedisBackendConnection con = checkListItor.next();
if ( con.isClosed() ) {
checkListItor.remove();
continue;
}
// 关闭 闲置过久的 connection
if (con.getLastTime() < closeTime) {
if(checkLis.remove(con)) {
con.close("heartbeate idle close ");
continue;
}
}
// 提取需要做心跳检测的 connection
if (con.getLastTime() < heartbeatTime && heartbeatCons.size() < maxConsInOneCheck) {
// 如果移除失败,说明该连接已经被其他线程使用
if(checkLis.remove(con)) {
con.setBorrowed(true);
heartbeatCons.add(con);
}
}
}
return heartbeatCons;
}
示例10: requestIterator
import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
public Iterator<ClientRequest> requestIterator(Node node) {
ConcurrentLinkedQueue<ClientRequest> requests = unsent.get(node);
return requests == null ? Collections.<ClientRequest>emptyIterator() : requests.iterator();
}