Search in sources :

Example 6 with GridClientDataConfiguration

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

the class GridClientImpl method data.

/** {@inheritDoc} */
@Override
public GridClientData data(@Nullable final String cacheName) throws GridClientException {
    checkClosed();
    Object key = maskNull(cacheName);
    GridClientDataImpl data = dataMap.get(key);
    if (data == null) {
        GridClientDataConfiguration dataCfg = cfg.getDataConfiguration(cacheName);
        if (dataCfg == null && cacheName != null)
            throw new GridClientException("Data configuration for given cache name was not provided: " + cacheName);
        GridClientLoadBalancer balancer = dataCfg != null ? dataCfg.getPinnedBalancer() : new GridClientRandomBalancer();
        GridClientPredicate<GridClientNode> cacheNodes = new GridClientPredicate<GridClientNode>() {

            @Override
            public boolean apply(GridClientNode e) {
                return e.caches().containsKey(cacheName);
            }

            @Override
            public String toString() {
                return "GridClientHasCacheFilter [cacheName=" + cacheName + "]";
            }
        };
        data = new GridClientDataImpl(cacheName, this, null, cacheNodes, balancer, null, cfg.isEnableMetricsCache());
        GridClientDataImpl old = dataMap.putIfAbsent(key, data);
        if (old != null)
            data = old;
    }
    return data;
}
Also used : GridClientException(org.apache.ignite.internal.client.GridClientException) GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientPredicate(org.apache.ignite.internal.client.GridClientPredicate) GridClientLoadBalancer(org.apache.ignite.internal.client.balancer.GridClientLoadBalancer) GridClientDataConfiguration(org.apache.ignite.internal.client.GridClientDataConfiguration) GridClientRandomBalancer(org.apache.ignite.internal.client.balancer.GridClientRandomBalancer)

Example 7 with GridClientDataConfiguration

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

the class ClientPropertiesConfigurationSelfTest method validateConfig.

/**
     * Validate loaded configuration.
     *
     * @param expDataCfgs Expected data configurations count.
     * @param cfg Client configuration to validate.
     */
private void validateConfig(int expDataCfgs, GridClientConfiguration cfg) {
    assertEquals(GridClientRandomBalancer.class, cfg.getBalancer().getClass());
    assertEquals(10000, cfg.getConnectTimeout());
    assertEquals(null, cfg.getSecurityCredentialsProvider());
    assertEquals(expDataCfgs, cfg.getDataConfigurations().size());
    if (expDataCfgs == 2) {
        GridClientDataConfiguration nullCfg = cfg.getDataConfiguration(null);
        assertEquals(null, nullCfg.getName());
        assertEquals(null, nullCfg.getAffinity());
        assertEquals(GridClientRandomBalancer.class, nullCfg.getPinnedBalancer().getClass());
        GridClientDataConfiguration partCfg = cfg.getDataConfiguration("partitioned");
        assertEquals("partitioned", partCfg.getName());
        assertEquals(GridClientPartitionAffinity.class, partCfg.getAffinity().getClass());
        assertEquals(GridClientRoundRobinBalancer.class, partCfg.getPinnedBalancer().getClass());
    }
    assertEquals(DFLT_MAX_CONN_IDLE_TIME, cfg.getMaxConnectionIdleTime());
    assertEquals(GridClientProtocol.TCP, cfg.getProtocol());
    assertEquals(Arrays.asList("localhost:11211"), new ArrayList<>(cfg.getServers()));
    assertEquals(true, cfg.isEnableAttributesCache());
    assertEquals(true, cfg.isEnableMetricsCache());
    assertEquals(true, cfg.isTcpNoDelay());
    assertEquals(null, cfg.getSslContextFactory(), null);
    assertEquals(DFLT_TOP_REFRESH_FREQ, cfg.getTopologyRefreshFrequency());
}
Also used : GridClientDataConfiguration(org.apache.ignite.internal.client.GridClientDataConfiguration)

Aggregations

GridClientDataConfiguration (org.apache.ignite.internal.client.GridClientDataConfiguration)7 GridClientConfiguration (org.apache.ignite.internal.client.GridClientConfiguration)5 GridClientPartitionAffinity (org.apache.ignite.internal.client.GridClientPartitionAffinity)2 ThreadFactory (java.util.concurrent.ThreadFactory)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 GridClientException (org.apache.ignite.internal.client.GridClientException)1 GridClientNode (org.apache.ignite.internal.client.GridClientNode)1 GridClientPredicate (org.apache.ignite.internal.client.GridClientPredicate)1 GridClientLoadBalancer (org.apache.ignite.internal.client.balancer.GridClientLoadBalancer)1 GridClientRandomBalancer (org.apache.ignite.internal.client.balancer.GridClientRandomBalancer)1 FileSystemXmlApplicationContext (org.springframework.context.support.FileSystemXmlApplicationContext)1