Java Code Examples for java.util.concurrent.ConcurrentMap#values()

The following examples show how to use java.util.concurrent.ConcurrentMap#values() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultMessageStore.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Override
public int cleanUnusedTopic(Set<String> topics) {
    Iterator<Entry<String, ConcurrentMap<Integer, ConsumeQueue>>> it = this.consumeQueueTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, ConcurrentMap<Integer, ConsumeQueue>> next = it.next();
        String topic = next.getKey();

        if (!topics.contains(topic) && !topic.equals(ScheduleMessageService.SCHEDULE_TOPIC)) {
            ConcurrentMap<Integer, ConsumeQueue> queueTable = next.getValue();
            for (ConsumeQueue cq : queueTable.values()) {
                cq.destroy();
                log.info("cleanUnusedTopic: {} {} ConsumeQueue cleaned",
                    cq.getTopic(),
                    cq.getQueueId()
                );

                this.commitLog.removeQueueFromTopicQueueTable(cq.getTopic(), cq.getQueueId());
            }
            it.remove();

            log.info("cleanUnusedTopic: {},topic destroyed", topic);
        }
    }

    return 0;
}
 
Example 2
Source File: SimpleVirtualFlowRuleStore.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public int getFlowRuleCount(NetworkId networkId) {
    int sum = 0;

    if (flowEntries.get(networkId) == null) {
        return 0;
    }

    for (ConcurrentMap<FlowId, List<StoredFlowEntry>> ft :
            flowEntries.get(networkId).values()) {
        for (List<StoredFlowEntry> fes : ft.values()) {
            sum += fes.size();
        }
    }
    return sum;
}
 
Example 3
Source File: DefaultMessageStore.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
private void deleteExpiredFiles() {
    int deleteLogicsFilesInterval = DefaultMessageStore.this.getMessageStoreConfig().getDeleteConsumeQueueFilesInterval();

    long minOffset = DefaultMessageStore.this.commitLog.getMinOffset();
    if (minOffset > this.lastPhysicalMinOffset) {
        this.lastPhysicalMinOffset = minOffset;

        ConcurrentMap<String, ConcurrentMap<Integer, ConsumeQueue>> tables = DefaultMessageStore.this.consumeQueueTable;

        for (ConcurrentMap<Integer, ConsumeQueue> maps : tables.values()) {
            for (ConsumeQueue logic : maps.values()) {
                int deleteCount = logic.deleteExpiredFile(minOffset);

                if (deleteCount > 0 && deleteLogicsFilesInterval > 0) {
                    try {
                        Thread.sleep(deleteLogicsFilesInterval);
                    } catch (InterruptedException ignored) {
                    }
                }
            }
        }

        DefaultMessageStore.this.indexService.deleteExpiredFile(minOffset);
    }
}
 
Example 4
Source File: DefaultMessageStore.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public void truncateDirtyLogicFiles(long phyOffset) {
    ConcurrentMap<String, ConcurrentMap<Integer, ConsumeQueue>> tables = DefaultMessageStore.this.consumeQueueTable;

    for (ConcurrentMap<Integer, ConsumeQueue> maps : tables.values()) {
        for (ConsumeQueue logic : maps.values()) {
            logic.truncateDirtyLogicFiles(phyOffset);
        }
    }
}
 
Example 5
Source File: DefaultMessageStore.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
public void truncateDirtyLogicFiles(long phyOffset) {
    ConcurrentMap<String, ConcurrentMap<Integer, ConsumeQueue>> tables = DefaultMessageStore.this.consumeQueueTable;

    for (ConcurrentMap<Integer, ConsumeQueue> maps : tables.values()) {
        for (ConsumeQueue logic : maps.values()) {
            logic.truncateDirtyLogicFiles(phyOffset);
        }
    }
}
 
Example 6
Source File: DefaultMessageStore.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public void truncateDirtyLogicFiles(long phyOffset) {
    ConcurrentMap<String, ConcurrentMap<Integer, ConsumeQueue>> tables = DefaultMessageStore.this.consumeQueueTable;

    for (ConcurrentMap<Integer, ConsumeQueue> maps : tables.values()) {
        for (ConsumeQueue logic : maps.values()) {
            logic.truncateDirtyLogicFiles(phyOffset);
        }
    }
}
 
