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:io.hops.metadata.util.RMUtilities.java

/**
 * Retrieves pending events from NDB and updates their status.
 * If numberOfEvents is zero, it retrieves all the events.
 * <p/>//from  ww  w.ja va 2 s  .  c  o  m
 *
 * @param numberOfEvents
 * @param status
 * @return
 * @throws IOException
 */
public static Map<String, ConcurrentSkipListSet<PendingEvent>> getAndUpdatePendingEvents(
        final int numberOfEvents, final byte status) throws IOException {
    LightWeightRequestHandler getAndUpdatePendingEventsHandler = new LightWeightRequestHandler(
            YARNOperationType.TEST) {
        @Override
        public Object performTask() throws StorageException {
            connector.beginTransaction();
            connector.writeLock();
            List<PendingEvent> pendingEvents;
            //Map groups events by RMNode to assign them to ThreadPool
            Map<String, ConcurrentSkipListSet<PendingEvent>> pendingEventsByRMNode = new HashMap<String, ConcurrentSkipListSet<PendingEvent>>();
            PendingEventDataAccess DA = (PendingEventDataAccess) RMStorageFactory
                    .getDataAccess(PendingEventDataAccess.class);
            //Check the number of events to retrieve
            if (numberOfEvents == 0) {
                pendingEvents = DA.getAll(status);
                if (pendingEvents != null && !pendingEvents.isEmpty()) {
                    List<PendingEvent> pendingEventsModified = new ArrayList<PendingEvent>();

                    for (PendingEvent hop : pendingEvents) {
                        if (!pendingEventsByRMNode.containsKey(hop.getRmnodeId())) {
                            pendingEventsByRMNode.put(hop.getRmnodeId(),
                                    new ConcurrentSkipListSet<PendingEvent>());
                        }
                        pendingEventsByRMNode.get(hop.getRmnodeId()).add(hop);
                        PendingEvent pending = new PendingEvent(hop.getRmnodeId(), hop.getType(),
                                TablesDef.PendingEventTableDef.PENDING, hop.getId());
                        pendingEventsModified.add(pending);
                    }
                    DA.prepare(pendingEventsModified, null);
                }
            }
            connector.commit();
            return pendingEventsByRMNode;
        }
    };
    return (Map<String, ConcurrentSkipListSet<PendingEvent>>) getAndUpdatePendingEventsHandler.handle();
}

From source file:org.epics.archiverappliance.config.DefaultConfigService.java

@Override
public void addAlias(String aliasName, String realName) {
    aliasNamesToRealNames.put(aliasName, realName);
    try {//  w  w w  . j a v a2  s .  c o m
        persistanceLayer.putAliasNamesToRealName(aliasName, realName);
    } catch (IOException ex) {
        logger.error("Exception adding alias name to persistence " + aliasName, ex);
    }

    // Add aliases into the trie
    String[] parts = this.pvName2KeyConverter.breakIntoParts(aliasName);
    for (String part : parts) {
        if (!parts2PVNamesForThisAppliance.containsKey(part)) {
            parts2PVNamesForThisAppliance.put(part, new ConcurrentSkipListSet<String>());
        }
        parts2PVNamesForThisAppliance.get(part).add(aliasName);
    }
}

From source file:org.epics.archiverappliance.config.DefaultConfigService.java

/**
 * Load typeInfos into the cluster hashmaps from the persistence layer on startup.
 * To avoid overwhelming the cluster, we batch the loads 
 *//*w  w w .java  2s .  co m*/
