Example usage for java.util LinkedList clear

List of usage examples for java.util LinkedList clear

Introduction

In this page you can find the example usage for java.util LinkedList clear.

Prototype

public void clear() 

Source Link

Document

Removes all of the elements from this list.

Usage

From source file:org.alfresco.repo.domain.audit.AuditDAOTest.java

public synchronized void testAuditQuery() throws Exception {
    // Some entries
    doAuditEntryImpl(1);/*w  w w.ja  va  2 s.c o  m*/

    final MutableInt count = new MutableInt(0);
    final LinkedList<Long> timestamps = new LinkedList<Long>();
    // Find everything, but look for a specific key
    final AuditQueryCallback callback = new AuditQueryCallback() {
        public boolean valuesRequired() {
            return false;
        }

        public boolean handleAuditEntry(Long entryId, String applicationName, String user, long time,
                Map<String, Serializable> values) {
            count.setValue(count.intValue() + 1);
            timestamps.add(time);
            return true;
        }

        public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error) {
            throw new AlfrescoRuntimeException(errorMsg, error);
        }
    };

    final AuditQueryParameters params = new AuditQueryParameters();
    params.addSearchKey("/a/b/c", null);

    RetryingTransactionCallback<Void> findCallback = new RetryingTransactionCallback<Void>() {
        public Void execute() throws Throwable {
            auditDAO.findAuditEntries(callback, params, 2);
            return null;
        }
    };
    count.setValue(0);
    timestamps.clear();
    txnHelper.doInTransaction(findCallback);
    assertTrue("Expected at least one result", count.intValue() > 0);

    //        // Make sure that the last two entries are in forward order (ascending time)
    //        Long lastTimestamp = timestamps.removeLast();
    //        Long secondLastTimeStamp = timestamps.removeLast();
    //        assertTrue("The timestamps should be in ascending order", lastTimestamp.compareTo(secondLastTimeStamp) > 0);
    //        
    // Make sure that the last two entries differ in time
    wait(1000L);

    // Search in reverse order
    doAuditEntryImpl(1);
    RetryingTransactionCallback<Void> findReverseCallback = new RetryingTransactionCallback<Void>() {
        public Void execute() throws Throwable {
            params.setForward(false);
            auditDAO.findAuditEntries(callback, params, 2);
            params.setForward(true);
            return null;
        }
    };
    timestamps.clear();
    txnHelper.doInTransaction(findReverseCallback);
    //        
    //        // Make sure that the last two entries are in reverse order (descending time)
    //        lastTimestamp = timestamps.removeLast();
    //        secondLastTimeStamp = timestamps.removeLast();
    //        assertTrue("The timestamps should be in descending order", lastTimestamp.compareTo(secondLastTimeStamp) < 0);
}

From source file:net.floodlightcontroller.devicemanager.internal.DeviceManagerImpl.java

/**
 * Clean up expired entities/devices/*from  w  ww . j  a va  2  s  .  c o  m*/
 */
protected void cleanupEntities() {

    Calendar c = Calendar.getInstance();
    c.add(Calendar.MILLISECOND, -ENTITY_TIMEOUT);
    Date cutoff = c.getTime();

    ArrayList<Entity> toRemove = new ArrayList<Entity>();
    ArrayList<Entity> toKeep = new ArrayList<Entity>();

    Iterator<Device> diter = deviceMap.values().iterator();
    LinkedList<DeviceUpdate> deviceUpdates = new LinkedList<DeviceUpdate>();

    while (diter.hasNext()) {
        Device d = diter.next();

        while (true) {
            deviceUpdates.clear();
            toRemove.clear();
            toKeep.clear();
            for (Entity e : d.getEntities()) {
                if (e.getLastSeenTimestamp() != null && 0 > e.getLastSeenTimestamp().compareTo(cutoff)) {
                    // individual entity needs to be removed
                    toRemove.add(e);
                } else {
                    toKeep.add(e);
                }
            }
            if (toRemove.size() == 0) {
                break;
            }

            for (Entity e : toRemove) {
                removeEntity(e, d.getEntityClass(), d, toKeep);
            }

            if (toKeep.size() > 0) {
                Device newDevice = allocateDevice(d.getDeviceKey(), d.getDhcpClientName(), d.getOldAPs(),
                        //XXX 
                        d.getAps(), toKeep, d.getEntityClass());

                EnumSet<DeviceField> changedFields = EnumSet.noneOf(DeviceField.class);
                for (Entity e : toRemove) {
                    changedFields.addAll(findChangedFields(newDevice, e));
                }
                DeviceUpdate update = null;
                if (changedFields.size() > 0)
                    update = new DeviceUpdate(d, CHANGE, changedFields);
                //FIXME
                if (!deviceMap.insert(newDevice.getDeviceKey(), newDevice)) {
                    // concurrent modification; try again
                    // need to use device that is the map now for the next
                    // iteration
                    d = deviceMap.get(d.getDeviceKey());
                    if (null != d)
                        continue;
                }
                if (update != null)
                    deviceUpdates.add(update);
            } else {
                DeviceUpdate update = new DeviceUpdate(d, DELETE, null);
                if (!deviceMap.remove(d.getDeviceKey(), d)) {
                    // concurrent modification; try again
                    // need to use device that is the map now for the next
                    // iteration
                    d = deviceMap.get(d.getDeviceKey());
                    if (null != d)
                        continue;
                }
                deviceUpdates.add(update);
            }
            processUpdates(deviceUpdates);
            break;
        }
    }
}

From source file:net.firejack.platform.core.store.process.CaseStore.java

