@Override public void shutdown() { // loop over all the sessions in memory (a few times if necessary to catch sessions that have // been // added while we're running int loop = 100; while (!_sessions.isEmpty() && loop-- > 0) { for (Session session : _sessions.values()) { // if we have a backing store and the session is dirty make sure it is written out if (_sessionDataStore != null) { if (session.getSessionData().isDirty()) { session.willPassivate(); try { _sessionDataStore.store(session.getId(), session.getSessionData()); } catch (Exception e) { LOG.warn(e); } } doDelete(session.getId()); // remove from memory } else { // not preserving sessions on exit try { session.invalidate(); } catch (Exception e) { LOG.ignore(e); } } } } }
/** Utility method to notify the mavlink listeners about a connection disconnect. */ protected void reportDisconnect(long disconnectTime) { if (mListeners.isEmpty()) return; for (MavLinkConnectionListener listener : mListeners.values()) { listener.onDisconnect(disconnectTime); } }
/** * Utility method to notify the mavlink listeners about received messages. * * @param packet received mavlink packet */ private void reportReceivedPacket(MAVLinkPacket packet) { if (mListeners.isEmpty()) return; for (MavLinkConnectionListener listener : mListeners.values()) { listener.onReceivePacket(packet); } }
/** remove timeout connections */ public void abandTimeOuttedConns() { if (allCons.isEmpty()) { return; } Collection<BackendConnection> abandCons = new LinkedList<BackendConnection>(); long curTime = System.currentTimeMillis(); Iterator<Entry<Long, HeartBeatCon>> itors = allCons.entrySet().iterator(); while (itors.hasNext()) { HeartBeatCon hbCon = itors.next().getValue(); if (hbCon.timeOutTimestamp < curTime) { abandCons.add(hbCon.conn); itors.remove(); } } if (!abandCons.isEmpty()) { for (BackendConnection con : abandCons) { try { // if(con.isBorrowed()) con.close("heartbeat timeout "); } catch (Exception e) { LOGGER.warn("close err:" + e); } } } }
/** * Utility method to notify the mavlink listeners about communication errors. * * @param errMsg */ protected void reportComError(String errMsg) { if (mListeners.isEmpty()) return; for (MavLinkConnectionListener listener : mListeners.values()) { listener.onComError(errMsg); } }
/** * This method returns the first {@link Album} of this object. If none exists, returns null. It's * needed to comply to the {@link * org.tomahawk.tomahawk_android.adapters.TomahawkBaseAdapter.TomahawkListItem} interface. * * @return First {@link Album} of this object. If none exists, returns null. */ @Override public Album getAlbum() { if (!mAlbums.isEmpty()) { ArrayList<Album> albums = new ArrayList<Album>(mAlbums.values()); return albums.get(0); } return null; }
/* * (non-Javadoc) * * @see org.mixare.mgr.downloader.DownloadManager#getNextResult() */ public synchronized DownloadResult getNextResult() { DownloadResult result = null; if (!doneList.isEmpty()) { String nextId = doneList.keySet().iterator().next(); result = doneList.get(nextId); doneList.remove(nextId); } return result; }
/** * Excute the pattern matching algorithm to determine if a the current connection must be * suspended or not, and when. * * @param ctx The current {@link Context} * @return true if the ProtocolChain should continue its execution, false if the connection has * been suspended. * @throws java.io.IOException */ public boolean postExecute(Context ctx) throws IOException { if (logger.isLoggable(Level.FINE)) { logger.fine("<----- " + ctx.getKeyRegistrationState()); } if (!suspendedKeys.isEmpty() && ctx.getKeyRegistrationState() == KeyRegistrationState.REGISTER) { suspend(ctx, false); return false; } return true; }
/** * Check whether all data can be read from this version. This requires that all chunks referenced * by this version are still available (not overwritten). * * @param version the version * @return true if all data can be read */ private boolean isKnownVersion(long version) { if (version > currentVersion || version < 0) { return false; } if (version == currentVersion || chunks.isEmpty()) { // no stored data return true; } // need to check if a chunk for this version exists BTreeChunk c = getChunkForVersion(version); if (c == null) { return false; } return true; }
/** * Goes over pending loading requests and displays loaded photos. If some of the photos still * haven't been loaded, sends another request for image loading. */ private void processLoadedImages() { Iterator<ImageView> iterator = mPendingRequests.keySet().iterator(); while (iterator.hasNext()) { ImageView view = iterator.next(); String path = mPendingRequests.get(view); boolean loaded = loadCachedPhoto(view, path); if (loaded) { iterator.remove(); } } if (!mPendingRequests.isEmpty()) { requestLoading(); } }
/** Returns an HttpEntity containing all request parameters */ public HttpEntity getEntity() { HttpEntity entity = null; if (!fileParams.isEmpty()) { SimpleMultipartEntity multipartEntity = new SimpleMultipartEntity(); // Add string params for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) { multipartEntity.addPart(entry.getKey(), entry.getValue()); } // Add dupe params for (ConcurrentHashMap.Entry<String, ArrayList<String>> entry : urlParamsWithArray.entrySet()) { ArrayList<String> values = entry.getValue(); for (String value : values) { multipartEntity.addPart(entry.getKey(), value); } } // Add file params int currentIndex = 0; int lastIndex = fileParams.entrySet().size() - 1; for (ConcurrentHashMap.Entry<String, FileWrapper> entry : fileParams.entrySet()) { FileWrapper file = entry.getValue(); if (file.inputStream != null) { boolean isLast = currentIndex == lastIndex; if (file.contentType != null) { multipartEntity.addPart( entry.getKey(), file.getFileName(), file.inputStream, file.contentType, isLast); } else { multipartEntity.addPart(entry.getKey(), file.getFileName(), file.inputStream, isLast); } } currentIndex++; } entity = multipartEntity; } else { try { entity = new UrlEncodedFormEntity(getParamsList(), ENCODING); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return entity; }
// TableAction has implemented selectTable() shared by multiple table Actions protected HTableDescriptor selectTable( ConcurrentHashMap<TableName, HTableDescriptor> tableMap) { // randomly select table from tableMap if (tableMap.isEmpty()) { return null; } // synchronization to prevent removal from multiple threads synchronized (tableMap) { ArrayList<TableName> tableList = new ArrayList<TableName>(tableMap.keySet()); TableName randomKey = tableList.get(RandomUtils.nextInt(tableList.size())); HTableDescriptor randomHtd = tableMap.get(randomKey); // remove from tableMap tableMap.remove(randomKey); return randomHtd; } }
// NamespaceAction has implemented selectNamespace() shared by multiple namespace Actions protected NamespaceDescriptor selectNamespace( ConcurrentHashMap<String, NamespaceDescriptor> namespaceMap) { // randomly select namespace from namespaceMap if (namespaceMap.isEmpty()) { return null; } // synchronization to prevent removal from multiple threads synchronized (namespaceMap) { ArrayList<String> namespaceList = new ArrayList<String>(namespaceMap.keySet()); String randomKey = namespaceList.get(RandomUtils.nextInt(namespaceList.size())); NamespaceDescriptor randomNsd = namespaceMap.get(randomKey); // remove from namespaceMap namespaceMap.remove(randomKey); return randomNsd; } }
/** Clean up and close all open databases. */ @Override public void onDestroy() { while (!dbrmap.isEmpty()) { String dbname = dbrmap.keySet().iterator().next(); this.closeDatabaseNow(dbname); DBRunner r = dbrmap.get(dbname); try { // stop the db runner thread: r.q.put(new DBQuery()); } catch (Exception e) { Log.e(SQLitePlugin.class.getSimpleName(), "couldn't stop db thread", e); } dbrmap.remove(dbname); } }
public boolean progress() { if (player.isDead() || !player.isOnline()) { remove(); return false; } speedfactor = speed * (ProjectKorra.time_step / 1000.); if (!charging) { if (elements.isEmpty()) { remove(); return false; } advanceSwipe(); } else { if (GeneralMethods.getBoundAbility(player) == null) { remove(); return false; } if (!GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirSwipe") || !GeneralMethods.canBend(player.getName(), "AirSwipe")) { remove(); return false; } if (!player.isSneaking()) { double factor = 1; if (System.currentTimeMillis() >= time + maxchargetime) { factor = maxfactor; } else if (AvatarState.isAvatarState(player)) { factor = AvatarState.getValue(factor); } else { factor = maxfactor * (double) (System.currentTimeMillis() - time) / (double) maxchargetime; } charging = false; launch(); if (factor < 1) factor = 1; damage *= factor; pushfactor *= factor; return true; } else if (System.currentTimeMillis() >= time + maxchargetime) { AirMethods.playAirbendingParticles(player.getEyeLocation(), 3); } } return true; }
/** save the meta data */ private void saveMetaDataOnceEveryDay() { HashMap<String, String> tempHashMap = new HashMap<String, String>(); tempHashMap.putAll(allarchiveFieldsData); if (runTimeFieldsData != null && !runTimeFieldsData.isEmpty()) { // This should store fields like the description at least once every day. tempHashMap.putAll(runTimeFieldsData); } if (this.totalMetaInfo != null) { if (this.totalMetaInfo.getUnit() != null) { tempHashMap.put("EGU", this.totalMetaInfo.getUnit()); } if (this.totalMetaInfo.getPrecision() != 0) { tempHashMap.put("PREC", Integer.toString(this.totalMetaInfo.getPrecision())); } } // dbrtimeevent.s dbrtimeevent.setFieldValues(tempHashMap, false); lastTimeStampWhenSavingarchiveFields = Calendar.getInstance(); }
public void progress() { if (player.isDead() || !player.isOnline()) { remove(); return; } if (!charging) { if (elements.isEmpty()) { remove(); return; } advanceSwipe(); } else { if (!bPlayer.canBend(this)) { remove(); return; } if (!player.isSneaking()) { double factor = 1; if (System.currentTimeMillis() >= startTime + maxChargeTime) { factor = maxChargeFactor; } else if (bPlayer.isAvatarState()) { factor = AvatarState.getValue(factor); } else { factor = maxChargeFactor * (double) (System.currentTimeMillis() - startTime) / (double) maxChargeTime; } charging = false; launch(); factor = Math.max(1, factor); damage *= factor; pushFactor *= factor; return; } else if (System.currentTimeMillis() >= startTime + maxChargeTime) { playAirbendingParticles(player.getEyeLocation(), particles); } } }
public static synchronized void addSnake(Snake snake) { if (snakes.isEmpty()) { startTimer(); } snakes.put(Integer.valueOf(snake.getId()), snake); }
/** * Returns <tt>true</tt> if this set contains no elements. * * @return <tt>true</tt> if this set contains no elements */ public boolean isEmpty() { return map.isEmpty(); }
@SuppressWarnings("deprecation") private void advanceSwipe() { affectedEntities.clear(); for (Vector direction : elements.keySet()) { Location location = elements.get(direction); if (direction != null && location != null) { location = location.clone().add(direction.clone().multiply(speed)); elements.replace(direction, location); if (location.distanceSquared(origin) > range * range || GeneralMethods.isRegionProtectedFromBuild(this, location)) { elements.remove(direction); } else { removeAirSpouts(location, player); WaterAbility.removeWaterSpouts(location, player); if (EarthBlast.annihilateBlasts(location, radius, player) || WaterManipulation.annihilateBlasts(location, radius, player) || FireBlast.annihilateBlasts(location, radius, player) || Combustion.removeAroundPoint(location, radius)) { elements.remove(direction); damage = 0; remove(); continue; } Block block = location.getBlock(); for (Block testblock : GeneralMethods.getBlocksAroundPoint(location, radius)) { if (testblock.getType() == Material.FIRE) { testblock.setType(Material.AIR); } if (isBlockBreakable(testblock)) { GeneralMethods.breakBlock(testblock); } } if (block.getType() != Material.AIR) { if (isBlockBreakable(block)) { GeneralMethods.breakBlock(block); } else { elements.remove(direction); } if (isLava(block)) { if (block.getData() == 0x0) { block.setType(Material.OBSIDIAN); } else { block.setType(Material.COBBLESTONE); } } } else { playAirbendingParticles(location, particles, 0.2F, 0.2F, 0); if (random.nextInt(4) == 0) { playAirbendingSound(location); } affectPeople(location, direction); } } } } if (elements.isEmpty()) { remove(); } }
@Override public boolean isEmpty() { return map.isEmpty(); }
public void clearCommandList() { if (!commands.isEmpty()) { commands.clear(); } }
public static synchronized void removeSnake(Snake snake) { snakes.remove(Integer.valueOf(snake.getId())); if (snakes.isEmpty()) { stopTimer(); } }
@SuppressWarnings("deprecation") private void advanceSwipe() { affectedentities.clear(); for (Vector direction : elements.keySet()) { Location location = elements.get(direction); if (direction != null && location != null) { location = location.clone().add(direction.clone().multiply(speedfactor)); elements.replace(direction, location); if (location.distance(origin) > range || GeneralMethods.isRegionProtectedFromBuild(player, "AirSwipe", location)) { elements.remove(direction); } else { AirMethods.removeAirSpouts(location, player); WaterMethods.removeWaterSpouts(location, player); double radius = FireBlast.AFFECTING_RADIUS; Player source = player; if (EarthBlast.annihilateBlasts(location, radius, source) || WaterManipulation.annihilateBlasts(location, radius, source) || FireBlast.annihilateBlasts(location, radius, source) || Combustion.removeAroundPoint(location, radius)) { elements.remove(direction); damage = 0; remove(); continue; } Block block = location.getBlock(); for (Block testblock : GeneralMethods.getBlocksAroundPoint(location, affectingradius)) { if (testblock.getType() == Material.FIRE) { testblock.setType(Material.AIR); } if (isBlockBreakable(testblock)) { GeneralMethods.breakBlock(testblock); } } if (block.getType() != Material.AIR) { if (isBlockBreakable(block)) { GeneralMethods.breakBlock(block); } else { elements.remove(direction); } if (block.getType() == Material.LAVA || block.getType() == Material.STATIONARY_LAVA) { if (block.getData() == full) { block.setType(Material.OBSIDIAN); } else { block.setType(Material.COBBLESTONE); } } } else { AirMethods.playAirbendingParticles(location, 3, 0.2F, 0.2F, 0); if (GeneralMethods.rand.nextInt(4) == 0) { AirMethods.playAirbendingSound(location); } affectPeople(location, direction); } } // } else { // elements.remove(direction); } } if (elements.isEmpty()) { remove(); } }
public HttpEntity b() { if (e == null) { if (b.isEmpty()) { break label354; } l locall = new l(); Iterator localIterator = a.entrySet().iterator(); Map.Entry localEntry; while (localIterator.hasNext()) { localEntry = (Map.Entry) localIterator.next(); locall.a((String) localEntry.getKey(), (String) localEntry.getValue()); } localIterator = c.entrySet().iterator(); Object localObject; while (localIterator.hasNext()) { localEntry = (Map.Entry) localIterator.next(); localObject = ((ArrayList) localEntry.getValue()).iterator(); while (((Iterator) localObject).hasNext()) { String str = (String) ((Iterator) localObject).next(); locall.a((String) localEntry.getKey(), str); } } int j = b.entrySet().size(); localIterator = b.entrySet().iterator(); int i = 0; if (localIterator.hasNext()) { localEntry = (Map.Entry) localIterator.next(); localObject = (j) localEntry.getValue(); boolean bool; if (a != null) { if (i != j - 1) { break label309; } bool = true; label263: if (c == null) { break label314; } locall.a((String) localEntry.getKey(), ((j) localObject).a(), a, c, bool); } for (; ; ) { i += 1; break; label309: bool = false; break label263; label314: locall.a((String) localEntry.getKey(), ((j) localObject).a(), a, bool); } } e = locall; } for (; ; ) { return e; try { label354: e = new UrlEncodedFormEntity(c(), d); } catch (UnsupportedEncodingException localUnsupportedEncodingException) { localUnsupportedEncodingException.printStackTrace(); } } }
/** Resumes loading photos from the database. */ public void resume() { mPaused = false; if (!mPendingRequests.isEmpty()) { requestLoading(); } }