private void loadTypeInfosFromPersistence() {
    try {
        configlogger.info("Loading PVTypeInfo from persistence");
        List<String> upgradedPVs = new LinkedList<String>();
        List<String> pvNamesFromPersistence = persistanceLayer.getTypeInfoKeys();
        HashMap<String, PVTypeInfo> newTypeInfos = new HashMap<String, PVTypeInfo>();
        HashMap<String, ApplianceInfo> newPVMappings = new HashMap<String, ApplianceInfo>();
        int objectCount = 0;
        int batch = 0;
        int clusterPVCount = 0;
        for (String pvNameFromPersistence : pvNamesFromPersistence) {
            PVTypeInfo typeInfo = persistanceLayer.getTypeInfo(pvNameFromPersistence);
            if (typeInfo.getApplianceIdentity().equals(myIdentity)) {
                // Here's where we put schema update logic
                upgradeTypeInfo(typeInfo, upgradedPVs);

                String pvName = typeInfo.getPvName();
                newTypeInfos.put(pvName, typeInfo);
                newPVMappings.put(pvName, appliances.get(typeInfo.getApplianceIdentity()));
                pvsForThisAppliance.add(pvName);
                if (typeInfo.isPaused()) {
                    pausedPVsForThisAppliance.add(pvName);
                }
                String[] parts = this.pvName2KeyConverter.breakIntoParts(pvName);
                for (String part : parts) {
                    if (!parts2PVNamesForThisAppliance.containsKey(part)) {
                        parts2PVNamesForThisAppliance.put(part, new ConcurrentSkipListSet<String>());
                    }
                    parts2PVNamesForThisAppliance.get(part).add(pvName);
                }

                objectCount++;
            }
            // Add in batch sizes of 1000 or so...
            if (objectCount > 1000) {
                this.typeInfos.putAll(newTypeInfos);
                this.pv2appliancemapping.putAll(newPVMappings);
                for (String pvName : newTypeInfos.keySet()) {
                    applianceAggregateInfo.addInfoForPV(pvName, newTypeInfos.get(pvName), this);
                }
                clusterPVCount += newTypeInfos.size();
                newTypeInfos = new HashMap<String, PVTypeInfo>();
                newPVMappings = new HashMap<String, ApplianceInfo>();
                objectCount = 0;
                logger.debug("Adding next batch of PVs " + batch++);
            }
        }

        if (newTypeInfos.size() > 0) {
            logger.debug("Adding final batch of PVs from persistence");
            this.typeInfos.putAll(newTypeInfos);
            this.pv2appliancemapping.putAll(newPVMappings);
            for (String pvName : newTypeInfos.keySet()) {
                applianceAggregateInfo.addInfoForPV(pvName, newTypeInfos.get(pvName), this);
            }
            clusterPVCount += newTypeInfos.size();
        }

        configlogger.info("Done loading " + +clusterPVCount + " PVs from persistence into cluster");

        for (String upgradedPVName : upgradedPVs) {
            logger.debug("PV " + upgradedPVName + "'s schema was upgraded");
            persistanceLayer.putTypeInfo(upgradedPVName, getTypeInfoForPV(upgradedPVName));
            logger.debug("Done persisting upgraded PV's " + upgradedPVName + "'s typeInfo");
        }
    } catch (Exception ex) {
        configlogger.error("Exception loading PVs from persistence", ex);
    }
}

From source file:org.epics.archiverappliance.config.DefaultConfigService.java

/**
 * Load alias mappings from persistence on startup in batches
 *//*from  w ww .j  ava 2 s  . c  o  m*/
private void loadAliasesFromPersistence() {
    try {
        configlogger.info("Loading aliases from persistence");
        List<String> pvNamesFromPersistence = persistanceLayer.getAliasNamesToRealNamesKeys();
        HashMap<String, String> newAliases = new HashMap<String, String>();
        int objectCount = 0;
        int batch = 0;
        int clusterPVCount = 0;
        for (String pvNameFromPersistence : pvNamesFromPersistence) {
            String realName = persistanceLayer.getAliasNamesToRealName(pvNameFromPersistence);
            if (this.pvsForThisAppliance.contains(realName)) {
                newAliases.put(pvNameFromPersistence, realName);
                // Add the alias into the trie
                String[] parts = this.pvName2KeyConverter.breakIntoParts(pvNameFromPersistence);
                for (String part : parts) {
                    if (!parts2PVNamesForThisAppliance.containsKey(part)) {
                        parts2PVNamesForThisAppliance.put(part, new ConcurrentSkipListSet<String>());
                    }
                    parts2PVNamesForThisAppliance.get(part).add(pvNameFromPersistence);
                }
            }
            // Add in batch sizes of 1000 or so...
            if (objectCount > 1000) {
                this.aliasNamesToRealNames.putAll(newAliases);
                clusterPVCount += newAliases.size();
                newAliases = new HashMap<String, String>();
                objectCount = 0;
                logger.debug("Adding next batch of aliases " + batch++);
            }
        }

        if (newAliases.size() > 0) {
            logger.debug("Adding final batch of aliases from persistence");
            this.aliasNamesToRealNames.putAll(newAliases);
            clusterPVCount += newAliases.size();
        }

        configlogger.info("Done loading " + clusterPVCount + " aliases from persistence into cluster ");
    } catch (Exception ex) {
        configlogger.error("Exception loading aliases from persistence", ex);
    }
}

