/** * The gossip digest is built based on randomization rather than just looping through the * collection of live endpoints. * * @param gDigests list of Gossip Digests. */ void makeRandomGossipDigest(List<GossipDigest> gDigests) { /* Add the local endpoint state */ EndpointState epState = endpointStateMap_.get(localEndpoint_); int generation = epState.getHeartBeatState().getGeneration(); int maxVersion = getMaxEndpointStateVersion(epState); gDigests.add(new GossipDigest(localEndpoint_, generation, maxVersion)); List<InetAddress> endpoints = new ArrayList<InetAddress>(endpointStateMap_.keySet()); Collections.shuffle(endpoints, random_); for (InetAddress endpoint : endpoints) { epState = endpointStateMap_.get(endpoint); if (epState != null) { generation = epState.getHeartBeatState().getGeneration(); maxVersion = getMaxEndpointStateVersion(epState); gDigests.add(new GossipDigest(endpoint, generation, maxVersion)); } else { gDigests.add(new GossipDigest(endpoint, 0, 0)); } } /* FOR DEBUG ONLY - remove later */ StringBuilder sb = new StringBuilder(); for (GossipDigest gDigest : gDigests) { sb.append(gDigest); sb.append(" "); } if (logger_.isTraceEnabled()) logger_.trace("Gossip Digests are : " + sb.toString()); }
private void generateRemainingPagesQueueForAllFiles() { List<Integer>[] array = new ArrayList[FILE_COUNT]; for (int k = 0; k < FILE_COUNT; ++k) { array[k] = new ArrayList<Integer>(PAGE_COUNT); for (Integer i = 0; i < PAGE_COUNT; ++i) { array[k].add(i); } } for (int i = 0; i < FILE_COUNT; ++i) { Collections.shuffle(array[i]); pagesQueue.set(i, new ConcurrentLinkedQueue<Integer>(array[i])); } }
public static void main(String[] args) throws Throwable { final int itrs = Integer.getInteger("iterations", 100000); // final int itrs = Integer.getInteger("iterations", 12); final int size = Integer.getInteger("size", 2048); final int subsize = Integer.getInteger("subsize", 128); final int maxchar = Integer.getInteger("maxchar", 128); final String regex = System.getProperty("filter"); final Pattern filter = (regex == null) ? null : Pattern.compile(regex); final boolean useSecurityManager = Boolean.getBoolean("SecurityManager"); if (useSecurityManager) System.setSecurityManager(new PermissiveSecurityManger()); final Random rnd = new Random(); String[] csns = new String[] { "Big5", "Johab", "EUC_CN", "EUC_KR", "MS932", "MS936", "MS949", "MS950", "GBK", "Big5_HKSCS", "Big5_HKSCS_2001", "Big5_Solaris", "MS950_HKSCS", "MS950_HKSCS_XP", "IBM1364", "IBM1381", "IBM1383", "IBM930", "IBM933", "IBM935", "IBM937", "IBM939", "IBM942", "IBM943", "IBM948", "IBM949", "IBM950", "IBM970", }; ArrayList<long[]> sum = new ArrayList<>(); for (final String csn : csns) { final Charset cs = Charset.forName(csn); List<Integer> cps = new ArrayList<>(0x4000); int off = 0; int cp = 0; int n = 0; CharsetEncoder enc = cs.newEncoder(); while (cp < 0x10000 && n < cps.size()) { if (enc.canEncode((char) cp)) { cps.add(cp); n++; } cp++; } Collections.shuffle(cps); char[] ca = new char[cps.size()]; for (int i = 0; i < cps.size(); i++) ca[i] = (char) (int) cps.get(i); System.out.printf("%n--------%s---------%n", csn); for (int sz = 8; sz <= 2048; sz *= 2) { System.out.printf(" [len=%d]%n", sz); final char[] chars = Arrays.copyOf(ca, sz); final String str = new String(chars); final byte[] bs = str.getBytes(cs); Job[] jobs = { new Job("String decode: csn") { public void work() throws Throwable { for (int i = 0; i < itrs; i++) new String(bs, csn); } }, new Job("String decode: cs") { public void work() throws Throwable { for (int i = 0; i < itrs; i++) new String(bs, cs); } }, new Job("String encode: csn") { public void work() throws Throwable { for (int i = 0; i < itrs; i++) str.getBytes(csn); } }, new Job("String encode: cs") { public void work() throws Throwable { for (int i = 0; i < itrs; i++) str.getBytes(cs); } }, }; sum.add(time(jobs)); } } }