
com.cinchapi.impromptu.server.api.backend.Backends Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of impromptu-server-api Show documentation
Show all versions of impromptu-server-api Show documentation
APIs for extending the functionality of Impromptu Server with custom recipes, actions, etc
The newest version!
/*
* Cinchapi Inc. CONFIDENTIAL
* Copyright (c) 2018 Cinchapi Inc. All Rights Reserved.
*
* All information contained herein is, and remains the property of Cinchapi.
* The intellectual and technical concepts contained herein are proprietary to
* Cinchapi and may be covered by U.S. and Foreign Patents, patents in process,
* and are protected by trade secret or copyright law. Dissemination of this
* information or reproduction of this material is strictly forbidden unless
* prior written permission is obtained from Cinchapi. Access to the source code
* contained herein is hereby forbidden to anyone except current Cinchapi
* employees, managers or contractors who have executed Confidentiality and
* Non-disclosure agreements explicitly covering such access.
*
* The copyright notice above does not evidence any actual or intended
* publication or disclosure of this source code, which includes information
* that is confidential and/or proprietary, and is a trade secret, of Cinchapi.
*
* ANY REPRODUCTION, MODIFICATION, DISTRIBUTION, PUBLIC PERFORMANCE, OR PUBLIC
* DISPLAY OF OR THROUGH USE OF THIS SOURCE CODE WITHOUT THE EXPRESS WRITTEN
* CONSENT OF COMPANY IS STRICTLY PROHIBITED, AND IN VIOLATION OF APPLICABLE
* LAWS AND INTERNATIONAL TREATIES. THE RECEIPT OR POSSESSION OF THIS SOURCE
* CODE AND/OR RELATED INFORMATION DOES NOT CONVEY OR IMPLY ANY RIGHTS TO
* REPRODUCE, DISCLOSE OR DISTRIBUTE ITS CONTENTS, OR TO MANUFACTURE, USE, OR
* SELL ANYTHING THAT IT MAY DESCRIBE, IN WHOLE OR IN PART.
*/
package com.cinchapi.impromptu.server.api.backend;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.SortedMap;
import com.google.common.collect.Maps;
import com.google.common.hash.Hasher;
import com.google.common.hash.Hashing;
/**
* A collection of utility functions for
* {@link com.cinchapi.impromptu.server.Backend backends}.
*
* @author Jeff Nelson
*/
public final class Backends {
/**
* Return the canonical identifier that should be used to refer to a
* {@link com.cinchapi.impromptu.server.Backend} with the specified
* connection parameters.
*
* @param a sorted map of the config data
* @return a unique string to identify the backend
*/
public static String identify(Map config) {
if(!(config instanceof SortedMap)) {
SortedMap sorted = Maps.newTreeMap();
config.forEach((key, value) -> {
sorted.put(key, value);
});
config = sorted;
}
return identify((SortedMap) config);
}
/**
* Return the canonical identifier that should be used to refer to a
* {@link com.cinchapi.impromptu.server.Backend} with the specified
* connection parameters.
*
* NOTE: Keys that start with __ are considered meta configuration
* and won't be used to identify the backend.
*
*
* @param config a sorted map of the config data
* @return a unique string to identify the backend
*/
public static String identify(SortedMap config) {
Hasher hasher = Hashing.murmur3_128().newHasher();
config.forEach((key, value) -> {
if(!key.startsWith("__")) {
hasher.putString(key, StandardCharsets.UTF_8);
hasher.putString(value.toString(), StandardCharsets.UTF_8);
}
});
return hasher.hash().toString();
}
private Backends() {/* no-op */}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy