List of usage examples for java.util LinkedList remove
public E remove()
From source file:org.wso2.carbon.device.mgt.iot.arduino.service.impl.ArduinoControllerServiceImpl.java
@Override @Path("device/{deviceId}/controls") @GET/*from ww w . ja v a 2s .c om*/ public Response readControls(@PathParam("deviceId") String deviceId) { try { if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized( new DeviceIdentifier(deviceId, ArduinoConstants.DEVICE_TYPE), DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS)) { return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); } String result; LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId); String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); if (deviceControlList == null) { result = "No controls have been set for device " + deviceId + " of owner " + owner; if (log.isDebugEnabled()) { log.debug(result); } return Response.status(Response.Status.CONFLICT.getStatusCode()).entity(result).build(); } else { try { result = deviceControlList.remove(); if (log.isDebugEnabled()) { log.debug(result); } return Response.status(Response.Status.ACCEPTED.getStatusCode()).entity(result).build(); } catch (NoSuchElementException ex) { result = "There are no more controls for device " + deviceId + " of owner " + owner; if (log.isDebugEnabled()) { log.debug(result); } return Response.status(Response.Status.NO_CONTENT.getStatusCode()).entity(result).build(); } } } catch (DeviceAccessAuthorizationException e) { log.error(e.getErrorMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } }
From source file:org.rhq.core.pc.operation.OperationThreadPoolGateway.java
/** * This is called by the {@link OperationInvocation} when it finished to notify this gateway that if there are any * other pending operations for the resource, that the next one is allowed to be executed. * * @param operation the operation that has just completed *///from w w w . j ava2s. c om public void operationCompleted(OperationInvocation operation) { Integer operationResourceId = Integer.valueOf(operation.getResourceId()); synchronized (resourceQueues) { if (stopped) { return; } allOperations.remove(operation.getJobId()); LinkedList<OperationInvocation> queuedOps = resourceQueues.get(operationResourceId); if (queuedOps != null) { // if there are no more operations waiting to be invoked on the resource, clean up the linked list; // otherwise, pop the next operation from the list and submit it to the thread pool for execution if (queuedOps.isEmpty()) { resourceQueues.remove(operationResourceId); } else { OperationInvocation nextOperation = queuedOps.remove(); try { log.debug("Resource is no longer busy - the next operation in line will be invoked: " + nextOperation); threadPool.execute(nextOperation); } catch (Exception e) { log.error("Failed to submit next operation: " + nextOperation); } } } } return; }
From source file:library.memorymonitor.ProcfsBasedProcessTree.java
/** * Get the process-tree with latest state. If the root-process is not alive, * an empty tree will be returned.//from w w w . j a v a 2 s .co m * * @return the process-tree with latest state. */ public ProcfsBasedProcessTree getProcessTree() { if (!pid.equals(deadPid)) { // Get the list of processes List<String> processList = getProcessList(); Map<String, ProcessInfo> allProcessInfo = new HashMap<String, ProcessInfo>(); // cache the processTree to get the age for processes Map<String, ProcessInfo> oldProcs = new HashMap<String, ProcessInfo>(processTree); processTree.clear(); ProcessInfo me = null; for (String proc : processList) { // Get information for each process ProcessInfo pInfo = new ProcessInfo(proc); if (constructProcessInfo(pInfo, procfsDir) != null) { allProcessInfo.put(proc, pInfo); if (proc.equals(this.pid)) { me = pInfo; // cache 'me' processTree.put(proc, pInfo); } } } if (me == null) { return this; } // Add each process to its parent. for (Map.Entry<String, ProcessInfo> entry : allProcessInfo.entrySet()) { String pID = entry.getKey(); if (!pID.equals("1")) { ProcessInfo pInfo = entry.getValue(); ProcessInfo parentPInfo = allProcessInfo.get(pInfo.getPpid()); if (parentPInfo != null) { parentPInfo.addChild(pInfo); } } } // now start constructing the process-tree LinkedList<ProcessInfo> pInfoQueue = new LinkedList<ProcessInfo>(); pInfoQueue.addAll(me.getChildren()); while (!pInfoQueue.isEmpty()) { ProcessInfo pInfo = pInfoQueue.remove(); if (!processTree.containsKey(pInfo.getPid())) { processTree.put(pInfo.getPid(), pInfo); } pInfoQueue.addAll(pInfo.getChildren()); } // update age values and compute the number of jiffies since last update for (Map.Entry<String, ProcessInfo> procs : processTree.entrySet()) { ProcessInfo oldInfo = oldProcs.get(procs.getKey()); if (procs.getValue() != null) { procs.getValue().updateJiffy(oldInfo); if (oldInfo != null) { procs.getValue().updateAge(oldInfo); } } } if (LOG.isDebugEnabled()) { // Log.debug the ProcfsBasedProcessTree LOG.debug(this.toString()); } } return this; }
From source file:com.twitter.distributedlog.service.balancer.ClusterBalancer.java
void moveRemainingStreamsFromSource(Host source, List<Host> hosts, Optional<RateLimiter> rateLimiter) { LinkedList<String> streamsToMove = new LinkedList<String>(source.streams); Collections.shuffle(streamsToMove); if (logger.isDebugEnabled()) { logger.debug("Try to move remaining streams from {} : {}", source, streamsToMove); }// w ww .j ava 2 s . c om int hostIdx = hosts.size() - 1; while (!streamsToMove.isEmpty()) { if (rateLimiter.isPresent()) { rateLimiter.get().acquire(); } Host target = hosts.get(hostIdx); if (!target.address.equals(source.address)) { String stream = streamsToMove.remove(); // move the stream if (moveStream(stream, source, target)) { source.streams.remove(stream); target.streams.add(stream); } } --hostIdx; if (hostIdx < 0) { hostIdx = hosts.size() - 1; } } }
From source file:org.apache.hadoop.mapred.util.ProcfsBasedProcessTree.java
/** * Get the process-tree with latest state. If the root-process is not alive, * an empty tree will be returned.//from w ww.j av a 2 s .co m * * @return the process-tree with latest state. */ public ProcfsBasedProcessTree getProcessTree() { if (pid != -1) { // Get the list of processes List<Integer> processList = getProcessList(); Map<Integer, ProcessInfo> allProcessInfo = new HashMap<Integer, ProcessInfo>(); // cache the processTree to get the age for processes Map<Integer, ProcessInfo> oldProcs = new HashMap<Integer, ProcessInfo>(processTree); processTree.clear(); ProcessInfo me = null; for (Integer proc : processList) { // Get information for each process ProcessInfo pInfo = new ProcessInfo(proc); if (constructProcessInfo(pInfo, procfsDir) != null) { allProcessInfo.put(proc, pInfo); if (proc.equals(this.pid)) { me = pInfo; // cache 'me' processTree.put(proc, pInfo); } } } if (me == null) { return this; } // Add each process to its parent. for (Map.Entry<Integer, ProcessInfo> entry : allProcessInfo.entrySet()) { Integer pID = entry.getKey(); if (pID != 1) { ProcessInfo pInfo = entry.getValue(); ProcessInfo parentPInfo = allProcessInfo.get(pInfo.getPpid()); if (parentPInfo != null) { parentPInfo.addChild(pInfo); } } } // now start constructing the process-tree LinkedList<ProcessInfo> pInfoQueue = new LinkedList<ProcessInfo>(); pInfoQueue.addAll(me.getChildren()); while (!pInfoQueue.isEmpty()) { ProcessInfo pInfo = pInfoQueue.remove(); if (!processTree.containsKey(pInfo.getPid())) { processTree.put(pInfo.getPid(), pInfo); } pInfoQueue.addAll(pInfo.getChildren()); } // update age values and compute the number of jiffies since last update for (Map.Entry<Integer, ProcessInfo> procs : processTree.entrySet()) { ProcessInfo oldInfo = oldProcs.get(procs.getKey()); if (procs.getValue() != null) { procs.getValue().updateJiffy(oldInfo); if (oldInfo != null) { procs.getValue().updateAge(oldInfo); } } } if (LOG.isDebugEnabled()) { // Log.debug the ProcfsBasedProcessTree LOG.debug(this.toString()); } } return this; }
From source file:com.oltpbenchmark.benchmarks.seats.SEATSWorker.java
/** * Take an existing Reservation that we know is legit and randomly decide to * either queue it for a later update or delete transaction * @param r//w w w .jav a 2 s. co m */ protected void requeueReservation(Reservation r) { CacheType ctype = null; // Queue this motha trucka up for a deletin' if (rng.nextBoolean()) { ctype = CacheType.PENDING_DELETES; } else { ctype = CacheType.PENDING_UPDATES; } assert (ctype != null); LinkedList<Reservation> cache = CACHE_RESERVATIONS.get(ctype); assert (cache != null); cache.add(r); if (LOG.isDebugEnabled()) LOG.debug(String.format("Queued %s for %s [cache=%d]", r, ctype, cache.size())); while (cache.size() > ctype.limit) { cache.remove(); } }
From source file:com.datatorrent.stram.webapp.OperatorDiscoverer.java
/** * Enrich portClassHier with class/interface names that map to a list of parent classes/interfaces. * For any class encountered, find its parents too.<br/> * Also find the port types which have assignable schema classes. * * @param oper Operator to work on * @param portClassHierarchy In-Out param that contains a mapping of class/interface to its parents * @param portTypesWithSchemaClasses Json that will contain all the ports which have any schema classes. */// ww w . ja va 2 s . c om public void buildAdditionalPortInfo(JSONObject oper, JSONObject portClassHierarchy, JSONObject portTypesWithSchemaClasses) { try { JSONArray ports = oper.getJSONArray(OperatorDiscoverer.PORT_TYPE_INFO_KEY); for (int i = 0; i < ports.length(); i++) { JSONObject port = ports.getJSONObject(i); String portType = port.optString("type"); if (portType == null) { //skipping if port type is null continue; } if (typeGraph.size() == 0) { buildTypeGraph(); } try { //building port class hierarchy LinkedList<String> queue = Lists.newLinkedList(); queue.add(portType); while (!queue.isEmpty()) { String currentType = queue.remove(); if (portClassHierarchy.has(currentType)) { //already present in the json so we skip. continue; } List<String> immediateParents = typeGraph.getParents(currentType); if (immediateParents == null) { portClassHierarchy.put(currentType, Lists.<String>newArrayList()); continue; } portClassHierarchy.put(currentType, immediateParents); queue.addAll(immediateParents); } } catch (JSONException e) { LOG.warn("building port type hierarchy {}", portType, e); } //finding port types with schema classes if (portTypesWithSchemaClasses.has(portType)) { //already present in the json so skipping continue; } if (portType.equals("byte") || portType.equals("short") || portType.equals("char") || portType.equals("int") || portType.equals("long") || portType.equals("float") || portType.equals("double") || portType.equals("java.lang.String") || portType.equals("java.lang.Object")) { //ignoring primitives, strings and object types as this information is needed only for complex types. continue; } if (port.has("typeArgs")) { //ignoring any type with generics continue; } boolean hasSchemaClasses = false; List<String> instantiableDescendants = typeGraph.getInstantiableDescendants(portType); if (instantiableDescendants != null) { for (String descendant : instantiableDescendants) { try { if (typeGraph.isInstantiableBean(descendant)) { hasSchemaClasses = true; break; } } catch (JSONException ex) { LOG.warn("checking descendant is instantiable {}", descendant); } } } portTypesWithSchemaClasses.put(portType, hasSchemaClasses); } } catch (JSONException e) { // should not reach this LOG.error("JSON Exception {}", e); throw new RuntimeException(e); } }
From source file:org.apache.hadoop.yarn.util.SmapsBasedProcessTree.java
/** * Update process-tree with latest state. If the root-process is not alive, * tree will be empty.//from w w w. j ava 2 s .co m * */ @Override public void updateProcessTree() { if (!pid.equals(deadPid)) { // Get the list of processes List<String> processList = getProcessList(); Map<String, ProcessInfo> allProcessInfo = new HashMap<String, ProcessInfo>(); // cache the processTree to get the age for processes Map<String, ProcessInfo> oldProcs = new HashMap<String, ProcessInfo>(processTree); processTree.clear(); ProcessInfo me = null; for (String proc : processList) { // Get information for each process ProcessInfo pInfo = new ProcessInfo(proc); if (constructProcessInfo(pInfo, procfsDir) != null) { allProcessInfo.put(proc, pInfo); if (proc.equals(this.pid)) { me = pInfo; // cache 'me' processTree.put(proc, pInfo); } } } if (me == null) { return; } // Add each process to its parent. for (Map.Entry<String, ProcessInfo> entry : allProcessInfo.entrySet()) { String pID = entry.getKey(); if (!pID.equals("1")) { ProcessInfo pInfo = entry.getValue(); ProcessInfo parentPInfo = allProcessInfo.get(pInfo.getPpid()); if (parentPInfo != null) { parentPInfo.addChild(pInfo); } } } // now start constructing the process-tree LinkedList<ProcessInfo> pInfoQueue = new LinkedList<ProcessInfo>(); pInfoQueue.addAll(me.getChildren()); while (!pInfoQueue.isEmpty()) { ProcessInfo pInfo = pInfoQueue.remove(); if (!processTree.containsKey(pInfo.getPid())) { processTree.put(pInfo.getPid(), pInfo); } pInfoQueue.addAll(pInfo.getChildren()); } // update age values and compute the number of jiffies since last update for (Map.Entry<String, ProcessInfo> procs : processTree.entrySet()) { ProcessInfo oldInfo = oldProcs.get(procs.getKey()); if (procs.getValue() != null) { procs.getValue().updateJiffy(oldInfo); if (oldInfo != null) { procs.getValue().updateAge(oldInfo); } } } if (LOG.isDebugEnabled()) { // Log.debug the ProcfsBasedProcessTree LOG.debug(this.toString()); } } // Update PSS related information for (ProcessInfo p : processTree.values()) { if (p != null) { // Get information for each process ProcessMemInfo memInfo = new ProcessMemInfo(p.getPid()); constructProcessSMAPInfo(memInfo, procfsDir); processSMAPTree.put(p.getPid(), memInfo); } } }
From source file:org.apache.hadoop.yarn.util.ProcfsBasedProcessTree.java
/** * Update process-tree with latest state. If the root-process is not alive, * tree will be empty./*from www . j a v a2 s. c o m*/ * */ @Override public void updateProcessTree() { if (!pid.equals(deadPid)) { // Get the list of processes List<String> processList = getProcessList(); Map<String, ProcessInfo> allProcessInfo = new HashMap<String, ProcessInfo>(); // cache the processTree to get the age for processes Map<String, ProcessInfo> oldProcs = new HashMap<String, ProcessInfo>(processTree); processTree.clear(); ProcessInfo me = null; for (String proc : processList) { // Get information for each process ProcessInfo pInfo = new ProcessInfo(proc); if (constructProcessInfo(pInfo, procfsDir) != null) { allProcessInfo.put(proc, pInfo); if (proc.equals(this.pid)) { me = pInfo; // cache 'me' processTree.put(proc, pInfo); } } } if (me == null) { return; } // Add each process to its parent. for (Map.Entry<String, ProcessInfo> entry : allProcessInfo.entrySet()) { String pID = entry.getKey(); if (!pID.equals("1")) { ProcessInfo pInfo = entry.getValue(); String ppid = pInfo.getPpid(); // If parent is init and process is not session leader, // attach to sessionID if (ppid.equals("1")) { String sid = pInfo.getSessionId().toString(); if (!pID.equals(sid)) { ppid = sid; } } ProcessInfo parentPInfo = allProcessInfo.get(ppid); if (parentPInfo != null) { parentPInfo.addChild(pInfo); } } } // now start constructing the process-tree LinkedList<ProcessInfo> pInfoQueue = new LinkedList<ProcessInfo>(); pInfoQueue.addAll(me.getChildren()); while (!pInfoQueue.isEmpty()) { ProcessInfo pInfo = pInfoQueue.remove(); if (!processTree.containsKey(pInfo.getPid())) { processTree.put(pInfo.getPid(), pInfo); } pInfoQueue.addAll(pInfo.getChildren()); } // update age values and compute the number of jiffies since last update for (Map.Entry<String, ProcessInfo> procs : processTree.entrySet()) { ProcessInfo oldInfo = oldProcs.get(procs.getKey()); if (procs.getValue() != null) { procs.getValue().updateJiffy(oldInfo); if (oldInfo != null) { procs.getValue().updateAge(oldInfo); } } } if (LOG.isDebugEnabled()) { // Log.debug the ProcfsBasedProcessTree LOG.debug(this.toString()); } if (smapsEnabled) { //Update smaps info processSMAPTree.clear(); for (ProcessInfo p : processTree.values()) { if (p != null) { // Get information for each process ProcessTreeSmapMemInfo memInfo = new ProcessTreeSmapMemInfo(p.getPid()); constructProcessSMAPInfo(memInfo, procfsDir); processSMAPTree.put(p.getPid(), memInfo); } } } } }
From source file:com.lenovo.tensorhusky.common.utils.ProcfsBasedProcessTree.java
/** * Update process-tree with latest state. If the root-process is not alive, * tree will be empty.//from w ww.j a va2s. com */ @Override public void updateProcessTree() { if (!pid.equals(deadPid)) { // Get the list of processes List<String> processList = getProcessList(); Map<String, ProcessInfo> allProcessInfo = new HashMap<String, ProcessInfo>(); // cache the processTree to get the age for processes Map<String, ProcessInfo> oldProcs = new HashMap<String, ProcessInfo>(processTree); processTree.clear(); ProcessInfo me = null; for (String proc : processList) { // Get information for each process ProcessInfo pInfo = new ProcessInfo(proc); if (constructProcessInfo(pInfo, procfsDir) != null) { allProcessInfo.put(proc, pInfo); if (proc.equals(this.pid)) { me = pInfo; // cache 'me' processTree.put(proc, pInfo); } } } if (me == null) { return; } // Add each process to its parent. for (Map.Entry<String, ProcessInfo> entry : allProcessInfo.entrySet()) { String pID = entry.getKey(); if (!pID.equals("1")) { ProcessInfo pInfo = entry.getValue(); ProcessInfo parentPInfo = allProcessInfo.get(pInfo.getPpid()); if (parentPInfo != null) { parentPInfo.addChild(pInfo); } } } // now start constructing the process-tree LinkedList<ProcessInfo> pInfoQueue = new LinkedList<ProcessInfo>(); pInfoQueue.addAll(me.getChildren()); while (!pInfoQueue.isEmpty()) { ProcessInfo pInfo = pInfoQueue.remove(); if (!processTree.containsKey(pInfo.getPid())) { processTree.put(pInfo.getPid(), pInfo); } pInfoQueue.addAll(pInfo.getChildren()); } // update age values and compute the number of jiffies since last // update for (Map.Entry<String, ProcessInfo> procs : processTree.entrySet()) { ProcessInfo oldInfo = oldProcs.get(procs.getKey()); if (procs.getValue() != null) { procs.getValue().updateJiffy(oldInfo); if (oldInfo != null) { procs.getValue().updateAge(oldInfo); } } } if (LOG.isDebugEnabled()) { // Log.debug the ProcfsBasedProcessTree LOG.debug(this.toString()); } if (smapsEnabled) { // Update smaps info processSMAPTree.clear(); for (ProcessInfo p : processTree.values()) { if (p != null) { // Get information for each process ProcessTreeSmapMemInfo memInfo = new ProcessTreeSmapMemInfo(p.getPid()); constructProcessSMAPInfo(memInfo, procfsDir); processSMAPTree.put(p.getPid(), memInfo); } } } } }