Search in sources :

Example 1 with SymbolTableMetadata

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());
}
Also used : SymbolTableMetadata(com.linkedin.data.codec.symbol.SymbolTableMetadata) Test(org.testng.annotations.Test)

Example 2 with SymbolTableMetadata

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());
}
Also used : SymbolTableMetadata(com.linkedin.data.codec.symbol.SymbolTableMetadata) Test(org.testng.annotations.Test)

Example 3 with SymbolTableMetadata

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);
}
Also used : SymbolTableMetadata(com.linkedin.data.codec.symbol.SymbolTableMetadata) InMemorySymbolTable(com.linkedin.data.codec.symbol.InMemorySymbolTable) SymbolTable(com.linkedin.data.codec.symbol.SymbolTable) EmptySymbolTable(com.linkedin.data.codec.symbol.EmptySymbolTable) ByteString(com.linkedin.data.ByteString) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

SymbolTableMetadata (com.linkedin.data.codec.symbol.SymbolTableMetadata)3 Test (org.testng.annotations.Test)2 ByteString (com.linkedin.data.ByteString)1 EmptySymbolTable (com.linkedin.data.codec.symbol.EmptySymbolTable)1 InMemorySymbolTable (com.linkedin.data.codec.symbol.InMemorySymbolTable)1 SymbolTable (com.linkedin.data.codec.symbol.SymbolTable)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1