Java Code Examples for org.apache.commons.lang3.concurrent.ConcurrentUtils#putIfAbsent()
The following examples show how to use
org.apache.commons.lang3.concurrent.ConcurrentUtils#putIfAbsent() .
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: AtriumGroupedThreadFactory.java From atrium-odl with Apache License 2.0 | 6 votes |
/** * Returns thread factory for producing threads associated with the specified * group name. The group name-space is hierarchical, based on slash-delimited * name segments, * * @param groupName group name * @return thread factory */ public static AtriumGroupedThreadFactory groupedThreadFactory(String groupName) { AtriumGroupedThreadFactory factory = FACTORIES.get(groupName); if (factory != null) { return factory; } // Find the parent group or root the group hierarchy under default group. int i = groupName.lastIndexOf(DELIMITER); if (i > 0) { String name = groupName.substring(0, i); ThreadGroup parentGroup = groupedThreadFactory(name).threadGroup(); factory = new AtriumGroupedThreadFactory(new ThreadGroup(parentGroup, groupName)); } else { factory = new AtriumGroupedThreadFactory(new ThreadGroup(groupName)); } return ConcurrentUtils.putIfAbsent(FACTORIES, groupName, factory); }
Example 2
Source File: GroupedThreadFactory.java From onos with Apache License 2.0 | 6 votes |
/** * Returns thread factory for producing threads associated with the specified * group name. The group name-space is hierarchical, based on slash-delimited * name segments, e.g. {@code onos/intent}. * * @param groupName group name * @return thread factory */ public static GroupedThreadFactory groupedThreadFactory(String groupName) { GroupedThreadFactory factory = FACTORIES.get(groupName); if (factory != null) { return factory; } // Find the parent group or root the group hierarchy under default group. int i = groupName.lastIndexOf(DELIMITER); if (i > 0) { String name = groupName.substring(0, i); ThreadGroup parentGroup = groupedThreadFactory(name).threadGroup(); factory = new GroupedThreadFactory(new ThreadGroup(parentGroup, groupName)); } else { factory = new GroupedThreadFactory(new ThreadGroup(groupName)); } return ConcurrentUtils.putIfAbsent(FACTORIES, groupName, factory); }
Example 3
Source File: MultiFileConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Returns the managed {@code FileBasedConfigurationBuilder} for the current * file name pattern. It is determined based on the evaluation of the file * name pattern using the configured {@code ConfigurationInterpolator}. If * this is the first access to this configuration file, the builder is * created. * * @return the configuration builder for the configuration corresponding to * the current evaluation of the file name pattern * @throws ConfigurationException if the builder cannot be determined (e.g. * due to missing initialization parameters) */ public FileBasedConfigurationBuilder<T> getManagedBuilder() throws ConfigurationException { final Map<String, Object> params = getParameters(); final MultiFileBuilderParametersImpl multiParams = MultiFileBuilderParametersImpl.fromParameters(params, true); if (multiParams.getFilePattern() == null) { throw new ConfigurationException("No file name pattern is set!"); } final String fileName = fetchFileName(multiParams); FileBasedConfigurationBuilder<T> builder = getManagedBuilders().get(fileName); if (builder == null) { builder = createInitializedManagedBuilder(fileName, createManagedBuilderParameters(params, multiParams)); final FileBasedConfigurationBuilder<T> newBuilder = ConcurrentUtils.putIfAbsent(getManagedBuilders(), fileName, builder); if (newBuilder == builder) { initListeners(newBuilder); } else { builder = newBuilder; } } return builder; }