本文整理汇总了Java中java.util.Deque.peekFirst方法的典型用法代码示例。如果您正苦于以下问题:Java Deque.peekFirst方法的具体用法?Java Deque.peekFirst怎么用?Java Deque.peekFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Deque
的用法示例。
在下文中一共展示了Deque.peekFirst方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMethodExitFinally
import java.util.Deque; //导入方法依赖的package包/类
@Override
public void onMethodExitFinally(String cls, final String method, String argTypes) {
final long threadId = Thread.currentThread().getId();
//方法无论是return退出还是异常throw退出,都会回调onMethodExitFinally()
//threadMethodStack无需remove,有两个原因:一是同线程可能再次记录调用栈,所以缓存调用栈结构;二是调用栈本身会清空。
Deque<MethodInfo> methodStack = threadMethodStack.get(threadId);
MethodInfo topMethod = methodStack.pop();
Config config = DroidTelescope.getConfig();
if (config == null) {
//TODO 还未初始化好,一般发生在Application.<init>方法中
return;
}
if (config.shouldRecordMethod(topMethod.getWallClockTimeNs(), topMethod.getCpuTimeMs())) {
//弹出当前线程的栈顶Method,如果栈为空了,说明这个栈顶Method是个rootMethod,保存到root列表
if (methodStack.isEmpty()) {
addRootMethod(topMethod);
} else {
//如果当前调用栈不为空,说明此方法是个子方法,于是添加到rootMethod的调用队列当中
MethodInfo rootMethod = methodStack.peekFirst();
rootMethod.addInnerMethod(topMethod);
}
}
}
示例2: getTrailingAverage
import java.util.Deque; //导入方法依赖的package包/类
private Integer getTrailingAverage(Deque<Entry<Long, Long>> list, int seconds) {
Entry<Long,Long> latest = list.peekLast();
Entry<Long,Long> old = list.peekFirst();
Iterator<Entry<Long,Long>> iter = list.descendingIterator();
while (iter.hasNext()) {
Entry<Long,Long> e = iter.next();
if (e.getKey() - latest.getKey() > seconds * ONE_BILLION) {
old = e;
break;
}
}
final long oldKey = old.getKey();
final long latestKey = latest.getKey();
if (oldKey == latestKey) {
return null;
} else {
return (int) (100 * (old.getValue() - latest.getValue()) / (oldKey - latestKey));
}
}
示例3: onMethodExit
import java.util.Deque; //导入方法依赖的package包/类
@Override
public void onMethodExit(final long wallClockTimeNs, final long cpuTimeMs, final String cls,
final String method, String argTypes) {
final long threadId = Thread.currentThread().getId();
//当方法非return语句退出时,不会回调onMethodExit()
Deque<MethodInfo> methodStack = threadMethodStack.get(threadId);
//获取当前线程调用栈的栈顶方法,并更新记录数据
MethodInfo topMethod = methodStack.peekFirst();
topMethod.setWallClockTimeNs(wallClockTimeNs);
topMethod.setCpuTimeMs(cpuTimeMs);
//进入这里的方法都是正常退出的方法
topMethod.setNormalExit();
}
示例4: getParentNode
import java.util.Deque; //导入方法依赖的package包/类
private Node getParentNode(){
Deque<PMMLObject> parents = getParents();
PMMLObject parent = parents.peekFirst();
if(parent instanceof Node){
return (Node)parent;
}
return null;
}
示例5: validateParenthesesMatching
import java.util.Deque; //导入方法依赖的package包/类
private void validateParenthesesMatching( final Deque<Token> operationStack ) {
final Token operationStackHead = operationStack.peekFirst();
if ( operationStackHead != null
&& operationStackHead.getType().isGrouper() ) {
throw new SyntaxExpressionException( "Mismatched parentheses: "
+ operationStackHead );
}
}
示例6: examineBuildingsWithSunset
import java.util.Deque; //导入方法依赖的package包/类
public static Deque<BuildingWithHeight> examineBuildingsWithSunset(Iterator<Integer> sequence) {
Deque<BuildingWithHeight> stack = new ArrayDeque<>();
int c = 0;
while (sequence.hasNext()) {
Integer temp = sequence.next();
while (stack.peekFirst()!=null && temp >= stack.peekFirst().height) {
stack.removeFirst();
}
stack.addFirst(new BuildingWithHeight(c++,temp));
}
return stack;
}
开发者ID:gardncl,项目名称:elements-of-programming-interviews-solutions,代码行数:13,代码来源:ComputeBuildingsWithView.java
示例7: locateSubGraph
import java.util.Deque; //导入方法依赖的package包/类
private static ParseGraph locateSubGraph(final ParseGraph graph, final ParseValue value, final Deque<Token> definitions, final Token terminator, final ParseGraph result) {
if (graph == EMPTY || graph.head == null) {
return EMPTY;
}
final Token currentDefinition = graph.getDefinition();
if (!definitions.isEmpty() && currentDefinition == definitions.peekFirst()) {
// found a token in the path
definitions.removeFirst();
}
ParseGraph resultGraph = result;
if (definitions.isEmpty() && currentDefinition == terminator) {
// found a deeper token matching the terminating token in the path (making the sub-graph smaller)
resultGraph = graph;
// in case we're not searching for a value at all, return immediately
if (value == null) {
return resultGraph;
}
}
if (graph.head.isValue() && graph.head.asValue() == value && definitions.isEmpty()) {
return resultGraph;
}
if (graph.head.isGraph()) {
final ParseGraph headResult = locateSubGraph(graph.head.asGraph(), value, new ArrayDeque<>(definitions), terminator, resultGraph);
if (headResult != EMPTY) {
return headResult;
}
}
return locateSubGraph(graph.tail, value, definitions, terminator, resultGraph);
}
示例8: getFirst
import java.util.Deque; //导入方法依赖的package包/类
public FormValue getFirst(String name) {
final Deque<FormValue> deque = values.get(name);
return deque == null ? null : deque.peekFirst();
}
示例9: ready
import java.util.Deque; //导入方法依赖的package包/类
/**
* Get a list of nodes whose partitions are ready to be sent, and the earliest time at which any non-sendable
* partition will be ready; Also return the flag for whether there are any unknown leaders for the accumulated
* partition batches.
* <p>
* A destination node is ready to send data if:
* <ol>
* <li>There is at least one partition that is not backing off its send
* <li><b>and</b> those partitions are not muted (to prevent reordering if
* {@value org.apache.kafka.clients.producer.ProducerConfig#MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION}
* is set to one)</li>
* <li><b>and <i>any</i></b> of the following are true</li>
* <ul>
* <li>The record set is full</li>
* <li>The record set has sat in the accumulator for at least lingerMs milliseconds</li>
* <li>The accumulator is out of memory and threads are blocking waiting for data (in this case all partitions
* are immediately considered ready).</li>
* <li>The accumulator has been closed</li>
* </ul>
* </ol>
*/
// 在sender线程中被调用 ,
// 获取集群中符合发送消息条件的节点集合 readyNodes集合 ,此集合还需要经过NetWorkClient的过滤
// deque中是否有多个RecordBatch或是第一个RecordBatch是否满了
// 是否超时了
// 是否还有其他线程在等待BufferPool释放空间
// 是否有其他线程正在等flush操作
// sender线程准备关闭
public ReadyCheckResult ready(Cluster cluster, long nowMs) {
Set<Node> readyNodes = new HashSet<>();
// 记录下次需要调用ready方法的时间间隔
long nextReadyCheckDelayMs = Long.MAX_VALUE;
Set<String> unknownLeaderTopics = new HashSet<>();
// 是否有线程在阻塞等待BufferPool释放空间
boolean exhausted = this.free.queued() > 0;
// 遍历batchs集合,对每个分区的leader副本所在的node进行判断
for (Map.Entry<TopicPartition, Deque<ProducerBatch>> entry : this.batches.entrySet()) {
TopicPartition part = entry.getKey();
Deque<ProducerBatch> deque = entry.getValue();
// 查找分区所在的leader
Node leader = cluster.leaderFor(part);
synchronized (deque) {
//没有leader的topic,不能发送消息
if (leader == null && !deque.isEmpty()) {
// This is a partition for which leader is not known, but messages are available to send.
// Note that entries are currently not removed from batches when deque is empty.
unknownLeaderTopics.add(part.topic());
} else if (!readyNodes.contains(leader) && !muted.contains(part)) {
// 读取batch中的第一个ProducerBatch
ProducerBatch batch = deque.peekFirst();
if (batch != null) {
// 计算下面几个条件
long waitedTimeMs = batch.waitedTimeMs(nowMs);
boolean backingOff = batch.attempts() > 0 && waitedTimeMs < retryBackoffMs;
long timeToWaitMs = backingOff ? retryBackoffMs : lingerMs;
boolean full = deque.size() > 1 || batch.isFull();
boolean expired = waitedTimeMs >= timeToWaitMs;
boolean sendable = full || expired || exhausted || closed || flushInProgress();
if (sendable && !backingOff) {
readyNodes.add(leader);
} else {
long timeLeftMs = Math.max(timeToWaitMs - waitedTimeMs, 0);
// Note that this results in a conservative estimate since an un-sendable partition may have
// a leader that will later be found to have sendable data. However, this is good enough
// since we'll just wake up and then sleep again for the remaining time.
// 记录下次需要调用Ready()方法检查的时间间隔
nextReadyCheckDelayMs = Math.min(timeLeftMs, nextReadyCheckDelayMs);
}
}
}
}
}
return new ReadyCheckResult(readyNodes, nextReadyCheckDelayMs, unknownLeaderTopics);
}