Example usage for java.util.concurrent ConcurrentSkipListSet ConcurrentSkipListSet

List of usage examples for java.util.concurrent ConcurrentSkipListSet ConcurrentSkipListSet

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentSkipListSet ConcurrentSkipListSet.

Prototype

public ConcurrentSkipListSet() 

Source Link

Document

Constructs a new, empty set that orders its elements according to their Comparable natural ordering .

Usage

From source file:at.uni_salzburg.cs.ckgroup.cpcc.engmap.EngMapServlet.java

public void init(ServletConfig servletConfig) throws ServletException {
    this.servletConfig = servletConfig;
    regdata = new ConcurrentSkipListMap<String, IRegistrationData>();
    centralEngines = new ConcurrentSkipListSet<String>();
    neighborZones = new ConcurrentSkipListSet<IZone>();
    super.init();
    myInit();//from w ww . ja va 2  s  . c o  m
}

From source file:com.srotya.monitoring.kafka.util.KafkaConsumerOffsetUtil.java

private KafkaConsumerOffsetUtil(KafkaMonitorConfiguration kafkaConfiguration, ZKClient zkClient,
        boolean enableHistory, StorageEngine server) {
    this.kafkaConfiguration = kafkaConfiguration;
    this.zkClient = zkClient;
    this.enableHistory = enableHistory;
    this.server = server;
    this.topics = new ConcurrentSkipListSet<>();
    brokerHosts = new ArrayBlockingQueue<>(kafkaConfiguration.getKafkaBroker().length);
    for (String broker : kafkaConfiguration.getKafkaBroker()) {
        brokerHosts.add(broker);//from ww  w. j  ava  2  s .  c om
    }
    Thread th = new Thread(new KafkaNewConsumerOffsetThread(this));
    th.setDaemon(true);
    th.start();
}

From source file:annis.gui.flatquerybuilder.SearchBox.java

@Override
public void textChange(TextChangeEvent event) {
    if ("specific".equals(sq.getFilterMechanism())) {
        ConcurrentSkipListSet<String> notInYet = new ConcurrentSkipListSet<String>();
        reducingStringComparator esc = new reducingStringComparator();
        String txt = event.getText();
        if (!txt.equals("")) {
            cb.removeAllItems();//ww  w  .j  a  v a  2 s . c  o m
            for (Iterator<String> it = annonames.iterator(); it.hasNext();) {
                String s = it.next();
                if (esc.compare(s, txt) == 0) {
                    cb.addItem(s);
                } else {
                    notInYet.add(s);
                }
            }
            //startsWith
            for (String s : notInYet) {
                if (esc.startsWith(s, txt)) {
                    cb.addItem(s);
                    notInYet.remove(s);
                }
            }
            //contains
            for (String s : notInYet) {
                if (esc.contains(s, txt)) {
                    cb.addItem(s);
                }
            }
        } else {
            //have a look and speed it up
            SpanBox.buildBoxValues(cb, ebene, sq);
        }
    }

    if ("levenshtein".equals(sq.getFilterMechanism())) {
        String txt = event.getText();
        HashMap<Integer, Collection> levdistvals = new HashMap<Integer, Collection>();
        if (txt.length() > 1) {
            cb.removeAllItems();
            for (String s : annonames) {
                Integer d = StringUtils.getLevenshteinDistance(removeAccents(txt), removeAccents(s));
                if (levdistvals.containsKey(d)) {
                    levdistvals.get(d).add(s);
                }
                if (!levdistvals.containsKey(d)) {
                    Set<String> newc = new TreeSet<String>();
                    newc.add(s);
                    levdistvals.put(d, newc);
                }
            }
            SortedSet<Integer> keys = new TreeSet<Integer>(levdistvals.keySet());
            for (Integer k : keys.subSet(0, 5)) {
                List<String> values = new ArrayList(levdistvals.get(k));
                Collections.sort(values, String.CASE_INSENSITIVE_ORDER);
                for (String v : values) {
                    cb.addItem(v);
                }
            }
        }
    }
}

