Get or create the singleton instance of the manager, loading all the plugins enabled in the given TSDB's Config. @return the shared instance of RpcManager. It's okay to hold this reference once obtained.
(final TSDB tsdb)
| 127 | * hold this reference once obtained. |
| 128 | */ |
| 129 | public static synchronized RpcManager instance(final TSDB tsdb) { |
| 130 | final RpcManager existing = INSTANCE.get(); |
| 131 | if (existing != null) { |
| 132 | return existing; |
| 133 | } |
| 134 | |
| 135 | final RpcManager manager = new RpcManager(tsdb); |
| 136 | |
| 137 | // Load any plugins that are enabled via Config. Fail if any plugin cannot be loaded. |
| 138 | |
| 139 | final ImmutableList.Builder<RpcPlugin> rpcBuilder = ImmutableList.builder(); |
| 140 | if (tsdb.getConfig().hasProperty("tsd.rpc.plugins")) { |
| 141 | final String[] plugins = tsdb.getConfig().getString("tsd.rpc.plugins").split(","); |
| 142 | manager.initializeRpcPlugins(plugins, rpcBuilder); |
| 143 | } |
| 144 | manager.rpc_plugins = rpcBuilder.build(); |
| 145 | |
| 146 | final ImmutableMap.Builder<String, TelnetRpc> telnetBuilder = ImmutableMap.builder(); |
| 147 | final ImmutableMap.Builder<String, HttpRpc> httpBuilder = ImmutableMap.builder(); |
| 148 | manager.initializeBuiltinRpcs(tsdb.getMode(), telnetBuilder, httpBuilder); |
| 149 | manager.telnet_commands = telnetBuilder.build(); |
| 150 | manager.http_commands = httpBuilder.build(); |
| 151 | |
| 152 | final ImmutableMap.Builder<String, HttpRpcPlugin> httpPluginsBuilder = ImmutableMap.builder(); |
| 153 | if (tsdb.getConfig().hasProperty("tsd.http.rpc.plugins")) { |
| 154 | final String[] plugins = tsdb.getConfig().getString("tsd.http.rpc.plugins").split(","); |
| 155 | manager.initializeHttpRpcPlugins(tsdb.getMode(), plugins, httpPluginsBuilder); |
| 156 | } |
| 157 | manager.http_plugin_commands = httpPluginsBuilder.build(); |
| 158 | |
| 159 | INSTANCE.set(manager); |
| 160 | return manager; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * @return {@code true} if the shared instance has been initialized; |