Search in sources :

Example 1 with GridClientClosedException

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

the class ClientAbstractSelfTest method testNoAsyncExceptions.

/**
     * Check async API methods don't generate exceptions.
     *
     * @throws Exception If failed.
     */
public void testNoAsyncExceptions() throws Exception {
    GridClient client = client();
    GridClientData data = client.data(CACHE_NAME);
    GridClientCompute compute = client.compute().projection(new GridClientPredicate<GridClientNode>() {

        @Override
        public boolean apply(GridClientNode e) {
            return false;
        }
    });
    Map<String, GridClientFuture<?>> futs = new LinkedHashMap<>();
    futs.put("exec", compute.executeAsync("taskName", "taskArg"));
    futs.put("affExec", compute.affinityExecuteAsync("taskName", "cacheName", "affKey", "taskArg"));
    futs.put("refreshById", compute.refreshNodeAsync(UUID.randomUUID(), true, true));
    futs.put("refreshByIP", compute.refreshNodeAsync("nodeIP", true, true));
    futs.put("refreshTop", compute.refreshTopologyAsync(true, true));
    GridClientFactory.stop(client.id(), false);
    futs.put("put", data.putAsync("key", "val"));
    futs.put("putAll", data.putAllAsync(F.asMap("key", "val")));
    futs.put("get", data.getAsync("key"));
    futs.put("getAll", data.getAllAsync(Collections.singletonList("key")));
    futs.put("remove", data.removeAsync("key"));
    futs.put("removeAll", data.removeAllAsync(Collections.singletonList("key")));
    futs.put("replace", data.replaceAsync("key", "val"));
    futs.put("cas", data.casAsync("key", "val", "val2"));
    futs.put("metrics", data.metricsAsync());
    for (Map.Entry<String, GridClientFuture<?>> e : futs.entrySet()) {
        try {
            e.getValue().get();
            info("Expects '" + e.getKey() + "' fails with grid client exception.");
        } catch (GridServerUnreachableException | GridClientClosedException ignore) {
        // No op: compute projection is empty.
        }
    }
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientFuture(org.apache.ignite.internal.client.GridClientFuture) GridClient(org.apache.ignite.internal.client.GridClient) LinkedHashMap(java.util.LinkedHashMap) GridServerUnreachableException(org.apache.ignite.internal.client.GridServerUnreachableException) GridClientData(org.apache.ignite.internal.client.GridClientData) GridClientClosedException(org.apache.ignite.internal.client.GridClientClosedException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with GridClientClosedException

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

the class ClientAbstractSelfTest method testForceShutdown.

/**
     * @throws Exception If failed.
     */
public void testForceShutdown() throws Exception {
    GridClientCompute compute = client.compute();
    Object taskArg = getTaskArgument();
    String taskName = getSleepTaskName();
    GridClientFuture<Object> fut = compute.executeAsync(taskName, taskArg);
    GridClientFactory.stop(client.id(), false);
    try {
        fut.get();
    } catch (GridClientClosedException ignored) {
        return;
    }
    Assert.fail("Expected GridClientClosedException.");
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientClosedException(org.apache.ignite.internal.client.GridClientClosedException)

Example 3 with GridClientClosedException

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

the class GridClientNioTcpConnection method makeRequest.

/**
     * Makes request to server via tcp protocol and returns a future that will be completed when response is received.
     *
     * @param msg Message to request,
     * @param fut Future that will handle response.
     * @param routeMode If {@code true} then this method should overwrite session token by the cached one,
     *     otherwise keep original value.
     * @return Response object.
     * @throws GridClientConnectionResetException If request failed.
     * @throws GridClientClosedException If client closed.
     */
private <R> GridClientFutureAdapter<R> makeRequest(GridClientMessage msg, final TcpClientFuture<R> fut, boolean routeMode) throws GridClientConnectionResetException, GridClientClosedException {
    assert msg != null;
    if (msg instanceof GridClientPingPacket) {
        long now = U.currentTimeMillis();
        if (Math.min(now, lastPingRcvTime) - lastPingSndTime >= pingTimeout)
            close(FAILED, false, new IOException("Did not receive any packets within ping response interval (connection is " + "considered to be half-opened) [lastPingReceiveTime=" + lastPingRcvTime + ", lastPingSendTime=" + lastPingSndTime + ", now=" + now + ", timeout=" + pingTimeout + ", addr=" + serverAddress() + ']'));
        else // or we've already waiting for ping response.
        if (now - lastPingSndTime > pingInterval && lastPingRcvTime != Long.MAX_VALUE) {
            lastPingRcvTime = Long.MAX_VALUE;
            ses.send(GridClientPingPacket.PING_MESSAGE);
            lastPingSndTime = now;
        }
    } else {
        long reqId = reqIdCntr.getAndIncrement();
        msg.requestId(reqId);
        if (!routeMode) {
            msg.clientId(clientId);
            msg.sessionToken(sesTok);
        }
        fut.pendingMessage(msg);
        checkClosed(closeReason);
        GridClientFutureAdapter old = pendingReqs.putIfAbsent(reqId, fut);
        assert old == null;
        GridNioFuture<?> sndFut = ses.send(msg);
        lastMsgSndTime = U.currentTimeMillis();
        if (routeMode) {
            sndFut.listen(new CI1<IgniteInternalFuture<?>>() {

                @Override
                public void apply(IgniteInternalFuture<?> sndFut) {
                    try {
                        sndFut.get();
                    } catch (Exception e) {
                        close(FAILED, false, e);
                        fut.onDone(getCloseReasonAsException(FAILED, e));
                    }
                }
            });
        } else {
            try {
                sndFut.get();
            } catch (Exception e) {
                throw new GridClientConnectionResetException("Failed to send message over connection " + "(will try to reconnect): " + serverAddress(), e);
            }
        }
    }
    return fut;
}
Also used : GridClientFutureAdapter(org.apache.ignite.internal.client.impl.GridClientFutureAdapter) GridClientPingPacket(org.apache.ignite.internal.processors.rest.client.message.GridClientPingPacket) IOException(java.io.IOException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridClientException(org.apache.ignite.internal.client.GridClientException) GridClientAuthenticationException(org.apache.ignite.internal.client.GridClientAuthenticationException) GridClientClosedException(org.apache.ignite.internal.client.GridClientClosedException) IOException(java.io.IOException)

Aggregations

GridClientClosedException (org.apache.ignite.internal.client.GridClientClosedException)3 GridClientCompute (org.apache.ignite.internal.client.GridClientCompute)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 GridClient (org.apache.ignite.internal.client.GridClient)1 GridClientAuthenticationException (org.apache.ignite.internal.client.GridClientAuthenticationException)1 GridClientData (org.apache.ignite.internal.client.GridClientData)1 GridClientException (org.apache.ignite.internal.client.GridClientException)1 GridClientFuture (org.apache.ignite.internal.client.GridClientFuture)1 GridClientNode (org.apache.ignite.internal.client.GridClientNode)1 GridServerUnreachableException (org.apache.ignite.internal.client.GridServerUnreachableException)1 GridClientFutureAdapter (org.apache.ignite.internal.client.impl.GridClientFutureAdapter)1 GridClientPingPacket (org.apache.ignite.internal.processors.rest.client.message.GridClientPingPacket)1