@Override public Collection<Notification> retrieveNotifications() { try { return Lists.newArrayList(notifications.asMap().values()); } finally { notifications.invalidateAll(); notifications.cleanUp(); } }
/** Clears all entries in the cache. */ public void clear() { lock.lock(); try { for (ClassLoader classLoader : classLoaderDetails.asMap().keySet()) { ClassLoaderUtils.tryClose(classLoader); } classLoaderDetails.invalidateAll(); classLoaderIds.invalidateAll(); } finally { lock.unlock(); } }
/* * (non-Javadoc) * * @see org.apache.bookkeeper.mledger.ManagedLedger#close() */ @Override public synchronized void close() throws InterruptedException, ManagedLedgerException { checkFenced(); for (LedgerHandle ledger : ledgerCache.asMap().values()) { log.debug("Closing ledger: {}", ledger.getId()); try { ledger.close(); } catch (BKException e) { throw new ManagedLedgerException(e); } } ledgerCache.invalidateAll(); log.info("Invalidated {} ledgers in cache", ledgerCache.size()); factory.close(this); }
/** * Loads the security groups attached to the node with the given ID and returns the group that is * unique to the node, per the application context. This method will also update {@link * #sharedGroupCache} if no mapping for the shared group's location previously existed (e.g. * Brooklyn was restarted and rebound to an existing application). * * <p>Notice that jclouds will attach 2 securityGroups to the node if the locationId is `aws-ec2` * so it needs to look for the uniqueSecurityGroup rather than the shared securityGroup. * * @param nodeId The id of the node in question * @param locationId The id of the location in question * @param securityApi The API to use to list security groups * @return the security group unique to the given node, or null if one could not be determined. */ private SecurityGroup getUniqueSecurityGroupForNodeCachingSharedGroupIfPreviouslyUnknown( String nodeId, String locationId, SecurityGroupExtension securityApi) { Set<SecurityGroup> groupsOnNode = securityApi.listSecurityGroupsForNode(nodeId); if (groupsOnNode == null || groupsOnNode.isEmpty()) { return null; } SecurityGroup unique; if (locationId.equals("aws-ec2")) { if (groupsOnNode.size() == 2) { String expectedSharedName = getNameForSharedSecurityGroup(); Iterator<SecurityGroup> it = groupsOnNode.iterator(); SecurityGroup shared = it.next(); if (shared.getName().endsWith(expectedSharedName)) { unique = it.next(); } else { unique = shared; shared = it.next(); } if (!shared.getName().endsWith(expectedSharedName)) { LOG.warn( "Couldn't determine which security group is shared between instances in app {}. Expected={}, found={}", new Object[] {applicationId, expectedSharedName, groupsOnNode}); return null; } // Shared entry might be missing if Brooklyn has rebound to an application SecurityGroup old = sharedGroupCache.asMap().putIfAbsent(shared.getLocation(), shared); LOG.info( "Loaded unique security group for node {} (in {}): {}", new Object[] {nodeId, applicationId, unique}); if (old == null) { LOG.info("Proactively set shared group for app {} to: {}", applicationId, shared); } return unique; } else { LOG.warn( "Expected to find two security groups on node {} in app {} (one shared, one unique). Found {}: {}", new Object[] {nodeId, applicationId, groupsOnNode.size(), groupsOnNode}); } } return Iterables.getOnlyElement(groupsOnNode); }
@Override protected void doDestroy() throws TddlException { for (ConfigDataHandler cdh : cdhs.asMap().values()) { try { cdh.destroy(); } catch (Exception e) { // ignore } } for (SchemaConfig schema : schemas.values()) { TDataSource dataSource = schema.getDataSource(); try { if (dataSource != null) { dataSource.destroy(); } } catch (Exception e) { // ignore } } }
@Override public String toString() { final Map<Integer, T> map = cache.asMap(); return Arrays.toString(map.entrySet().toArray()).replace("],", "],\n"); }