use of com.linkedin.data.codec.symbol.SymbolTableMetadata in project rest.li by linkedin.
the class TestSymbolTableNameHandler method testExtractTableInfoLocalTable.
@Test
public void testExtractTableInfoLocalTable() {
SymbolTableMetadata metadata = SYMBOL_TABLE_NAME_HANDLER.extractMetadata("https://OtherHost:100/service|Prefix-1000");
Assert.assertEquals(metadata.getServerNodeUri(), "https://OtherHost:100/service");
Assert.assertEquals(metadata.getSymbolTableName(), "Prefix-1000");
Assert.assertTrue(metadata.isRemote());
}
use of com.linkedin.data.codec.symbol.SymbolTableMetadata in project rest.li by linkedin.
the class TestSymbolTableNameHandler method testExtractTableInfoRemoteTable.
@Test
public void testExtractTableInfoRemoteTable() {
SymbolTableMetadata metadata = SYMBOL_TABLE_NAME_HANDLER.extractMetadata("https://Host:100/service|Prefix-1000");
Assert.assertEquals(metadata.getServerNodeUri(), "https://Host:100/service");
Assert.assertEquals(metadata.getSymbolTableName(), "Prefix-1000");
Assert.assertFalse(metadata.isRemote());
}
use of com.linkedin.data.codec.symbol.SymbolTableMetadata in project rest.li by linkedin.
the class RestLiSymbolTableProvider method getSymbolTable.
@Override
public SymbolTable getSymbolTable(String symbolTableName) {
try {
SymbolTableMetadata metadata = _symbolTableNameHandler.extractMetadata(symbolTableName);
String serverNodeUri = metadata.getServerNodeUri();
String tableName = metadata.getSymbolTableName();
boolean isRemote = metadata.isRemote();
// Check if it's the default table name.
if (tableName.equals(_defaultResponseSymbolTableName)) {
return _defaultResponseSymbolTable;
}
// First check the cache.
SymbolTable symbolTable = _symbolTableNameToSymbolTableCache.getIfPresent(tableName);
if (symbolTable != null) {
return symbolTable;
}
// If this is a local table, and we didn't find it in the cache, cry foul.
if (!isRemote) {
throw new IllegalStateException("Unable to fetch symbol table with name: " + symbolTableName);
}
// Ok, we didn't find it in the cache, let's go query the service the table was served from.
URI symbolTableUri = new URI(serverNodeUri + "/" + RestLiSymbolTableRequestHandler.SYMBOL_TABLE_URI_PATH + "/" + tableName);
symbolTable = fetchRemoteSymbolTable(symbolTableUri, Collections.emptyMap(), false);
if (symbolTable != null) {
// Cache the retrieved table.
_symbolTableNameToSymbolTableCache.put(tableName, symbolTable);
return symbolTable;
}
} catch (URISyntaxException ex) {
LOGGER.error("Failed to construct symbol table URI from symbol table name: " + symbolTableName, ex);
}
throw new IllegalStateException("Unable to fetch symbol table with name: " + symbolTableName);
}
Aggregations