Search in sources :

Example 1 with GridClientPredicate

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

the class ClientAbstractMultiNodeSelfTest method testEmptyProjections.

/**
     * @throws Exception If failed.
     */
public void testEmptyProjections() throws Exception {
    final GridClientCompute dflt = client.compute();
    Collection<? extends GridClientNode> nodes = dflt.nodes();
    assertEquals(NODES_CNT, nodes.size());
    Iterator<? extends GridClientNode> iter = nodes.iterator();
    final GridClientCompute singleNodePrj = dflt.projection(Collections.singletonList(iter.next()));
    final GridClientNode second = iter.next();
    final GridClientPredicate<GridClientNode> targetFilter = new GridClientPredicate<GridClientNode>() {

        @Override
        public boolean apply(GridClientNode node) {
            return node.nodeId().equals(second.nodeId());
        }
    };
    GridTestUtils.assertThrows(log(), new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return singleNodePrj.projection(second);
        }
    }, GridClientException.class, null);
    GridTestUtils.assertThrows(log(), new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return singleNodePrj.projection(targetFilter);
        }
    }, GridClientException.class, null);
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientPredicate(org.apache.ignite.internal.client.GridClientPredicate) IgniteException(org.apache.ignite.IgniteException) GridClientException(org.apache.ignite.internal.client.GridClientException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 2 with GridClientPredicate

use of org.apache.ignite.internal.client.GridClientPredicate 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)

Aggregations

GridClientException (org.apache.ignite.internal.client.GridClientException)2 GridClientNode (org.apache.ignite.internal.client.GridClientNode)2 GridClientPredicate (org.apache.ignite.internal.client.GridClientPredicate)2 IgniteException (org.apache.ignite.IgniteException)1 GridClientCompute (org.apache.ignite.internal.client.GridClientCompute)1 GridClientDataConfiguration (org.apache.ignite.internal.client.GridClientDataConfiguration)1 GridClientLoadBalancer (org.apache.ignite.internal.client.balancer.GridClientLoadBalancer)1 GridClientRandomBalancer (org.apache.ignite.internal.client.balancer.GridClientRandomBalancer)1 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)1