Skip to content

Instantly share code, notes, and snippets.

@gurbuzali
Created May 14, 2015 09:01
Show Gist options
  • Save gurbuzali/394f5be8fd4efc61ca40 to your computer and use it in GitHub Desktop.
Save gurbuzali/394f5be8fd4efc61ca40 to your computer and use it in GitHub Desktop.
/*
* Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package coh;
import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;
import com.tangosol.util.Filter;
import com.tangosol.util.filter.LimitFilter;
import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
/**
* TODO add a proper JavaDoc
*/
public class CohMain {
public static final int DATA_COUNT = 200 * 1000;
static NamedCache c;
static MyComparator comparator;
static LimitFilter limitFilter;
public static void main(String[] args) {
c = CacheFactory.getCache("c");
while (c.size() != DATA_COUNT) {
sleepSeconds(5);
}
sleepSeconds(10);
comparator = new MyComparator();
MyFilter filter = new MyFilter();
limitFilter = new LimitFilter(filter, 50);
getPage(1500);
}
static void getPage(int page) {
limitFilter.setPage(page);
long begin = System.nanoTime();
Set set = c.entrySet(limitFilter, comparator);
long elapsed = System.nanoTime() - begin;
System.err.println("fatal page: " + page + " elapsed : " + (elapsed / 1000000));
printSet(set);
}
static void printSet(Set set) {
for (Object o : set) {
System.err.println("qwe \t " + o);
}
System.err.println("");
}
static void sleepSeconds(int seconds) {
try {
Thread.sleep(seconds * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static class MyFilter implements Filter, Serializable {
public MyFilter() {
}
public boolean evaluate(Object o) {
// System.err.println("eval o: " + o);
return true;
}
}
public static class MyComparator implements Comparator, Serializable {
public int compare(Object o1, Object o2) {
//System.err.println("compare o1: " + o1 + "\t\t o2: " + o2);
return ((Comparable) o1).compareTo(o2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment