Skip to content

Commit

Permalink
Removing custom shorthand registration
Browse files Browse the repository at this point in the history
This is a follow-on to 110e22c

I just changed the resource containing shorthand->class mappings to a
fully-qualified package-and-filename string.  That dramatically
reduces the odds of accidentally overwriting the file with nonsense,
but it also provides no clean way for third-party implementors to add
mappings.  I don't think centralizing this information in a file is
the way we want to approach custom shorthands anyway.  Removing the
custom shorthand feature and making the index and storage backend
mappings immutable again.

This commit does not affect the standard shorthands.  For example,
"cassandra" is still a valid shorthand.

For #929
  • Loading branch information
dalaro committed Jan 23, 2015
1 parent 110e22c commit 7bd3abf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 64 deletions.
Expand Up @@ -703,48 +703,4 @@ private static Locker openManagedLocker(String classname, String lockerName) {
throw new IllegalArgumentException("Could not instantiate implementation: " + classname, e);
}
}

static {
Properties props;

try {
props = new Properties();
final String res = TitanConstants.TITAN_PROPERTIES_RESOURCE_NAME;
log.debug("Reading Titan config resource: {}", res);
InputStream in = TitanFactory.class.getClassLoader().getResourceAsStream(res);
if (in != null && in.available() > 0) {
props.load(in);
}
} catch (IOException e) {
throw new AssertionError(e);
}
registerShorthands(props, "storage.", StandardStoreManager.getAllManagerClasses());
registerShorthands(props, "index.", StandardIndexProvider.getAllProviderClasses());
}

public static final void registerShorthands(Properties props, String prefix, Map<String, String> shorthands) {
for (String key : props.stringPropertyNames()) {
if (key.toLowerCase().startsWith(prefix)) {
String shorthand = key.substring(prefix.length()).toLowerCase();
String clazz = props.getProperty(key);
shorthands.put(shorthand, clazz);
log.debug("Registering shorthand [{}] for [{}]", shorthand, clazz);
}
}
}

//
// public synchronized static final void registerStorageManager(String name, Class<? extends StoreManager> clazz) {
// Preconditions.checkNotNull(name);
// Preconditions.checkNotNull(clazz);
// Preconditions.checkArgument(!StringUtils.isEmpty(name));
// Preconditions.checkNotNull(!REGISTERED_STORAGE_MANAGERS.containsKey(name),"A storage manager has already been registered for name: " + name);
// REGISTERED_STORAGE_MANAGERS.put(name,clazz);
// }
//
// public synchronized static final void removeStorageManager(String name) {
// Preconditions.checkNotNull(name);
// REGISTERED_STORAGE_MANAGERS.remove(name);
// }

}
Expand Up @@ -29,8 +29,8 @@ public enum StandardIndexProvider {
this.shorthands = shorthands;
}

private static final List<String> ALL_SHORTHANDS;
private static final Map<String, String> ALL_MANAGER_CLASSES;
private static final ImmutableList<String> ALL_SHORTHANDS;
private static final ImmutableMap<String, String> ALL_MANAGER_CLASSES;

public List<String> getShorthands() {
return shorthands;
Expand All @@ -42,16 +42,16 @@ public String getProviderName() {

static {
StandardIndexProvider backends[] = values();
List<String> shorthandList = new ArrayList<String>();
Map<String, String> shorthandClassMap = new HashMap<String, String>();
List<String> tempShorthands = new ArrayList<String>();
Map<String, String> tempClassMap = new HashMap<String, String>();
for (int i = 0; i < backends.length; i++) {
shorthandList.addAll(backends[i].getShorthands());
tempShorthands.addAll(backends[i].getShorthands());
for (String shorthand : backends[i].getShorthands()) {
shorthandClassMap.put(shorthand, backends[i].getProviderName());
tempClassMap.put(shorthand, backends[i].getProviderName());
}
}
ALL_SHORTHANDS = shorthandList;
ALL_MANAGER_CLASSES = shorthandClassMap;
ALL_SHORTHANDS = ImmutableList.copyOf(tempShorthands);
ALL_MANAGER_CLASSES = ImmutableMap.copyOf(tempClassMap);
}

public static final List<String> getAllShorthands() {
Expand Down
Expand Up @@ -37,21 +37,21 @@ public String getManagerClass() {
return managerClass;
}

private static final List<String> ALL_SHORTHANDS;
private static final Map<String, String> ALL_MANAGER_CLASSES;
private static final ImmutableList<String> ALL_SHORTHANDS;
private static final ImmutableMap<String, String> ALL_MANAGER_CLASSES;

static {
StandardStoreManager backends[] = values();
List<String> shorthandList = new ArrayList<String>();
Map<String, String> shorthandClassMap = new HashMap<String, String>();
List<String> tempShorthands = new ArrayList<String>();
Map<String, String> tempClassMap = new HashMap<String, String>();
for (int i = 0; i < backends.length; i++) {
shorthandList.addAll(backends[i].getShorthands());
tempShorthands.addAll(backends[i].getShorthands());
for (String shorthand : backends[i].getShorthands()) {
shorthandClassMap.put(shorthand, backends[i].getManagerClass());
tempClassMap.put(shorthand, backends[i].getManagerClass());
}
}
ALL_SHORTHANDS = shorthandList;
ALL_MANAGER_CLASSES = shorthandClassMap;
ALL_SHORTHANDS = ImmutableList.copyOf(tempShorthands);
ALL_MANAGER_CLASSES = ImmutableMap.copyOf(tempClassMap);
}

public static List<String> getAllShorthands() {
Expand Down
Expand Up @@ -18,8 +18,6 @@ public class TitanConstants {

public static final String TITAN_PROPERTIES_FILE = "titan.internal.properties";

public static final String TITAN_PROPERTIES_RESOURCE_NAME;

/**
* Runtime version of Titan, as read from a properties file inside the core jar
*/
Expand All @@ -46,8 +44,6 @@ public class TitanConstants {
InputStream is = TitanFactory.class.getClassLoader().getResourceAsStream(resourceName);
Preconditions.checkNotNull(is, "Unable to locate classpath resource " + resourceName + " containing Titan version");

TITAN_PROPERTIES_RESOURCE_NAME = resourceName;

Properties props = new Properties();

try {
Expand Down

0 comments on commit 7bd3abf

Please sign in to comment.