@Override
@Transactional/*from   w  w  w .j  a va2  s.co m*/
public CaseModel moveCaseToActivity(Long entityId, Long activityActionId, Long assigneeId, Long currentUserId,
        String comment) {
    CaseModel processCase;
    if (entityId == null || activityActionId == null || currentUserId == null) {
        processCase = null;
    } else {
        UserModel currentUser = userStore.findById(currentUserId);
        LinkedList<Criterion> restrictions = new LinkedList<Criterion>();
        restrictions.add(Restrictions.idEq(activityActionId));
        Map<String, String> aliases = new HashMap<String, String>();
        aliases.put("activityFrom", "from");
        aliases.put("activityTo", "to");
        aliases.put("status", "status");
        List<ActivityActionModel> foundActions = activityActionStore.search(restrictions, aliases, null);
        ActivityActionModel activityAction = foundActions.get(0);
        UserModel assignee = assigneeId == null ? null : userStore.findById(assigneeId);

        restrictions.clear();
        restrictions.add(Restrictions.idEq(activityAction.getActivityFrom().getId()));
        aliases.clear();
        aliases.put("parent", "parent");
        List<ProcessModel> processList = activityStore.searchWithProjection(restrictions,
                Projections.property("parent"), aliases, null);

        CaseObjectModel caseObjectModel;
        if (processList.isEmpty()) {
            processCase = null;
            caseObjectModel = null;
        } else {
            ProcessModel processModel = processList.get(0);
            EntityModel entityModel = getHibernateTemplate().get(EntityModel.class,
                    processModel.getMain().getId());
            restrictions.clear();
            restrictions.add(Restrictions.eq("entityType", entityModel.getLookup()));
            restrictions.add(Restrictions.eq("entityId", entityId));
            restrictions.add(Restrictions.eq("case.process.id", processModel.getId()));
            aliases.clear();
            aliases.put("case", "case");
            List<CaseObjectModel> caseObjects = caseObjectStore.search(restrictions, aliases, null, false);
            caseObjectModel = caseObjects.isEmpty() ? null : caseObjects.get(0);
            processCase = caseObjectModel == null ? null : caseObjectModel.getCase();
        }

        if (processCase != null) {
            restrictions.clear();
            restrictions.add(Restrictions.and(Restrictions.eq("case.id", processCase.getId()),
                    Restrictions.eq("active", Boolean.TRUE)));
            List<TaskModel> currentActiveTasks = taskStore.search(restrictions, null);
            TaskModel oldActiveTaskModel;
            if (currentActiveTasks.isEmpty()) {
                oldActiveTaskModel = null;
            } else {
                oldActiveTaskModel = currentActiveTasks.get(0);
                for (TaskModel activeTask : currentActiveTasks) {
                    activeTask.setActive(Boolean.FALSE);
                }
                taskStore.saveOrUpdateAll(currentActiveTasks);
            }

            StatusModel status = activityAction.getStatus();

            ActivityModel toActivity = activityAction.getActivityTo();

            boolean isNotFinalStep = !status.getName().equals(StatusModel.STATUS_FINISHED)
                    && toActivity.getActivityOrder() != ActivityOrder.END;

            String taskDescription = StringUtils.isBlank(toActivity.getDescription())
                    ? processCase.getDescription()
                    : toActivity.getDescription();
            Date updateDate = new Date(System.currentTimeMillis());
            TaskModel nextTaskModel = new TaskModel();
            nextTaskModel.setDescription(taskDescription);
            nextTaskModel.setActivity(toActivity);
            nextTaskModel.setCase(processCase);
            nextTaskModel.setUpdateDate(updateDate);
            nextTaskModel.setAssignee(assignee);
            nextTaskModel.setActive(isNotFinalStep);
            taskStore.saveOrUpdate(nextTaskModel);
            processCase.setStatus(status);
            processCase.setActive(isNotFinalStep);
            saveOrUpdate(processCase);

            caseObjectModel.setTask(nextTaskModel);
            caseObjectModel.setStatus(status);
            caseObjectModel.setUpdateDate(updateDate);
            caseObjectModel.setUpdatedBy(currentUser);
            caseObjectStore.saveOrUpdate(caseObjectModel);

            if (oldActiveTaskModel != null) {
                CaseActionModel caseAction = new CaseActionModel();
                caseAction.setPerformedOn(updateDate);
                caseAction.setType(CaseActionType.PERFORM_ACTIVITY);
                caseAction.setCase(processCase);
                caseAction.setUser(currentUser);
                caseAction.setTaskModel(oldActiveTaskModel);
                if (StringUtils.isNotBlank(comment)) {
                    CaseNoteModel caseNote = new CaseNoteModel();
                    caseNote.setProcessCase(processCase);
                    caseNote.setText(comment);
                    caseNote.setUser(currentUser);
                    caseNoteStore.saveOrUpdate(caseNote);
                    caseAction.setCaseNote(caseNote);
                }
                caseActionStore.saveOrUpdate(caseAction);
            }
        }
    }
    return processCase;
}

From source file:com.zimbra.cs.service.FileUploadServlet.java