Example 7
Source File: ShowSqlResultSet.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();

    // write header
    buffer = HEADER.write(buffer, c, true);

    // write fields
    for (FieldPacket field : FIELDS) {
        buffer = field.write(buffer, c, true);
    }

    // write eof
    buffer = EOF.write(buffer, c, true);

    // write rows
    byte packetId = EOF.getPacketId();
    int i = 0;
    Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
    for (UserStat userStat : statMap.values()) {
        String user = userStat.getUser();
        ConcurrentMap<String, SqlResultSet> map = userStat.getSqlResultSizeRecorder().getSqlResultSet();
        if (map != null) {
            for (SqlResultSet sqlResultSet : map.values()) {
                RowDataPacket row = getRow(++i, user, sqlResultSet.getSql(), sqlResultSet.getCount(), sqlResultSet.getResultSetSize(), c.getCharset().getResults());
                row.setPacketId(++packetId);
                buffer = row.write(buffer, c, true);
            }
        }
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);

    // write buffer
    c.write(buffer);
}
 
Example 8
Source File: ConcurrentHashMapIteratorTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void checkForInitialSet(int i, ConcurrentMap testMap, Map initialSet) {
  HashSet found = new HashSet(testMap.values());
  if(!found.containsAll(initialSet.values())) {
    HashSet missed = new HashSet(initialSet.values());
    missed.removeAll(found);
    fail("On run " + i + " did not find these elements of the initial set using the iterator " + missed);
  }
}
 
Example 9
Source File: DefaultMessageStore.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
private void recoverConsumeQueue() {
        for (ConcurrentMap<Integer, ConsumeQueue> maps : this.consumeQueueTable.values()) {
            for (ConsumeQueue logic : maps.values()) {
//                恢复单个消息队列=》
                logic.recover();
            }
        }
    }
 
Example 10
Source File: DistributedGroupStore.java    From onos with Apache License 2.0 5 votes vote down vote up
private Group getMatchingExtraneousGroupbyBuckets(DeviceId deviceId,
                                                  GroupBuckets buckets) {
    ConcurrentMap<GroupId, Group> extraneousMap =
            extraneousGroupEntriesById.get(deviceId);
    if (extraneousMap == null) {
        return null;
    }

    for (Group extraneousGroup : extraneousMap.values()) {
        if (extraneousGroup.buckets().equals(buckets)) {
            return extraneousGroup;
        }
    }
    return null;
}
 
Example 11
Source File: ForwardingTokenGenerator.java    From blynk-server with GNU General Public License v3.0 5 votes vote down vote up
private static void process(DBManager dbManager, String region, String ip) throws Exception {
    System.out.println("Reading all users from region : " + region + ". Forward to " + ip);
    ConcurrentMap<UserKey, User> users = dbManager.userDBDao.getAllUsers(region);
    System.out.println("Read " + users.size() + " users.");
    int count = 0;
    List<ForwardingTokenEntry> entryList = new ArrayList<>(1100);
    for (User user : users.values()) {
        for (DashBoard dashBoard : user.profile.dashBoards) {
            for (Device device : dashBoard.devices) {
                if (device != null && device.token != null) {
                    count++;
                    entryList.add(new ForwardingTokenEntry(device.token, ip, user.email, dashBoard.id, device.id));
                }
            }
        }
        if (entryList.size() > 1000) {
            dbManager.forwardingTokenDBDao.insertTokenHostBatch(entryList);
            System.out.println(entryList.size() + " tokens inserted.");
            entryList = new ArrayList<>(1100);
        }
    }

    if (entryList.size() > 0) {
        dbManager.forwardingTokenDBDao.insertTokenHostBatch(entryList);
        System.out.println(entryList.size() + " tokens inserted.");
    }

    System.out.println("Total entries : " + count);
}
 
Example 12
Source File: DefaultMessageStore.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
private void deleteExpiredFiles() {
    int deleteLogicsFilesInterval = DefaultMessageStore.this.getMessageStoreConfig().getDeleteConsumeQueueFilesInterval();
    int readConsumeQueueFilesMaxWhenDel = DefaultMessageStore.this.getMessageStoreConfig().getReadConsumeQueueFilesMaxWhenDel();

    long minOffset = DefaultMessageStore.this.commitLog.getMinOffset();
    if (minOffset > this.lastPhysicalMinOffset) {
        this.lastPhysicalMinOffset = minOffset;

        ConcurrentMap<String, ConcurrentMap<Integer, ConsumeQueue>> tables = DefaultMessageStore.this.consumeQueueTable;

        int readCount = 0;
        for (ConcurrentMap<Integer, ConsumeQueue> maps : tables.values()) {
            for (ConsumeQueue logic : maps.values()) {
                int deleteCount = logic.deleteExpiredFile(minOffset);

                if ((deleteCount > 0 || readCount++ > readConsumeQueueFilesMaxWhenDel) && deleteLogicsFilesInterval > 0) {
                    try {
                        Thread.sleep(deleteLogicsFilesInterval);
                        readCount = 0;
                    } catch (InterruptedException ignored) {
                    }
                }
            }
        }

        DefaultMessageStore.this.indexService.deleteExpiredFile(minOffset);
    }
}
 
