List of usage examples for java.util ListIterator remove
void remove();
From source file:org.opennms.netmgt.collectd.Collectd.java
/** * Process the 'primarySnmpInterfaceChanged' event. Extract the old and * new primary SNMP interface addresses from the event parms. Any * CollectableService objects located in the collectable services list * which match the IP address of the old primary interface and have a * service name of "SNMP" are flagged for deletion. This will ensure that * the old primary interface is no longer collected against. Finally the * new primary SNMP interface is scheduled. The packages are examined and * new CollectableService objects are created, initialized and scheduled * for collection./* w w w.j av a 2 s.c om*/ * * @param event * The event to process. * @throws InsufficientInformationException */ private void handlePrimarySnmpInterfaceChanged(Event event) throws InsufficientInformationException { EventUtils.checkNodeId(event); EventUtils.checkInterface(event); LOG.debug("primarySnmpInterfaceChangedHandler: processing primary SNMP interface changed event..."); // Currently only support SNMP data collection. // if (!event.getService().equals("SNMP")) return; // Extract the old and new primary SNMP interface addresses from the // event parms. // String oldPrimaryIfAddr = null; String parmName = null; Value parmValue = null; String parmContent = null; for (Parm parm : event.getParmCollection()) { parmName = parm.getParmName(); parmValue = parm.getValue(); if (parmValue == null) continue; else parmContent = parmValue.getContent(); // old primary SNMP interface (optional parameter) if (parmName.equals(EventConstants.PARM_OLD_PRIMARY_SNMP_ADDRESS)) { oldPrimaryIfAddr = parmContent; } } if (oldPrimaryIfAddr != null) { // Mark the service for deletion so that it will not be // rescheduled // for // collection. // // Iterate over the CollectableService objects in the service // updates map // and mark any which have the same interface address as the old // primary SNMP interface and a service name of "SNMP" for // deletion. // synchronized (getCollectableServices()) { CollectableService cSvc = null; ListIterator<CollectableService> liter = getCollectableServices().listIterator(); while (liter.hasNext()) { cSvc = liter.next(); final InetAddress addr = (InetAddress) cSvc.getAddress(); final String addrString = str(addr); if (addrString != null && addrString.equals(oldPrimaryIfAddr)) { synchronized (cSvc) { // Got a match! Retrieve the CollectorUpdates // object // associated // with this CollectableService. CollectorUpdates updates = cSvc.getCollectorUpdates(); // Now set the deleted flag updates.markForDeletion(); LOG.debug("primarySnmpInterfaceChangedHandler: marking {} as deleted for service SNMP.", oldPrimaryIfAddr); } // Now safe to remove the collectable service from // the collectable services list liter.remove(); } } } } // Now we can schedule the new service... // scheduleForCollection(event); LOG.debug( "primarySnmpInterfaceChangedHandler: processing of primarySnmpInterfaceChanged event for nodeid {} completed.", event.getNodeid()); }
From source file:org.wso2.carbon.appmgt.hostobjects.APIStoreHostObject.java
private static List<String> filterUrlsByTransport(List<String> urlsList, List<String> transportList, String transportName) {// w w w .j ava2s .c o m if (!transportList.contains(transportName)) { ListIterator<String> it = urlsList.listIterator(); while (it.hasNext()) { String url = it.next(); if (url.startsWith(transportName + ":")) { it.remove(); } } return urlsList; } return urlsList; }
From source file:org.opennms.ng.services.collectd.Collectd.java
/** * This method is responsible for handling interfaceDeleted events. * * @param event The event to process.//from w w w .j ava2 s .c om * @throws InsufficientInformationException */ private void handleInterfaceDeleted(Event event) throws InsufficientInformationException { EventUtils.checkNodeId(event); String ipAddr = event.getInterface(); if (EventUtils.isNonIpInterface(ipAddr)) { LOG.debug("handleInterfaceDeleted: the deleted interface was a non-ip interface. Nothing to do here."); return; } Long nodeId = event.getNodeid(); // Iterate over the collectable services list and mark any entries // which match the deleted nodeId/IP address pair for deletion synchronized (getCollectableServices()) { CollectableService cSvc = null; ListIterator<CollectableService> liter = getCollectableServices().listIterator(); while (liter.hasNext()) { cSvc = liter.next(); // Only interested in entries with matching nodeId and IP // address InetAddress addr = (InetAddress) cSvc.getAddress(); if (!(cSvc.getNodeId() == nodeId && addr.getHostName().equals(ipAddr))) { continue; } synchronized (cSvc) { // Retrieve the CollectorUpdates object associated with // this CollectableService if one exists. CollectorUpdates updates = cSvc.getCollectorUpdates(); // Now set the update's deletion flag so the next // time it is selected for execution by the scheduler // the collection will be skipped and the service will not // be rescheduled. LOG.debug( "Marking CollectableService for deletion because an interface was deleted: Service nodeid={}, " + "deleted node:{}service address:{}deleted interface:{}", cSvc.getNodeId(), nodeId, addr.getHostName(), ipAddr); updates.markForDeletion(); } // Now safe to remove the collectable service from // the collectable services list liter.remove(); } } LOG.debug("interfaceDeletedHandler: processing of interfaceDeleted event for {}/{} completed", nodeId, ipAddr); }
From source file:org.opennms.netmgt.collectd.Collectd.java
/** * This method is responsible for handling interfaceDeleted events. * /*from w ww.j a v a2 s. c o m*/ * @param event * The event to process. * @throws InsufficientInformationException */ private void handleInterfaceDeleted(Event event) throws InsufficientInformationException { EventUtils.checkNodeId(event); String ipAddr = event.getInterface(); if (EventUtils.isNonIpInterface(ipAddr)) { LOG.debug("handleInterfaceDeleted: the deleted interface was a non-ip interface. Nothing to do here."); return; } Long nodeId = event.getNodeid(); // Iterate over the collectable services list and mark any entries // which match the deleted nodeId/IP address pair for deletion synchronized (getCollectableServices()) { CollectableService cSvc = null; ListIterator<CollectableService> liter = getCollectableServices().listIterator(); while (liter.hasNext()) { cSvc = liter.next(); // Only interested in entries with matching nodeId and IP // address InetAddress addr = (InetAddress) cSvc.getAddress(); if (!(cSvc.getNodeId() == nodeId && addr.getHostName().equals(ipAddr))) continue; synchronized (cSvc) { // Retrieve the CollectorUpdates object associated with // this CollectableService if one exists. CollectorUpdates updates = cSvc.getCollectorUpdates(); // Now set the update's deletion flag so the next // time it is selected for execution by the scheduler // the collection will be skipped and the service will not // be rescheduled. LOG.debug( "Marking CollectableService for deletion because an interface was deleted: Service nodeid={}, deleted node:{}service address:{}deleted interface:{}", cSvc.getNodeId(), nodeId, addr.getHostName(), ipAddr); updates.markForDeletion(); } // Now safe to remove the collectable service from // the collectable services list liter.remove(); } } LOG.debug("interfaceDeletedHandler: processing of interfaceDeleted event for {}/{} completed", nodeId, ipAddr); }
From source file:zemin.notification.NotificationBoard.java
private void updateRowViews() { synchronized (mLock) { final int count = mCenter.getEntryCount(); final int childCount = mContainer.getChildCount(); if (DBG)// ww w . java 2 s. c o m Log.v(TAG, "updateRowViews - old: " + childCount + ", new: " + count); if (count != childCount) { ArrayList<NotificationEntry> entries = mCenter.getEntries(); ArrayList<RowView> toRemove = null; for (int i = 0; i < childCount; i++) { RowView rowView = (RowView) mContainer.getChildAt(i); boolean found = false; ListIterator<NotificationEntry> iter = entries.listIterator(); while (iter.hasNext()) { NotificationEntry entry = iter.next(); if (entry.ID == rowView.notification) { removePendingCancel(entry); iter.remove(); found = true; break; } } if (!found) { if (toRemove == null) { toRemove = new ArrayList<RowView>(); } toRemove.add(rowView); } } if (toRemove != null) { for (RowView r : toRemove) { removeRowView(r); } } for (NotificationEntry entry : entries) { addRowView(entry); } } } }
From source file:org.apache.lens.cube.metadata.CubeMetastoreClient.java
/** * @param factOrDimTable//from ww w. j a v a 2s . c o m * @param storageName * @param updatePeriod * @param storagePartitionDescs * @param type * @return * @throws HiveException * @throws LensException */ private List<Partition> addPartitions(String factOrDimTable, String storageName, UpdatePeriod updatePeriod, List<StoragePartitionDesc> storagePartitionDescs, CubeTableType type) throws HiveException, LensException { String storageTableName = getStorageTableName(factOrDimTable, storageName, updatePeriod); if (type == CubeTableType.DIM_TABLE) { // Adding partition in dimension table. Map<Map<String, String>, LatestInfo> latestInfos = Maps.newHashMap(); for (Map.Entry<Map<String, String>, List<StoragePartitionDesc>> entry : groupByNonTimePartitions( storagePartitionDescs).entrySet()) { latestInfos.put(entry.getKey(), getDimTableLatestInfo(storageTableName, entry.getKey(), getTimePartSpecs(entry.getValue()), updatePeriod)); } List<Partition> partsAdded = getStorage(storageName).addPartitions(getClient(), factOrDimTable, updatePeriod, storagePartitionDescs, latestInfos, storageTableName); ListIterator<Partition> iter = partsAdded.listIterator(); while (iter.hasNext()) { if (iter.next().getSpec().values().contains(StorageConstants.LATEST_PARTITION_VALUE)) { iter.remove(); } } latestLookupCache.add(storageTableName); return partsAdded; } else if (type == CubeTableType.FACT) { List<Partition> partsAdded = new ArrayList<>(); // first update in memory, then add to hive table's partitions. delete is reverse. partitionTimelineCache.updateForAddition(factOrDimTable, storageName, updatePeriod, getTimePartSpecs(storagePartitionDescs, getStorageTableStartDate(storageTableName, factOrDimTable), getStorageTableEndDate(storageTableName, factOrDimTable))); // Adding partition in fact table. if (storagePartitionDescs.size() > 0) { partsAdded = getStorage(storageName).addPartitions(getClient(), factOrDimTable, updatePeriod, storagePartitionDescs, null, storageTableName); } // update hive table alterTablePartitionCache((Storage.getPrefix(storageName) + factOrDimTable).toLowerCase(), updatePeriod, storageTableName); return partsAdded; } else { throw new LensException("Can't add partitions to anything other than fact or dimtable"); } }
From source file:com.koma.music.service.MusicService.java
/** * Removes the range of tracks specified from the play list. If a file * within the range is the file currently being played, playback will move * to the next file after the range.// w ww .ja va2s.co m * * @param first The first file to be removed * @param last The last file to be removed * @return the number of tracks deleted */ private int removeTracksInternal(int first, int last) { synchronized (this) { if (last < first) { return 0; } else if (first < 0) { first = 0; } else if (last >= mPlaylist.size()) { last = mPlaylist.size() - 1; } boolean gotonext = false; if (first <= mPlayPos && mPlayPos <= last) { mPlayPos = first; gotonext = true; } else if (mPlayPos > last) { mPlayPos -= last - first + 1; } final int numToRemove = last - first + 1; if (first == 0 && last == mPlaylist.size() - 1) { mPlayPos = -1; mNextPlayPos = -1; mPlaylist.clear(); mHistory.clear(); } else { for (int i = 0; i < numToRemove; i++) { mPlaylist.remove(first); } // remove the items from the history // this is not ideal as the history shouldn't be impacted by this // but since we are removing items from the array, it will throw // an exception if we keep it around. Idealistically with the queue // rewrite this should be all be fixed // https://cyanogen.atlassian.net/browse/MUSIC-44 ListIterator<Integer> positionIterator = mHistory.listIterator(); while (positionIterator.hasNext()) { int pos = positionIterator.next(); if (pos >= first && pos <= last) { positionIterator.remove(); } else if (pos > last) { positionIterator.set(pos - numToRemove); } } } if (gotonext) { if (mPlaylist.size() == 0) { stop(true); mPlayPos = -1; closeCursor(); } else { if (mShuffleMode != MusicServiceConstants.SHUFFLE_NONE) { mPlayPos = getNextPosition(true); } else if (mPlayPos >= mPlaylist.size()) { mPlayPos = 0; } final boolean wasPlaying = isPlaying(); stop(false); openCurrentAndNext(); if (wasPlaying) { play(); } } notifyChange(META_CHANGED); } return last - first + 1; } }
From source file:com.bluros.music.MusicService.java
private int removeTracksInternal(int first, int last) { synchronized (this) { if (last < first) { return 0; } else if (first < 0) { first = 0;//from w ww .j av a 2s . c om } else if (last >= mPlaylist.size()) { last = mPlaylist.size() - 1; } boolean gotonext = false; if (first <= mPlayPos && mPlayPos <= last) { mPlayPos = first; gotonext = true; } else if (mPlayPos > last) { mPlayPos -= last - first + 1; } final int numToRemove = last - first + 1; if (first == 0 && last == mPlaylist.size() - 1) { mPlayPos = -1; mNextPlayPos = -1; mPlaylist.clear(); mHistory.clear(); } else { for (int i = 0; i < numToRemove; i++) { mPlaylist.remove(first); } ListIterator<Integer> positionIterator = mHistory.listIterator(); while (positionIterator.hasNext()) { int pos = positionIterator.next(); if (pos >= first && pos <= last) { positionIterator.remove(); } else if (pos > last) { positionIterator.set(pos - numToRemove); } } } if (gotonext) { if (mPlaylist.size() == 0) { stop(true); mPlayPos = -1; closeCursor(); } else { if (mShuffleMode != SHUFFLE_NONE) { mPlayPos = getNextPosition(true); } else if (mPlayPos >= mPlaylist.size()) { mPlayPos = 0; } final boolean wasPlaying = isPlaying(); stop(false); openCurrentAndNext(); if (wasPlaying) { play(); } } notifyChange(META_CHANGED); } return last - first + 1; } }
From source file:org.restcomm.connect.telephony.Call.java
private void sendBye(Hangup hangup) throws IOException, TransitionNotFoundException, TransitionFailedException, TransitionRollbackException {/*ww w .ja va2 s.com*/ final SipSession session = invite.getSession(); final String sessionState = session.getState().name(); if (sessionState == SipSession.State.TERMINATED.name()) { if (logger.isInfoEnabled()) { logger.info("SipSession already TERMINATED, will not send BYE"); } return; } else { if (logger.isInfoEnabled()) { logger.info("About to send BYE, session state: " + sessionState); } } if (sessionState == SipSession.State.INITIAL.name() || (sessionState == SipSession.State.EARLY.name() && isInbound())) { int sipResponse = (enable200OkDelay && hangup.getSipResponse() != null) ? hangup.getSipResponse() : Response.SERVER_INTERNAL_ERROR; final SipServletResponse resp = invite.createResponse(sipResponse); if (hangup.getMessage() != null && !hangup.getMessage().equals("")) { resp.addHeader("Reason", hangup.getMessage()); } addCustomHeaders(resp); resp.send(); fsm.transition(hangup, completed); return; } if (sessionState == SipSession.State.EARLY.name()) { final SipServletRequest cancel = invite.createCancel(); if (hangup.getMessage() != null && !hangup.getMessage().equals("")) { cancel.addHeader("Reason", hangup.getMessage()); } addCustomHeaders(cancel); cancel.send(); external = CallStateChanged.State.CANCELED; fsm.transition(hangup, completed); return; } else { final SipServletRequest bye = session.createRequest("BYE"); addCustomHeaders(bye); if (hangup.getMessage() != null && !hangup.getMessage().equals("")) { bye.addHeader("Reason", hangup.getMessage()); } SipURI realInetUri = (SipURI) session.getAttribute("realInetUri"); InetAddress byeRURI = InetAddress.getByName(((SipURI) bye.getRequestURI()).getHost()); // INVITE sip:+12055305520@107.21.247.251 SIP/2.0 // Record-Route: <sip:10.154.28.245:5065;transport=udp;lr;node_host=10.13.169.214;node_port=5080;version=0> // Record-Route: <sip:10.154.28.245:5060;transport=udp;lr;node_host=10.13.169.214;node_port=5080;version=0> // Record-Route: <sip:67.231.8.195;lr=on;ftag=gK0043eb81> // Record-Route: <sip:67.231.4.204;r2=on;lr=on;ftag=gK0043eb81> // Record-Route: <sip:192.168.6.219;r2=on;lr=on;ftag=gK0043eb81> // Accept: application/sdp // Allow: INVITE,ACK,CANCEL,BYE // Via: SIP/2.0/UDP 10.154.28.245:5065;branch=z9hG4bK1cdb.193075b2.058724zsd_0 // Via: SIP/2.0/UDP 10.154.28.245:5060;branch=z9hG4bK1cdb.193075b2.058724_0 // Via: SIP/2.0/UDP 67.231.8.195;branch=z9hG4bK1cdb.193075b2.0 // Via: SIP/2.0/UDP 67.231.4.204;branch=z9hG4bK1cdb.f9127375.0 // Via: SIP/2.0/UDP 192.168.16.114:5060;branch=z9hG4bK00B6ff7ff87ed50497f // From: <sip:+1302109762259@192.168.16.114>;tag=gK0043eb81 // To: <sip:12055305520@192.168.6.219> // Call-ID: 587241765_133360558@192.168.16.114 // CSeq: 393447729 INVITE // Max-Forwards: 67 // Contact: <sip:+1302109762259@192.168.16.114:5060> // Diversion: <sip:+112055305520@192.168.16.114:5060>;privacy=off;screen=no; reason=unknown; counter=1 // Supported: replaces // Content-Disposition: session;handling=required // Content-Type: application/sdp // Remote-Party-ID: <sip:+1302109762259@192.168.16.114:5060>;privacy=off;screen=no // X-Sip-Balancer-InitialRemoteAddr: 67.231.8.195 // X-Sip-Balancer-InitialRemotePort: 5060 // Route: <sip:10.13.169.214:5080;transport=udp;lr> // Content-Length: 340 ListIterator<String> recordRouteList = invite.getHeaders(RecordRouteHeader.NAME); if (invite.getHeader("X-Sip-Balancer-InitialRemoteAddr") != null) { if (logger.isInfoEnabled()) { logger.info( "We are behind LoadBalancer and will remove the first two RecordRoutes since they are the LB node"); } recordRouteList.next(); recordRouteList.remove(); recordRouteList.next(); recordRouteList.remove(); } if (recordRouteList.hasNext()) { if (logger.isInfoEnabled()) { logger.info("Record Route is set, wont change the Request URI"); } } else { if (logger.isInfoEnabled()) { logger.info("Checking RURI, realInetUri: " + realInetUri + " byeRURI: " + byeRURI); } if (logger.isDebugEnabled()) { logger.debug("byeRURI.isSiteLocalAddress(): " + byeRURI.isSiteLocalAddress()); logger.debug("byeRURI.isAnyLocalAddress(): " + byeRURI.isAnyLocalAddress()); logger.debug("byeRURI.isLoopbackAddress(): " + byeRURI.isLoopbackAddress()); } if (realInetUri != null && (byeRURI.isSiteLocalAddress() || byeRURI.isAnyLocalAddress() || byeRURI.isLoopbackAddress())) { if (logger.isInfoEnabled()) { logger.info("real ip address of the sip client " + realInetUri.toString() + " is not null, checking if the request URI needs to be patched"); } boolean patchRURI = true; try { // https://github.com/RestComm/Restcomm-Connect/issues/1336 checking if the initial IP and Port behind LB is part of the route set or not ListIterator<? extends Address> routes = bye.getAddressHeaders(RouteHeader.NAME); while (routes.hasNext() && patchRURI) { SipURI route = (SipURI) routes.next().getURI(); String routeHost = route.getHost(); int routePort = route.getPort(); if (routePort < 0) { routePort = 5060; } if (logger.isDebugEnabled()) { logger.debug("Checking if route " + routeHost + ":" + routePort + " is matching ip and port of realNetURI " + realInetUri.getHost() + ":" + realInetUri.getPort() + " for the BYE request"); } if (routeHost.equalsIgnoreCase(realInetUri.getHost()) && routePort == realInetUri.getPort()) { if (logger.isDebugEnabled()) { logger.debug("route " + route + " is matching ip and port of realNetURI " + realInetUri.getHost() + ":" + realInetUri.getPort() + " for the BYE request, so not patching the Request-URI"); } patchRURI = false; } } } catch (ServletParseException e) { logger.error("Impossible to parse the route set from the BYE " + bye, e); } if (patchRURI) { if (logger.isInfoEnabled()) { logger.info("Using the real ip address of the sip client " + realInetUri.toString() + " as a request uri of the BYE request"); } bye.setRequestURI(realInetUri); } } } if (logger.isInfoEnabled()) { logger.info("Will sent out BYE to: " + bye.getRequestURI()); } try { bye.send(); sentBye = true; } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Exception during Send Bye: " + e.toString()); } } } }
From source file:org.opennms.ng.services.collectd.Collectd.java
/** * This method is responsible for handling serviceDeleted events. * * @param event The event to process./*from w w w . j a va 2 s . c om*/ * @throws InsufficientInformationException */ private void handleServiceDeleted(Event event) throws InsufficientInformationException { EventUtils.checkNodeId(event); EventUtils.checkInterface(event); EventUtils.checkService(event); //INCORRECT; we now support all *sorts* of data collection. This is *way* out of date // Currently only support SNMP data collection. // //if (!event.getService().equals("SNMP")) // return; Long nodeId = event.getNodeid(); String ipAddr = event.getInterface(); String svcName = event.getService(); // Iterate over the collectable services list and mark any entries // which match the nodeId/ipAddr of the deleted service // for deletion. synchronized (getCollectableServices()) { CollectableService cSvc = null; ListIterator<CollectableService> liter = getCollectableServices().listIterator(); while (liter.hasNext()) { cSvc = liter.next(); // Only interested in entries with matching nodeId, IP address // and service InetAddress addr = (InetAddress) cSvc.getAddress(); //WATCH the brackets; there used to be an extra close bracket after the ipAddr comparison which borked this whole expression if (!(cSvc.getNodeId() == nodeId && addr.getHostName().equals(ipAddr) && cSvc.getServiceName().equals(svcName))) { continue; } synchronized (cSvc) { // Retrieve the CollectorUpdates object associated with // this CollectableService if one exists. CollectorUpdates updates = cSvc.getCollectorUpdates(); // Now set the update's deletion flag so the next // time it is selected for execution by the scheduler // the collection will be skipped and the service will not // be rescheduled. LOG.debug( "Marking CollectableService for deletion because a service was deleted: Service nodeid={}, deleted node:{}, " + "service address:{}, deleted interface:{}, service servicename:{}, deleted service name:{}, event source {}", cSvc.getNodeId(), nodeId, addr.getHostName(), ipAddr, cSvc.getServiceName(), svcName, event.getSource()); updates.markForDeletion(); } // Now safe to remove the collectable service from // the collectable services list liter.remove(); } } LOG.debug("serviceDeletedHandler: processing of serviceDeleted event for {}/{}/{} completed.", nodeId, ipAddr, svcName); }