Search in sources :

Example 16 with ClientException

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

Example 17 with ClientException

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

the class JavaThinClient method veiwsystemview.

void veiwsystemview() {
    // tag::system-views[]
    ClientConfiguration cfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
    try (IgniteClient igniteClient = Ignition.startClient(cfg)) {
        // getting the id of the first node
        UUID nodeId = (UUID) igniteClient.query(new SqlFieldsQuery("SELECT * from NODES").setSchema("IGNITE")).getAll().iterator().next().get(0);
        double cpu_load = (Double) igniteClient.query(new SqlFieldsQuery("select CUR_CPU_LOAD * 100 from NODE_METRICS where NODE_ID = ? ").setSchema("IGNITE").setArgs(nodeId.toString())).getAll().iterator().next().get(0);
        System.out.println("node's cpu load = " + cpu_load);
    } catch (ClientException e) {
        System.err.println(e.getMessage());
    } catch (Exception e) {
        System.err.format("Unexpected failure: %s\n", e);
    }
// end::system-views[]
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientException(org.apache.ignite.client.ClientException) UUID(java.util.UUID) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) ClientException(org.apache.ignite.client.ClientException) ClientConnectionException(org.apache.ignite.client.ClientConnectionException) ClientAuthenticationException(org.apache.ignite.client.ClientAuthenticationException) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException)

Example 18 with ClientException

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

the class ClientCacheEntryListenerHandler method startListen.

/**
 * Send request to the server and start
 */
public synchronized void startListen(CacheEntryUpdatedListener<K, V> locLsnr, ClientDisconnectListener disconnectLsnr, Factory<? extends CacheEntryEventFilter<? super K, ? super V>> rmtFilterFactory, int pageSize, long timeInterval, boolean includeExpired) {
    assert locLsnr != null;
    if (clientCh != null)
        throw new IllegalStateException("Listener was already started");
    this.locLsnr = locLsnr;
    this.disconnectLsnr = disconnectLsnr;
    Consumer<PayloadOutputChannel> qryWriter = payloadCh -> {
        BinaryOutputStream out = payloadCh.out();
        out.writeInt(ClientUtils.cacheId(jCacheAdapter.getName()));
        out.writeByte(keepBinary ? KEEP_BINARY_FLAG_MASK : 0);
        out.writeInt(pageSize);
        out.writeLong(timeInterval);
        out.writeBoolean(includeExpired);
        if (rmtFilterFactory == null)
            out.writeByte(GridBinaryMarshaller.NULL);
        else {
            utils.writeObject(out, rmtFilterFactory);
            out.writeByte(JAVA_PLATFORM);
        }
    };
    Function<PayloadInputChannel, T2<ClientChannel, Long>> qryReader = payloadCh -> {
        ClientChannel ch = payloadCh.clientChannel();
        Long rsrcId = payloadCh.in().readLong();
        ch.addNotificationListener(CONTINUOUS_QUERY_EVENT, rsrcId, this);
        return new T2<>(ch, rsrcId);
    };
    try {
        T2<ClientChannel, Long> params = ch.service(ClientOperation.QUERY_CONTINUOUS, qryWriter, qryReader);
        clientCh = params.get1();
        rsrcId = params.get2();
    } catch (ClientError e) {
        throw new ClientException(e);
    }
}
Also used : Factory(javax.cache.configuration.Factory) BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream) EventType(javax.cache.event.EventType) ClientDisconnectListener(org.apache.ignite.client.ClientDisconnectListener) CONTINUOUS_QUERY_EVENT(org.apache.ignite.internal.client.thin.ClientNotificationType.CONTINUOUS_QUERY_EVENT) U(org.apache.ignite.internal.util.typedef.internal.U) BinaryOutputStream(org.apache.ignite.internal.binary.streams.BinaryOutputStream) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) Function(java.util.function.Function) ByteBuffer(java.nio.ByteBuffer) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) ArrayList(java.util.ArrayList) T2(org.apache.ignite.internal.util.typedef.T2) Consumer(java.util.function.Consumer) List(java.util.List) CacheEntryEvent(javax.cache.event.CacheEntryEvent) CacheEntryEventFilter(javax.cache.event.CacheEntryEventFilter) ClientException(org.apache.ignite.client.ClientException) BinaryByteBufferInputStream(org.apache.ignite.internal.binary.streams.BinaryByteBufferInputStream) Cache(javax.cache.Cache) CacheEntryUpdatedListener(javax.cache.event.CacheEntryUpdatedListener) JAVA_PLATFORM(org.apache.ignite.internal.client.thin.TcpClientCache.JAVA_PLATFORM) BinaryOutputStream(org.apache.ignite.internal.binary.streams.BinaryOutputStream) ClientException(org.apache.ignite.client.ClientException) T2(org.apache.ignite.internal.util.typedef.T2)

Example 19 with ClientException

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

the class ClientCacheEntryListenerHandler method acceptNotification.

/**
 * {@inheritDoc}
 */
