Search in sources :

Example 1 with ContinuousQueryViewWalker

use of org.apache.ignite.internal.managers.systemview.walker.ContinuousQueryViewWalker in project ignite by apache.

the class GridContinuousProcessor method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws IgniteCheckedException {
    ctx.systemView().registerView(CQ_SYS_VIEW, CQ_SYS_VIEW_DESC, new ContinuousQueryViewWalker(), new ReadOnlyCollectionView2X<>(rmtInfos.entrySet(), locInfos.entrySet()), e -> new ContinuousQueryView(e.getKey(), e.getValue()));
    discoProtoVer = ctx.discovery().mutableCustomMessages() ? 1 : 2;
    if (discoProtoVer == 2)
        routinesInfo = new ContinuousRoutinesInfo();
    if (ctx.config().isDaemon())
        return;
    retryDelay = ctx.config().getNetworkSendRetryDelay();
    retryCnt = ctx.config().getNetworkSendRetryCount();
    marsh = ctx.config().getMarshaller();
    ctx.event().addLocalEventListener(new DiscoveryListener(), EVT_NODE_LEFT, EVT_NODE_FAILED);
    ctx.event().addLocalEventListener(new GridLocalEventListener() {

        @Override
        public void onEvent(Event evt) {
            cancelFutures(new IgniteCheckedException("Topology segmented"));
        }
    }, EVT_NODE_SEGMENTED);
    ctx.discovery().setCustomEventListener(StartRoutineDiscoveryMessage.class, new CustomEventListener<StartRoutineDiscoveryMessage>() {

        @Override
        public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, StartRoutineDiscoveryMessage msg) {
            assert discoProtoVer == 1 : discoProtoVer;
            if (ctx.isStopping())
                return;
            processStartRequest(snd, msg);
        }
    });
    ctx.discovery().setCustomEventListener(StartRoutineDiscoveryMessageV2.class, new CustomEventListener<StartRoutineDiscoveryMessageV2>() {

        @Override
        public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, StartRoutineDiscoveryMessageV2 msg) {
            assert discoProtoVer == 2 : discoProtoVer;
            if (ctx.isStopping())
                return;
            processStartRequestV2(topVer, snd, msg);
        }
    });
    ctx.discovery().setCustomEventListener(StartRoutineAckDiscoveryMessage.class, new CustomEventListener<StartRoutineAckDiscoveryMessage>() {

        @Override
        public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, StartRoutineAckDiscoveryMessage msg) {
            if (ctx.isStopping())
                return;
            processStartAckRequest(topVer, msg);
        }
    });
    ctx.discovery().setCustomEventListener(StopRoutineDiscoveryMessage.class, new CustomEventListener<StopRoutineDiscoveryMessage>() {

        @Override
        public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, StopRoutineDiscoveryMessage msg) {
            if (discoProtoVer == 2)
                routinesInfo.removeRoutine(msg.routineId);
            if (ctx.isStopping())
                return;
            processStopRequest(snd, msg);
        }
    });
    ctx.discovery().setCustomEventListener(StopRoutineAckDiscoveryMessage.class, new CustomEventListener<StopRoutineAckDiscoveryMessage>() {

        @Override
        public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, StopRoutineAckDiscoveryMessage msg) {
            if (ctx.isStopping())
                return;
            processStopAckRequest(msg);
        }
    });
    ctx.io().addMessageListener(TOPIC_CONTINUOUS, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object obj, byte plc) {
            if (obj instanceof ContinuousRoutineStartResultMessage)
                processRoutineStartResultMessage(nodeId, (ContinuousRoutineStartResultMessage) obj);
            else {
                GridContinuousMessage msg = (GridContinuousMessage) obj;
                if (msg.data() == null && msg.dataBytes() != null) {
                    try {
                        msg.data(U.unmarshal(marsh, msg.dataBytes(), U.resolveClassLoader(ctx.config())));
                    } catch (IgniteCheckedException e) {
                        U.error(log, "Failed to process message (ignoring): " + msg, e);
                        return;
                    }
                }
                switch(msg.type()) {
                    case MSG_EVT_NOTIFICATION:
                        processNotification(nodeId, msg);
                        break;
                    case MSG_EVT_ACK:
                        processMessageAck(msg);
                        break;
                    default:
                        assert false : "Unexpected message received: " + msg.type();
                }
            }
        }
    });
    ctx.cacheObjects().onContinuousProcessorStarted(ctx);
    if (log.isDebugEnabled())
        log.debug("Continuous processor started.");
}
Also used : GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) UUID(java.util.UUID) ClusterNode(org.apache.ignite.cluster.ClusterNode) ContinuousQueryViewWalker(org.apache.ignite.internal.managers.systemview.walker.ContinuousQueryViewWalker) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ContinuousQueryView(org.apache.ignite.spi.systemview.view.ContinuousQueryView) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject)

Example 2 with ContinuousQueryViewWalker

use of org.apache.ignite.internal.managers.systemview.walker.ContinuousQueryViewWalker in project gridgain by gridgain.

