Search in sources :

Example 1 with PARTITION_AWARENESS

use of org.apache.ignite.internal.client.thin.ProtocolVersionFeature.PARTITION_AWARENESS in project ignite by apache.

the class TcpClientChannel method processNextMessage.

/**
 * Process next message from the input stream and complete corresponding future.
 */
private void processNextMessage(ByteBuffer buf) throws ClientProtocolError, ClientConnectionException {
    BinaryInputStream dataInput = BinaryByteBufferInputStream.create(buf);
    if (protocolCtx == null) {
        // Process handshake.
        pendingReqs.remove(-1L).onDone(buf);
        return;
    }
    Long resId = dataInput.readLong();
    int status = 0;
    ClientOperation notificationOp = null;
    if (protocolCtx.isFeatureSupported(PARTITION_AWARENESS)) {
        short flags = dataInput.readShort();
        if ((flags & ClientFlag.AFFINITY_TOPOLOGY_CHANGED) != 0) {
            long topVer = dataInput.readLong();
            int minorTopVer = dataInput.readInt();
            srvTopVer = new AffinityTopologyVersion(topVer, minorTopVer);
            for (Consumer<ClientChannel> lsnr : topChangeLsnrs) lsnr.accept(this);
        }
        if ((flags & ClientFlag.NOTIFICATION) != 0) {
            short notificationCode = dataInput.readShort();
            notificationOp = ClientOperation.fromCode(notificationCode);
            if (notificationOp == null || notificationOp.notificationType() == null)
                throw new ClientProtocolError(String.format("Unexpected notification code [%d]", notificationCode));
        }
        if ((flags & ClientFlag.ERROR) != 0)
            status = dataInput.readInt();
    } else
        status = dataInput.readInt();
    int hdrSize = dataInput.position();
    int msgSize = buf.limit();
    ByteBuffer res;
    Exception err;
    if (status == 0) {
        err = null;
        res = msgSize > hdrSize ? buf : null;
    } else if (status == ClientStatus.SECURITY_VIOLATION) {
        err = new ClientAuthorizationException();
        res = null;
    } else {
        String errMsg = ClientUtils.createBinaryReader(null, dataInput).readString();
        err = new ClientServerError(errMsg, status, resId);
        res = null;
    }
    if (notificationOp == null) {
        // Respone received.
        ClientRequestFuture pendingReq = pendingReqs.remove(resId);
        if (pendingReq == null)
            throw new ClientProtocolError(String.format("Unexpected response ID [%s]", resId));
        pendingReq.onDone(res, err);
    } else {
        // Notification received.
        ClientNotificationType notificationType = notificationOp.notificationType();
        asyncContinuationExecutor.execute(() -> {
            NotificationListener lsnr = null;
            notificationLsnrsGuard.readLock().lock();
            try {
                Map<Long, NotificationListener> lsrns = notificationLsnrs[notificationType.ordinal()];
                if (lsrns != null)
                    lsnr = lsrns.get(resId);
                if (notificationType.keepNotificationsWithoutListener() && lsnr == null) {
                    pendingNotifications[notificationType.ordinal()].computeIfAbsent(resId, k -> new ConcurrentLinkedQueue<>()).add(new T2<>(res, err));
                }
            } finally {
                notificationLsnrsGuard.readLock().unlock();
            }
            if (lsnr != null)
                lsnr.acceptNotification(res, err);
        });
    }
}
Also used : BinaryCachingMetadataHandler(org.apache.ignite.internal.binary.BinaryCachingMetadataHandler) Arrays(java.util.Arrays) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) ClientFeatureNotSupportedByServerException(org.apache.ignite.client.ClientFeatureNotSupportedByServerException) BinaryOutputStream(org.apache.ignite.internal.binary.streams.BinaryOutputStream) ClientListenerNioListener(org.apache.ignite.internal.processors.odbc.ClientListenerNioListener) BITMAP_FEATURES(org.apache.ignite.internal.client.thin.ProtocolVersionFeature.BITMAP_FEATURES) ByteBuffer(java.nio.ByteBuffer) ClientException(org.apache.ignite.client.ClientException) Map(java.util.Map) ClientListenerRequest(org.apache.ignite.internal.processors.odbc.ClientListenerRequest) ClientReconnectedException(org.apache.ignite.client.ClientReconnectedException) ClientStatus(org.apache.ignite.internal.processors.platform.client.ClientStatus) EnumSet(java.util.EnumSet) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ClientAuthenticationException(org.apache.ignite.client.ClientAuthenticationException) V1_5_0(org.apache.ignite.internal.client.thin.ProtocolVersion.V1_5_0) V1_7_0(org.apache.ignite.internal.client.thin.ProtocolVersion.V1_7_0) V1_1_0(org.apache.ignite.internal.client.thin.ProtocolVersion.V1_1_0) BinaryContext(org.apache.ignite.internal.binary.BinaryContext) V1_3_0(org.apache.ignite.internal.client.thin.ProtocolVersion.V1_3_0) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) USER_ATTRIBUTES(org.apache.ignite.internal.client.thin.ProtocolBitmaskFeature.USER_ATTRIBUTES) UUID(java.util.UUID) PARTITION_AWARENESS(org.apache.ignite.internal.client.thin.ProtocolVersionFeature.PARTITION_AWARENESS) InetSocketAddress(java.net.InetSocketAddress) ClientConnectionMultiplexer(org.apache.ignite.internal.client.thin.io.ClientConnectionMultiplexer) Nullable(org.jetbrains.annotations.Nullable) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Queue(java.util.Queue) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ClientConnection(org.apache.ignite.internal.client.thin.io.ClientConnection) AUTHORIZATION(org.apache.ignite.internal.client.thin.ProtocolVersionFeature.AUTHORIZATION) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) U(org.apache.ignite.internal.util.typedef.internal.U) CompletableFuture(java.util.concurrent.CompletableFuture) BinaryWriterExImpl(org.apache.ignite.internal.binary.BinaryWriterExImpl) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Function(java.util.function.Function) LATEST_VER(org.apache.ignite.internal.client.thin.ProtocolVersion.LATEST_VER) BinaryHeapOutputStream(org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream) ClientConnectionStateHandler(org.apache.ignite.internal.client.thin.io.ClientConnectionStateHandler) BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) ClientFlag(org.apache.ignite.internal.processors.platform.client.ClientFlag) ClientConnectionException(org.apache.ignite.client.ClientConnectionException) ClientAuthorizationException(org.apache.ignite.client.ClientAuthorizationException) BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream) F(org.apache.ignite.internal.util.typedef.F) V1_4_0(org.apache.ignite.internal.client.thin.ProtocolVersion.V1_4_0) V1_6_0(org.apache.ignite.internal.client.thin.ProtocolVersion.V1_6_0) Executor(java.util.concurrent.Executor) V1_0_0(org.apache.ignite.internal.client.thin.ProtocolVersion.V1_0_0) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) V1_2_0(org.apache.ignite.internal.client.thin.ProtocolVersion.V1_2_0) IOException(java.io.IOException) T2(org.apache.ignite.internal.util.typedef.T2) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) BinaryByteBufferInputStream(org.apache.ignite.internal.binary.streams.BinaryByteBufferInputStream) ClientMessageHandler(org.apache.ignite.internal.client.thin.io.ClientMessageHandler) ForkJoinPool(java.util.concurrent.ForkJoinPool) BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ByteBuffer(java.nio.ByteBuffer) ClientFeatureNotSupportedByServerException(org.apache.ignite.client.ClientFeatureNotSupportedByServerException) ClientException(org.apache.ignite.client.ClientException) ClientReconnectedException(org.apache.ignite.client.ClientReconnectedException) ClientAuthenticationException(org.apache.ignite.client.ClientAuthenticationException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClientConnectionException(org.apache.ignite.client.ClientConnectionException) ClientAuthorizationException(org.apache.ignite.client.ClientAuthorizationException) IOException(java.io.IOException) ClientAuthorizationException(org.apache.ignite.client.ClientAuthorizationException) AtomicLong(java.util.concurrent.atomic.AtomicLong) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue)

Aggregations

IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ByteBuffer (java.nio.ByteBuffer)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 EnumSet (java.util.EnumSet)1 Map (java.util.Map)1 Queue (java.util.Queue)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Executor (java.util.concurrent.Executor)1 ForkJoinPool (java.util.concurrent.ForkJoinPool)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 Consumer (java.util.function.Consumer)1