@Override
public void acceptNotification(ByteBuffer payload, Exception err) {
    if (err == null && payload != null) {
        BinaryInputStream in = BinaryByteBufferInputStream.create(payload);
        int cnt = in.readInt();
        List<CacheEntryEvent<? extends K, ? extends V>> evts = new ArrayList<>(cnt);
        for (int i = 0; i < cnt; i++) {
            K key = utils.readObject(in, keepBinary);
            V oldVal = utils.readObject(in, keepBinary);
            V val = utils.readObject(in, keepBinary);
            byte evtTypeByte = in.readByte();
            EventType evtType = eventType(evtTypeByte);
            if (evtType == null)
                onChannelClosed(new ClientException("Unknown event type: " + evtTypeByte));
            evts.add(new CacheEntryEventImpl<>(jCacheAdapter, evtType, key, oldVal, val));
        }
        locLsnr.onUpdated(evts);
    }
}
Also used : BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream) EventType(javax.cache.event.EventType) ArrayList(java.util.ArrayList) ClientException(org.apache.ignite.client.ClientException) CacheEntryEvent(javax.cache.event.CacheEntryEvent)

Example 20 with ClientException

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

the class ClientComputeImpl method executeAsync0.

/**
 * @param taskName Task name.
 * @param arg Argument.
 * @param clusterGrp Cluster group.
 * @param flags Flags.
 * @param timeout Timeout.
 */
private <T, R> IgniteClientFuture<R> executeAsync0(String taskName, @Nullable T arg, ClientClusterGroupImpl clusterGrp, byte flags, long timeout) throws ClientException {
    Collection<UUID> nodeIds = clusterGrp.nodeIds();
    if (F.isEmpty(taskName))
        throw new ClientException("Task name can't be null or empty.");
    if (nodeIds != null && nodeIds.isEmpty())
        throw new ClientException("Cluster group is empty.");
    Consumer<PayloadOutputChannel> payloadWriter = ch -> writeExecuteTaskRequest(ch, taskName, arg, nodeIds, flags, timeout);
    Function<PayloadInputChannel, ClientComputeTask<R>> payloadReader = ch -> {
        Long taskId = ch.in().readLong();
        ClientComputeTask<R> task = new ClientComputeTask<>(utils, ch.clientChannel(), taskId);
        ch.clientChannel().addNotificationListener(COMPUTE_TASK_FINISHED, taskId, task);
        return task;
    };
    IgniteClientFuture<ClientComputeTask<R>> initFut = ch.serviceAsync(COMPUTE_TASK_EXECUTE, payloadWriter, payloadReader);
    CompletableFuture<R> resFut = new CompletableFuture<>();
    AtomicReference<Object> cancellationToken = new AtomicReference<>();
    initFut.handle((task, err) -> handleExecuteInitFuture(resFut, cancellationToken, task, err));
    return new IgniteClientFutureImpl<>(resFut, mayInterruptIfRunning -> {
        // 2. initFut has completed - cancel compute future.
        if (!cancellationToken.compareAndSet(null, mayInterruptIfRunning)) {
            GridFutureAdapter<?> fut = (GridFutureAdapter<?>) cancellationToken.get();
            if (!cancelGridFuture(fut, mayInterruptIfRunning))
                return false;
        }
        resFut.cancel(mayInterruptIfRunning);
        return true;
    });
}
Also used : ClientClusterGroup(org.apache.ignite.client.ClientClusterGroup) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) ClientFeatureNotSupportedByServerException(org.apache.ignite.client.ClientFeatureNotSupportedByServerException) U(org.apache.ignite.internal.util.typedef.internal.U) CompletableFuture(java.util.concurrent.CompletableFuture) RESOURCE_CLOSE(org.apache.ignite.internal.client.thin.ClientOperation.RESOURCE_CLOSE) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ByteBuffer(java.nio.ByteBuffer) Future(java.util.concurrent.Future) ClientException(org.apache.ignite.client.ClientException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientConnectionException(org.apache.ignite.client.ClientConnectionException) COMPUTE_TASK_FINISHED(org.apache.ignite.internal.client.thin.ClientNotificationType.COMPUTE_TASK_FINISHED) ClientStatus(org.apache.ignite.internal.processors.platform.client.ClientStatus) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) F(org.apache.ignite.internal.util.typedef.F) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteClientFuture(org.apache.ignite.client.IgniteClientFuture) UUID(java.util.UUID) COMPUTE_TASK_EXECUTE(org.apache.ignite.internal.client.thin.ClientOperation.COMPUTE_TASK_EXECUTE) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) BinaryByteBufferInputStream(org.apache.ignite.internal.binary.streams.BinaryByteBufferInputStream) ClientCompute(org.apache.ignite.client.ClientCompute) AtomicReference(java.util.concurrent.atomic.AtomicReference) CompletableFuture(java.util.concurrent.CompletableFuture) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) ClientException(org.apache.ignite.client.ClientException) UUID(java.util.UUID)

Aggregations

ClientException (org.apache.ignite.client.ClientException)20 ArrayList (java.util.ArrayList)9 UUID (java.util.UUID)6 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)6 ClientConnectionException (org.apache.ignite.client.ClientConnectionException)5 IgniteClient (org.apache.ignite.client.IgniteClient)5 HashMap (java.util.HashMap)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 Consumer (java.util.function.Consumer)4 Function (java.util.function.Function)4 BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)4 InetSocketAddress (java.net.InetSocketAddress)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 ClientAuthenticationException (org.apache.ignite.client.ClientAuthenticationException)3 ClientFeatureNotSupportedByServerException (org.apache.ignite.client.ClientFeatureNotSupportedByServerException)3