@SuppressWarnings("unchecked")
List<Upload> handleMultipartUpload(HttpServletRequest req, HttpServletResponse resp, String fmt, Account acct,
        boolean limitByFileUploadMaxSize, AuthToken at, boolean csrfCheckComplete)
        throws IOException, ServiceException {
    List<FileItem> items = null;
    String reqId = null;//from  w w w.j  ava 2s. co  m

    ServletFileUpload upload = getUploader2(limitByFileUploadMaxSize);
    try {
        items = upload.parseRequest(req);

        if (!csrfCheckComplete && !CsrfUtil.checkCsrfInMultipartFileUpload(items, at)) {
            drainRequestStream(req);
            mLog.info("CSRF token validation failed for account: %s, Auth token is CSRF enabled",
                    acct.getName());
            sendResponse(resp, HttpServletResponse.SC_UNAUTHORIZED, fmt, null, null, items);
            return Collections.emptyList();
        }
    } catch (FileUploadBase.SizeLimitExceededException e) {
        // at least one file was over max allowed size
        mLog.info("Exceeded maximum upload size of " + upload.getSizeMax() + " bytes: " + e);
        drainRequestStream(req);
        sendResponse(resp, HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE, fmt, reqId, null, items);
        return Collections.emptyList();
    } catch (FileUploadBase.InvalidContentTypeException e) {
        // at least one file was of a type not allowed
        mLog.info("File upload failed", e);
        drainRequestStream(req);
        sendResponse(resp, HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, fmt, reqId, null, items);
        return Collections.emptyList();
    } catch (FileUploadException e) {
        // parse of request failed for some other reason
        mLog.info("File upload failed", e);
        drainRequestStream(req);
        sendResponse(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, fmt, reqId, null, items);
        return Collections.emptyList();
    }

    String charset = "utf-8";
    LinkedList<String> names = new LinkedList<String>();
    HashMap<FileItem, String> filenames = new HashMap<FileItem, String>();
    if (items != null) {
        for (Iterator<FileItem> it = items.iterator(); it.hasNext();) {
            FileItem fi = it.next();
            if (fi == null)
                continue;

            if (fi.isFormField()) {
                if (fi.getFieldName().equals("requestId")) {
                    // correlate this file upload session's request and response
                    reqId = fi.getString();
                } else if (fi.getFieldName().equals("_charset_") && !fi.getString().equals("")) {
                    // get the form value charset, if specified
                    charset = fi.getString();
                } else if (fi.getFieldName().startsWith("filename")) {
                    // allow a client to explicitly provide filenames for the uploads
                    names.clear();
                    String value = fi.getString(charset);
                    if (!Strings.isNullOrEmpty(value)) {
                        for (String name : value.split("\n")) {
                            names.add(name.trim());
                        }
                    }
                }
                // strip form fields out of the list of uploads
                it.remove();
            } else {
                if (fi.getName() == null || fi.getName().trim().equals("")) {
                    it.remove();
                } else {
                    filenames.put(fi, names.isEmpty() ? null : names.remove());
                }
            }
        }
    }

    // restrict requestId value for safety due to later use in javascript
    if (reqId != null && reqId.length() != 0) {
        if (!ALLOWED_REQUESTID_CHARS.matcher(reqId).matches()) {
            mLog.info("Rejecting upload with invalid chars in reqId: %s", reqId);
            sendResponse(resp, HttpServletResponse.SC_BAD_REQUEST, fmt, null, null, items);
            return Collections.emptyList();
        }
    }

    // empty upload is not a "success"
    if (items == null || items.isEmpty()) {
        mLog.info("No data in upload for reqId: %s", reqId);
        sendResponse(resp, HttpServletResponse.SC_NO_CONTENT, fmt, reqId, null, items);
        return Collections.emptyList();
    }

    // cache the uploaded files in the hash and construct the list of upload IDs
    List<Upload> uploads = new ArrayList<Upload>(items.size());
    for (FileItem fi : items) {
        String name = filenames.get(fi);
        if (name == null || name.trim().equals(""))
            name = fi.getName();
        Upload up = new Upload(acct.getId(), fi, name);

        mLog.info("Received multipart: %s", up);
        synchronized (mPending) {
            mPending.put(up.uuid, up);
        }
        uploads.add(up);
    }

    sendResponse(resp, HttpServletResponse.SC_OK, fmt, reqId, uploads, items);
    return uploads;
}

From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.BusStopMapFragment.java

/**
 * {@inheritDoc}/*  w w w. j  a  va  2 s .co m*/
 */