From source file:lockstep.LockstepServer.java

public LockstepServer(int tcpPort, int clientsNumber, int tickrate, int maxUDPPayloadLength,
        int connectionTimeout) {
    //late fail left to Socket class
    this.tcpPort = tcpPort;

    if (clientsNumber <= 1)
        throw new IllegalArgumentException("clientsNumber must be at least 2");
    else// w  w  w.j a  va 2  s. co  m
        this.clientsNumber = clientsNumber;

    if (tickrate <= 0)
        throw new IllegalArgumentException("Tickrate must be an integer greater than 0");
    else
        this.tickrate = tickrate;

    if (maxUDPPayloadLength <= 0)
        throw new IllegalArgumentException("Max UDP payload length must be an integer greater than 0");
    else
        this.maxUDPPayloadLength = maxUDPPayloadLength;

    if (connectionTimeout < 0)
        throw new IllegalArgumentException("Connection timeout must be greater or equal than zero");
    else
        this.connectionTimeout = connectionTimeout;

    receivers = new HashMap<>();
    transmitters = new HashMap<>();

    executionSemaphore = new Semaphore(0);
    receivingQueues = new ConcurrentHashMap<>();
    transmissionFrameQueueTree = new ConcurrentHashMap<>();
    ackQueues = new HashMap<>();
    clientIDs = new ConcurrentSkipListSet<>();
    openSockets = new ArrayList<>();
}

From source file:org.apache.hadoop.raid.RaidHistogram.java

public synchronized void initialize(ArrayList<Long> newWindows) {
    windows = newWindows;/*from ww w  .j  ava2  s.c o  m*/
    Collections.sort(windows);
    points = new ConcurrentSkipListSet<Point>();
    windowNum = windows.size();
    totalPoints = new CounterArray(windowNum);
    totalFailedPaths = new CounterArray(windowNum);
    histo = new ConcurrentSkipListMap<Long, CounterArray>();
    failedRecoveredFiles = new ConcurrentHashMap<String, AtomicInteger>();
}

From source file:org.nuxeo.ecm.core.io.registry.MarshallerRegistryImpl.java

@Override
public void register(Class<?> marshaller) {
    if (marshaller == null) {
        throw new MarshallingException("Cannot register null marshaller");
    }//from w  w  w  . ja  v  a2 s  . co m
    MarshallerInspector inspector = new MarshallerInspector(marshaller);
    if (!inspector.isWriter() && !inspector.isReader()) {
        throw new MarshallingException(
                "The marshaller registry just supports Writer and Reader for now. You have to implement "
                        + Writer.class.getName() + " or " + Reader.class.getName());
    }
    if (marshallersByType.get(marshaller) != null) {
        log.warn("The marshaller " + marshaller.getName() + " is already registered.");
        return;
    } else {
        marshallersByType.put(marshaller, inspector);
    }
    if (inspector.isWriter()) {
        writers.add(inspector);
        for (MediaType mediaType : inspector.getSupports()) {
            Set<MarshallerInspector> inspectors = writersByMediaType.get(mediaType);
            if (inspectors == null) {
                inspectors = new ConcurrentSkipListSet<MarshallerInspector>();
                writersByMediaType.put(mediaType, inspectors);
            }
            inspectors.add(inspector);
        }
    }
    if (inspector.isReader()) {
        readers.add(inspector);
        for (MediaType mediaType : inspector.getSupports()) {
            Set<MarshallerInspector> inspectors = readersByMediaType.get(mediaType);
            if (inspectors == null) {
                inspectors = new ConcurrentSkipListSet<MarshallerInspector>();
                readersByMediaType.put(mediaType, inspectors);
            }
            inspectors.add(inspector);
        }
    }
}

From source file:com.enitalk.configs.DateCache.java

