Search in sources :

Example 16 with GridMessageListener

use of org.apache.ignite.internal.managers.communication.GridMessageListener in project ignite by apache.

the class IgniteAuthenticationProcessor method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws IgniteCheckedException {
    super.start();
    if (isEnabled && !GridCacheUtils.isPersistenceEnabled(ctx.config())) {
        isEnabled = false;
        throw new IgniteCheckedException("Authentication can be enabled only for cluster with enabled persistence." + " Check the DataRegionConfiguration");
    }
    ctx.addNodeAttribute(IgniteNodeAttributes.ATTR_AUTHENTICATION_ENABLED, isEnabled);
    GridDiscoveryManager discoMgr = ctx.discovery();
    GridIoManager ioMgr = ctx.io();
    discoMgr.setCustomEventListener(UserProposedMessage.class, new UserProposedListener());
    discoMgr.setCustomEventListener(UserAcceptedMessage.class, new UserAcceptedListener());
    discoLsnr = new DiscoveryEventListener() {

        @Override
        public void onEvent(DiscoveryEvent evt, DiscoCache discoCache) {
            if (!isEnabled || ctx.isStopping())
                return;
            switch(evt.type()) {
                case EVT_NODE_LEFT:
                case EVT_NODE_FAILED:
                    onNodeLeft(evt.eventNode().id());
                    break;
                case EVT_NODE_JOINED:
                    onNodeJoin(evt.eventNode());
                    break;
            }
        }
    };
    ctx.event().addDiscoveryEventListener(discoLsnr, DISCO_EVT_TYPES);
    ioLsnr = new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg, byte plc) {
            if (!isEnabled || ctx.isStopping())
                return;
            if (msg instanceof UserManagementOperationFinishedMessage)
                onFinishMessage(nodeId, (UserManagementOperationFinishedMessage) msg);
            else if (msg instanceof UserAuthenticateRequestMessage)
                onAuthenticateRequestMessage(nodeId, (UserAuthenticateRequestMessage) msg);
            else if (msg instanceof UserAuthenticateResponseMessage)
                onAuthenticateResponseMessage((UserAuthenticateResponseMessage) msg);
        }
    };
    ioMgr.addMessageListener(GridTopic.TOPIC_AUTH, ioLsnr);
    exec = new IgniteThreadPoolExecutor("auth", ctx.config().getIgniteInstanceName(), 1, 1, 0, new LinkedBlockingQueue<>());
}
Also used : DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) IgniteThreadPoolExecutor(org.apache.ignite.thread.IgniteThreadPoolExecutor) DiscoveryEventListener(org.apache.ignite.internal.managers.eventstorage.DiscoveryEventListener) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) UUID(java.util.UUID)

Example 17 with GridMessageListener

use of org.apache.ignite.internal.managers.communication.GridMessageListener in project ignite by apache.

the class HadoopShuffle method start.

/**
 * {@inheritDoc}
 */
@Override
public void start(HadoopContext ctx) throws IgniteCheckedException {
    super.start(ctx);
    ctx.kernalContext().io().addMessageListener(GridTopic.TOPIC_HADOOP_MSG, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg, byte plc) {
            onMessageReceived(nodeId, (HadoopMessage) msg);
        }
    });
    ctx.kernalContext().io().addUserMessageListener(GridTopic.TOPIC_HADOOP, new IgniteBiPredicate<UUID, Object>() {

        @Override
        public boolean apply(UUID nodeId, Object msg) {
            return onMessageReceived(nodeId, (HadoopMessage) msg);
        }
    });
}
Also used : GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) HadoopMessage(org.apache.ignite.internal.processors.hadoop.message.HadoopMessage) UUID(java.util.UUID)

Example 18 with GridMessageListener

use of org.apache.ignite.internal.managers.communication.GridMessageListener in project ignite by apache.

the class GridH2IndexBase method initDistributedJoinMessaging.

/**
 * @param tbl Table.
 */
protected final void initDistributedJoinMessaging(GridH2Table tbl) {
    final GridH2RowDescriptor desc = tbl.rowDescriptor();
    if (desc != null && desc.context() != null) {
        ctx = desc.context();
        GridKernalContext ctx = desc.context().kernalContext();
        log = ctx.log(getClass());
        msgTopic = new IgniteBiTuple<>(GridTopic.TOPIC_QUERY, tbl.identifierString() + '.' + getName());
        msgLsnr = new GridMessageListener() {

            @Override
            public void onMessage(UUID nodeId, Object msg, byte plc) {
                GridSpinBusyLock l = desc.indexing().busyLock();
                if (!l.enterBusy())
                    return;
                try {
                    onMessage0(nodeId, msg);
                } finally {
                    l.leaveBusy();
                }
            }
        };
        ctx.io().addMessageListener(msgTopic, msgLsnr);
    } else {
        msgTopic = null;
        msgLsnr = null;
        log = new NullLogger();
    }
}
Also used : GridSpinBusyLock(org.apache.ignite.internal.util.GridSpinBusyLock) NullLogger(org.apache.ignite.logger.NullLogger) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) UUID(java.util.UUID)

