Mercurial > hg > Members > shoshi > distributedalgorithm
view src/main/java/suikwasha/distributedalgorithm/simulator/Summary.java @ 1:d24bcb819032
trying to add Selector
author | suikwasha |
---|---|
date | Fri, 19 Oct 2012 23:48:11 +0900 |
parents | 38a110b13db1 |
children |
line wrap: on
line source
package suikwasha.distributedalgorithm.simulator; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; import suikwasha.distributedalgorithm.framework.MessageChain; public class Summary { private final AtomicLong messageComplexity; private final AtomicLong bitComplexity; private final AtomicReference<MessageChain> longestMessageChain; public Summary() { messageComplexity = new AtomicLong(0); bitComplexity = new AtomicLong(0); longestMessageChain = new AtomicReference<MessageChain>(MessageChain.NIL_MESSAGECHAIN); } public void incrementMessageCount() { messageComplexity.incrementAndGet(); } public void addMessageBitCount(long _size) { bitComplexity.addAndGet(_size); } public long getCurrentMessageComplexity() { return messageComplexity.get(); } public long getCurrentBitComplexity() { return bitComplexity.get(); } public MessageChain getLongestMessageChain() { return longestMessageChain.get(); } public boolean trySetMessageChain(MessageChain _chain) { MessageChain currentLongestChain; do{ currentLongestChain = longestMessageChain.get(); if(currentLongestChain.getMessageCount() > _chain.getMessageCount()){ return false; } }while(!longestMessageChain.compareAndSet(currentLongestChain,_chain)); return true; } public void print() { System.out.println("Summary:"); System.out.println(String.format("MessageComplexity :\t\t%d",messageComplexity.get())); System.out.println(String.format("MessageBitComplexity :\t\t%d",bitComplexity.get())); System.out.println(String.format("TimeComplexity :\t\t%d",longestMessageChain.get().getMessageCount())); } }