Search in sources :

Example 1 with GridNearSingleGetResponse

use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetResponse in project ignite by apache.

the class GridDhtAtomicCache method start.

/**
 * {@inheritDoc}
 */
@SuppressWarnings({ "IfMayBeConditional", "SimplifiableIfStatement" })
@Override
public void start() throws IgniteCheckedException {
    super.start();
    CacheMetricsImpl m = new CacheMetricsImpl(ctx);
    if (ctx.dht().near() != null)
        m.delegate(ctx.dht().near().metrics0());
    metrics = m;
    ctx.io().addCacheHandler(ctx.cacheId(), GridNearGetRequest.class, new CI2<UUID, GridNearGetRequest>() {

        @Override
        public void apply(UUID nodeId, GridNearGetRequest req) {
            processNearGetRequest(nodeId, req);
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridNearSingleGetRequest.class, new CI2<UUID, GridNearSingleGetRequest>() {

        @Override
        public void apply(UUID nodeId, GridNearSingleGetRequest req) {
            processNearSingleGetRequest(nodeId, req);
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridNearAtomicAbstractUpdateRequest.class, new CI2<UUID, GridNearAtomicAbstractUpdateRequest>() {

        @Override
        public void apply(UUID nodeId, GridNearAtomicAbstractUpdateRequest req) {
            processNearAtomicUpdateRequest(nodeId, req);
        }

        @Override
        public String toString() {
            return "GridNearAtomicAbstractUpdateRequest handler " + "[msgIdx=" + GridNearAtomicAbstractUpdateRequest.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridNearAtomicUpdateResponse.class, new CI2<UUID, GridNearAtomicUpdateResponse>() {

        @Override
        public void apply(UUID nodeId, GridNearAtomicUpdateResponse res) {
            processNearAtomicUpdateResponse(nodeId, res);
        }

        @Override
        public String toString() {
            return "GridNearAtomicUpdateResponse handler " + "[msgIdx=" + GridNearAtomicUpdateResponse.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridDhtAtomicAbstractUpdateRequest.class, new CI2<UUID, GridDhtAtomicAbstractUpdateRequest>() {

        @Override
        public void apply(UUID nodeId, GridDhtAtomicAbstractUpdateRequest req) {
            processDhtAtomicUpdateRequest(nodeId, req);
        }

        @Override
        public String toString() {
            return "GridDhtAtomicUpdateRequest handler " + "[msgIdx=" + GridDhtAtomicUpdateRequest.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridDhtAtomicUpdateResponse.class, new CI2<UUID, GridDhtAtomicUpdateResponse>() {

        @Override
        public void apply(UUID nodeId, GridDhtAtomicUpdateResponse res) {
            processDhtAtomicUpdateResponse(nodeId, res);
        }

        @Override
        public String toString() {
            return "GridDhtAtomicUpdateResponse handler " + "[msgIdx=" + GridDhtAtomicUpdateResponse.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridDhtAtomicDeferredUpdateResponse.class, new CI2<UUID, GridDhtAtomicDeferredUpdateResponse>() {

        @Override
        public void apply(UUID nodeId, GridDhtAtomicDeferredUpdateResponse res) {
            processDhtAtomicDeferredUpdateResponse(nodeId, res);
        }

        @Override
        public String toString() {
            return "GridDhtAtomicDeferredUpdateResponse handler " + "[msgIdx=" + GridDhtAtomicDeferredUpdateResponse.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridDhtAtomicNearResponse.class, new CI2<UUID, GridDhtAtomicNearResponse>() {

        @Override
        public void apply(UUID uuid, GridDhtAtomicNearResponse msg) {
            processDhtAtomicNearResponse(uuid, msg);
        }

        @Override
        public String toString() {
            return "GridDhtAtomicNearResponse handler " + "[msgIdx=" + GridDhtAtomicNearResponse.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridNearAtomicCheckUpdateRequest.class, new CI2<UUID, GridNearAtomicCheckUpdateRequest>() {

        @Override
        public void apply(UUID uuid, GridNearAtomicCheckUpdateRequest msg) {
            processCheckUpdateRequest(uuid, msg);
        }

        @Override
        public String toString() {
            return "GridNearAtomicCheckUpdateRequest handler " + "[msgIdx=" + GridNearAtomicCheckUpdateRequest.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridDhtForceKeysRequest.class, new MessageHandler<GridDhtForceKeysRequest>() {

        @Override
        public void onMessage(ClusterNode node, GridDhtForceKeysRequest msg) {
            processForceKeysRequest(node, msg);
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridDhtForceKeysResponse.class, new MessageHandler<GridDhtForceKeysResponse>() {

        @Override
        public void onMessage(ClusterNode node, GridDhtForceKeysResponse msg) {
            processForceKeyResponse(node, msg);
        }
    });
    if (near == null) {
        ctx.io().addCacheHandler(ctx.cacheId(), GridNearGetResponse.class, new CI2<UUID, GridNearGetResponse>() {

            @Override
            public void apply(UUID nodeId, GridNearGetResponse res) {
                processNearGetResponse(nodeId, res);
            }
        });
        ctx.io().addCacheHandler(ctx.cacheId(), GridNearSingleGetResponse.class, new CI2<UUID, GridNearSingleGetResponse>() {

            @Override
            public void apply(UUID nodeId, GridNearSingleGetResponse res) {
                processNearSingleGetResponse(nodeId, res);
            }
        });
    }
}
Also used : GridDhtForceKeysResponse(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysResponse) CacheMetricsImpl(org.apache.ignite.internal.processors.cache.CacheMetricsImpl) GridDhtForceKeysRequest(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysRequest) GridNearGetRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest) UUID(java.util.UUID) GridNearGetResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetResponse) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridNearSingleGetResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetResponse) GridNearSingleGetRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetRequest)

Example 2 with GridNearSingleGetResponse

use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetResponse in project ignite by apache.

the class GridDhtCacheAdapter method processNearSingleGetRequest.

/**
 * @param nodeId Node ID.
 * @param req Get request.
 */
protected void processNearSingleGetRequest(final UUID nodeId, final GridNearSingleGetRequest req) {
    assert ctx.affinityNode();
    final CacheExpiryPolicy expiryPlc = CacheExpiryPolicy.fromRemote(req.createTtl(), req.accessTtl());
    IgniteInternalFuture<GridCacheEntryInfo> fut = getDhtSingleAsync(nodeId, req.messageId(), req.key(), req.addReader(), req.readThrough(), req.topologyVersion(), req.taskNameHash(), expiryPlc, req.skipValues(), req.recovery(), req.txLabel(), req.mvccSnapshot());
    fut.listen(new CI1<IgniteInternalFuture<GridCacheEntryInfo>>() {

        @Override
        public void apply(IgniteInternalFuture<GridCacheEntryInfo> f) {
            GridNearSingleGetResponse res;
            GridDhtFuture<GridCacheEntryInfo> fut = (GridDhtFuture<GridCacheEntryInfo>) f;
            try {
                GridCacheEntryInfo info = fut.get();
                if (F.isEmpty(fut.invalidPartitions())) {
                    Message res0 = null;
                    if (info != null) {
                        if (req.needEntryInfo()) {
                            info.key(null);
                            res0 = info;
                        } else if (req.needVersion())
                            res0 = new CacheVersionedValue(info.value(), info.version());
                        else
                            res0 = info.value();
                    }
                    res = new GridNearSingleGetResponse(ctx.cacheId(), req.futureId(), null, res0, false, req.addDeploymentInfo());
                    if (info != null && req.skipValues())
                        res.setContainsValue();
                } else {
                    AffinityTopologyVersion topVer = ctx.shared().exchange().lastTopologyFuture().initialVersion();
                    res = new GridNearSingleGetResponse(ctx.cacheId(), req.futureId(), topVer, null, true, req.addDeploymentInfo());
                }
            } catch (NodeStoppingException ignored) {
                return;
            } catch (IgniteCheckedException e) {
                U.error(log, "Failed processing get request: " + req, e);
                res = new GridNearSingleGetResponse(ctx.cacheId(), req.futureId(), req.topologyVersion(), null, false, req.addDeploymentInfo());
                res.error(e);
            }
            try {
                ctx.io().send(nodeId, res, ctx.ioPolicy());
            } catch (ClusterTopologyCheckedException e) {
                if (log.isDebugEnabled())
                    log.debug("Failed to send get response to node, node failed: " + nodeId);
            } catch (IgniteCheckedException e) {
                U.error(log, "Failed to send get response to node (is node still alive?) [nodeId=" + nodeId + ",req=" + req + ", res=" + res + ']', e);
            }
            sendTtlUpdateRequest(expiryPlc);
        }
    });
}
Also used : GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) CacheVersionedValue(org.apache.ignite.internal.processors.cache.distributed.near.CacheVersionedValue) Message(org.apache.ignite.plugin.extensions.communication.Message) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) GridNearSingleGetResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetResponse) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteCacheExpiryPolicy(org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Aggregations

GridNearSingleGetResponse (org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetResponse)2 UUID (java.util.UUID)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)1 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)1 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 CacheMetricsImpl (org.apache.ignite.internal.processors.cache.CacheMetricsImpl)1 GridCacheEntryInfo (org.apache.ignite.internal.processors.cache.GridCacheEntryInfo)1 IgniteCacheExpiryPolicy (org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy)1 GridDhtForceKeysRequest (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysRequest)1 GridDhtForceKeysResponse (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysResponse)1 CacheVersionedValue (org.apache.ignite.internal.processors.cache.distributed.near.CacheVersionedValue)1 GridNearGetRequest (org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest)1 GridNearGetResponse (org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetResponse)1 GridNearSingleGetRequest (org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetRequest)1 Message (org.apache.ignite.plugin.extensions.communication.Message)1