From f6cc6bbb7d6922f2d9fcac63c969230960371a23 Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@maiol.ru> Date: Fri, 24 Mar 2017 07:27:25 +0100 Subject: [PATCH] more work on webstart --- build.xml | 2 +- nbproject/private/config.properties | 1 + nbproject/project.properties | 8 +- src/gui/EditStrategies.java | 2 +- src/sesim/AutoTraderLoader.java | 156 ++++++++++++++++----------- src/traders/ManTrader/ManTrader.java | 3 +- 6 files changed, 104 insertions(+), 68 deletions(-) diff --git a/build.xml b/build.xml index 0626b31..5e7db6f 100644 --- a/build.xml +++ b/build.xml @@ -109,7 +109,7 @@ --> - + diff --git a/nbproject/private/config.properties b/nbproject/private/config.properties index e69de29..47f9049 100644 --- a/nbproject/private/config.properties +++ b/nbproject/private/config.properties @@ -0,0 +1 @@ +config=sesimws diff --git a/nbproject/project.properties b/nbproject/project.properties index 570584d..3694714 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,4 +1,4 @@ -#Tue, 21 Mar 2017 02:08:14 +0100 +#Thu, 23 Mar 2017 20:54:23 +0100 annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processors.list= @@ -58,12 +58,14 @@ javadoc.version=false javadoc.windowtitle= jnlp.applet.height=300 jnlp.applet.width=300 -jnlp.codebase.type=no.codebase +jnlp.codebase.type=user +jnlp.codebase.url=$$$$codebase +jnlp.codebase.user=https\://blog.cauwersin.com/sesim https\://blog.cauwersin.com/sesim/lib jnlp.descriptor=application jnlp.enabled=true jnlp.icon= jnlp.mixed.code=default -jnlp.offline-allowed=false +jnlp.offline-allowed=true jnlp.signed=true jnlp.signing=key jnlp.signing.alias=SeSim diff --git a/src/gui/EditStrategies.java b/src/gui/EditStrategies.java index 7f6916f..4e879e4 100644 --- a/src/gui/EditStrategies.java +++ b/src/gui/EditStrategies.java @@ -284,7 +284,7 @@ public final class EditStrategies extends javax.swing.JDialog { } - System.out.printf("Base %s\n", base); + Globals.LOGGER.info(String.format("Base %s\n", base)); ac = Globals.tloader.getStrategyBase(base); if (ac == null) { diff --git a/src/sesim/AutoTraderLoader.java b/src/sesim/AutoTraderLoader.java index 2774b59..1d79e74 100644 --- a/src/sesim/AutoTraderLoader.java +++ b/src/sesim/AutoTraderLoader.java @@ -49,21 +49,19 @@ import java.util.logging.Logger; * @author 7u83 <7u83@mail.ru> */ public class AutoTraderLoader { - - private ArrayList pathlist; + + private ArrayList pathlist; private ArrayList> traders_cache; - - public AutoTraderLoader(ArrayList pathlist){ + + public AutoTraderLoader(ArrayList pathlist) { setPathList(pathlist); } - - - public final void setPathList(ArrayList pathlist){ - this.pathlist=pathlist; - this.traders_cache=null; + + public final void setPathList(ArrayList pathlist) { + this.pathlist = pathlist; + this.traders_cache = null; } - - + /** * Check if a given class can instaciated as AutoTrader. * @@ -78,15 +76,15 @@ public class AutoTraderLoader { do { for (Class i : cls.getInterfaces()) { Globals.LOGGER.info(String.format("Interface: %s", i.getCanonicalName())); - + String cn = AutoTraderInterface.class.getCanonicalName(); - Globals.LOGGER.info(String.format("Interface1: %s", cn)); - - // if (i == (AutoTraderInterface.class)) { - if (cn.endsWith(i.getCanonicalName())){ - + Globals.LOGGER.info(String.format("Interface1: %s", cn)); + + // if (i == (AutoTraderInterface.class)) { + if (cn.endsWith(i.getCanonicalName())) { + Globals.LOGGER.info("YEEEEA"); - + return true; } } @@ -94,15 +92,34 @@ public class AutoTraderLoader { } while ((cls = cls.getSuperclass()) != null); return false; } + + + private ClassLoader cl; + + public AutoTraderInterface MakeInstance(Class cls){ + ClassLoader cur = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(cl); + + AutoTraderInterface ai; + Globals.LOGGER.info("Going to load"); + try { + ai = (AutoTraderInterface)cls.newInstance(); + } catch (InstantiationException | IllegalAccessException ex) { + Globals.LOGGER.info("Ist was passiert"); + Logger.getLogger(AutoTraderLoader.class.getName()).log(Level.SEVERE, null, ex); + ai=null; + } + Thread.currentThread().setContextClassLoader(cur); + + return ai; + } + Class loadAutoTraderClass(String filename, String classname) { - - - - System.out.printf("Comming in width %s %s\n", filename, classname); - Globals.LOGGER.info(String.format("Comming in width %s %s\n", filename, classname)); - + System.out.printf("Comming in width %s %s", filename, classname); + Globals.LOGGER.info(String.format("Comming in width %s %s\n", filename, classname)); + if (classname == null) { System.out.printf("Calssname is null\n"); @@ -121,44 +138,51 @@ public class AutoTraderLoader { } Globals.LOGGER.info(String.format("URL: %s", url.toString())); - + URL[] urls = new URL[]{url}; + // Create a new class loader with the directory - ClassLoader cl = new URLClassLoader(urls); + cl = new URLClassLoader(urls); + + + //Thread.currentThread().setContextClassLoader(cl); + + cl = Thread.currentThread().getContextClassLoader(); + try { Globals.LOGGER.info("try cl"); - // Class cls = cl.loadClass(clnam); - Classc = cl.loadClass(clnam); - if (c==null){ + // Class cls = cl.loadClass(clnam); + Class c = cl.loadClass(clnam); + if (c == null) { Globals.LOGGER.info("loader c was null"); } Globals.LOGGER.info("Ccast"); - Class cls = (Class)c; // cl.loadClass(clnam); - return cls; - /* if (cls == null){ - + Class cls = (Class) c; // cl.loadClass(clnam); + // return cls; + if (cls == null) { + } - - System.out.printf("Check Class: %s\n", cls.getCanonicalName()); + + System.out.printf("Check Class: %s\n", cls.getCanonicalName()); Globals.LOGGER.info(String.format("Class prope %s", cls.getCanonicalName())); - + if (isAutoTrader(cls)) { - + Globals.LOGGER.info("We have found an autotrader interface"); Class claa; claa = (Class) cls; - - if (claa==null){ + + if (claa == null) { Globals.LOGGER.info("claa = null"); } - + Globals.LOGGER.info("return ok"); return claa; //return (Class) cls; //return (Class) cls; } - */ + } catch (ClassNotFoundException ex) { // something wnet wrong, but we ignore it System.out.printf("Class not found\n"); @@ -168,17 +192,12 @@ public class AutoTraderLoader { } - - - /* public ArrayList> getTradersX() { + /* public ArrayList> getTradersX() { String[] a = System.getProperty("java.class.path").split(System.getProperty("path.separator")); this.pathlist=new ArrayList<>(Arrays.asList(a)); return getTraders0(); } - */ - - - + */ public ArrayList> getTraders() { if (traders_cache != null) { @@ -188,12 +207,10 @@ public class AutoTraderLoader { ArrayList> traders; traders = new ArrayList<>(); - - for (String classpathEntry : pathlist) { Globals.LOGGER.info(String.format("Here we ar looking now %s", classpathEntry)); - + Consumer pf = (Object t) -> { String fn = ((Path) t).toString(); @@ -213,37 +230,39 @@ public class AutoTraderLoader { if (fn.toLowerCase().endsWith(".jar")) { System.out.printf("Its a jar!\n"); Globals.LOGGER.info("Its a jar"); - + JarInputStream is = null; try { File jar = new File(fn); is = new JarInputStream(new FileInputStream(jar)); JarEntry entry; - - Globals.LOGGER.info("starting entries"); + + Globals.LOGGER.info("starting entries"); while ((entry = is.getNextJarEntry()) != null) { Globals.LOGGER.info(String.format("Jar entry: %s", entry)); - + if (entry.getName().endsWith(".class")) { System.out.printf("Entry: %s\n", entry.getName()); - + String fn0 = entry.getName(); - Class cls = loadAutoTraderClass(fn, "/"+entry.getName()); + Class cls = loadAutoTraderClass(fn, "/" + entry.getName()); if (cls != null) { + Globals.LOGGER.info("Class is not null!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); traders.add(cls); } - Globals.LOGGER.info("clas was null"); + //Globals.LOGGER.info("clas was null"); } } } catch (IOException ex) { - Globals.LOGGER.info("ioeception"); + Globals.LOGGER.info("ioeception"); Logger.getLogger(AutoTraderLoader.class.getName()).log(Level.SEVERE, null, ex); } finally { try { is.close(); } catch (IOException ex) { + Logger.getLogger(AutoTraderLoader.class.getName()).log(Level.SEVERE, null, ex); } } @@ -260,6 +279,9 @@ public class AutoTraderLoader { } traders_cache = traders; + + Globals.LOGGER.info(String.format("We hav found %d traders", traders.size())); + return traders; } @@ -267,14 +289,16 @@ public class AutoTraderLoader { public ArrayList getDefaultStrategyNames(boolean devel) { ArrayList> trclasses; trclasses = this.getTraders(); - + ArrayList ret = new ArrayList<>(); trclasses = getTraders(); for (int i = 0; i < trclasses.size(); i++) { try { - AutoTraderInterface ac = trclasses.get(i).newInstance(); + //AutoTraderInterface ac = trclasses.get(i).newInstance(); + AutoTraderInterface ac = this.MakeInstance(trclasses.get(i)); + if (ac.getDevelStatus() && devel == false) { continue; } @@ -297,7 +321,14 @@ public class AutoTraderLoader { ArrayList> traders = this.getTraders(); for (int i = 0; i < traders.size(); i++) { try { - AutoTraderInterface ac = traders.get(i).newInstance(); + Globals.LOGGER.info(String.format("Making lll instance of %s", traders.get(i).getCanonicalName())); + + if (traders.get(i)==null){ + Globals.LOGGER.info("We have null"); + } + +// AutoTraderInterface ac = traders.get(i).newInstance(); + AutoTraderInterface ac = this.MakeInstance(traders.get(i)); System.out.printf("Looking for in %s == %s\n", ac.getClass().getCanonicalName(), name); @@ -308,6 +339,7 @@ public class AutoTraderLoader { // return ac;} } } catch (Exception ex) { + Globals.LOGGER.info(String.format("Instance failed %s", ex.getMessage())); } } diff --git a/src/traders/ManTrader/ManTrader.java b/src/traders/ManTrader/ManTrader.java index 7f4fefc..964d91d 100644 --- a/src/traders/ManTrader/ManTrader.java +++ b/src/traders/ManTrader/ManTrader.java @@ -34,6 +34,7 @@ import sesim.AutoTraderBase; import sesim.AutoTraderConfigBase; import sesim.AutoTraderConfig; import sesim.AutoTraderGui; +import sesim.AutoTraderInterface; import sesim.Exchange; import sesim.Exchange.AccountListener; import sesim.Exchange.OrderStatus; @@ -42,7 +43,7 @@ import sesim.Exchange.OrderStatus; * * @author 7u83 <7u83@mail.ru> */ -public class ManTrader extends AutoTraderBase implements AccountListener { +public class ManTrader extends AutoTraderBase implements AccountListener, AutoTraderInterface{ public ManTrader(Exchange se, long id, String name, double money, double shares, AutoTraderConfig config) { // super(se, id, name, money, shares, null);