List of usage examples for java.util IdentityHashMap put
public V put(K key, V value)
From source file:org.rhq.core.pc.inventory.InventoryManager.java
@NotNull Set<Resource> executeComponentDiscovery(ResourceType resourceType, ResourceDiscoveryComponent discoveryComponent, ResourceContainer parentContainer, List<ProcessScanResult> processScanResults) { ResourceContext parentResourceContext = parentContainer.getResourceContext(); ResourceComponent parentComponent = parentContainer.getResourceComponent(); Resource parentResource = parentContainer.getResource(); long startTime = System.currentTimeMillis(); log.debug("Executing discovery for [" + resourceType.getName() + "] Resources..."); Set<Resource> newResources; try {//from w w w . ja v a 2 s . c o m ResourceDiscoveryContext context = new ResourceDiscoveryContext(resourceType, parentComponent, parentResourceContext, SystemInfoFactory.createSystemInfo(), processScanResults, Collections.EMPTY_LIST, this.configuration.getContainerName(), this.configuration.getPluginContainerDeployment()); newResources = new HashSet<Resource>(); try { Set<DiscoveredResourceDetails> discoveredResources = invokeDiscoveryComponent(parentContainer, discoveryComponent, context); if ((discoveredResources != null) && (!discoveredResources.isEmpty())) { IdentityHashMap<Configuration, DiscoveredResourceDetails> pluginConfigObjects = new IdentityHashMap<Configuration, DiscoveredResourceDetails>(); for (DiscoveredResourceDetails discoveredResource : discoveredResources) { if (discoveredResource == null) { throw new IllegalStateException( "Plugin error: Discovery class " + discoveryComponent.getClass().getName() + " returned a Set containing one or more null items."); } if (!discoveredResource.getResourceType().equals(resourceType)) { throw new IllegalStateException("Plugin error: Discovery class " + discoveryComponent.getClass().getName() + " returned a DiscoveredResourceDetails with an incorrect ResourceType (was " + discoveredResource.getResourceType().getName() + " but should have been " + resourceType.getName()); } if (null != pluginConfigObjects.put(discoveredResource.getPluginConfiguration(), discoveredResource)) { throw new IllegalStateException("The plugin component " + discoveryComponent.getClass().getName() + " returned multiple resources that point to the same plugin configuration object on the " + "resource type [" + resourceType + "]. This is not allowed, please use " + "ResourceDiscoveryContext.getDefaultPluginConfiguration() " + "for each discovered resource."); } Resource newResource = InventoryManager.createNewResource(discoveredResource); newResources.add(newResource); } } } catch (DiscoverySuspendedException e) { //ok, the discovery is suspended for this resource type under this parent. //but we can continue the discovery in the child resource types of the existing resources. //we can therefore pretend that the discovery returned the existing resources so that //we can recurse into their children up in the call-chain. for (Resource existingResource : parentResource.getChildResources()) { if (resourceType.equals(existingResource.getResourceType())) { newResources.add(existingResource); } } } } catch (Throwable e) { // TODO GH: Add server/parent - up/down semantics so this won't happen just because a server is not up long elapsedTime = System.currentTimeMillis() - startTime; log.warn("Failure during discovery for [" + resourceType.getName() + "] Resources - failed after " + elapsedTime + " ms.", e); return Collections.EMPTY_SET; } long elapsedTime = System.currentTimeMillis() - startTime; if (elapsedTime > 20000) log.info("Discovery for [" + resourceType.getName() + "] resources took [" + elapsedTime + "] ms"); else log.debug("Discovery for [" + resourceType.getName() + "] resources completed in [" + elapsedTime + "] ms"); return newResources; }