Example 13
Source File: DefaultMessageStore.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
private void recoverTopicQueueTable() {
    ConcurrentHashMap<String/* topic-queueid */, Long/* offset */> table = new ConcurrentHashMap<String, Long>(1024);
    long minPhyOffset = this.commitLog.getMinOffset();
    for (ConcurrentMap<Integer, ConsumeQueue> maps : this.consumeQueueTable.values()) {
        for (ConsumeQueue logic : maps.values()) {
            String key = logic.getTopic() + "-" + logic.getQueueId();
            table.put(key, logic.getMaxOffsetInQueue());
            logic.correctMinOffset(minPhyOffset);
        }
    }

    this.commitLog.setTopicQueueTable(table);
}
 
Example 14
Source File: WeakCache.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
void expungeFrom(ConcurrentMap<?, ? extends ConcurrentMap<?, ?>> map,
                 ConcurrentMap<?, Boolean> reverseMap) {
    // removing just by key is always safe here because after a CacheKey
    // is cleared and enqueue-ed it is only equal to itself
    // (see equals method)...
    ConcurrentMap<?, ?> valuesMap = map.remove(this);
    // remove also from reverseMap if needed
    if (valuesMap != null) {
        for (Object cacheValue : valuesMap.values()) {
            reverseMap.remove(cacheValue);
        }
    }
}
 
Example 15
Source File: CachedConnectionManagerImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Close all connections.
 * @param key The key
 * @return true if close
 */
private boolean closeAll(KeyConnectionAssociation key)
{
   ConcurrentMap<ConnectionCacheListener, CopyOnWriteArrayList<ConnectionRecord>> cmToConnectionsMap =
      key.getCMToConnectionsMap();
   boolean unclosed = false;

   Collection<CopyOnWriteArrayList<ConnectionRecord>> connections = cmToConnectionsMap.values();
   if (connections.size() != 0)
   {
      for (Iterator<CopyOnWriteArrayList<ConnectionRecord>> i = connections.iterator(); i.hasNext();)
      {
         CopyOnWriteArrayList<ConnectionRecord> conns = i.next();
         for (ConnectionRecord cr : conns)
         {
            Object c = cr.getConnection();
            CloseConnectionSynchronization cas = getCloseConnectionSynchronization(true);
            if (cas == null)
            {
               unclosed = true;

               if (Tracer.isEnabled())
               {
                  ConnectionListener cl = (ConnectionListener)cr.getConnectionListener();
                  Tracer.closeCCMConnection(cl.getPool().getName(), cl.getManagedConnectionPool(),
                                            cl, c, key.toString());
               }

               closeConnection(c);
            }
            else
            {
               cas.add(c);
            }
         }
      }
   }

   return unclosed;
}
 
Example 16
Source File: WeakCache.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
void expungeFrom(ConcurrentMap<?, ? extends ConcurrentMap<?, ?>> map,
                 ConcurrentMap<?, Boolean> reverseMap) {
    // removing just by key is always safe here because after a CacheKey
    // is cleared and enqueue-ed it is only equal to itself
    // (see equals method)...
    ConcurrentMap<?, ?> valuesMap = map.remove(this);
    // remove also from reverseMap if needed
    if (valuesMap != null) {
        for (Object cacheValue : valuesMap.values()) {
            reverseMap.remove(cacheValue);
        }
    }
}
 
