Search in sources :

Example 1 with DiscoveryEventListener

use of org.apache.ignite.internal.managers.eventstorage.DiscoveryEventListener 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)

Aggregations

UUID (java.util.UUID)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)1 GridIoManager (org.apache.ignite.internal.managers.communication.GridIoManager)1 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)1 DiscoCache (org.apache.ignite.internal.managers.discovery.DiscoCache)1 GridDiscoveryManager (org.apache.ignite.internal.managers.discovery.GridDiscoveryManager)1 DiscoveryEventListener (org.apache.ignite.internal.managers.eventstorage.DiscoveryEventListener)1 IgniteThreadPoolExecutor (org.apache.ignite.thread.IgniteThreadPoolExecutor)1