1 files added
5 files modified
| | |
| | | |
| | | private Map<String, List<MessageHandler>> routes; |
| | | |
| | | private Map<String, ReentrantLock> lockMap = new HashMap<>(); |
| | | |
| | | private Map<String, ConcurrentLinkedQueue> messageQueue = new HashMap<>(); |
| | | |
| | | |
| | | @Override |
| | | public void run(ApplicationArguments args) throws Exception { |
| | |
| | | String getName(); |
| | | |
| | | /** |
| | | * 返回任务的路由key |
| | | * 返回任务的路由key,当有对应key的事件发生时,消息管理器会触发handle方法。 |
| | | * key 支持正则表达式 |
| | | * @return |
| | | */ |
| | | String getRouteKey(); |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Configuration |
| | | /** |
| | | * 小型应用弃用rabbitmq,直接通过观察者模式对消息进行同步消费 参考 AsyncMessageManager |
| | | */ |
| | | //@Configuration |
| | | public class RabbitMqConfig { |
| | | |
| | | @Value("${rabbitmq.host}") |
| | |
| | | public class InitWebContainer implements ApplicationRunner { |
| | | |
| | | |
| | | private static ConcurrentMap<String,Object> localCache=new ConcurrentHashMap(60); |
| | | |
| | | private static final String TRUE = "true"; |
| | | |
| | | static private final String LANGUAGE_ZH = "zh"; |
| | |
| | | for (SysCompany sysCompany : company) { |
| | | companyMap.put(sysCompany.getComWebUrl(), sysCompany); |
| | | } |
| | | saveLocalCache("companyMap", companyMap); |
| | | LocalCache.save("companyMap", companyMap); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取本地缓存 |
| | | * @param key |
| | | * @param <T> |
| | | * @return |
| | | */ |
| | | public static <T> T getLocalCache(String key){ |
| | | return (T)localCache.get(key); |
| | | } |
| | | |
| | | /** |
| | | * 保存一个本地缓存 |
| | | * @param key |
| | | * @param value |
| | | */ |
| | | public static void saveLocalCache(String key,Object value){ |
| | | if(null!=localCache.put(key,value)){ |
| | | LogUtil.debug("覆盖原有缓存{}",key); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.matrix.system.common.init; |
| | | |
| | | import com.matrix.core.tools.LogUtil; |
| | | |
| | | import java.util.Date; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.ConcurrentMap; |
| | | |
| | | public class LocalCache { |
| | | |
| | | |
| | | private static ConcurrentMap<String,Value> localCache=new ConcurrentHashMap(60); |
| | | |
| | | /** |
| | | * 获取本地缓存 |
| | | * @param key |
| | | * @param <T> |
| | | * @return |
| | | */ |
| | | public static <T> T get(String key){ |
| | | return (T)localCache.get(key); |
| | | } |
| | | |
| | | /** |
| | | * 保存一个本地缓存 |
| | | * @param key |
| | | * @param value |
| | | */ |
| | | public static void save(String key,Object value){ |
| | | if(null!=localCache.put(key,value)){ |
| | | LogUtil.debug("覆盖原有缓存{}",key); |
| | | } |
| | | } |
| | | |
| | | public static void save(String key,Object value,long timeOut){ |
| | | if(null!=localCache.put(key,value)){ |
| | | LogUtil.debug("覆盖原有缓存{}",key); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 缓存对象 |
| | | */ |
| | | class Value{ |
| | | |
| | | /** |
| | | * 过期时间,0 表示不过期 |
| | | */ |
| | | private long timeOut=0; |
| | | /** |
| | | * 缓存值 |
| | | */ |
| | | private Object value; |
| | | |
| | | /** |
| | | * 缓存创建时间 |
| | | */ |
| | | private long createTime; |
| | | |
| | | |
| | | |
| | | |
| | | public static Value build(String value,long timeOut){ |
| | | Value instances=new Value(); |
| | | instances.createTime=System.currentTimeMillis(); |
| | | instances.value=value; |
| | | instances.timeOut=timeOut; |
| | | return instances; |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | import com.matrix.core.tools.WebUtil; |
| | | import com.matrix.system.common.bean.SysCompany; |
| | | import com.matrix.system.common.init.InitWebContainer; |
| | | import com.matrix.system.common.init.LocalCache; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; |
| | |
| | | return false; |
| | | } |
| | | |
| | | Map<String, SysCompany> companyMap = InitWebContainer.getLocalCache("companyMap"); |
| | | Map<String, SysCompany> companyMap = LocalCache.get("companyMap"); |
| | | SysCompany company=companyMap.get(host); |
| | | if(Objects.nonNull(company)){ |
| | | // 查到公司后存到sesssion中 |