All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.larksuite.oapi.core.event.IHandler Maven / Gradle / Ivy

Go to download

Larksuite open platform facilitates the integration of enterprise applications and larksuite, making collaboration and management more efficient

There is a newer version: 1.0.18-rc8
Show newest version
package com.larksuite.oapi.core.event;

import com.larksuite.oapi.core.Config;
import com.larksuite.oapi.core.Context;

import java.util.HashMap;
import java.util.Map;

public interface IHandler {
    E getEvent();

    void Handle(Context context, E event) throws Exception;


    class Hub {
        public static final Map> appID2EventType2Handler = new HashMap<>();

        public static void setEventTypeHandler(Config config, String eventType, IHandler handler) {
            String appID = config.getAppSettings().getAppID();
            Map eventType2Handler = appID2EventType2Handler.computeIfAbsent(appID, k -> new HashMap<>());
            eventType2Handler.put(eventType, handler);
        }

        public static void setEventTypeHandler(Config config, String eventType, DefaultHandler handler) {
            setEventTypeHandler(config, eventType, new defaultHandler(handler));
        }

        public static IHandler GetEventHandler(Config config, String eventType) {
            String appID = config.getAppSettings().getAppID();
            Map eventType2Handler = appID2EventType2Handler.get(appID);
            if (eventType2Handler == null) {
                return null;
            }
            return eventType2Handler.get(eventType);
        }

    }

    class defaultHandler implements IHandler> {

        private final DefaultHandler handler;

        public defaultHandler(DefaultHandler handler) {
            this.handler = handler;
        }

        @Override
        public Map getEvent() {
            return new HashMap<>();
        }

        @Override
        public void Handle(Context context, Map event) throws Exception {
            this.handler.Handle(context, event);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy