@Override public synchronized void afterCompletion(int status) { completed = true; synchronizations.remove(id); if (transactionMode == TransactionMode.ISOLATE_READS) { for (TempTable table : tables.values()) { table.getActive().decrementAndGet(); } } else { HashSet<TempTable> current = new HashSet<TempTable>(tempTables.values()); current.retainAll(tables.values()); for (TempTable table : current) { table.getActive().set(0); table.getTree().clearClonedFlags(); } } for (TransactionCallback callback : callbacks) { if (status == Status.STATUS_COMMITTED) { callback.commit(); } else { callback.rollback(); } } callbacks.clear(); }
public Raster getFrame() { // lock the model so other people don't modify it while we do paint // calls based on it. synchronized (m) { // presumes that you instantiated Raster with a PGraphics. PGraphics myRaster = (PGraphics) (r.getRaster()); myRaster.beginDraw(); // TODO THIS SHOULD BE THE NORMAL WAY TO FIND NEW PEOPLE/CREATE NEW SPRITES ConcurrentHashMap<Integer, Person> people = m.getPeople(); Iterator<Person> iter = people.values().iterator(); while (iter.hasNext()) { Person p = iter.next(); if (p.isNew()) { // TODO instantiate new sprites here Cross cross = new Cross(spriteIndex, r, p, 1, 1, sm, 3, 3); // 3x3 cross int[] loc = p.getLoc(); // System.out.println(loc[0]+" "+loc[1]); cross.moveTo(loc[0] * tileSize, loc[1] * tileSize); cross.addListener(this); // sprites.add(cross); sprites.put(spriteIndex, cross); spriteIndex++; } } /* myRaster.background(0); // clear the raster Cross cross = new Cross(r, null, 1, 1, 3, 3); // 3x3 cross boolean[] sensorlist = m.getSensors(); for(int i=0; i<sensorlist.length; i++){ // sensorlist is 16x11 if(sensorlist[i]){ int x = i % 16; // probably shouldn't be static values int y = i / 16; // position is offset by 1 because of the extra column on each side cross.moveTo((x+1)*tileSize, y*tileSize); // moves instance of sprite to active tile cross.draw(); // draws instance } } */ // TODO THIS SHOULD BE THE NORMAL WAY TO DRAW ALL SPRITES try { myRaster.background(0); // clear the raster Iterator<Sprite> spriteiter = sprites.values().iterator(); while (spriteiter.hasNext()) { Sprite sprite = (Sprite) spriteiter.next(); sprite.draw(); } } catch (ConcurrentModificationException e) { // TODO WHY DOES IT THROW THESE ERRORS? e.printStackTrace(); } // myRaster.background(255,0,0); // FULLY ON myRaster.endDraw(); } return r; }
@Override protected DbFuture<Void> doClose(CloseMode mode) { final DefaultDbFuture<Void> toComplete = new DefaultDbFuture<Void>(stackTracingOptions()); final ArrayList<UsersConnectionPool> toClose = new ArrayList<UsersConnectionPool>(connectionsPerUser.values()); final AtomicInteger countDown = new AtomicInteger(toClose.size()); final AtomicReference<Exception> failure = new AtomicReference(null); for (UsersConnectionPool pool : connectionsPerUser.values()) { pool.close(mode) .addListener( new DbListener<Void>() { @Override public void onCompletion(DbFuture<Void> future) { if (future.getState() == FutureState.FAILURE) { failure.compareAndSet(null, future.getException()); } int pendingCloses = countDown.decrementAndGet(); if (pendingCloses == 0) { if (failure.get() == null) { toComplete.trySetResult(null); } else { toComplete.trySetException(failure.get()); } } } }); } return toComplete; }
/** * Get a list of all {@link Album}s from this object. * * @return list of all {@link Album}s from this object. */ public ArrayList<Album> getAlbums() { if (mAlbumsFetchedViaHatchet.size() > 0) { return new ArrayList<Album>(mAlbumsFetchedViaHatchet.values()); } ArrayList<Album> albums = new ArrayList<Album>(mAlbums.values()); Collections.sort( albums, new TomahawkListItemComparator(TomahawkListItemComparator.COMPARE_ALPHA)); return albums; }
/** * We need to make sure that all resources are closed, we don't actually do this when a * resourceConfig is closed but maybe we should. */ public void stop() { for (RecoveryDiscovery recoveryDiscovery : configSet.values()) { recoveryDiscovery.stop(); } for (HornetQXAResourceWrapper hornetQXAResourceWrapper : recoveries.values()) { hornetQXAResourceWrapper.close(); } recoveries.clear(); configSet.clear(); }
/** Stops an entity from being suffocated * */ public static void breakSuffocate(Entity entity) { for (Suffocate suffocate : instances.values()) { if (suffocate.targets.contains(entity)) { suffocate.breakSuffocateLocal(entity); } } }
public void sendMessage(String receivers, String msg, String sender) { String messageString = "MESSAGE#" + sender + "#" + msg; String[] receiversarray = receivers.split(","); if (receiversarray.length == 1) { String receiver = receiversarray[0]; if (receiver.equals("*")) { for (Handler handler : handlers.values()) { handler.sendMessage(messageString); Logger.getLogger(EchoServer.class.getName()) .log( Level.INFO, handler.getUsername() + " Sent a message to all: " + messageString, new Object[] {handler.getUsername()}); } } else { Handler handler = (Handler) handlers.get(receiver); handler.sendMessage(messageString); Logger.getLogger(EchoServer.class.getName()) .log( Level.INFO, handler.getUsername() + " Sent a message: " + messageString + " to: " + receiver, new Object[] {handler.getUsername()}); } } }
@Override public void close() throws IOException { if (threads != null) { threads.values().forEach(java.lang.Thread::interrupt); } if (dataSourceBuilderListener != null) { this.context.removeServiceListener(dataSourceBuilderListener); } if (dataSources != null) { for (DataSource s : dataSources.values()) { s.close(); } } }
@Override public void onClientDisconnected(String id) { if (serverAlreadyExists(id)) { TumpiServer server = getServer(id); try { Map<String, Cliente> clientes_socket = socket.clientes; for (TumpiClient cliente_tumpi : server) { Cliente cliente_socket = clientes_socket.get(cliente_tumpi.id); cliente_socket.close(); } server.removeAllClients(); } catch (IOException ex) { Log.$.error("Error al desconectar al cliente"); } servidores.remove(id); } else { Collection<TumpiServer> values = servidores.values(); for (TumpiServer server : values) { if (server.isClient(id)) { server.removeCliente(id); sendClientNotification(server.id, id, "off"); } } } Log.$.info("Cliente desconectado >> " + id); }
@Override public void dispose() { this.scheduledExecutorService.shutdown(); if (this.scheduler != null) { try { this.scheduler.shutdown(true); } catch (final SchedulerException e) { log.error("Shutdown quartz scheduler failed", e); } } for (final ConcurrentHashMap<Integer /* partition */, MessageStore> subMap : MessageStoreManager.this.stores.values()) { if (subMap != null) { for (final MessageStore msgStore : subMap.values()) { if (msgStore != null) { try { msgStore.close(); } catch (final Throwable e) { log.error( "Try to run close " + msgStore.getTopic() + "," + msgStore.getPartition() + " failed", e); } } } } } this.stores.clear(); }
@Override public ImmutableList<FundsMutationSubject> nameLikeSearch(String str) { final ImmutableList.Builder<FundsMutationSubject> builder = ImmutableList.builder(); table .values() .stream() .forEach( subject -> { final int length = str.length(); if (length > 0) { if (str.charAt(0) == '%') { if (str.charAt(length - 1) == '%') { if (length > 2) { if (subject.name.contains(str.substring(1, length - 1))) { builder.add(subject); } } else { builder.add(subject); } } else if (subject.name.endsWith(str.substring(1))) { builder.add(subject); } } else if (str.charAt(length - 1) == '%') { if (subject.name.startsWith(str.substring(0, length - 1))) { builder.add(subject); } } else if (str.equals(subject.name)) { builder.add(subject); } } }); return builder.build(); }
void checkServers() { servers .values() .stream() .filter(server -> !server.isOnline()) .forEach( server -> { ProxyServer.getInstance() .getLogger() .severe( "[Servers] Server " + server.getName() + " detected as offline, removing."); remove(server.getName()); BungeeBridge.getInstance() .getExecutor() .addTask( () -> { Jedis jedis = BungeeBridge.getInstance().getConnector().getBungeeResource(); jedis.hdel("servers", server.getName()); jedis.sadd("offlineservers", server.getName()); jedis.del("connectedonserv:" + server.getName()); jedis.publish("servers", "stop " + server.getName()); jedis.close(); }); }); }
@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); } } } } }
private boolean mix(short[] outBuffer, int bufferSize) { List<AudioOutputSpeech> mix = new ArrayList<AudioOutputSpeech>(); List<AudioOutputSpeech> del = new ArrayList<AudioOutputSpeech>(); // TODO add priority speaker support for (AudioOutputSpeech speech : mAudioOutputs.values()) { if (!speech.needSamples(bufferSize)) del.add(speech); else mix.add(speech); } if (!mix.isEmpty()) { for (AudioOutputSpeech speech : mix) { float[] buffer = speech.getBuffer(); for (int i = 0; i < bufferSize; i++) { short pcm = (short) (buffer[i] * Short.MAX_VALUE); // Convert float to short pcm = (short) Math.max(Math.min(pcm, Short.MAX_VALUE), Short.MIN_VALUE); // Clip audio outBuffer[i] += pcm; } } } for (AudioOutputSpeech speech : del) mAudioOutputs.remove(speech.getSession()); return !mix.isEmpty(); }
public ArrayList<String> listShops() { ArrayList<String> names = new ArrayList<String>(); for (Shop shop : shops.values()) { names.add(shop.getName()); } return names; }
public ArrayList<Shop> getShops() { ArrayList<Shop> shopList = new ArrayList<Shop>(); for (Shop shop : shops.values()) { shopList.add(shop); } return shopList; }
private void readAllChunks(boolean readPagePositions) { String[] files = new File(btreeStorageName).list(); if (files != null && files.length > 0) { for (String f : files) { int chunkId = Integer.parseInt(f.substring(0, f.length() - AOStorage.SUFFIX_AO_FILE_LENGTH)); if (!chunks.containsKey(chunkId)) { readChunkHeader(chunkId); } } if (readPagePositions) { for (BTreeChunk c : chunks.values()) { if (c.pagePositions == null) { ByteBuffer pagePositions = c.fileStorage.readFully( c.pagePositionsOffset + CHUNK_HEADER_SIZE, c.pageCount * 2 * 8); int size = c.pageCount * 2; c.pagePositions = new ArrayList<Long>(); for (int i = 0; i < size; i++) { c.pagePositions.add(pagePositions.getLong()); } } } } } }
/** Check the transactions info that have expired */ public void checkMsrpTransactionInfo() { if (mTransactionInfoMap != null) { List<MsrpTransactionInfo> msrpTransactionInfos = null; synchronized (mTransactionMsgIdMapLock) { // Copy the transaction info items to accelerate the locking while doing // expiring process msrpTransactionInfos = new ArrayList<MsrpTransactionInfo>(mTransactionInfoMap.values()); } for (MsrpTransactionInfo msrpTransactionInfo : msrpTransactionInfos) { long delta = System.currentTimeMillis() - msrpTransactionInfo.mTimestamp; if ((delta >= TRANSACTION_INFO_EXPIRY_PERIOD) || (delta < 0)) { if (sLogger.isActivated()) { sLogger.debug( "Transaction info have expired (transactionId: " + msrpTransactionInfo.mTransactionId + ", msgId: " + msrpTransactionInfo.mMsrpMsgId + ")"); } mTransactionInfoMap.remove(msrpTransactionInfo.mTransactionId); if (mMessageTransactionMap != null) { mMessageTransactionMap.remove(msrpTransactionInfo.mMsrpMsgId); } } } } }
Collection<MessageStore> getMessageStoresByTopic(final String topic) { final ConcurrentHashMap<Integer /* partition */, MessageStore> map = this.stores.get(topic); if (map == null) { return Collections.emptyList(); } return map.values(); }
@Override public synchronized void stop() { if (!live) { return; } live = false; logger.finest("Stopping ConnectionManager"); if (acceptorThread != null) { acceptorThread.shutdown(); } for (SocketChannelWrapper socketChannel : acceptedSockets) { closeResource(socketChannel); } for (Connection conn : connectionsMap.values()) { destroySilently(conn); } for (TcpIpConnection conn : activeConnections) { destroySilently(conn); } ioThreadingModel.shutdown(); acceptedSockets.clear(); connectionsInProgress.clear(); connectionsMap.clear(); monitors.clear(); activeConnections.clear(); }
@Override public void close() throws BackendException { for (InMemoryKeyColumnValueStore store : stores.values()) { store.close(); } stores.clear(); }
public int getCount() { int c = 0; for (StatisticCollector statisticCollector : statusCodes.values()) { c += statisticCollector.getCount(); } return c; }
@Override public void close() { for (OScheduledEvent event : events.values()) { event.interrupt(); } events.clear(); }
// Test method public LinkedList<Integer> getLiveAuctionsIds() throws RemoteException { LinkedList<Integer> ll = new LinkedList<Integer>(); for (AuctionItem t : liveAuctionItems.values()) { ll.add(t.getAuctionId()); } return ll; }
public List<Events> getEventsByParams() { ConcurrentHashMap<Integer, Events> eventBeforeSearch = AppStorage.INSTANCE.getEventStorageCopy(); ConcurrentHashMap<Integer, Events> eventAfterSearch = new ConcurrentHashMap<Integer, Events>(); if (city != null && city.length() != 0) { for (Map.Entry<Integer, Events> entry : eventBeforeSearch.entrySet()) { if (city.equalsIgnoreCase(entry.getValue().getCity())) eventAfterSearch.put(entry.getKey(), entry.getValue()); } } eventBeforeSearch.clear(); eventBeforeSearch = AppStorage.INSTANCE.getEventStorageCopy(); if (description != null && description.length() > 0 && !description.equals("")) { eventAfterSearch.clear(); for (Map.Entry<Integer, Events> entry : eventBeforeSearch.entrySet()) { if (entry.getValue().getDescription().contains(description)) eventAfterSearch.put(entry.getKey(), entry.getValue()); } } eventBeforeSearch = new ConcurrentHashMap<Integer, Events>(eventAfterSearch); /* if(date != null){ for(Map.Entry<Integer,Events> entry : eventBeforeSearch.entrySet()){ GregorianCalendar eventDate = entry.getValue().getDate(); GregorianCalendar before = new GregorianCalendar(eventDate.get(1),eventDate.get(2),eventDate.get(4)+1); GregorianCalendar after = new GregorianCalendar(eventDate.get(1),eventDate.get(2),eventDate.get(4)); if(date.after(after) && date.before(before)) eventAfterSearch.put(entry.getKey(),entry.getValue()); } } */ return new ArrayList<Events>(eventAfterSearch.values()); }
/** * 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); } }
public final boolean isEmptyWriteSet() { if (readOnly) return true; lock.lock(); try { final Iterator<ILocalBTreeView> itr = indices.values().iterator(); while (itr.hasNext()) { final IsolatedFusedView ndx = (IsolatedFusedView) itr.next(); if (!ndx.isEmptyWriteSet()) { // At least one isolated index was written on. return false; } } return true; } finally { lock.unlock(); } }
/** 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); } }
/** flush all regions to HDFS */ public static synchronized void flushTable() { for (int i = 0; i < jobQueue; i++) { for (HTable table : indexSpecToTables[i].values()) { try { // System.out.println("begain flush table!"); table.flushCommits(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } for (HTable table : indexSpecToCCTS[i].values()) { try { // System.out.println("begain flush table!"); table.flushCommits(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } for (HTable table : tableToCCTS.values()) { try { // System.out.println("begain flush table!"); table.flushCommits(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } IndexedRegion.flushTable(); }
/** * 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); } }