You've already forked FrameTour-BE
INotify
This commit is contained in:
45
src/main/java/com/ycwl/basic/notify/NotifyFactory.java
Normal file
45
src/main/java/com/ycwl/basic/notify/NotifyFactory.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package com.ycwl.basic.notify;
|
||||
|
||||
import com.ycwl.basic.notify.adapters.INotifyAdapter;
|
||||
import com.ycwl.basic.notify.enums.NotifyType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class NotifyFactory {
|
||||
public static INotifyAdapter get(NotifyType type) {
|
||||
switch (type) {
|
||||
case SERVER_CHAN:
|
||||
return new com.ycwl.basic.notify.adapters.ServerChanNotifyAdapter();
|
||||
default:
|
||||
throw new RuntimeException("不支持的通知类型");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected static Map<String, INotifyAdapter> namedNotifier = new HashMap<>();
|
||||
protected static INotifyAdapter defaultNotifier = null;
|
||||
|
||||
public static void register(String name, INotifyAdapter adapter) {
|
||||
namedNotifier.put(name, adapter);
|
||||
}
|
||||
|
||||
public static INotifyAdapter to(String name) {
|
||||
INotifyAdapter adapter = namedNotifier.get(name);
|
||||
if (adapter == null) {
|
||||
throw new RuntimeException("未定义的通知方式:"+name);
|
||||
}
|
||||
return adapter;
|
||||
}
|
||||
|
||||
public static INotifyAdapter to() {
|
||||
if (defaultNotifier == null) {
|
||||
throw new RuntimeException("未定义默认通知方式");
|
||||
}
|
||||
return defaultNotifier;
|
||||
}
|
||||
|
||||
public static void setDefault(String defaultStorage) {
|
||||
NotifyFactory.defaultNotifier = to(defaultStorage);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user