Search in sources :

Example 1 with ClientAddressFinder

use of org.apache.ignite.client.ClientAddressFinder in project ignite by apache.

the class ThinClientPartitionAwarenessDiscoveryTest method getClientConfigurationWithDiscovery.

/**
 * Provide ClientConfiguration with addrResolver that find all alive nodes.
 */
private ClientConfiguration getClientConfigurationWithDiscovery(int... excludeIdx) {
    Set<Integer> exclude = Arrays.stream(excludeIdx).boxed().collect(Collectors.toSet());
    ClientAddressFinder addrFinder = () -> IgnitionEx.allGrids().stream().map(node -> {
        int port = (Integer) node.cluster().localNode().attributes().get(CLIENT_LISTENER_PORT);
        if (exclude.contains(port - DFLT_PORT))
            return null;
        return "127.0.0.1:" + port;
    }).filter(Objects::nonNull).toArray(String[]::new);
    return new ClientConfiguration().setAddressesFinder(addrFinder).setPartitionAwarenessEnabled(true);
}
Also used : ClientAddressFinder(org.apache.ignite.client.ClientAddressFinder) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration)

Example 2 with ClientAddressFinder

use of org.apache.ignite.client.ClientAddressFinder in project ignite by apache.

the class JavaThinClient method clientAddressFinder.

void clientAddressFinder() throws Exception {
    // tag::client-address-finder[]
    ClientAddressFinder finder = () -> {
        String[] dynamicServerAddresses = fetchServerAddresses();
        return dynamicServerAddresses;
    };
    ClientConfiguration cfg = new ClientConfiguration().setAddressesFinder(finder).setPartitionAwarenessEnabled(true);
    try (IgniteClient client = Ignition.startClient(cfg)) {
        ClientCache<Integer, String> cache = client.cache("myCache");
    // Put, get, or remove data from the cache...
    } catch (ClientException e) {
        System.err.println(e.getMessage());
    }
// end::client-address-finder[]
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientAddressFinder(org.apache.ignite.client.ClientAddressFinder) ClientException(org.apache.ignite.client.ClientException) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration)

Aggregations

ClientAddressFinder (org.apache.ignite.client.ClientAddressFinder)2 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)2 ClientException (org.apache.ignite.client.ClientException)1 IgniteClient (org.apache.ignite.client.IgniteClient)1 ThinClientConfiguration (org.apache.ignite.configuration.ThinClientConfiguration)1