Search in sources :

Example 1 with GridClientPartitionAffinity

use of org.apache.ignite.internal.client.GridClientPartitionAffinity in project ignite by apache.

the class ClientAbstractMultiNodeSelfTest method clientConfiguration.

/**
 * @return Client configuration for the test.
 */
protected GridClientConfiguration clientConfiguration() throws GridClientException {
    GridClientConfiguration cfg = new GridClientConfiguration();
    cfg.setBalancer(getBalancer());
    cfg.setTopologyRefreshFrequency(TOP_REFRESH_FREQ);
    cfg.setProtocol(protocol());
    cfg.setServers(Arrays.asList(serverAddress()));
    cfg.setSslContextFactory(sslContextFactory());
    GridClientDataConfiguration loc = new GridClientDataConfiguration();
    GridClientDataConfiguration partitioned = new GridClientDataConfiguration();
    partitioned.setName(PARTITIONED_CACHE_NAME);
    partitioned.setAffinity(new GridClientPartitionAffinity());
    GridClientDataConfiguration replicated = new GridClientDataConfiguration();
    replicated.setName(REPLICATED_CACHE_NAME);
    GridClientDataConfiguration replicatedAsync = new GridClientDataConfiguration();
    replicatedAsync.setName(REPLICATED_ASYNC_CACHE_NAME);
    cfg.setDataConfigurations(Arrays.asList(loc, partitioned, replicated, replicatedAsync));
    return cfg;
}
Also used : GridClientPartitionAffinity(org.apache.ignite.internal.client.GridClientPartitionAffinity) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) GridClientDataConfiguration(org.apache.ignite.internal.client.GridClientDataConfiguration)

Example 2 with GridClientPartitionAffinity

use of org.apache.ignite.internal.client.GridClientPartitionAffinity in project ignite by apache.

the class ClientCacheBenchmark method configuration.

/**
 * @return Test client configuration.
 */
private GridClientConfiguration configuration() {
    GridClientConfiguration cfg = new GridClientConfiguration();
    cfg.setServers(Collections.singleton("localhost:11211"));
    GridClientDataConfiguration cacheCfg = new GridClientDataConfiguration();
    cacheCfg.setName("partitioned");
    cacheCfg.setAffinity(new GridClientPartitionAffinity());
    cfg.setDataConfigurations(Collections.singletonList(cacheCfg));
    return cfg;
}
Also used : GridClientPartitionAffinity(org.apache.ignite.internal.client.GridClientPartitionAffinity) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) GridClientDataConfiguration(org.apache.ignite.internal.client.GridClientDataConfiguration)

Example 3 with GridClientPartitionAffinity

use of org.apache.ignite.internal.client.GridClientPartitionAffinity in project ignite by apache.

the class GridClientImpl method tryInitTopology.

/**
 * Tries to init client topology using configured set of servers or routers.
 *
 * @throws GridClientException If initialisation failed.
 * @throws InterruptedException If initialisation was interrupted.
 */
private void tryInitTopology() throws GridClientException, InterruptedException {
    boolean hasSrvs = routers.isEmpty();
    final Collection<InetSocketAddress> connSrvs = (hasSrvs) ? new LinkedHashSet<>(srvs) : routers;
    if (hasSrvs) {
        // Add REST endpoints for all nodes from previous topology snapshot.
        try {
            for (GridClientNodeImpl node : top.nodes()) {
                Collection<InetSocketAddress> endpoints = node.availableAddresses(cfg.getProtocol(), true);
                List<InetSocketAddress> resolvedEndpoints = new ArrayList<>(endpoints.size());
                for (InetSocketAddress endpoint : endpoints) if (!endpoint.isUnresolved())
                    resolvedEndpoints.add(endpoint);
                boolean sameHost = node.attributes().isEmpty() || F.containsAny(U.allLocalMACs(), node.attribute(ATTR_MACS).toString().split(", "));
                if (sameHost) {
                    Collections.sort(resolvedEndpoints, U.inetAddressesComparator(true));
                    connSrvs.addAll(resolvedEndpoints);
                } else {
                    for (InetSocketAddress endpoint : resolvedEndpoints) if (!endpoint.getAddress().isLoopbackAddress())
                        connSrvs.add(endpoint);
                }
            }
        } catch (GridClientDisconnectedException ignored) {
        // Ignore if latest topology update failed.
        }
    }
    connMgr.init(connSrvs);
    Map<String, GridClientCacheMode> overallCaches = new HashMap<>();
    for (GridClientNodeImpl node : top.nodes()) overallCaches.putAll(node.caches());
    for (Map.Entry<String, GridClientCacheMode> entry : overallCaches.entrySet()) {
        GridClientDataAffinity affinity = affinity(entry.getKey());
        if (affinity instanceof GridClientPartitionAffinity && entry.getValue() != GridClientCacheMode.PARTITIONED)
            log.warning(GridClientPartitionAffinity.class.getSimpleName() + " is used for a cache configured " + "for non-partitioned mode [cacheName=" + entry.getKey() + ", cacheMode=" + entry.getValue() + ']');
    }
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GridClientPartitionAffinity(org.apache.ignite.internal.client.GridClientPartitionAffinity) InetSocketAddress(java.net.InetSocketAddress) GridClientDisconnectedException(org.apache.ignite.internal.client.GridClientDisconnectedException) ArrayList(java.util.ArrayList) GridClientDataAffinity(org.apache.ignite.internal.client.GridClientDataAffinity) GridClientCacheMode(org.apache.ignite.internal.client.GridClientCacheMode) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 4 with GridClientPartitionAffinity

use of org.apache.ignite.internal.client.GridClientPartitionAffinity in project ignite by apache.

the class GridClientImpl method tryInit.

/**
 * Tries to init connection manager using configured set of servers or routers.
 *
 * @throws GridClientException If initialisation failed.
 * @throws InterruptedException If initialisation was interrupted.
 */
private void tryInit() throws GridClientException, InterruptedException {
    connMgr.init(addresses());
    Map<String, GridClientCacheMode> overallCaches = new HashMap<>();
    for (GridClientNodeImpl node : top.nodes()) overallCaches.putAll(node.caches());
    for (Map.Entry<String, GridClientCacheMode> entry : overallCaches.entrySet()) {
        GridClientDataAffinity affinity = affinity(entry.getKey());
        if (affinity instanceof GridClientPartitionAffinity && entry.getValue() != GridClientCacheMode.PARTITIONED)
            log.warning(GridClientPartitionAffinity.class.getSimpleName() + " is used for a cache configured " + "for non-partitioned mode [cacheName=" + entry.getKey() + ", cacheMode=" + entry.getValue() + ']');
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) GridClientPartitionAffinity(org.apache.ignite.internal.client.GridClientPartitionAffinity) GridClientCacheMode(org.apache.ignite.internal.client.GridClientCacheMode) GridClientDataAffinity(org.apache.ignite.internal.client.GridClientDataAffinity) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Aggregations

GridClientPartitionAffinity (org.apache.ignite.internal.client.GridClientPartitionAffinity)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 GridClientCacheMode (org.apache.ignite.internal.client.GridClientCacheMode)2 GridClientConfiguration (org.apache.ignite.internal.client.GridClientConfiguration)2 GridClientDataAffinity (org.apache.ignite.internal.client.GridClientDataAffinity)2 GridClientDataConfiguration (org.apache.ignite.internal.client.GridClientDataConfiguration)2 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 GridClientDisconnectedException (org.apache.ignite.internal.client.GridClientDisconnectedException)1