the class GridContinuousProcessor method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws IgniteCheckedException {
    ctx.systemView().registerView(CQ_SYS_VIEW, CQ_SYS_VIEW_DESC, new ContinuousQueryViewWalker(), new ReadOnlyCollectionView2X<>(rmtInfos.entrySet(), locInfos.entrySet()), e -> new ContinuousQueryView(e.getKey(), e.getValue()));
    discoProtoVer = ctx.discovery().mutableCustomMessages() ? 1 : 2;
    if (discoProtoVer == 2)
        routinesInfo = new ContinuousRoutinesInfo();
    if (ctx.config().isDaemon())
        return;
    retryDelay = ctx.config().getNetworkSendRetryDelay();
    retryCnt = ctx.config().getNetworkSendRetryCount();
    marsh = ctx.config().getMarshaller();
    ctx.event().addLocalEventListener(new DiscoveryListener(), EVT_NODE_LEFT, EVT_NODE_FAILED);
    ctx.event().addLocalEventListener(new GridLocalEventListener() {

        @Override
        public void onEvent(Event evt) {
            cancelFutures(new IgniteCheckedException("Topology segmented"));
        }
    }, EVT_NODE_SEGMENTED);
    ctx.discovery().setCustomEventListener(StartRoutineDiscoveryMessage.class, new CustomEventListener<StartRoutineDiscoveryMessage>() {

        @Override
        public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, StartRoutineDiscoveryMessage msg) {
            assert discoProtoVer == 1 : discoProtoVer;
            if (ctx.isStopping())
                return;
            processStartRequest(snd, msg);
        }
    });
    ctx.discovery().setCustomEventListener(StartRoutineDiscoveryMessageV2.class, new CustomEventListener<StartRoutineDiscoveryMessageV2>() {

        @Override
        public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, StartRoutineDiscoveryMessageV2 msg) {
            assert discoProtoVer == 2 : discoProtoVer;
            if (ctx.isStopping())
                return;
            processStartRequestV2(topVer, snd, msg);
        }
    });
    ctx.discovery().setCustomEventListener(StartRoutineAckDiscoveryMessage.class, new CustomEventListener<StartRoutineAckDiscoveryMessage>() {

        @Override
        public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, StartRoutineAckDiscoveryMessage msg) {
            if (ctx.isStopping())
                return;
            processStartAckRequest(topVer, msg);
        }
    });
    ctx.discovery().setCustomEventListener(StopRoutineDiscoveryMessage.class, new CustomEventListener<StopRoutineDiscoveryMessage>() {

        @Override
        public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, StopRoutineDiscoveryMessage msg) {
            if (discoProtoVer == 2)
                routinesInfo.removeRoutine(msg.routineId);
            if (ctx.isStopping())
                return;
            processStopRequest(snd, msg);
        }
    });
    ctx.discovery().setCustomEventListener(StopRoutineAckDiscoveryMessage.class, new CustomEventListener<StopRoutineAckDiscoveryMessage>() {

        @Override
        public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, StopRoutineAckDiscoveryMessage msg) {
            if (ctx.isStopping())
                return;
            processStopAckRequest(msg);
        }
    });
    ctx.io().addMessageListener(TOPIC_CONTINUOUS, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object obj, byte plc) {
            if (obj instanceof ContinuousRoutineStartResultMessage)
                processRoutineStartResultMessage(nodeId, (ContinuousRoutineStartResultMessage) obj);
            else {
                GridContinuousMessage msg = (GridContinuousMessage) obj;
                if (msg.data() == null && msg.dataBytes() != null) {
                    try {
                        msg.data(U.unmarshal(marsh, msg.dataBytes(), U.resolveClassLoader(ctx.config())));
                    } catch (IgniteCheckedException e) {
                        U.error(log, "Failed to process message (ignoring): " + msg, e);
                        return;
                    }
                }
                switch(msg.type()) {
                    case MSG_EVT_NOTIFICATION:
                        processNotification(nodeId, msg);
                        break;
                    case MSG_EVT_ACK:
                        processMessageAck(msg);
                        break;
                    default:
                        assert false : "Unexpected message received: " + msg.type();
                }
            }
        }
    });
    ctx.cacheObjects().onContinuousProcessorStarted(ctx);
    if (ctx.service() instanceof GridServiceProcessor)
        ((GridServiceProcessor) ctx.service()).onContinuousProcessorStarted(ctx);
    if (log.isDebugEnabled())
        log.debug("Continuous processor started.");
}
Also used : GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridServiceProcessor(org.apache.ignite.internal.processors.service.GridServiceProcessor) UUID(java.util.UUID) ClusterNode(org.apache.ignite.cluster.ClusterNode) ContinuousQueryViewWalker(org.apache.ignite.internal.managers.systemview.walker.ContinuousQueryViewWalker) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ContinuousQueryView(org.apache.ignite.spi.systemview.view.ContinuousQueryView) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject)

Aggregations

UUID (java.util.UUID)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)2 Event (org.apache.ignite.events.Event)2 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)2 GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)2 ContinuousQueryViewWalker (org.apache.ignite.internal.managers.systemview.walker.ContinuousQueryViewWalker)2 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)2 GridTimeoutObject (org.apache.ignite.internal.processors.timeout.GridTimeoutObject)2 ContinuousQueryView (org.apache.ignite.spi.systemview.view.ContinuousQueryView)2 GridServiceProcessor (org.apache.ignite.internal.processors.service.GridServiceProcessor)1