Example 17
Source File: ReplicationEndpoint.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized void stop() throws Exception {
   if (!started) {
      return;
   }

   logger.trace("Stopping endpoint");

   started = false;

   OrderedExecutorFactory.flushExecutor(executor);

   // Channel may be null if there isn't a connection to a live server
   if (channel != null) {
      channel.close();
   }

   for (ReplicatedLargeMessage largeMessage : largeMessages.values()) {
      largeMessage.releaseResources(true);
   }
   largeMessages.clear();

   for (Entry<JournalContent, Map<Long, JournalSyncFile>> entry : filesReservedForSync.entrySet()) {
      for (JournalSyncFile filesReserved : entry.getValue().values()) {
         filesReserved.close();
      }
   }

   filesReservedForSync.clear();
   if (journals != null) {
      for (Journal j : journals) {
         if (j instanceof FileWrapperJournal)
            j.stop();
      }
   }

   for (ConcurrentMap<Integer, Page> map : pageIndex.values()) {
      for (Page page : map.values()) {
         try {
            page.close(false);
         } catch (Exception e) {
            ActiveMQServerLogger.LOGGER.errorClosingPageOnReplication(e);
         }
      }
   }
   pageManager.stop();

   pageIndex.clear();

   // Storage needs to be the last to stop
   storageManager.stop();

   started = false;
}
 
Example 18
Source File: VolatileBulletinRepository.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
public List<Bulletin> findBulletins(final BulletinQuery bulletinQuery) {
    final Filter<Bulletin> filter = new Filter<Bulletin>() {
        @Override
        public boolean select(final Bulletin bulletin) {
            final long fiveMinutesAgo = System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5);
            if (bulletin.getTimestamp().getTime() < fiveMinutesAgo) {
                return false;
            }

            // only include bulletins after the specified id
            if (bulletinQuery.getAfter() != null && bulletin.getId() <= bulletinQuery.getAfter()) {
                return false;
            }

            // if group pattern was specified see if it should be excluded
            if (bulletinQuery.getGroupIdPattern() != null) {
                // exclude if this bulletin doesnt have a group or if it doesnt match
                if (bulletin.getGroupId() == null || !bulletinQuery.getGroupIdPattern().matcher(bulletin.getGroupId()).find()) {
                    return false;
                }
            }

            // if a message pattern was specified see if it should be excluded
            if (bulletinQuery.getMessagePattern() != null) {
                // exclude if this bulletin doesnt have a message or if it doesnt match
                if (bulletin.getMessage() == null || !bulletinQuery.getMessagePattern().matcher(bulletin.getMessage()).find()) {
                    return false;
                }
            }

            // if a name pattern was specified see if it should be excluded
            if (bulletinQuery.getNamePattern() != null) {
                // exclude if this bulletin doesnt have a source name or if it doesnt match
                if (bulletin.getSourceName() == null || !bulletinQuery.getNamePattern().matcher(bulletin.getSourceName()).find()) {
                    return false;
                }
            }

            // if a source id was specified see if it should be excluded
            if (bulletinQuery.getSourceIdPattern() != null) {
                // exclude if this bulletin doesn't have a source id or if it doesn't match
                if (bulletin.getSourceId() == null || !bulletinQuery.getSourceIdPattern().matcher(bulletin.getSourceId()).find()) {
                    return false;
                }
            }

            // if a source component type was specified see if it should be excluded
            if (bulletinQuery.getSourceType() != null) {
                // exclude if this bulletin source type doesn't match
                if (bulletin.getSourceType() == null || !bulletinQuery.getSourceType().equals(bulletin.getSourceType())) {
                    return false;
                }
            }

            return true;
        }
    };

    final List<Bulletin> selected = new ArrayList<>();
    int max = bulletinQuery.getLimit() == null ? Integer.MAX_VALUE : bulletinQuery.getLimit();

    for (final ConcurrentMap<String, RingBuffer<Bulletin>> componentMap : bulletinStoreMap.values()) {
        for (final RingBuffer<Bulletin> ringBuffer : componentMap.values()) {
            final List<Bulletin> bulletinsForComponent = ringBuffer.getSelectedElements(filter, max);
            selected.addAll(bulletinsForComponent);
            max -= bulletinsForComponent.size();
            if (max <= 0) {
                break;
            }
        }
    }

    // sort by descending ID
    Collections.sort(selected);

    return selected;
}
 