From source file:org.sakaiproject.assignment.tool.AssignmentAction.java

/**
 * Populate the state object, if needed - override to do something!
 *//*from w w  w . j  a va  2s  .c  om*/
protected void initState(SessionState state, VelocityPortlet portlet, JetspeedRunData data) {
    super.initState(state, portlet, data);

    if (m_contentHostingService == null) {
        m_contentHostingService = (ContentHostingService) ComponentManager
                .get("org.sakaiproject.content.api.ContentHostingService");
    }

    if (m_assignmentSupplementItemService == null) {
        m_assignmentSupplementItemService = (AssignmentSupplementItemService) ComponentManager
                .get("org.sakaiproject.assignment.api.model.AssignmentSupplementItemService");
    }

    if (m_eventTrackingService == null) {
        m_eventTrackingService = (EventTrackingService) ComponentManager
                .get("org.sakaiproject.event.api.EventTrackingService");
    }

    if (m_notificationService == null) {
        m_notificationService = (NotificationService) ComponentManager
                .get("org.sakaiproject.event.api.NotificationService");
    }

    if (m_securityService == null) {
        m_securityService = (SecurityService) ComponentManager
                .get("org.sakaiproject.authz.api.SecurityService");
    }
    if (assignmentPeerAssessmentService == null) {
        assignmentPeerAssessmentService = (AssignmentPeerAssessmentService) ComponentManager
                .get("org.sakaiproject.assignment.api.AssignmentPeerAssessmentService");
    }

    if (authzGroupService == null) {
        authzGroupService = ComponentManager.get(AuthzGroupService.class);
    }

    String siteId = ToolManager.getCurrentPlacement().getContext();

    // show the list of assignment view first
    if (state.getAttribute(STATE_SELECTED_VIEW) == null) {
        state.setAttribute(STATE_SELECTED_VIEW, MODE_LIST_ASSIGNMENTS);
    }

    if (state.getAttribute(STATE_USER) == null) {
        state.setAttribute(STATE_USER, UserDirectoryService.getCurrentUser());
    }

    /** The content type image lookup service in the State. */
    ContentTypeImageService iService = (ContentTypeImageService) state
            .getAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE);
    if (iService == null) {
        iService = org.sakaiproject.content.cover.ContentTypeImageService.getInstance();
        state.setAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE, iService);
    } // if

    if (state.getAttribute(SUBMISSIONS_SEARCH_ONLY) == null) {
        String propValue = null;
        // save the option into tool configuration
        try {
            Site site = SiteService.getSite(siteId);
            ToolConfiguration tc = site.getToolForCommonId(ASSIGNMENT_TOOL_ID);
            propValue = tc.getPlacementConfig().getProperty(SUBMISSIONS_SEARCH_ONLY);
        } catch (IdUnusedException e) {
            M_log.warn(this + ":init()  Cannot find site with id " + siteId);
        }
        state.setAttribute(SUBMISSIONS_SEARCH_ONLY,
                propValue == null ? Boolean.FALSE : Boolean.valueOf(propValue));
    }

    /** The calendar tool  */
    if (state.getAttribute(CALENDAR_TOOL_EXIST) == null) {
        CalendarService cService = org.sakaiproject.calendar.cover.CalendarService.getInstance();
        if (cService != null) {
            if (!siteHasTool(siteId, cService.getToolId())) {
                state.setAttribute(CALENDAR_TOOL_EXIST, Boolean.FALSE);
                state.removeAttribute(CALENDAR);
            } else {
                state.setAttribute(CALENDAR_TOOL_EXIST, Boolean.TRUE);
                if (state.getAttribute(CALENDAR) == null) {
                    state.setAttribute(CALENDAR_TOOL_EXIST, Boolean.TRUE);
                    state.setAttribute(STATE_CALENDAR_SERVICE, cService);

                    String calendarId = ServerConfigurationService.getString("calendar", null);
                    if (calendarId == null) {
                        calendarId = cService.calendarReference(siteId, SiteService.MAIN_CONTAINER);
                        try {
                            state.setAttribute(CALENDAR, cService.getCalendar(calendarId));
                        } catch (IdUnusedException e) {
                            state.removeAttribute(CALENDAR);
                            M_log.info(this + ":initState No calendar found for site " + siteId + " "
                                    + e.getMessage());
                        } catch (PermissionException e) {
                            state.removeAttribute(CALENDAR);
                            M_log.info(
                                    this + ":initState No permission to get the calender. " + e.getMessage());
                        } catch (Exception ex) {
                            state.removeAttribute(CALENDAR);
                            M_log.info(
                                    this + ":initState Assignment : Action : init state : calendar exception : "
                                            + ex.getMessage());

                        }
                    }
                }
            }
        }
    }

    /** Additional Calendar tool */
    // Setting this attribute to true or false currently makes no difference as it is never checked for true or false.
    // true: means the additional calendar is ready to be used with assignments.
    // false: means the tool may not be deployed at all or may be at the site but not ready to be used.
    if (state.getAttribute(ADDITIONAL_CALENDAR_TOOL_READY) == null) {
        // Get a handle to the Google calendar service class from the Component Manager. It will be null if not deployed.
        CalendarService additionalCalendarService = (CalendarService) ComponentManager
                .get(CalendarService.ADDITIONAL_CALENDAR);
        if (additionalCalendarService != null) {
            // If tool is not used/used on this site, we set the appropriate flag in the state.
            if (!siteHasTool(siteId, additionalCalendarService.getToolId())) {
                state.setAttribute(ADDITIONAL_CALENDAR_TOOL_READY, Boolean.FALSE);
                state.removeAttribute(ADDITIONAL_CALENDAR);
            } else { // Also check that this calendar has been fully created (initialized) in the additional calendar service.
                if (additionalCalendarService.isCalendarToolInitialized(siteId)) {
                    state.setAttribute(ADDITIONAL_CALENDAR_TOOL_READY, Boolean.TRUE); // Alternate calendar ready for events.
                    if (state.getAttribute(ADDITIONAL_CALENDAR) == null) {
                        try {
                            state.setAttribute(ADDITIONAL_CALENDAR,
                                    additionalCalendarService.getCalendar(null));
                        } catch (IdUnusedException e) {
                            M_log.info(this + ":initState No calendar found for site " + siteId + " "
                                    + e.getMessage());
                        } catch (PermissionException e) {
                            M_log.info(
                                    this + ":initState No permission to get the calendar. " + e.getMessage());
                        }
                    }
                } else {
                    state.setAttribute(ADDITIONAL_CALENDAR_TOOL_READY, Boolean.FALSE); // Tool on site but alternate calendar not yet created.
                }

            }
        } else {
            state.setAttribute(ADDITIONAL_CALENDAR_TOOL_READY, Boolean.FALSE); // Tool not deployed on the server.
        }
    }

    /** The Announcement tool  */
    if (state.getAttribute(ANNOUNCEMENT_TOOL_EXIST) == null) {
        if (!siteHasTool(siteId, "sakai.announcements")) {
            state.setAttribute(ANNOUNCEMENT_TOOL_EXIST, Boolean.FALSE);
            state.removeAttribute(ANNOUNCEMENT_CHANNEL);
        } else {
            state.setAttribute(ANNOUNCEMENT_TOOL_EXIST, Boolean.TRUE);
            if (state.getAttribute(ANNOUNCEMENT_CHANNEL) == null) {
                /** The announcement service in the State. */
                AnnouncementService aService = (AnnouncementService) state
                        .getAttribute(STATE_ANNOUNCEMENT_SERVICE);
                if (aService == null) {
                    aService = org.sakaiproject.announcement.cover.AnnouncementService.getInstance();
                    state.setAttribute(STATE_ANNOUNCEMENT_SERVICE, aService);

                    String channelId = ServerConfigurationService.getString("channel", null);
                    if (channelId == null) {
                        channelId = aService.channelReference(siteId, SiteService.MAIN_CONTAINER);
                        try {
                            state.setAttribute(ANNOUNCEMENT_CHANNEL,
                                    aService.getAnnouncementChannel(channelId));
                        } catch (IdUnusedException e) {
                            M_log.warn(this + ":initState No announcement channel found. " + e.getMessage());
                            state.removeAttribute(ANNOUNCEMENT_CHANNEL);
                        } catch (PermissionException e) {
                            M_log.warn(this + ":initState No permission to annoucement channel. "
                                    + e.getMessage());
                        } catch (Exception ex) {
                            M_log.warn(
                                    this + ":initState Assignment : Action : init state : calendar exception : "
                                            + ex.getMessage());
                        }
                    }
                }
            }
        }
    } // if

    if (state.getAttribute(STATE_CONTEXT_STRING) == null
            || ((String) state.getAttribute(STATE_CONTEXT_STRING)).length() == 0) {
        state.setAttribute(STATE_CONTEXT_STRING, siteId);
    } // if context string is null

    if (state.getAttribute(SORTED_BY) == null) {
        setDefaultSort(state);
    }

    if (state.getAttribute(SORTED_GRADE_SUBMISSION_BY) == null) {
        state.setAttribute(SORTED_GRADE_SUBMISSION_BY, SORTED_GRADE_SUBMISSION_BY_LASTNAME);
    }

    if (state.getAttribute(SORTED_GRADE_SUBMISSION_ASC) == null) {
        state.setAttribute(SORTED_GRADE_SUBMISSION_ASC, Boolean.TRUE.toString());
    }

    if (state.getAttribute(SORTED_SUBMISSION_BY) == null) {
        state.setAttribute(SORTED_SUBMISSION_BY, SORTED_SUBMISSION_BY_LASTNAME);
    }

    if (state.getAttribute(SORTED_SUBMISSION_ASC) == null) {
        state.setAttribute(SORTED_SUBMISSION_ASC, Boolean.TRUE.toString());
    }

    if (state.getAttribute(STUDENT_LIST_SHOW_TABLE) == null) {
        state.setAttribute(STUDENT_LIST_SHOW_TABLE, new ConcurrentSkipListSet());
    }

    if (state.getAttribute(ATTACHMENTS_MODIFIED) == null) {
        state.setAttribute(ATTACHMENTS_MODIFIED, Boolean.valueOf(false));
    }

    // SECTION MOD
    if (state.getAttribute(STATE_SECTION_STRING) == null) {

        state.setAttribute(STATE_SECTION_STRING, "001");
    }

    // // setup the observer to notify the Main panel
    // if (state.getAttribute(STATE_OBSERVER) == null)
    // {
    // // the delivery location for this tool
    // String deliveryId = clientWindowId(state, portlet.getID());
    //
    // // the html element to update on delivery
    // String elementId = mainPanelUpdateId(portlet.getID());
    //
    // // the event resource reference pattern to watch for
    // String pattern = AssignmentService.assignmentReference((String) state.getAttribute (STATE_CONTEXT_STRING), "");
    //
    // state.setAttribute(STATE_OBSERVER, new MultipleEventsObservingCourier(deliveryId, elementId, pattern));
    // }

    if (state.getAttribute(STATE_MODE) == null) {
        state.setAttribute(STATE_MODE, MODE_LIST_ASSIGNMENTS);
    }

    if (state.getAttribute(STATE_TOP_PAGE_MESSAGE) == null) {
        state.setAttribute(STATE_TOP_PAGE_MESSAGE, Integer.valueOf(0));
    }

    if (state.getAttribute(WITH_GRADES) == null) {
        PortletConfig config = portlet.getPortletConfig();
        String withGrades = StringUtils.trimToNull(config.getInitParameter("withGrades"));
        if (withGrades == null) {
            withGrades = Boolean.FALSE.toString();
        }
        state.setAttribute(WITH_GRADES, Boolean.valueOf(withGrades));
    }

    // whether to display the number of submission/ungraded submission column
    // default to show
    if (state.getAttribute(SHOW_NUMBER_SUBMISSION_COLUMN) == null) {
        PortletConfig config = portlet.getPortletConfig();
        String value = StringUtils.trimToNull(config.getInitParameter(SHOW_NUMBER_SUBMISSION_COLUMN));
        if (value == null) {
            value = Boolean.TRUE.toString();
        }
        state.setAttribute(SHOW_NUMBER_SUBMISSION_COLUMN, Boolean.valueOf(value));
    }

    if (state.getAttribute(NEW_ASSIGNMENT_YEAR_RANGE_FROM) == null) {
        state.setAttribute(NEW_ASSIGNMENT_YEAR_RANGE_FROM,
                Integer.valueOf(GregorianCalendar.getInstance().get(GregorianCalendar.YEAR) - 4));
    }

    if (state.getAttribute(NEW_ASSIGNMENT_YEAR_RANGE_TO) == null) {
        state.setAttribute(NEW_ASSIGNMENT_YEAR_RANGE_TO,
                Integer.valueOf(GregorianCalendar.getInstance().get(GregorianCalendar.YEAR) + 4));
    }
}