WANG 6 rokov pred
rodič
commit
c516807f99

+ 59 - 0
src/main/java/cn/com/qmth/examcloud/web/cache/CacheCloudServiceProvider.java

@@ -0,0 +1,59 @@
+package cn.com.qmth.examcloud.web.cache;
+
+import java.util.Map;
+
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.google.common.collect.Maps;
+
+import cn.com.qmth.examcloud.api.commons.CloudService;
+import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
+import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
+import cn.com.qmth.examcloud.commons.util.JsonUtil;
+import cn.com.qmth.examcloud.web.support.SpringContextHolder;
+
+/**
+ * cache
+ *
+ * @author WANGWEI
+ * @date 2018年8月23日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+@RestController
+@RequestMapping("cache")
+public class CacheCloudServiceProvider implements CloudService {
+
+	private static final long serialVersionUID = -5326807830421467943L;
+
+	protected static final ExamCloudLog LOG = ExamCloudLogFactory
+			.getLog(CacheCloudServiceProvider.class);
+
+	private static Map<String, ObjectCache<?>> map = Maps.newConcurrentMap();
+
+	@RequestMapping(value = "refresh", method = RequestMethod.POST)
+	public String post(@RequestBody RefreshCacheReq req) {
+
+		String className = req.getClassName();
+		Object[] keys = req.getKeys();
+
+		ObjectCache<?> objectCache = map.get(className);
+		if (null == objectCache) {
+
+			try {
+				Class<?> c = Class.forName(className);
+				objectCache = (ObjectCache<?>) SpringContextHolder.getBean(c);
+				map.put(className, objectCache);
+			} catch (ClassNotFoundException e) {
+				throw new StatusException("008001", "class not found");
+			}
+		}
+		objectCache.refresh(keys);
+		Object object = objectCache.get(keys);
+		return JsonUtil.toJson(object);
+	}
+
+}

+ 39 - 0
src/main/java/cn/com/qmth/examcloud/web/cache/RefreshCacheReq.java

@@ -0,0 +1,39 @@
+package cn.com.qmth.examcloud.web.cache;
+
+import cn.com.qmth.examcloud.api.commons.exchange.BaseRequest;
+
+/**
+ * 刷新缓存请求
+ *
+ * @author WANGWEI
+ * @date 2019年5月9日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class RefreshCacheReq extends BaseRequest {
+
+	/**
+	 * 属性注释
+	 */
+	private static final long serialVersionUID = -6516842403328041136L;
+
+	private String className;
+
+	private String[] keys;
+
+	public String getClassName() {
+		return className;
+	}
+
+	public void setClassName(String className) {
+		this.className = className;
+	}
+
+	public String[] getKeys() {
+		return keys;
+	}
+
+	public void setKeys(String[] keys) {
+		this.keys = keys;
+	}
+
+}

+ 0 - 9
src/main/java/cn/com/qmth/examcloud/web/cloud/CloudClientSupport.java

@@ -66,14 +66,6 @@ public abstract class CloudClientSupport {
 	 */
 	protected abstract String getRequestMappingPrefix();
 
-	/**
-	 * 获取端口
-	 *
-	 * @author WANGWEI
-	 * @return
-	 */
-	protected abstract Integer getPort();
-
 	/**
 	 * 获取 RestTemplate
 	 *
@@ -99,7 +91,6 @@ public abstract class CloudClientSupport {
 		StringBuilder sb = new StringBuilder();
 		sb.append("http://");
 		sb.append(appName);
-		sb.append(":").append(getPort());
 		String rmp = getRequestMappingPrefix();
 		if (rmp.startsWith("/")) {
 			sb.append(rmp);