Example 19
Source File: VolatileBulletinRepository.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public List<Bulletin> findBulletins(final BulletinQuery bulletinQuery) {
    final Filter<Bulletin> filter = new Filter<Bulletin>() {
        @Override
        public boolean select(final Bulletin bulletin) {
            final long fiveMinutesAgo = System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5);
            if (bulletin.getTimestamp().getTime() < fiveMinutesAgo) {
                return false;
            }

            // only include bulletins after the specified id
            if (bulletinQuery.getAfter() != null && bulletin.getId() <= bulletinQuery.getAfter()) {
                return false;
            }

            // if group pattern was specified see if it should be excluded
            if (bulletinQuery.getGroupIdPattern() != null) {
                // exclude if this bulletin doesnt have a group or if it doesnt match
                if (bulletin.getGroupId() == null || !bulletinQuery.getGroupIdPattern().matcher(bulletin.getGroupId()).find()) {
                    return false;
                }
            }

            // if a message pattern was specified see if it should be excluded
            if (bulletinQuery.getMessagePattern() != null) {
                // exclude if this bulletin doesnt have a message or if it doesnt match
                if (bulletin.getMessage() == null || !bulletinQuery.getMessagePattern().matcher(bulletin.getMessage()).find()) {
                    return false;
                }
            }

            // if a name pattern was specified see if it should be excluded
            if (bulletinQuery.getNamePattern() != null) {
                // exclude if this bulletin doesnt have a source name or if it doesnt match
                if (bulletin.getSourceName() == null || !bulletinQuery.getNamePattern().matcher(bulletin.getSourceName()).find()) {
                    return false;
                }
            }

            // if a source id was specified see if it should be excluded
            if (bulletinQuery.getSourceIdPattern() != null) {
                // exclude if this bulletin doesn't have a source id or if it doesn't match
                if (bulletin.getSourceId() == null || !bulletinQuery.getSourceIdPattern().matcher(bulletin.getSourceId()).find()) {
                    return false;
                }
            }

            // if a source component type was specified see if it should be excluded
            if (bulletinQuery.getSourceType() != null) {
                // exclude if this bulletin source type doesn't match
                if (bulletin.getSourceType() == null || !bulletinQuery.getSourceType().equals(bulletin.getSourceType())) {
                    return false;
                }
            }

            return true;
        }
    };

    final Set<Bulletin> selected = new TreeSet<>();
    int max = bulletinQuery.getLimit() == null ? Integer.MAX_VALUE : bulletinQuery.getLimit();

    for (final ConcurrentMap<String, RingBuffer<Bulletin>> componentMap : bulletinStoreMap.values()) {
        for (final RingBuffer<Bulletin> ringBuffer : componentMap.values()) {
            final List<Bulletin> bulletinsForComponent = ringBuffer.getSelectedElements(filter, max);
            selected.addAll(bulletinsForComponent);
            max -= bulletinsForComponent.size();
            if (max <= 0) {
                break;
            }
        }
    }

    return new ArrayList<>(selected);
}
 
Example 20
Source File: PreparedStatementDUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public static int verifyWrapperSize(int expectedSize) throws SQLException {
  int mapSize = 0;
  for (int i = 1; i <= 5; i++) {
    if (i > 1) {
      // increase the memory pressure to force a GC
      long dummy = 0;
      for (int j = 1; j <= 100000; j++) {
        Object[] obj = new Object[50];
        dummy += obj.hashCode();
      }
      getLogWriter().info("statement not GCed, dummy=" + dummy);
    }
    invokeGC();
    GfxdConnectionHolder holder = GfxdConnectionHolder.getHolder();
    ConcurrentMap<Long, GfxdConnectionWrapper> idToConnMap = holder
        .getWrapperMap();
    assertNotNull(idToConnMap);
    // now there is one for GFXD mbean service
    GfxdConnectionWrapper wrapper = null;
    InternalManagementService ims = InternalManagementService
        .getAnyInstance();
    for (GfxdConnectionWrapper o : idToConnMap.values()) {
      if (ims != null && o == ims.getConnectionWrapperForTEST()) {
        continue;
      }
      if (wrapper == null) {
        wrapper = o;
      }
      else {
        fail("found more than one user connection wrappers");
      }
    }
    if (wrapper == null) {
      // can happen if the connection got GCed
      //fail("no user connection wrapper found");
      return 0;
    }

    TLongObjectHashMap stmntMap = wrapper.getStatementMapForTEST();
    // invoke a getStatement to force drain refQueue
    final long[] allKeys = stmntMap.keys();
    if (allKeys.length > 0) {
      EmbedConnection conn = wrapper.getConnectionForSynchronization();
      synchronized (conn.getConnectionSynchronization()) {
        wrapper.getStatement(null, allKeys[0], true, false, false, false,
            null, false, 0, 0);
      }
    }
    mapSize = stmntMap.size();
    if (mapSize <= expectedSize) {
      return mapSize;
    }
  }
  return mapSize;
}