From 35a3c8139190cba2b2b67f3d0f2b9fdb57953db1 Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Fri, 18 May 2018 15:11:18 +0800 Subject: [PATCH] --- src/org/redkale/boot/NodeServer.java | 120 --------------------------- 1 file changed, 120 deletions(-) diff --git a/src/org/redkale/boot/NodeServer.java b/src/org/redkale/boot/NodeServer.java index b0e46122c..09e45b5a5 100644 --- a/src/org/redkale/boot/NodeServer.java +++ b/src/org/redkale/boot/NodeServer.java @@ -19,7 +19,6 @@ import javax.annotation.*; import javax.persistence.Transient; import static org.redkale.boot.Application.*; import org.redkale.boot.ClassFilter.FilterEntry; -import org.redkale.convert.bson.*; import org.redkale.net.Filter; import org.redkale.net.*; import org.redkale.net.http.*; @@ -500,125 +499,6 @@ public abstract class NodeServer { maxClassNameLength = Math.max(maxClassNameLength, Sncp.getResourceType(y).getName().length() + 1); } - //尚未完整实现, 先屏蔽, 单个Service在多个Server中存在的情况下进行缓存的方案还未考虑清楚 - @SuppressWarnings("unchecked") - private void loadPersistData() throws Exception { - File home = application.getHome(); - if (home == null || !home.isDirectory()) return; - File cachedir = new File(home, "cache"); - if (!cachedir.isDirectory()) return; - int port = this.server.getSocketAddress().getPort(); - final String prefix = "persist-" + port + "-"; - final BsonConvert convert = BsonFactory.create().skipAllIgnore(true).getConvert(); - synchronized (this.application) { - for (final File file : cachedir.listFiles((dir, name) -> name.startsWith(prefix))) { - if (!file.getName().endsWith(".bat")) continue; - String classAndResname = file.getName().substring(prefix.length(), file.getName().length() - 4); //去掉尾部的.bat - int pos = classAndResname.indexOf('-'); - String servtype = pos > 0 ? classAndResname.substring(0, pos) : classAndResname; - String resname = pos > 0 ? classAndResname.substring(pos + 1) : ""; - - FileInputStream in = new FileInputStream(file); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - int b; - while ((b = in.read()) != '\n') out.write(b); - final String[] fieldNames = out.toString().split(","); - int timeout = (int) ((System.currentTimeMillis() - file.lastModified()) / 1000); - for (final Service service : this.localServices) { - if (!servtype.equals(Sncp.getResourceType(service).getName())) continue; - if (!resname.equals(Sncp.getResourceName(service))) continue; - for (final String fieldName : fieldNames) { - Field field = null; - Class clzz = service.getClass(); - do { - try { - field = clzz.getDeclaredField(fieldName); - break; - } catch (Exception e) { - } - } while ((clzz = clzz.getSuperclass()) != Object.class); - field.setAccessible(true); - Object val = convert.convertFrom(field.getGenericType(), in); - Persist persist = field.getAnnotation(Persist.class); - if (persist.timeout() == 0 || persist.timeout() >= timeout) { - if (Modifier.isFinal(field.getModifiers())) { - if (Map.class.isAssignableFrom(field.getType())) { - ((Map) field.get(service)).putAll((Map) val); - } else if (Collection.class.isAssignableFrom(field.getType())) { - ((Collection) field.get(service)).addAll((Collection) val); - } - } else { - field.set(service, val); - } - } - if (in.read() != '\n') logger.log(Level.SEVERE, servtype + "'s [" + resname + "] load value error"); - } - } - in.close(); - } - } - } - - //尚未完整实现, 先屏蔽 - @SuppressWarnings("unchecked") - private void savePersistData() throws IOException { - File home = application.getHome(); - if (home == null || !home.isDirectory()) return; - File cachedir = new File(home, "cache"); - int port = this.server.getSocketAddress().getPort(); - final String prefix = "persist-" + port + "-"; - final BsonConvert convert = BsonFactory.create().skipAllIgnore(true).getConvert(); - for (final Service service : this.localServices) { - Class clzz = service.getClass(); - final Set fieldNameSet = new HashSet<>(); - final List fields = new ArrayList<>(); - final StringBuilder sb = new StringBuilder(); - do { - for (Field field : clzz.getDeclaredFields()) { - if (field.getAnnotation(Persist.class) == null) continue; - if (fieldNameSet.contains(field.getName())) continue; - if (Modifier.isStatic(field.getModifiers())) throw new RuntimeException(field + " cannot static on @" + Persist.class.getName() + " in " + clzz.getName()); - if (Modifier.isFinal(field.getModifiers()) && !Map.class.isAssignableFrom(field.getType()) && !Collection.class.isAssignableFrom(field.getType())) { - throw new RuntimeException(field + " cannot final on @" + Persist.class.getName() + " in " + clzz.getName()); - } - fieldNameSet.add(field.getName()); - field.setAccessible(true); - try { - if (field.get(service) == null) continue; - } catch (Exception e) { - logger.log(Level.SEVERE, field + " get value error", e); - continue; - } - fields.add(field); - if (sb.length() > 0) sb.append(','); - sb.append(field.getName()); - } - } while ((clzz = clzz.getSuperclass()) != Object.class); - - if (fields.isEmpty()) continue; //没有数据需要缓存 -// synchronized (this.application.localServices) { -// if (this.application.localServices.contains(service)) continue; -// this.application.localServices.add(service); -// } - if (!cachedir.isDirectory()) cachedir.mkdirs(); - String resname = Sncp.getResourceName(service); - FileOutputStream out = new FileOutputStream(new File(cachedir, prefix + Sncp.getResourceType(service).getName() + (resname.isEmpty() ? "" : ("-" + resname)) + ".bat")); - out.write(sb.toString().getBytes()); - out.write('\n'); - for (Field field : fields) { - Object val = null; - try { - val = field.get(service); - } catch (Exception e) { - logger.log(Level.SEVERE, field + " save value error", e); - } - convert.convertTo(out, field.getGenericType(), val); - out.write('\n'); - } - out.close(); - } - } - protected abstract ClassFilter createFilterClassFilter(); protected abstract ClassFilter createServletClassFilter();