Example usage for java.util Collections unmodifiableMap

List of usage examples for java.util Collections unmodifiableMap

Introduction

In this page you can find the example usage for java.util Collections unmodifiableMap.

Prototype

public static <K, V> Map<K, V> unmodifiableMap(Map<? extends K, ? extends V> m) 

Source Link

Document

Returns an unmodifiable view of the specified map.

Usage

From source file:com.amazonaws.internal.config.InternalConfig.java

private <C extends Builder<T>, T> Map<String, T> merge(JsonIndex<C, T>[] defaults,
        JsonIndex<C, T>[] overrides) {
    Map<String, T> map = buildMap(defaults);
    Map<String, T> mapOverride = buildMap(overrides);
    map.putAll(mapOverride);//from  w ww.  j a v a  2  s. com
    return Collections.unmodifiableMap(map);
}

From source file:com.hurence.logisland.classloading.PluginLoader.java

public static Map<String, ClassLoader> getRegistry() {
    return Collections.unmodifiableMap(registry);
}

From source file:com.netflix.genie.agent.execution.services.impl.LaunchJobServiceImpl.java

/**
 * {@inheritDoc}//from ww  w  .  ja  v  a  2s. co m
 */
@Override
public void launchProcess(final File jobDirectory, final Map<String, String> environmentVariablesMap,
        final List<String> commandLine, final boolean interactive) throws JobLaunchException {

    if (!launched.compareAndSet(false, true)) {
        throw new IllegalStateException("Job already launched");
    }

    final ProcessBuilder processBuilder = new ProcessBuilder();

    // Validate job running directory
    if (jobDirectory == null) {
        throw new JobLaunchException("Job directory is null");
    } else if (!jobDirectory.exists()) {
        throw new JobLaunchException("Job directory does not exist: " + jobDirectory);
    } else if (!jobDirectory.isDirectory()) {
        throw new JobLaunchException("Job directory is not a directory: " + jobDirectory);
    } else if (!jobDirectory.canWrite()) {
        throw new JobLaunchException("Job directory is not writable: " + jobDirectory);
    }

    final Map<String, String> currentEnvironmentVariables = processBuilder.environment();

    if (environmentVariablesMap == null) {
        throw new JobLaunchException("Job environment variables map is null");
    }

    // Merge job environment variables into process inherited environment
    environmentVariablesMap.forEach((key, value) -> {
        final String replacedValue = currentEnvironmentVariables.put(key, value);
        if (StringUtils.isBlank(replacedValue)) {
            log.debug("Added job environment variable: {}={}", key, value);
        } else if (!replacedValue.equals(value)) {
            log.debug("Set job environment variable: {}={} (previous value: {})", key, value, replacedValue);
        }
    });

    // Validate arguments
    if (commandLine == null) {
        throw new JobLaunchException("Job command-line arguments is null");
    } else if (commandLine.isEmpty()) {
        throw new JobLaunchException("Job command-line arguments are empty");
    }

    // Configure arguments
    log.info("Job command-line: {}", Arrays.toString(commandLine.toArray()));

    final List<String> expandedCommandLine;
    try {
        expandedCommandLine = expandCommandLineVariables(commandLine,
                Collections.unmodifiableMap(currentEnvironmentVariables));
    } catch (final EnvUtils.VariableSubstitutionException e) {
        throw new JobLaunchException("Job command-line arguments variables could not be expanded");
    }

    if (!commandLine.equals(expandedCommandLine)) {
        log.info("Job command-line with variables expanded: {}",
                Arrays.toString(expandedCommandLine.toArray()));
    }

    processBuilder.command(expandedCommandLine);

    if (interactive) {
        processBuilder.inheritIO();
    } else {
        processBuilder.redirectError(PathUtils.jobStdErrPath(jobDirectory).toFile());
        processBuilder.redirectOutput(PathUtils.jobStdOutPath(jobDirectory).toFile());
    }

    if (killed.get()) {
        log.info("Job aborted, skipping launch");
    } else {
        log.info("Launching job");
        try {
            processReference.set(processBuilder.start());
        } catch (final IOException | SecurityException e) {
            throw new JobLaunchException("Failed to launch job: ", e);
        }
        log.info("Process launched (pid: {})", getPid(processReference.get()));
    }
}

From source file:ru.jts_dev.gameserver.parser.impl.SettingsHolder.java

/**
 * fills map with initial character equipment
 *
 * @param ctx - parsed context//from  w w  w.  j a v a2 s.c  om
 */
@Override
public final void exitInitial_equipment(final Initial_equipmentContext ctx) {
    for (final Character_equipmentContext cectx : ctx.character_equipment()) {
        final CharacterClass klass = cectx.klass;
        final Map<String, Integer> equipment = cectx.equipmentMap;

        initialEquipments.put(klass, Collections.unmodifiableMap(equipment));
    }
    super.exitInitial_equipment(ctx);
}

From source file:de.skuzzle.polly.http.internal.HttpEventImpl.java

@Override
public Map<String, String> parameterMap() {
    synchronized (this) {
        if (this.combinedParameters == null) {
            this.combinedParameters = new HashMap<>(this.get.size() + this.post.size() + this.cookies.size());

            this.combinedParameters.putAll(this.cookies);
            join(this.combinedParameters, this.get);
            join(this.combinedParameters, this.post);
            this.combinedParameters = Collections.unmodifiableMap(this.combinedParameters);
        }/*ww w.jav  a2  s  . co m*/
        return this.combinedParameters;
    }
}

From source file:com.opengamma.engine.view.compilation.CompiledViewDefinitionImpl.java

@Override
public Map<ValueSpecification, Set<ValueRequirement>> getTerminalValuesRequirements() {
    Map<ValueSpecification, Set<ValueRequirement>> allRequirements = new HashMap<ValueSpecification, Set<ValueRequirement>>();
    for (CompiledViewCalculationConfiguration compiledCalcConfig : getCompiledCalculationConfigurations()) {
        merge(allRequirements, compiledCalcConfig.getTerminalOutputSpecifications());
    }/* w  w  w.j a  v a2 s.c  om*/
    return Collections.unmodifiableMap(allRequirements);
}

From source file:com.opengamma.examples.livedata.ExampleLiveDataServer.java

/**
 * Gets the marketValues.//from   w w w  . j a  v  a 2  s  .co m
 * @return the marketValues
 */
public Map<String, FudgeMsg> getMarketValues() {
    return Collections.unmodifiableMap(_marketValues);
}

From source file:me.st28.flexseries.flexcore.player.uuid_tracker.PlayerUuidTracker.java

/**
 * @return an unmodifiable view of the name to UUID index map.
 *//* w  ww .  j a v a 2  s .  c o  m*/
public Map<String, UUID> getNamesToUuids() {
    return Collections.unmodifiableMap(namesToUuids);
}

From source file:com.sinosoft.one.mvc.web.portal.impl.WindowImpl.java

public Map<String, Object> getAttributes() {
    if (privateAttributes == null) {
        return Collections.emptyMap();
    } else {/*from   w  w  w  . j  a v a2 s.com*/
        return Collections.unmodifiableMap(privateAttributes);
    }
}