public NavigableSet<DateTime> days(JsonNode tree, String tz, JsonNode teacherNode) {
    ConcurrentSkipListSet<DateTime> dates = new ConcurrentSkipListSet<>();

    Iterator<JsonNode> els = tree.elements();
    DateTimeZone dz = DateTimeZone.forID(tz);
    DateTimeFormatter hour = DateTimeFormat.forPattern("HH:mm").withZone(dz);

    DateTime today = DateTime.now().millisOfDay().setCopy(0);
    while (els.hasNext()) {

        JsonNode el = els.next();//w  w w.java 2  s  .c o  m
        String day = el.path("day").asText();

        boolean plus = today.getDayOfWeek() > days.get(day);
        if (el.has("start") && el.has("end")) {
            DateTime start = hour.parseDateTime(el.path("start").asText()).dayOfMonth()
                    .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year()
                    .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0);
            DateTime end = hour.parseDateTime(el.path("end").asText()).dayOfMonth()
                    .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year()
                    .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0);

            Hours hours = Hours.hoursBetween(start, end);
            int hh = hours.getHours() + 1;

            while (hh-- > 0) {
                dates.add(start.plusHours(hh).toDateTime(DateTimeZone.UTC));
            }
        } else {
            List<String> datesAv = jackson.convertValue(el.path("times"), List.class);
            logger.info("Array of dates {} {}", datesAv, day);

            datesAv.forEach((String dd) -> {
                DateTime date = hour.parseDateTime(dd).dayOfMonth().setCopy(today.getDayOfMonth()).monthOfYear()
                        .setCopy(today.getMonthOfYear()).year().setCopy(today.getYear())
                        .withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0);
                dates.add(date.toDateTime(DateTimeZone.UTC));
            });

        }

    }

    final TreeSet<DateTime> addWeek = new TreeSet<>();
    for (int i = 1; i < 2; i++) {
        for (DateTime e : dates) {
            addWeek.add(e.plusWeeks(i));

        }
    }

    dates.addAll(addWeek);

    DateTime nowUtc = DateTime.now().toDateTime(DateTimeZone.UTC);
    nowUtc = nowUtc.plusHours(teacherNode.path("notice").asInt(2));

    NavigableSet<DateTime> ss = dates.tailSet(nowUtc, true);

    return ss;

}

From source file:org.apdplat.superword.tools.ProxyIp.java

private static void save() {
    try {//from w  ww.ja v  a  2  s. co  m
        //??IP??
        Set<String> ips = new ConcurrentSkipListSet<>();
        ips.addAll(Files.readAllLines(PROXY_IPS_FILE));
        ips.addAll(IPS);
        //???IP
        ips.removeAll(NORMAL_IPS);
        Files.write(PROXY_IPS_FILE, toVerify(ips));
        LOGGER.info("" + ips.size() + "??IP?");
        Set<String> excellentIps = new HashSet<>();
        excellentIps.addAll(Files.readAllLines(EXCELLENT_PROXY_IPS_FILE));
        excellentIps.addAll(EXCELLENT_IPS);
        Files.write(EXCELLENT_PROXY_IPS_FILE, toVerify(excellentIps));
        LOGGER.info("" + excellentIps.size() + "????IP?");
        Set<String> excellentUsaIps = new HashSet<>();
        excellentUsaIps.addAll(Files.readAllLines(EXCELLENT_USA_PROXY_IPS_FILE));
        excellentUsaIps.addAll(EXCELLENT_USA_IPS);
        Files.write(EXCELLENT_USA_PROXY_IPS_FILE, toVerify(excellentUsaIps));
        LOGGER.info("" + excellentUsaIps.size() + "????IP?");
        Set<String> normalIps = new HashSet<>();
        normalIps.addAll(Files.readAllLines(NORMAL_PROXY_IPS_FILE));
        normalIps.addAll(NORMAL_IPS);
        Files.write(NORMAL_PROXY_IPS_FILE, toVerify(normalIps));
        LOGGER.info("" + normalIps.size() + "?????IP?");
    } catch (Exception e) {
        LOGGER.error("?", e);
    }
}