@Override
public void onServicesChosen(final String[] chosenServices) {
    this.chosenServices = chosenServices;

    // If the user has chosen services in the services filter, force a
    // refresh of the marker icons.
    refreshBusStops(null);

    final LinkedList<String> tempList = new LinkedList<String>();
    boolean found;

    // Loop through the existing route lines. If a service doesn't exist in
    // the chosen services list, add it to the to-be-removed list.
    for (String key : routeLines.keySet()) {
        found = false;

        for (String fs : chosenServices) {
            if (key.equals(fs)) {
                found = true;
                break;
            }
        }

        if (!found) {
            tempList.add(key);
        }
    }

    LinkedList<Polyline> polyLines;
    // Loop through the to-be-removed list and remove the Polylines and the
    // entry from the routeLines HashMap.
    for (String toRemove : tempList) {
        polyLines = routeLines.get(toRemove);
        routeLines.remove(toRemove);

        for (Polyline pl : polyLines) {
            pl.remove();
        }
    }

    // The tempList is going to be reused, so clear it out.
    tempList.clear();

    // Loop through the filteredServices array. If the element does not
    // appear in the existing route lines, then add it to the to-be-added
    // list.
    for (String fs : chosenServices) {
        if (!routeLines.containsKey(fs)) {
            tempList.add(fs);
        }
    }

    final int size = tempList.size();
    // Execute the load if there are routes to be loaded.
    if (size > 0) {
        final String[] servicesToLoad = new String[size];
        tempList.toArray(servicesToLoad);

        final Bundle b = new Bundle();
        b.putStringArray(LOADER_ARG_FILTERED_SERVICES, servicesToLoad);
        getLoaderManager().restartLoader(LOADER_ID_ROUTE_LINES, b, this);
    }
}

From source file:com.ws.WS_TCS201.java

@Path("/GetDETAIL/{com}/{account}")
@JSONP(queryParam = "callback")
@GET/*  www.j  a v a  2s.  c om*/
@Produces({ "application/x-javascript" })
public String GetDETAIL(@QueryParam("callback") String callback, @PathParam("com") String com,
        @PathParam("account") String account) {

    JSONObject obj1 = new JSONObject();
    LinkedList l1 = new LinkedList();

    PreparedStatement prepStmt = null;

    try {
        //

        String cSQL = " SELECT tceemp, tceapd, tceall, tcetkb, tcetkt FROM TCSTCE "
                + " WHERE tcecom= ? AND tceemp= ? " + " ORDER BY tceapd DESC";
        prepStmt = connection.prepareStatement(cSQL);
        prepStmt.setString(1, com);
        prepStmt.setString(2, account);
        ResultSet result = prepStmt.executeQuery();

        if (result.next()) {
            LinkedHashMap m1 = new LinkedHashMap();

            Object obj = result.getObject(2);

            //?
            m1.put("arrive", obj.toString().substring(0, 4) + "/" + obj.toString().substring(4, 6) + "/"
                    + obj.toString().substring(6, 8));

            //
            if (Integer.parseInt(obj.toString()) < 20100913) {
                m1.put("start", "01/01");
            } else {
                m1.put("start", obj.toString().substring(4, 6) + "/" + obj.toString().substring(6, 8));
            }

            //
            obj = result.getObject(3);
            m1.put("allday", obj.toString());

            l1.add(m1);
        }
        obj1.put("base", l1);

        //
        result.close();
        l1.clear();

        cSQL = " SELECT tch.tchyer,CONCAT(tch.tchtcd,\" - \",tcc.tcctxt) AS tcdnam,tch.tchdst,tch.tchded,tch.tchday,tch.tchlst,tch.tchtxt,tch.tchtcd,tch.tchtck, "
                + "        IFNULL(tchgrp.maxtck,\"\") AS maxtck, IFNULL(tchgrp.maxdst,0) AS maxdst "
                + " FROM TCSTCH AS tch "
                + " LEFT JOIN (SELECT DISTINCT tcecom,tceemp,tcenam FROM TCSTCE) AS tce "
                + "        ON tcecom=tchcom AND tce.tceemp=tch.tchemp "
                + " LEFT JOIN (SELECT tcctcd, tcctxt FROM TCSTCC ) AS tcc "
                + "        ON tcc.tcctcd=tch.tchtcd "
                + " LEFT JOIN ( SELECT tchcom,tchemp,tchyer,max(tchtck) AS maxtck,max(tchdst) AS maxdst FROM TCSTCH "
                + "             WHERE tchtcd not in (\"B\",\"T\",\"M\",\"F\",\"W\") "
                + "             GROUP BY tchcom,tchemp,tchyer ) AS tchgrp "
                + "        ON tch.tchcom = tchgrp.tchcom AND tch.tchemp = tchgrp.tchemp "
                + "       AND tch.tchyer = tchgrp.tchyer " + " WHERE tch.tchcom= ? AND tch.tchemp= ? "
                + "   AND tcc.tcctcd NOT IN (\"A\",\"L\",\"R\",\"J\",\"N\") "
                + "   AND tch.tchmrk=\" \" AND tch.tchyer >= 2014 " + " ORDER BY tch.tchemp,tch.tchdst DESC ";
        //"       tchmrk=\" \" AND tchyer >= CONV( SUBSTR(NOW( ),1,4),10,10) -1 " +
        prepStmt = connection.prepareStatement(cSQL);
        prepStmt.setString(1, com);
        prepStmt.setString(2, account);
        result = prepStmt.executeQuery();
        ResultSetMetaData rsmd = result.getMetaData();
        int numcols = rsmd.getColumnCount();

        while (result.next()) {
            LinkedHashMap m1 = new LinkedHashMap();
            for (int j = 1; j <= numcols; j++) {
                Object obj = result.getObject(j);
                m1.put(rsmd.getColumnName(j).toString(), obj.toString());
            }
            Object obj = result.getObject("tchtcd");
            String chk1 = obj.toString();
            obj = result.getObject("tchtck");
            String chk2 = obj.toString();
            obj = result.getObject("tchdst");
            String chk3 = obj.toString();
            obj = result.getObject("maxdst");
            String chk4 = obj.toString();
            if (((chk1.equals("M") || chk1.equals("F") || chk1.equals("W") || chk1.equals("B")
                    || chk1.equals("T")) && chk2.equals("-"))
                    || (!chk1.equals("M") && !chk1.equals("F") && !chk1.equals("W") && !chk1.equals("B")
                            && !chk1.equals("T") && chk3.equals(chk4))) {
                m1.put("edit", "Y");
            } else {
                m1.put("edit", "N");
            }
            l1.add(m1);
        }
        obj1.put("detail", l1);
    } catch (SQLException e) {
        prepStmt = null;
        e.printStackTrace();
    } catch (Exception e) {
        prepStmt = null;
        e.printStackTrace();
    }
    return obj1.toString();
}

