com.larksuite.oapi.core.event.IHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of larksuite-oapi Show documentation
Show all versions of larksuite-oapi Show documentation
Larksuite open platform facilitates the integration of enterprise applications and larksuite, making
collaboration and management more efficient
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