Example 19 with GridMessageListener

use of org.apache.ignite.internal.managers.communication.GridMessageListener in project ignite by apache.

the class GridMapQueryExecutor method start.

/**
 * @param ctx Context.
 * @param h2 H2 Indexing.
 * @throws IgniteCheckedException If failed.
 */
public void start(final GridKernalContext ctx, IgniteH2Indexing h2) throws IgniteCheckedException {
    this.ctx = ctx;
    this.h2 = h2;
    log = ctx.log(GridMapQueryExecutor.class);
    final UUID locNodeId = ctx.localNodeId();
    ctx.event().addLocalEventListener(new GridLocalEventListener() {

        @Override
        public void onEvent(final Event evt) {
            UUID nodeId = ((DiscoveryEvent) evt).eventNode().id();
            GridH2QueryContext.clearAfterDeadNode(locNodeId, nodeId);
            MapNodeResults nodeRess = qryRess.remove(nodeId);
            if (nodeRess == null)
                return;
            nodeRess.cancelAll();
        }
    }, EventType.EVT_NODE_FAILED, EventType.EVT_NODE_LEFT);
    ctx.io().addMessageListener(GridTopic.TOPIC_QUERY, new GridMessageListener() {

        @SuppressWarnings("deprecation")
        @Override
        public void onMessage(UUID nodeId, Object msg, byte plc) {
            if (!busyLock.enterBusy())
                return;
            try {
                if (msg instanceof GridCacheQueryMarshallable)
                    ((GridCacheQueryMarshallable) msg).unmarshall(ctx.config().getMarshaller(), ctx);
                GridMapQueryExecutor.this.onMessage(nodeId, msg);
            } finally {
                busyLock.leaveBusy();
            }
        }
    });
}
Also used : GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) GridCacheQueryMarshallable(org.apache.ignite.internal.processors.cache.query.GridCacheQueryMarshallable) CacheQueryExecutedEvent(org.apache.ignite.events.CacheQueryExecutedEvent) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) UUID(java.util.UUID)

Example 20 with GridMessageListener

use of org.apache.ignite.internal.managers.communication.GridMessageListener in project ignite by apache.

the class GridReduceQueryExecutor method start.

/**
 * @param ctx Context.
 * @param h2 H2 Indexing.
 * @throws IgniteCheckedException If failed.
 */
public void start(final GridKernalContext ctx, final IgniteH2Indexing h2) throws IgniteCheckedException {
    this.ctx = ctx;
    this.h2 = h2;
    log = ctx.log(GridReduceQueryExecutor.class);
    ctx.io().addMessageListener(GridTopic.TOPIC_QUERY, new GridMessageListener() {

        @SuppressWarnings("deprecation")
        @Override
        public void onMessage(UUID nodeId, Object msg, byte plc) {
            if (!busyLock.enterBusy())
                return;
            try {
                if (msg instanceof GridCacheQueryMarshallable)
                    ((GridCacheQueryMarshallable) msg).unmarshall(ctx.config().getMarshaller(), ctx);
                GridReduceQueryExecutor.this.onMessage(nodeId, msg);
            } finally {
                busyLock.leaveBusy();
            }
        }
    });
    ctx.event().addLocalEventListener(new GridLocalEventListener() {

        @Override
        public void onEvent(final Event evt) {
            UUID nodeId = ((DiscoveryEvent) evt).eventNode().id();
            for (ReduceQueryRun r : runs.values()) {
                for (GridMergeIndex idx : r.indexes()) {
                    if (idx.hasSource(nodeId)) {
                        handleNodeLeft(r, nodeId);
                        break;
                    }
                }
            }
            for (DistributedUpdateRun r : updRuns.values()) r.handleNodeLeft(nodeId);
        }
    }, EventType.EVT_NODE_FAILED, EventType.EVT_NODE_LEFT);
}
Also used : GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) GridCacheQueryMarshallable(org.apache.ignite.internal.processors.cache.query.GridCacheQueryMarshallable) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) UUID(java.util.UUID)

Aggregations

UUID (java.util.UUID)30 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)30 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 ClusterNode (org.apache.ignite.cluster.ClusterNode)12 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)11 Event (org.apache.ignite.events.Event)11 GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)11 GridIoManager (org.apache.ignite.internal.managers.communication.GridIoManager)7 Test (org.junit.Test)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 Collection (java.util.Collection)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 IgniteKernal (org.apache.ignite.internal.IgniteKernal)4 Message (org.apache.ignite.plugin.extensions.communication.Message)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 IgniteException (org.apache.ignite.IgniteException)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3