Search in sources :

Example 1 with CacheContinuousQueryHandler

use of org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryHandler in project ignite by apache.

the class GridContinuousProcessor method registerStaticRoutine.

/**
     * Registers routine info to be sent in discovery data during this node join
     * (to be used for internal queries started from client nodes).
     *
     * @param cacheName Cache name.
     * @param locLsnr Local listener.
     * @param rmtFilter Remote filter.
     * @param prjPred Projection predicate.
     * @return Routine ID.
     * @throws IgniteCheckedException If failed.
     */
@SuppressWarnings("unchecked")
public UUID registerStaticRoutine(String cacheName, CacheEntryUpdatedListener<?, ?> locLsnr, CacheEntryEventSerializableFilter rmtFilter, @Nullable IgnitePredicate<ClusterNode> prjPred) throws IgniteCheckedException {
    String topicPrefix = "CONTINUOUS_QUERY_STATIC" + "_" + cacheName;
    CacheContinuousQueryHandler hnd = new CacheContinuousQueryHandler(cacheName, TOPIC_CACHE.topic(topicPrefix, ctx.localNodeId(), seq.incrementAndGet()), locLsnr, rmtFilter, true, false, true, false);
    hnd.internal(true);
    final UUID routineId = UUID.randomUUID();
    LocalRoutineInfo routineInfo = new LocalRoutineInfo(prjPred, hnd, 1, 0, true);
    locInfos.put(routineId, routineInfo);
    registerMessageListener(hnd);
    return routineId;
}
Also used : CacheContinuousQueryHandler(org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryHandler) UUID(java.util.UUID)

Example 2 with CacheContinuousQueryHandler

use of org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryHandler in project ignite by apache.

the class GridContinuousProcessor method processStartRequest.

/**
     * @param node Sender.
     * @param req Start request.
     */
private void processStartRequest(ClusterNode node, StartRoutineDiscoveryMessage req) {
    UUID routineId = req.routineId();
    StartRequestData data = req.startRequestData();
    GridContinuousHandler hnd = data.handler();
    if (req.keepBinary()) {
        assert hnd instanceof CacheContinuousQueryHandler;
        ((CacheContinuousQueryHandler) hnd).keepBinary(true);
    }
    IgniteCheckedException err = null;
    try {
        if (ctx.config().isPeerClassLoadingEnabled()) {
            String clsName = data.className();
            if (clsName != null) {
                GridDeploymentInfo depInfo = data.deploymentInfo();
                GridDeployment dep = ctx.deploy().getGlobalDeployment(depInfo.deployMode(), clsName, clsName, depInfo.userVersion(), node.id(), depInfo.classLoaderId(), depInfo.participants(), null);
                if (dep == null)
                    throw new IgniteDeploymentCheckedException("Failed to obtain deployment for class: " + clsName);
                data.p2pUnmarshal(marsh, U.resolveClassLoader(dep.classLoader(), ctx.config()));
            }
            hnd.p2pUnmarshal(node.id(), ctx);
        }
    } catch (IgniteCheckedException e) {
        err = e;
        U.error(log, "Failed to register handler [nodeId=" + node.id() + ", routineId=" + routineId + ']', e);
    }
    GridContinuousHandler hnd0 = hnd instanceof GridMessageListenHandler ? new GridMessageListenHandler((GridMessageListenHandler) hnd) : hnd;
    if (node.isClient()) {
        Map<UUID, LocalRoutineInfo> clientRoutineMap = clientInfos.get(node.id());
        if (clientRoutineMap == null) {
            clientRoutineMap = new HashMap<>();
            Map<UUID, LocalRoutineInfo> old = clientInfos.put(node.id(), clientRoutineMap);
            assert old == null;
        }
        clientRoutineMap.put(routineId, new LocalRoutineInfo(data.projectionPredicate(), hnd0, data.bufferSize(), data.interval(), data.autoUnsubscribe()));
    }
    if (err == null) {
        try {
            IgnitePredicate<ClusterNode> prjPred = data.projectionPredicate();
            if (prjPred != null)
                ctx.resource().injectGeneric(prjPred);
            if ((prjPred == null || prjPred.apply(ctx.discovery().node(ctx.localNodeId()))) && !locInfos.containsKey(routineId))
                registerHandler(node.id(), routineId, hnd0, data.bufferSize(), data.interval(), data.autoUnsubscribe(), false);
            if (!data.autoUnsubscribe())
                // Register routine locally.
                locInfos.putIfAbsent(routineId, new LocalRoutineInfo(prjPred, hnd0, data.bufferSize(), data.interval(), data.autoUnsubscribe()));
        } catch (IgniteCheckedException e) {
            err = e;
            U.error(log, "Failed to register handler [nodeId=" + node.id() + ", routineId=" + routineId + ']', e);
        }
    }
    // Load partition counters.
    if (hnd0.isQuery()) {
        GridCacheProcessor proc = ctx.cache();
        if (proc != null) {
            GridCacheAdapter cache = ctx.cache().internalCache(hnd0.cacheName());
            if (cache != null && !cache.isLocal() && cache.context().userCache())
                req.addUpdateCounters(ctx.localNodeId(), cache.context().topology().updateCounters(false));
        }
    }
    if (err != null)
        req.addError(ctx.localNodeId(), err);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteDeploymentCheckedException(org.apache.ignite.internal.IgniteDeploymentCheckedException) CacheContinuousQueryHandler(org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryHandler) GridDeploymentInfo(org.apache.ignite.internal.managers.deployment.GridDeploymentInfo) GridCacheProcessor(org.apache.ignite.internal.processors.cache.GridCacheProcessor) GridDeployment(org.apache.ignite.internal.managers.deployment.GridDeployment) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridMessageListenHandler(org.apache.ignite.internal.GridMessageListenHandler) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) UUID(java.util.UUID)

Aggregations

UUID (java.util.UUID)2 CacheContinuousQueryHandler (org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryHandler)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 GridMessageListenHandler (org.apache.ignite.internal.GridMessageListenHandler)1 IgniteDeploymentCheckedException (org.apache.ignite.internal.IgniteDeploymentCheckedException)1 GridDeployment (org.apache.ignite.internal.managers.deployment.GridDeployment)1 GridDeploymentInfo (org.apache.ignite.internal.managers.deployment.GridDeploymentInfo)1 GridCacheAdapter (org.apache.ignite.internal.processors.cache.GridCacheAdapter)1 GridCacheProcessor (org.apache.ignite.internal.processors.cache.GridCacheProcessor)1