From source file:org.alfresco.repo.domain.audit.AuditDAOTest.java

public synchronized void testAuditQueryCombos() throws Exception {
    // Some entries
    doAuditEntryImpl(10);//from  w  ww . j  a  v  a  2  s.co  m

    final MutableInt count = new MutableInt(0);
    final LinkedList<Long> timestamps = new LinkedList<Long>();
    final List<Long> entryIds = new LinkedList<>();
    // Find everything
    final AuditQueryCallback callback = new AuditQueryCallback() {
        public boolean valuesRequired() {
            return false;
        }

        public boolean handleAuditEntry(Long entryId, String applicationName, String user, long time,
                Map<String, Serializable> values) {
            count.setValue(count.intValue() + 1);
            timestamps.add(time);
            entryIds.add(entryId);
            return true;
        }

        public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error) {
            throw new AlfrescoRuntimeException(errorMsg, error);
        }
    };

    final AuditQueryParameters params = new AuditQueryParameters();
    params.addSearchKey("/a/b/c", null);

    //. get them all
    RetryingTransactionCallback<Void> findCallback = new RetryingTransactionCallback<Void>() {
        public Void execute() throws Throwable {
            auditDAO.findAuditEntries(callback, params, 10);
            return null;
        }
    };
    count.setValue(0);
    timestamps.clear();
    txnHelper.doInTransaction(findCallback);
    assertEquals(10, count.intValue());

    // copy what we found so that we can compare subsequent audit queries
    List<Long> allEntryIds = new ArrayList<>(entryIds);
    List<Long> allTimestamps = new ArrayList<>(timestamps);

    // test fromId and maxResults
    entryIds.clear();
    timestamps.clear();
    params.setFromId(allEntryIds.get(2));
    findCallback = new RetryingTransactionCallback<Void>() {
        public Void execute() throws Throwable {
            auditDAO.findAuditEntries(callback, params, 2);
            return null;
        }
    };
    txnHelper.doInTransaction(findCallback);
    assertTrue(allEntryIds.subList(2, 2 + 2).equals(entryIds));

    // test toId and maxResults
    entryIds.clear();
    timestamps.clear();
    params.setFromId(null);
    params.setFromTime(null);
    params.setToTime(null);
    params.setToId(allEntryIds.get(2));
    findCallback = new RetryingTransactionCallback<Void>() {
        public Void execute() throws Throwable {
            auditDAO.findAuditEntries(callback, params, 2);
            return null;
        }
    };
    txnHelper.doInTransaction(findCallback);
    assertTrue(allEntryIds.subList(0, 2).equals(entryIds));

    // test fromId and toId and maxResults
    entryIds.clear();
    timestamps.clear();
    params.setFromId(allEntryIds.get(2));
    params.setToId(allEntryIds.get(5));
    params.setFromTime(null);
    params.setToTime(null);
    findCallback = new RetryingTransactionCallback<Void>() {
        public Void execute() throws Throwable {
            auditDAO.findAuditEntries(callback, params, 1);
            return null;
        }
    };
    txnHelper.doInTransaction(findCallback);
    assertTrue(allEntryIds.subList(2, 3).equals(entryIds));

    // test fromTime and maxResults
    entryIds.clear();
    timestamps.clear();
    params.setFromTime(allTimestamps.get(2));
    params.setFromId(null);
    params.setToTime(null);
    params.setToId(null);
    findCallback = new RetryingTransactionCallback<Void>() {
        public Void execute() throws Throwable {
            auditDAO.findAuditEntries(callback, params, 2);
            return null;
        }
    };
    txnHelper.doInTransaction(findCallback);
    assertTrue(allTimestamps.subList(2, 4).equals(timestamps));

    // test toTime and maxResults
    entryIds.clear();
    timestamps.clear();
    params.setFromTime(null);
    params.setFromId(null);
    params.setToTime(allTimestamps.get(4));
    params.setToId(null);
    findCallback = new RetryingTransactionCallback<Void>() {
        public Void execute() throws Throwable {
            auditDAO.findAuditEntries(callback, params, 2);
            return null;
        }
    };
    txnHelper.doInTransaction(findCallback);
    assertTrue(allTimestamps.subList(0, 2).equals(timestamps));

    // test fromTime and toTime and maxResults
    entryIds.clear();
    timestamps.clear();
    params.setFromTime(allTimestamps.get(2));
    params.setFromId(null);
    params.setToTime(allTimestamps.get(5));
    params.setToId(null);
    findCallback = new RetryingTransactionCallback<Void>() {
        public Void execute() throws Throwable {
            auditDAO.findAuditEntries(callback, params, 2);
            return null;
        }
    };
    txnHelper.doInTransaction(findCallback);
    assertTrue(allTimestamps.subList(2, 4).equals(timestamps));
}

