List of usage examples for java.util LinkedList clear
public void clear()
From source file:net.cellcloud.talk.TalkService.java
/** * ??/* w w w . j ava2 s . c om*/ * @param timeout */ protected void checkSessionHeartbeat() { if (null == this.tagContexts) { return; } LinkedList<Session> closeList = new LinkedList<Session>(); for (Map.Entry<String, TalkSessionContext> entry : this.tagContexts.entrySet()) { TalkSessionContext ctx = entry.getValue(); List<Session> sl = ctx.getSessions(); for (Session s : sl) { long time = ctx.getSessionHeartbeat(s); if (time == 0) { continue; } if (this.daemon.getTickTime() - time > this.sessionTimeout) { // Session closeList.add(s); Logger.d(this.getClass(), "Session timeout in heartbeat: " + s.getAddress().getHostString()); } } } for (Session session : closeList) { this.closeSession(session); } closeList.clear(); closeList = null; }
From source file:org.openspaces.admin.internal.admin.DefaultAdmin.java
public void flushEvents() { assertStateChangesPermitted();//ww w.j av a 2 s .c om synchronized (DefaultAdmin.this) { if (closeStarted.get()) { //clear all pending events in queue that may have arrived just before closing of the admin. for (LinkedList<Runnable> l : eventsQueue) { l.clear(); } return; } for (int i = 0; i < eventsExecutorServices.length; i++) { for (Runnable notifier : eventsQueue[i]) { eventsExecutorServices[i].submit(notifier); } eventsQueue[i].clear(); } } }
From source file:de.zib.scalaris.examples.wikipedia.bliki.WikiServlet.java
@Override public void storeUserReq(WikiPageBeanBase page, long servertime) { long timestamp = page.getStartTime(); String serviceUser = page.getServiceUser(); if (!eventHandlers.isEmpty()) { Connection connection = getConnection(null); for (WikiEventHandler handler : eventHandlers) { try { handler.onPageView(page, connection); } catch (Exception e) { e.printStackTrace();/*w w w . j av a2 s . c o m*/ } } releaseConnection(null, connection); } if (userReqLogs != null && userReqLogs.length > 0) { int timestamp_s = (int) (timestamp / 1000); // build log entry: Map<String, Object> entry = new HashMap<String, Object>(); entry.put("timestamp", timestamp_s); entry.put("serviceuser", serviceUser == null ? "" : serviceUser); entry.put("servertime", servertime); // get the correct bucket: LinkedList<Map<String, Object>> curReqLogList; synchronized (userReqLogs) { curReqLogList = userReqLogs[curReqLog]; int diffInMin = (timestamp_s - curReqLogStartTime) / 60; if (diffInMin > 0) { if (diffInMin > userReqLogs.length) { for (LinkedList<Map<String, Object>> log : userReqLogs) { log.clear(); } curReqLog = 0; curReqLogList = userReqLogs[curReqLog]; } else { while ((curReqLogStartTime + 60) < timestamp_s) { curReqLogList = userReqLogs[curReqLog]; curReqLogList.clear(); curReqLog = (++curReqLog) % userReqLogs.length; } } curReqLogStartTime += 60 * diffInMin; } } curReqLogList.add(entry); } }
From source file:org.wings.SForm.java
/** * This method fires the low level events for all "armed" components of * this thread (http session) in an ordered manner: * <ul><li>forms/*from ww w. ja v a 2 s . c o m*/ * <li>buttons / clickables * <li>"regular" components</ul> * This order derives out of the assumption, that a user first modifies * regular components before he presses the button submitting his changes. * Otherwise button actions would get fired before the edit components * fired their events. */ public static void fireEvents() { Set armedComponents = (Set) threadArmedComponents.get(); // use a copy to avoid concurrent modification exceptions if a // LowLevelEventListener adds itself to the armedComponents again Set armedComponentsCopy = new HashSet(armedComponents); try { // handle form special, form event should be fired last // hopefully there is only one form ;-) Iterator iterator = armedComponentsCopy.iterator(); LinkedList formEvents = null; LinkedList buttonEvents = null; while (iterator.hasNext()) { LowLevelEventListener component = (LowLevelEventListener) iterator.next(); /* fire form events at last * there could be more than one form event (e.g. mozilla posts a * hidden element even if it is in a form outside the posted * form (if the form is nested). Forms should not be nested in HTML. */ if (component instanceof SForm) { if (formEvents == null) { formEvents = new LinkedList(); } // end of if () formEvents.add(component); iterator.remove(); } else if (component instanceof SAbstractIconTextCompound) { if (buttonEvents == null) { buttonEvents = new LinkedList(); } buttonEvents.add(component); iterator.remove(); } else { component.fireIntermediateEvents(); } } /* * no buttons in forms pressed ? Then consider the default-Button. */ // Wrong - this fires default button for page scrollers! /*if (buttonEvents == null && formEvents != null) { Iterator fit = formEvents.iterator(); while (fit.hasNext()) { SForm form = (SForm) fit.next(); SButton defaultButton = form.getDefaultButton(); if (defaultButton != null) { if (buttonEvents == null) { buttonEvents = new LinkedList(); } buttonEvents.add(defaultButton); } } } */ if (buttonEvents != null) { iterator = buttonEvents.iterator(); while (iterator.hasNext()) { ((SAbstractIconTextCompound) iterator.next()).fireIntermediateEvents(); } } if (formEvents != null) { iterator = formEvents.iterator(); while (iterator.hasNext()) { ((SForm) iterator.next()).fireIntermediateEvents(); } } iterator = armedComponentsCopy.iterator(); while (iterator.hasNext()) { LowLevelEventListener component = (LowLevelEventListener) iterator.next(); // fire form events at last component.fireFinalEvents(); } if (buttonEvents != null) { iterator = buttonEvents.iterator(); while (iterator.hasNext()) { ((SAbstractIconTextCompound) iterator.next()).fireFinalEvents(); } buttonEvents.clear(); } if (formEvents != null) { iterator = formEvents.iterator(); while (iterator.hasNext()) { ((SForm) iterator.next()).fireFinalEvents(); } formEvents.clear(); } } finally { armedComponents.clear(); } }
From source file:org.openspaces.admin.internal.admin.DefaultAdmin.java
public void flushScheduleMonitorCorrelatedEvents() { assertStateChangesPermitted();//from ww w .java2 s.c o m synchronized (DefaultAdmin.this) { if (closeStarted.get()) { //clear all pending events in queue that may have arrived just before closing of the admin. for (LinkedList<Runnable> l : scheduleMonitorCorrelatedEventsQueue) { l.clear(); } return; } for (int i = 0; i < eventsExecutorServices.length; i++) { for (Runnable notifier : scheduleMonitorCorrelatedEventsQueue[i]) { eventsExecutorServices[i].submit(notifier); } scheduleMonitorCorrelatedEventsQueue[i].clear(); } } }
From source file:com.ikanow.infinit.e.harvest.extraction.document.file.FileHarvester.java
private void processFiles(SourcePojo source) throws Exception { // Can override system settings if less: if ((null != source.getThrottleDocs()) && (source.getThrottleDocs() < maxDocsPerCycle)) { maxDocsPerCycle = source.getThrottleDocs(); }/*from w w w . java2 s. c om*/ sourceUrlsGettingUpdated = new HashSet<String>(); LinkedList<String> duplicateSources = new LinkedList<String>(); try { // Compile regexes if they are present if ((null != source.getFileConfig()) && (null != source.getFileConfig().pathInclude)) { includeRegex = Pattern.compile(source.getFileConfig().pathInclude, Pattern.CASE_INSENSITIVE); } if ((null != source.getFileConfig()) && (null != source.getFileConfig().pathExclude)) { excludeRegex = Pattern.compile(source.getFileConfig().pathExclude, Pattern.CASE_INSENSITIVE); } if ((null != source.getFileConfig()) && (null != source.getFileConfig().maxDepth)) { this.maxDepth = source.getFileConfig().maxDepth; } // Process the fileshare getFiles(source); } catch (Exception e) { // If an exception here this is catastrophic, throw it upwards: errors++; throw e; } try { //Dedup code, ironically enough partly duplicated in parse(), probably unnecessarily DuplicateManager qr = _context.getDuplicateManager(); for (DocumentPojo doc : files) { try { duplicateSources.clear(); if (null != doc.getSourceUrl()) { boolean add = true; // However still need to check for duplicates so can update entities correctly (+maintain _ids, etc) // We only do this if the source URL changes (unless URL is taken from the object in which case all bets are off) boolean sourceUrlUpdated = sourceUrlsGettingUpdated.contains(doc.getSourceUrl()); if (!doc.getHasDefaultUrl() || sourceUrlUpdated) { // src URL for a given URL // (only if the the sourceUrl is not new...) if (qr.isDuplicate_Url(doc.getUrl(), source, duplicateSources)) { doc.setUpdateId(qr.getLastDuplicateId()); // (set _id to doc we're going to replace) if (!sourceUrlUpdated && !_deleteExistingFilesBySourceKey) { // Here update instead so we delete the old doc and add the new one add = false; docsToUpdate.add(doc); } //TESTED else { // (else *still* don't add this to updates because we've added the source URL or source key to the delete list) // (hence approximate create with the updateId...) if (null != doc.getUpdateId()) { doc.setCreated(new Date(doc.getUpdateId().getTime())); } //TESTED } //TESTED } //(note we don't get about duplicate sources in this case - just too complex+rare a case) } //TESTED (src url changing, different src url, non-default URL) // For composite files we (almost always) delete everything that already exists (via docsToRemove) and then add new docs if (add) { docsToAdd.add(doc); } //TESTED } else if (qr.isDuplicate_Url(doc.getUrl(), source, duplicateSources)) { // Other files, if the file already exists then update it (essentially, delete/add) doc.setUpdateId(qr.getLastDuplicateId()); // (set _id to doc we're going to replace) docsToUpdate.add(doc); } else { // if duplicateSources is non-empty then this URL is a duplicate of one from a different source if (!duplicateSources.isEmpty()) { doc.setDuplicateFrom(duplicateSources.getFirst()); } docsToAdd.add(doc); } } catch (Exception e) { errors++; _context.getHarvestStatus() .logMessage(HarvestExceptionUtils.createExceptionMessage(e).toString(), true); } } } catch (Exception e) { // If an exception here this is catastrophic, throw it upwards: errors++; throw e; } }
From source file:com.projity.pm.task.Task.java
void cleanUp(Object eventSource, boolean deep, boolean undo, boolean cleanDependencies) { //if (!cleanDependencies) return; //TODO was for undo of paste of linked tasks, but doesn't work markAllDependentTasksAsNeedingRecalculation(false); // remove sentinel dependencies if any project.removeStartSentinelDependency(this); project.removeEndSentinelDependency(this); // remove all links to or from LinkedList toRemove = new LinkedList(); //fix DependencyService.getInstance().remove(getPredecessorList(), toRemove); for (Iterator j = toRemove.iterator(); j.hasNext();) { DependencyService.getInstance().remove((Dependency) j.next(), eventSource, undo); //fix }/* w ww. j av a2s . c o m*/ toRemove.clear(); DependencyService.getInstance().remove(getSuccessorList(), toRemove); for (Iterator j = toRemove.iterator(); j.hasNext();) { DependencyService.getInstance().remove((Dependency) j.next(), eventSource, undo); //fix } }
From source file:com.yahoo.egads.models.adm.AdaptiveKernelDensityChangePointDetector.java
protected float[] computeKLScore(float residual, int preWindowSize, int postWindowSize, float confidence) { float dKL = 0; float levelThreshold = 0; int len = buffer.size(); // Filling the pre-window if (len < preWindowSize) { buffer.addLast(residual);// w w w.j a va 2 s .c om postKernelSum.addLast(0F); if (len == (preWindowSize - 1)) { int n = preWindowSize; sumBuffer = ListUtils.sumQ(buffer); sqrSumBuffer = ListUtils.sum2Q(buffer); float temp = (float) Math.max(1e-5, Math.sqrt(2 * (n * sqrSumBuffer - sumBuffer * sumBuffer) / (n * (n - 1)))); ListUtils.repQ(sdBuffer, temp, n); for (float x : buffer) { preKernelSum.addLast(ListUtils.kernelSum(x, buffer, sdBuffer)); } } } else if (len < (preWindowSize + postWindowSize)) { // Filling the post-window sumBuffer = sumBuffer + residual; sqrSumBuffer = sqrSumBuffer + residual * residual; int n = len + 1; float temp = (float) Math.max(1e-5, Math.sqrt(2 * (n * sqrSumBuffer - sumBuffer * sumBuffer) / (n * (n - 1)))); sdBuffer.addLast(temp); LinkedList<Float> tempQ1 = new LinkedList<Float>(); tempQ1.add(residual); LinkedList<Float> tempQ2 = new LinkedList<Float>(); tempQ2.add(temp); ListUtils.addQ(postKernelSum, ListUtils.kernelQ(buffer, tempQ1, tempQ2)); buffer.addLast(residual); preKernelSum.addLast(ListUtils.kernelSubSum(residual, buffer, sdBuffer, 0, preWindowSize - 1)); postKernelSum .addLast(ListUtils.kernelSubSum(residual, buffer, sdBuffer, preWindowSize, buffer.size() - 1)); } else { // updating the pre-stats LinkedList<Float> preRemovedValues = ListUtils.kernelQ(buffer, buffer.subList(0, 1), sdBuffer.subList(0, 1)); ListUtils.subtractQ(preKernelSum, preRemovedValues); LinkedList<Float> midExchangedValues = ListUtils.kernelQ(buffer, buffer.subList(preWindowSize, preWindowSize + 1), sdBuffer.subList(preWindowSize, preWindowSize + 1)); ListUtils.addQ(preKernelSum, midExchangedValues); // Computing the new sd int n = len; sumBuffer += (residual - buffer.getFirst()); sqrSumBuffer += (residual * residual - Math.pow(buffer.getFirst(), 2)); float temp = (float) Math.max(1e-5, Math.sqrt(2 * (n * sqrSumBuffer - sumBuffer * sumBuffer) / (n * (n - 1)))); // updating the post-stats LinkedList<Float> tempQ1 = new LinkedList<Float>(); tempQ1.add(residual); LinkedList<Float> tempQ2 = new LinkedList<Float>(); tempQ2.add(temp); ListUtils.subtractQ(postKernelSum, midExchangedValues); LinkedList<Float> postAddedValues = ListUtils.kernelQ(buffer, tempQ1, tempQ2); ListUtils.addQ(postKernelSum, postAddedValues); // updating the window buffer.addLast(residual); buffer.removeFirst(); sdBuffer.addLast(temp); sdBuffer.removeFirst(); preKernelSum.addLast(ListUtils.kernelSubSum(residual, buffer, sdBuffer, 0, preWindowSize - 1)); postKernelSum.addLast(ListUtils.kernelSubSum(residual, buffer, sdBuffer, preWindowSize, preWindowSize + postWindowSize - 1)); preKernelSum.removeFirst(); postKernelSum.removeFirst(); float eps = 1e-10F; LinkedList<Float> preDensity = ListUtils .maxQ(preKernelSum.subList(preWindowSize, preWindowSize + postWindowSize), eps); LinkedList<Float> postDensity = ListUtils .maxQ(postKernelSum.subList(preWindowSize, preWindowSize + postWindowSize), eps); tempQ1.clear(); tempQ1.addAll(preKernelSum.subList(0, preWindowSize)); tempQ2.clear(); tempQ2.add(1.0F / preWindowSize); ListUtils.multiplyQ(tempQ1, tempQ2); float levelSet = ListUtils.quantile(tempQ1, 1 - confidence); levelThreshold = (float) (-Math.log(levelSet) - Math.log(2 * Math.PI) / 2 - ListUtils.sumLog(sdBuffer.subList(preWindowSize, preWindowSize + postWindowSize)) / postWindowSize); // computing the KL-divergence dKL = (float) ((ListUtils.sumLog(postDensity) - ListUtils.sumLog(preDensity) + Math.log(preWindowSize / postWindowSize)) / postWindowSize + Math.log(levelSet * Math.sqrt(2 * Math.PI)) + ListUtils.sumLog(sdBuffer.subList(preWindowSize, preWindowSize + postWindowSize)) / postWindowSize); } return new float[] { dKL, levelThreshold }; }
From source file:de._13ducks.cor.game.server.movement.SectorPathfinder.java
public static List<SimplePosition> optimizePath(List<Node> path, SimplePosition startPos, SimplePosition endPos, MovementMap moveMap) {/*from w w w . j ava 2s .c o m*/ // Besseres, iteratives Vorgehen FreePolygon startPolygon = moveMap.containingPoly(startPos.x(), startPos.y()); if (startPolygon == null) { System.out.println("ERROR! Target unreachable (no poly found)"); return null; } boolean improved = true; while (improved) { improved = false; FreePolygon currentPoly = startPolygon; // Weg durchgehen for (int i = 1; i < path.size() - 1; i++) { Node pre = path.get(i - 1); Node cur = path.get(i); Node nxt = path.get(i + 1); // Testweise Kante zwischen pre und nxt erstellen Edge edge = new Edge(pre, nxt); // Im Folgenden wird untersucht, ob der neue Weg "edge" passierbar ist. // Eventuell mssen fr Polygonwechsel neue Nodes eingefgt werden LinkedList<Node> extraNodes = new LinkedList<Node>(); // Damit wir beim Dreieckwechsel nicht wieder zurck gehen: Node lastNode = null; boolean routeAllowed = true; // Jetzt so lange weiter laufen, bis wir im Ziel-Polygon sind while (!nxt.getPolygons().contains(currentPoly)) { // Untersuchen, ob es eine Seite des currentPolygons gibt, die sich mit der alternativRoute schneidet List<Edge> edges = currentPoly.calcEdges(); Edge intersecting = null; for (Edge testedge : edges) { // Gibts da einen Schnitt? SimplePosition intersection = edge.intersectionWithEndsNotAllowed(testedge); if (intersection != null && !intersection.equals(lastNode)) { intersecting = testedge; break; } } // Kandidat fr den nchsten Polygon FreePolygon nextPoly = null; // Kante gefunden if (intersecting != null) { // Von dieser Kante die Enden suchen nextPoly = getOtherPoly(intersecting.getStart(), intersecting.getEnd(), currentPoly); } if (intersecting != null && nextPoly != null) { // Wir haben einen Schnittpunkt und eine Kante gefunden, sind jetzt also in einem neuen Polygon // Extra Node einfgen Node extraNode = intersecting.intersectionWithEndsNotAllowed(edge).toNode(); if (extraNode.equals(cur)) { // Abbruch, das ist eine Gerade, hier kann man nicht abkrzen! FreePolygon currentCand = commonSector(cur, nxt); if (currentCand != null) { currentPoly = currentCand; } routeAllowed = false; break; } extraNode.addPolygon(nextPoly); extraNode.addPolygon(currentPoly); extraNodes.add(extraNode); lastNode = extraNode; currentPoly = nextPoly; // Der nchste Schleifendurchlauf wird den nchsten Polygon untersuchen } else { // Es gab leider keinen betretbaren Polygon hier. // Das bedeutet, dass wir die Suche abbrechen knnen, der derzeit untersuchte Wegpunkt (cur) // Ist also unverzichtbar. // Es soll also der nchste Punkt untersucht werden, also die for einfach weiter laufen // Eventuell muss aber der currentPoly gendert werden. // CurrentPoly ndern, wenn in neuem Sektor: FreePolygon currentCand = commonSector(cur, nxt); if (currentCand != null) { currentPoly = currentCand; } routeAllowed = false; break; } } // Wenn der neue Weg gltig war, einbauen. Sonst weiter mit dem nchsten Knoten if (routeAllowed) { // Den ursprnglichen Knoten lschen und die neuen Einbauen path.remove(i); path.addAll(i, extraNodes); // Der Weg wurde gendert, die for muss neu starten improved = true; break; } // Wenn wir hier hinkommen, soll der nchste Knoten getestet werden. extraNodes.clear(); } } // Hier ist der Weg fertig optimiert // Start wieder lschen und zurckgeben path.remove(0); LinkedList<SimplePosition> retList = new LinkedList<SimplePosition>(); for (Node n : path) { retList.add(n); } return retList; }
From source file:de.innovationgate.wgpublisher.webtml.utils.TMLContext.java
public static void clearThreadMainContext() { LinkedList<TMLContext> contexts = _threadMainContexts.get(); if (contexts != null) { contexts.clear(); }/*from ww w . j ava2 s .co m*/ }