From source file:com.vaadin.spring.navigator.SpringViewProvider.java

@PostConstruct
void init() {/*from   w ww.ja  v  a  2 s .c om*/
    LOGGER.info("Looking up SpringViews");
    int count = 0;
    final String[] viewBeanNames = applicationContext.getBeanNamesForAnnotation(SpringView.class);
    for (String beanName : viewBeanNames) {
        final Class<?> type = applicationContext.getType(beanName);
        if (View.class.isAssignableFrom(type)) {
            final SpringView annotation = applicationContext.findAnnotationOnBean(beanName, SpringView.class);
            final String viewName = getViewNameFromAnnotation(type, annotation);
            LOGGER.debug("Found SpringView bean [{}] with view name [{}]", beanName, viewName);
            if (applicationContext.isSingleton(beanName)) {
                throw new IllegalStateException("SpringView bean [" + beanName + "] must not be a singleton");
            }
            Set<String> beanNames = viewNameToBeanNamesMap.get(viewName);
            if (beanNames == null) {
                beanNames = new ConcurrentSkipListSet<String>();
                viewNameToBeanNamesMap.put(viewName, beanNames);
            }
            beanNames.add(beanName);
            count++;
        } else {
            LOGGER.error("The view bean [{}] does not implement View", beanName);
            throw new IllegalStateException("SpringView bean [" + beanName + "] must implement View");
        }
    }
    if (count == 0) {
        LOGGER.warn("No SpringViews found");
    } else if (count == 1) {
        LOGGER.info("1 SpringView found");
    } else {
        LOGGER.info("{} SpringViews found", count);
    }
}

From source file:org.sindice.siren.index.Utils.java

/**
 * Flatten a list of triples to n-tuples containing many objects for the same
 * predicate. Generate one n-tuple per predicate.
 * /*from  ww  w .  jav  a2 s .c  o  m*/
 * @param values
 *          The list of n-triples.
 * @return The n-tuples concatenated.
 */
private static synchronized void flattenNTriples(final StringBuilder triples,
        final ConcurrentHashMap<String, ConcurrentSkipListSet<String>> map,
        final ConcurrentSkipListSet<String> types, final ConcurrentSkipListSet<String> label,
        final ConcurrentSkipListSet<String> description, final boolean isOut) {
    try {
        initParser();
        parser.parse(new StringReader(triples.toString()), "");
        for (Statement st : collector.getStatements()) {
            sb.setLength(0);
            final String subject = sb.append('<').append(st.getSubject().toString()).append('>').toString();
            sb.setLength(0);
            final String predicate = sb.append('<').append(st.getPredicate().toString()).append('>').toString();
            sb.setLength(0);
            final String object = (st.getObject() instanceof URI)
                    ? sb.append('<').append(st.getObject().toString()).append('>').toString()
                    : st.getObject().toString();
            if (label != null && predicate.equals(RDFS_LABEL))
                label.add(object);
            if (description != null && predicate.equals(DC_DESCRIPTION))
                description.add(object);
            if (description != null && predicate.equals(DBP_ABSTRACT))
                description.add(object);
            if (types != null && predicate.equals(RDF_TYPE)) {
                types.add(object);
            } else {
                ConcurrentSkipListSet<String> hs = map.get(predicate);
                final String toAdd = isOut ? object : subject;
                if (hs == null) {
                    hs = new ConcurrentSkipListSet<String>();
                    map.put(predicate, hs);
                }
                if (hs.size() < 65535) // 2 ^ 16 - 1
                    hs.add(toAdd);
            }
        }
    } catch (RDFParseException e1) {
    } catch (RDFHandlerException e1) {
    } catch (IOException e1) {
    }
    triples.setLength(0);
}