From source file:com.runwaysdk.dataaccess.database.general.SQLServer.java

public void initialSetup(String rootUser, String rootPass, String rootDb) {
    // Set up the root data source
    JtdsDataSource rootSource = new JtdsDataSource();
    rootSource.setServerName(DatabaseProperties.getServerName());
    rootSource.setPortNumber(DatabaseProperties.getPort());
    rootSource.setDatabaseName(rootDb);/*from  w  w  w.j a v  a2s  .c om*/
    rootSource.setUser(rootUser);
    rootSource.setPassword(rootPass);
    this.rootDataSource = rootSource;

    LinkedList<String> statements = new LinkedList<String>();
    String dbName = DatabaseProperties.getDatabaseName();

    this.dropUser();

    this.dropDb();

    this.createDb(rootDb);

    this.createUser();

    statements.clear();
    statements.add("USE " + dbName);
    statements.add("EXEC sp_dbcmptlevel " + dbName + ", 80");
    executeAsRoot(statements, true);
}

From source file:dk.dma.ais.decode.DecodeTest.java

/**
 * Decode all messages in a file Tries to handle proprietary messages
 * //from w  ww . j a va2 s. c o m
 * Demonstrates and tests the process of decoding lines into Vdm messages, and the decoding into AIS messages
 * 
 * @throws IOException
 */
@Test
public void readLoopTest() throws IOException {
    // Make a list of proprietary handlers

    // Open file
    URL url = ClassLoader.getSystemResource("stream_example.txt");
    Assert.assertNotNull(url);
    try (BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()))) {
        Assert.assertNotNull(in);
        String line;

        // Prepare message classes
        AisMessage message;
        Vdm vdm = new Vdm();
        LinkedList<IProprietaryTag> tags = new LinkedList<>();

        while ((line = in.readLine()) != null) {

            // Ignore everything else than sentences
            if (!line.startsWith("$") && !line.startsWith("!")) {
                continue;
            }

            // Check if proprietary line
            if (ProprietaryFactory.isProprietaryTag(line)) {
                // Try to parse with one the registered factories in
                // META-INF/services/dk.dma.ais.proprietary.ProprietaryFactory
                IProprietaryTag tag = ProprietaryFactory.parseTag(new SentenceLine(line));
                if (tag != null) {
                    tags.add(tag);
                }
                continue;
            }

            // Handle VDM/VDO line
            try {
                int result = vdm.parse(new SentenceLine(line));
                // LOG.info("result = " + result);
                if (result == 0) {
                    message = AisMessage.getInstance(vdm);
                    Assert.assertNotNull(message);
                    if (tags.size() > 0) {
                        message.setTags(tags);
                    }

                    // Message ready for handling

                } else if (result == 1) {
                    // Wait for more data
                    continue;
                } else {
                    LOG.error("Failed to parse line: " + line + " result = " + result);
                    Assert.assertTrue(false);
                }

            } catch (Exception e) {
                LOG.info("VDM failed: " + e.getMessage() + " line: " + line + " tag: "
                        + (tags.size() > 0 ? tags.peekLast() : "null"));
                Assert.assertTrue(false);
            }

            // Create new VDM
            vdm = new Vdm();
            tags.clear();
        }
    }
}

From source file:org.commoncrawl.service.crawler.CrawlQueue.java

private void purgeIdleHosts() {

    LinkedList<CrawlQueueHost> purgeCandidates = new LinkedList<CrawlQueueHost>();

    long currentTime = System.currentTimeMillis();

    // walk active hosts ... 
    for (CrawlQueueHost host : _activeHosts.values()) {

        if (currentTime - host.getLastModifiedTime() >= getEngine().getServer().getHostIdleFlushThreshold()) {
            if (host.noActiveLists()) {
                // LOG.info("BUG: Host:" + host.getIPAddressAsString() + " shows NOT_IDLE but is really IDLE");
                purgeCandidates.add(host);
            }//from w ww. jav  a 2 s  .  co m
        }
    }

    // move inactive but not idled hosts into idle host bucket ... 
    for (CrawlQueueHost host : purgeCandidates) {
        idleHost(host);
    }

    // walk idle hosts ... 
    for (CrawlQueueHost host : _idleHosts.values()) {
        if (host.noActiveLists()) {
            if (currentTime - host.getLastModifiedTime() >= getEngine().getServer()
                    .getHostIdleFlushThreshold()) {
                purgeCandidates.add(host);
            }
        }
    }

    if (purgeCandidates.size() != 0) {
        if (Environment.detailLogEnabled())
            LOG.info("Purging " + purgeCandidates.size() + " IDLE Hosts");
    }
    for (CrawlQueueHost host : purgeCandidates) {
        if (Environment.detailLogEnabled())
            LOG.info("Purging IDLE Host:" + host.getIPAddressAsString());

        // clear the host ... 
        host.purgeReferences();
        // and remove it from the map ... 
        _idleHosts.remove(host.getIPAddress());
        // increment stats ... 
        ++_purgedHostCount;
    }

    purgeCandidates.clear();

}