Changeset 88 for java/main/src
- Timestamp:
- 06/30/13 12:48:20 (11 years ago)
- Location:
- java/main/src
- Files:
-
- 30 added
- 12 deleted
- 51 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/communication/ClientConnection.java
r85 r88 32 32 protected final Map<String, Subscription<?>> subscriptions = new HashMap<>(); 33 33 34 public String getAddress() { 35 return address; 36 } 37 38 public void connect(StateFunctor connectedFunctor) { 34 /** 35 * @param connectedFunctor the connectedFunctor to set 36 */ 37 public void setConnectedFunctor(StateFunctor connectedFunctor) { 38 this.connectedFunctor = connectedFunctor; 39 } 40 41 42 protected StateFunctor connectedFunctor; 43 44 @Override 45 protected void joinableStart() { 39 46 try { 40 47 log.info("connecting to " + address); … … 46 53 log.info("connected to " + hostName + ":" + port); 47 54 connected = true; 48 49 55 runThreads(); 50 56 … … 56 62 log.error("buffer creation failure"); 57 63 connectedFunctor.call(e); 58 close(); 59 } 60 } 64 // close(); 65 } 66 } 67 61 68 62 69 private static abstract class InboundMessage { … … 149 156 150 157 151 protected final String address;152 158 protected final String hostName; 153 159 protected final int port; … … 156 162 157 163 public ClientConnection(String address) { 158 assert address != null; 159 this.address = address; 164 super(address); 160 165 Matcher matcher = addressPattern.matcher(address); 161 166 if (!matcher.matches()) { … … 235 240 @Override 236 241 public String toString() { 237 return address;242 return "client connection " + address; 238 243 } 239 244 … … 328 333 private int nextQueryId = 0; 329 334 330 protected void processMessage(InboundMessage inboundMessage) throws Exception{335 protected void processMessage(InboundMessage inboundMessage) { 331 336 if (inboundMessage == null) { 332 337 log.error("failed to use any inbound message"); … … 342 347 } 343 348 344 protected void processEvent(String rest) throws Exception{349 protected void processEvent(String rest) { 345 350 Matcher matcher = eventPattern.matcher(rest); 346 351 if (!matcher.matches()) { … … 359 364 360 365 361 protected void processMessageStartingWith(String line) throws Exception{366 protected void processMessageStartingWith(String line) { 362 367 Pair<String, String> command = Strings.splitIntoPair(line, ' ', "\n"); 363 368 if (command.first.equals("event")) { … … 384 389 385 390 @Override 386 protected void receiverThreadRoutine() throws Exception{391 protected void receiverThreadRoutine() { 387 392 while (connected) { 388 processMessageStartingWith(getLine()); 389 } 390 } 393 try { 394 processMessageStartingWith(getLine()); 395 } catch (Exception e) { 396 break; 397 } 398 } 399 } 400 391 401 392 402 } -
java/main/src/main/java/com/framsticks/communication/Connection.java
r85 r88 1 1 package com.framsticks.communication; 2 2 3 import com.framsticks.util.FramsticksException; 3 4 import com.framsticks.util.io.Encoding; 4 5 import com.framsticks.util.lang.Pair; … … 14 15 import java.util.regex.Pattern; 15 16 17 import com.framsticks.util.dispatching.AbstractJoinable; 18 import com.framsticks.util.dispatching.Dispatching; 19 import com.framsticks.util.dispatching.Joinable; 20 import com.framsticks.util.dispatching.JoinableCollection; 21 import com.framsticks.util.dispatching.JoinableParent; 22 import com.framsticks.util.dispatching.JoinableState; 16 23 import com.framsticks.util.dispatching.RunAt; 17 24 import com.framsticks.util.dispatching.Thread; 18 25 19 public abstract class Connection {26 public abstract class Connection extends AbstractJoinable implements JoinableParent { 20 27 21 28 protected final static Logger log = Logger.getLogger(Connection.class); … … 32 39 protected int protocolVersion = -1; 33 40 41 public String getAddress() { 42 return address; 43 } 44 protected final String address; 45 34 46 protected final Thread<Connection> senderThread = new Thread<>(); 35 47 protected final Thread<Connection> receiverThread = new Thread<>(); 36 48 protected final JoinableCollection<Thread<Connection>> threads = new JoinableCollection<>(true); 49 50 /** 51 * 52 */ 53 public Connection(String address) { 54 this.address = address; 55 threads.add(senderThread); 56 threads.add(receiverThread); 57 } 37 58 public boolean isConnected() { 38 59 return connected; 39 60 } 40 61 41 public void close() {42 protocolVersion = -1;43 try {44 connected = false;45 46 senderThread.interrupt();47 senderThread.join();48 49 receiverThread.interrupt();50 receiverThread.join();51 52 if (output != null) {53 output.close();54 output = null;55 }56 57 if (input != null) {58 input.close();59 input = null;60 }61 62 63 if (socket != null) {64 socket.close();65 socket = null;66 }67 68 log.info("connection closed");69 } catch (Exception e) {70 log.error(e);71 }72 73 }74 62 75 63 protected static final String ARGUMENT_PATTERN_FRAGMENT = "((?:\\S+)|(?:\"[^\"]*\"))"; … … 95 83 char[] readBuffer = new char[BUFFER_LENGTH]; 96 84 97 protected String getLine() throws Exception{85 protected String getLine() { 98 86 StringBuilder lineBuffer = new StringBuilder(); 99 while (!Thread.interrupted()) { 100 while (iterator < readChars) { 101 if (readBuffer[iterator] != '\n') { 87 try { 88 while (!Thread.interrupted()) { 89 while (iterator < readChars) { 90 if (readBuffer[iterator] != '\n') { 91 ++iterator; 92 continue; 93 } 94 lineBuffer.append(readBuffer, bufferStart, iterator - bufferStart + 1); 102 95 ++iterator; 103 continue; 96 bufferStart = iterator; 97 return lineBuffer.toString(); 104 98 } 105 lineBuffer.append(readBuffer, bufferStart, iterator - bufferStart + 1); 106 ++iterator; 107 bufferStart = iterator; 108 return lineBuffer.toString(); 109 } 110 lineBuffer.append(readBuffer, bufferStart, readChars - bufferStart); 111 112 readChars = 0; 113 while (readChars == 0) { 114 try { 115 readChars = input.read(readBuffer); 116 } catch (SocketTimeoutException ignored) { 117 //timeout - continue 99 lineBuffer.append(readBuffer, bufferStart, readChars - bufferStart); 100 101 readChars = 0; 102 while (readChars == 0) { 103 try { 104 readChars = input.read(readBuffer); 105 } catch (SocketTimeoutException ignored) { 106 //timeout - continue 107 } 118 108 } 119 } 120 iterator = 0; 121 bufferStart = 0; 122 } 123 throw new InterruptedException(); 124 } 125 126 protected abstract void receiverThreadRoutine() throws Exception; 109 iterator = 0; 110 bufferStart = 0; 111 } 112 throw new InterruptedException(); 113 } catch (Exception e) { 114 throw new FramsticksException().msg("failed to read line").cause(e); 115 } 116 } 117 118 protected abstract void receiverThreadRoutine(); 119 120 protected void setUpThread(Thread<Connection> thread, String name) { 121 thread.setName("connection thread " + address + " " + name); 122 } 127 123 128 124 protected void runThreads() { … … 132 128 } catch (IOException e) { 133 129 log.error("buffer creation failure"); 134 close();135 130 return; 136 131 } 137 132 138 senderThread.setName(this + "-sender"); 139 receiverThread.setName(this + "-receiver"); 140 141 senderThread.start(); 142 receiverThread.start(); 133 setUpThread(senderThread, "sender"); 134 setUpThread(receiverThread, "receiver"); 135 Dispatching.use(threads, this); 143 136 144 137 receiverThread.invokeLater(new RunAt<Connection>() { 145 138 @Override 146 139 public void run() { 147 try { 148 receiverThreadRoutine(); 149 } catch (InterruptedException ignored) { 150 log.debug("receiver thread interrupted"); 151 } catch (Exception e) { 152 log.error("error: " + e); 153 close(); 154 } 140 receiverThreadRoutine(); 155 141 } 156 142 }); 157 143 158 144 } 159 160 145 161 146 /** … … 164 149 * @return Query associated with query getId. 165 150 */ 166 167 151 public int getProtocolVersion() { 168 152 return protocolVersion; 169 153 } 170 154 171 155 @Override 156 protected void joinableInterrupt() { 157 protocolVersion = -1; 158 159 connected = false; 160 Dispatching.drop(threads, this); 161 162 // finish(); 163 } 164 165 @Override 166 protected void joinableFinish() { 167 try { 168 if (output != null) { 169 output.close(); 170 output = null; 171 } 172 173 if (input != null) { 174 input.close(); 175 input = null; 176 } 177 178 179 if (socket != null) { 180 socket.close(); 181 socket = null; 182 } 183 } catch (Exception e) { 184 log.error("failed to stop connection: ", e); 185 } 186 log.debug("connection closed"); 187 } 188 189 @Override 190 public void childChangedState(Joinable joinable, JoinableState state) { 191 proceedToState(state); 192 } 193 194 @Override 195 protected void joinableJoin() throws InterruptedException { 196 Dispatching.join(threads); 197 198 } 172 199 173 200 } -
java/main/src/main/java/com/framsticks/communication/ServerConnection.java
r85 r88 20 20 21 21 public ServerConnection(Socket socket, RequestHandler requestHandler) { 22 super("todo"); 22 23 this.socket = socket; 23 24 this.requestHandler = requestHandler; 24 25 connected = true; 25 26 26 }27 28 public void start() {29 runThreads();30 27 } 31 28 … … 36 33 37 34 @Override 38 protected void receiverThreadRoutine() throws Exception{35 protected void receiverThreadRoutine() { 39 36 while (connected) { 40 37 processNextRequest(); … … 98 95 } 99 96 100 protected void processNextRequest() throws Exception{97 protected void processNextRequest() { 101 98 String line = getLine(); 102 99 Pair<String, String> command = Strings.splitIntoPair(line, ' ', "\n"); … … 124 121 }); 125 122 } 123 124 @Override 125 protected void joinableStart() { 126 // TODO Auto-generated method stub 127 128 } 126 129 } -
java/main/src/main/java/com/framsticks/core/Entity.java
r86 r88 1 1 package com.framsticks.core; 2 2 3 import javax.annotation.OverridingMethodsMustInvokeSuper;4 3 5 4 import com.framsticks.params.annotations.FramsClassAnnotation; 6 import com.framsticks.params.annotations.ParamAnnotation; 7 import com.framsticks.util.dispatching.Thread; 8 import com.framsticks.util.dispatching.Dispatcher; 9 10 import org.apache.commons.configuration.Configuration; 11 import org.apache.log4j.Logger; 12 import com.framsticks.util.dispatching.RunAt; 5 import com.framsticks.util.dispatching.Joinable; 13 6 14 7 /** … … 16 9 */ 17 10 @FramsClassAnnotation 18 public abstract class Entity implements Dispatcher<Entity>{11 public interface Entity extends Joinable { 19 12 20 p rivate final static Logger log = Logger.getLogger(Entity.class);13 public String getName(); 21 14 22 @ParamAnnotation 23 protected String name = "entity"; 24 protected EntityOwner owner; 25 protected Dispatcher<Entity> dispatcher; 26 27 public Entity() { 28 } 29 30 public final String getName() { 31 return name; 32 } 33 34 /** 35 * @param name the name to set 36 */ 37 public final void setName(String name) { 38 this.name = name; 39 if (dispatcher instanceof Thread) { 40 ((Thread<Entity>) dispatcher).setName(name); 41 } 42 } 43 44 /** 45 * @return the owner 46 */ 47 public EntityOwner getOwner() { 48 return owner; 49 } 50 51 /** 52 * @param owner the owner to set 53 */ 54 public void setOwner(EntityOwner owner) { 55 this.owner = owner; 56 } 57 58 @Override 59 public final boolean isActive() { 60 return dispatcher == null || dispatcher.isActive(); 61 } 62 63 @Override 64 public final void invokeLater(RunAt<? extends Entity> runnable) { 65 assert dispatcher != null; 66 dispatcher.invokeLater(runnable); 67 } 68 69 public Dispatcher<Entity> createDefaultDispatcher() { 70 return new Thread<Entity>(name).start(); 71 } 72 73 @OverridingMethodsMustInvokeSuper 74 protected void run() { 75 assert isActive(); 76 log.info("running: " + this); 77 } 15 // /** 16 // * @param name the name to set 17 // */ 18 // @ParamAnnotation 19 // public final void setName(String name) { 20 // this.name = name; 21 // if (dispatcher instanceof Thread) { 22 // ((Thread<Entity>) dispatcher).setName(name); 23 // } 24 // } 78 25 79 26 80 public void configure(Configuration config) { 81 } 27 // public Dispatcher<Entity> createDefaultDispatcher() { 28 // return new Thread<Entity>().setName(name).start(); 29 // } 82 30 83 public Dispatcher<Entity> getDispatcher() { 84 return dispatcher; 85 } 86 87 /** 88 * @param dispatcher the dispatcher to set 89 */ 90 public void setDispatcher(Dispatcher<Entity> dispatcher) { 91 this.dispatcher = dispatcher; 92 } 93 94 public final void start() { 95 if (dispatcher == null) { 96 log.debug("no dispatcher set for " + this + ", creating default one"); 97 setDispatcher(createDefaultDispatcher()); 98 } 99 invokeLater(new RunAt<Entity>() { 100 @Override 101 public void run() { 102 Entity.this.run(); 103 } 104 }); 105 } 106 107 public final void done() { 108 log.info("stopping entity"); 109 if (owner != null) { 110 owner.onDone(); 111 } 112 } 113 31 // public void start() { 32 // if (dispatcher == null) { 33 // log.debug("no dispatcher set for " + this + ", creating default one"); 34 // dispatcher = createDefaultDispatcher(); 35 // } 36 // invokeLater(new RunAt<Entity>() { 37 // @Override 38 // public void run() { 39 // Entity.this.run(); 40 // } 41 // }); 42 // } 114 43 } -
java/main/src/main/java/com/framsticks/core/Instance.java
r87 r88 1 1 package com.framsticks.core; 2 2 3 import com.framsticks.communication.*; 4 import com.framsticks.params.*; 3 import java.util.HashSet; 4 import java.util.Iterator; 5 import java.util.LinkedList; 6 import java.util.List; 7 import java.util.Set; 8 9 import javax.annotation.Nonnull; 10 import javax.annotation.OverridingMethodsMustInvokeSuper; 11 12 import org.apache.log4j.Logger; 13 14 import com.framsticks.communication.File; 15 import com.framsticks.params.AccessInterface; 16 import com.framsticks.params.ConstructionException; 17 import com.framsticks.params.FramsClass; 18 import com.framsticks.params.ListAccess; 19 import com.framsticks.params.Param; 20 import com.framsticks.params.Registry; 21 import com.framsticks.params.ValueParam; 22 import com.framsticks.params.annotations.FramsClassAnnotation; 5 23 import com.framsticks.params.types.ObjectParam; 6 24 import com.framsticks.parsers.Loaders; 7 25 import com.framsticks.parsers.MultiParamLoader; 8 import com.framsticks.util. *;26 import com.framsticks.util.StateFunctor; 9 27 import com.framsticks.util.UnsupportedOperationException; 10 28 import com.framsticks.util.dispatching.Dispatching; 11 29 import com.framsticks.util.dispatching.Future; 30 import com.framsticks.util.dispatching.RunAt; 31 import com.framsticks.util.dispatching.Thread; 12 32 import com.framsticks.util.lang.Casting; 13 import org.apache.log4j.Logger;14 import com.framsticks.util.dispatching.RunAt;15 16 import java.util.*;17 33 18 34 /** 19 35 * @author Piotr Sniegowski 20 36 */ 21 public abstract class Instance extends Entity { 37 @FramsClassAnnotation 38 public abstract class Instance extends Thread<Instance> implements Entity { 22 39 23 40 private static final Logger log = Logger.getLogger(Instance.class.getName()); … … 25 42 protected Node root; 26 43 27 p ublicSet<InstanceListener> listeners = new HashSet<InstanceListener>();44 protected Set<InstanceListener> listeners = new HashSet<InstanceListener>(); 28 45 29 46 public Instance() { 30 } 31 32 @Override 33 protected void run() { 34 super.run(); 35 root = new Node(Param.build().name("Instance").id(name).type("o"), null); 36 com.framsticks.model.Package.register(registry); 47 setName("entity"); 37 48 } 38 49 … … 262 273 263 274 264 public FramsClass processFetchedInfo(File file) {275 public @Nonnull FramsClass processFetchedInfo(File file) { 265 276 assert isActive(); 266 277 FramsClass framsClass = Loaders.loadFramsClass(file.getContent()); 267 278 if ("/".equals(file.getPath())) { 268 279 if (root.getParam().getContainedTypeName() == null) { 269 root = new Node(Param.build().name("Instance").id( name).type("o " + framsClass.getId()), root.getObject());280 root = new Node(Param.build().name("Instance").id(getName()).type("o " + framsClass.getId()), root.getObject()); 270 281 } 271 282 } … … 346 357 return getPath("/"); 347 358 } 359 360 @Override 361 @OverridingMethodsMustInvokeSuper 362 protected void firstTask() { 363 root = new Node(Param.build().name("Instance").id(getName()).type("o"), null); 364 com.framsticks.model.Package.register(registry); 365 } 366 348 367 } 349 368 -
java/main/src/main/java/com/framsticks/core/LocalInstance.java
r85 r88 4 4 import com.framsticks.util.dispatching.Thread; 5 5 6 import org.apache.commons.configuration.Configuration;7 6 import org.apache.log4j.Logger; 8 7 … … 27 26 } 28 27 29 @Override30 public void configure(Configuration config) {31 Integer accept = config.getInteger("accept", null);32 if (accept != null) {33 try {34 acceptSocket = new ServerSocket();35 acceptSocket.setReuseAddress(true);36 acceptThread = new Thread<Accept>(name + "-accept").start();37 tryBind(accept);38 } catch (IOException e) {39 log.fatal("failed to create accept socket: " + e);40 }41 }42 }28 // @Override 29 // public void configure(Configuration config) { 30 // Integer accept = config.getInteger("accept", null); 31 // if (accept != null) { 32 // try { 33 // acceptSocket = new ServerSocket(); 34 // acceptSocket.setReuseAddress(true); 35 // acceptThread = new Thread<Accept>().setName(name + "-accept").start(); 36 // tryBind(accept); 37 // } catch (IOException e) { 38 // log.fatal("failed to create accept socket: " + e); 39 // } 40 // } 41 // } 43 42 44 43 protected final Set<InstanceClient> clients = new HashSet<InstanceClient>(); -
java/main/src/main/java/com/framsticks/diagnostics/Diagnostics.java
r84 r88 1 1 package com.framsticks.diagnostics; 2 2 3 import org.apache.commons.configuration.Configuration;4 3 5 import com.framsticks.observers.Endpoint; 6 import com.framsticks.observers.Observer; 4 import java.util.Date; 5 import java.io.File; 6 import java.io.FileOutputStream; 7 import java.io.IOException; 8 import java.io.OutputStreamWriter; 9 import java.io.PrintWriter; 10 import java.text.SimpleDateFormat; 11 12 import org.apache.log4j.Logger; 13 14 import com.framsticks.core.AbstractInstanceListener; 15 import com.framsticks.core.Instance; 16 import com.framsticks.dumping.PrintWriterSink; 17 import com.framsticks.dumping.SaveStream; 18 import com.framsticks.params.annotations.AutoAppendAnnotation; 19 import com.framsticks.remote.RecursiveFetcher; 20 import com.framsticks.util.Logging; 21 import com.framsticks.util.PeriodicTask; 22 import com.framsticks.util.StateFunctor; 23 import com.framsticks.util.dispatching.JoinableCollection; 24 import com.framsticks.util.io.Encoding; 7 25 8 26 /** 9 27 * @author Piotr Sniegowski 10 28 */ 11 public class Diagnostics extends Observer { 29 public class Diagnostics extends JoinableCollection<Instance> { 30 private static final Logger log = 31 Logger.getLogger(Diagnostics.class); 32 12 33 13 34 Integer dumpsInterval; … … 19 40 } 20 41 42 21 43 @Override 22 public void configure(Configuration config) { 23 super.configure(config); 24 dumpsInterval = config.getInteger("dumps.interval", null); 25 dumpsPath = config.getString("dumps.path", null); 26 dumpsFormat = config.getString("dumps.format", null); 44 @AutoAppendAnnotation 45 public void add(final Instance instance) { 46 super.add(instance); 47 48 instance.addListener(new AbstractInstanceListener() { 49 @Override 50 public void onRun(Exception e) { 51 if (e != null) { 52 return; 53 } 54 55 if (dumpsInterval != null) { 56 new PeriodicTask<Instance>(instance, dumpsInterval * 1000) { 57 @Override 58 public void run() { 59 60 log.info("starting periodic dump"); 61 new RecursiveFetcher(instance, instance.getRootPath(), new StateFunctor() { 62 @Override 63 public void call(Exception e) { 64 if (Logging.log(log, "recursively fetch", instance, e)) { 65 again(); 66 return; 67 } 68 log.info("instance resolved, saving"); 69 try { 70 final String fileName = dumpsPath + "/" + instance + "_" + new SimpleDateFormat(dumpsFormat).format(new Date()) + ".param"; 71 File file = new File(fileName); 72 new SaveStream(new PrintWriterSink(new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), Encoding.getFramsticksCharset()))), instance, instance.getRootPath(), new StateFunctor() { 73 @Override 74 public void call(Exception e) { 75 Logging.log(log, "periodic dump in " + fileName + " of", instance, e); 76 again(); 77 } 78 }); 79 } catch (IOException ex) { 80 log.info("failed to initiate dump: " + ex); 81 again(); 82 } 83 84 } 85 }); 86 } 87 }; 88 } 89 } 90 }); 91 92 93 27 94 } 28 95 29 30 @Override 31 protected Endpoint createEndpoint() { 32 return new DiagnosticsEndpoint(); 33 } 34 96 // @Override 97 // public void configure(Configuration config) { 98 // super.configure(config); 99 // dumpsInterval = config.getInteger("dumps.interval", null); 100 // dumpsPath = config.getString("dumps.path", null); 101 // dumpsFormat = config.getString("dumps.format", null); 102 // } 35 103 36 104 } -
java/main/src/main/java/com/framsticks/dumping/FileInstance.java
r85 r88 4 4 import com.framsticks.core.Path; 5 5 import com.framsticks.core.Instance; 6 import com.framsticks.params.annotations.FramsClassAnnotation; 7 import com.framsticks.params.annotations.ParamAnnotation; 6 8 import com.framsticks.util.dispatching.Future; 7 9 import com.framsticks.util.io.Encoding; 8 10 9 import org.apache.commons.configuration.Configuration;10 11 import org.apache.log4j.Logger; 11 12 … … 16 17 import java.io.InputStreamReader; 17 18 19 import javax.annotation.OverridingMethodsMustInvokeSuper; 20 18 21 /** 19 22 * @author Piotr Sniegowski 20 23 */ 24 @FramsClassAnnotation 21 25 public class FileInstance extends LocalInstance { 22 26 … … 27 31 } 28 32 29 @Override 30 public void configure(Configuration config) { 31 super.configure(config); 32 file = new File(config.getString("filename")); 33 @ParamAnnotation 34 public void setFilename(String filename) { 35 file = new File(filename); 36 } 37 38 @ParamAnnotation 39 public String getFilename() { 40 return file.getName(); 33 41 } 34 42 35 43 @Override 36 public void run() { 44 @OverridingMethodsMustInvokeSuper 45 protected void firstTask() { 37 46 assert isActive(); 38 super. run();47 super.firstTask(); 39 48 try { 40 49 LoadStream stream = new LoadStream(this.getRootPath(), new BufferedReader(new InputStreamReader(new FileInputStream(file), Encoding.getFramsticksCharset())), this, new Future<Path>() { -
java/main/src/main/java/com/framsticks/examples/GenotypeBrowser.java
r87 r88 2 2 3 3 import com.framsticks.core.Instance; 4 import com.framsticks.core.Node;5 4 import com.framsticks.dumping.PrintWriterSink; 6 5 import com.framsticks.model.*; 7 import com.framsticks.model. Package;6 import com.framsticks.model.f0.Schema; 8 7 import com.framsticks.params.*; 9 8 import com.framsticks.parsers.F0Parser; 10 9 import com.framsticks.parsers.F0Writer; 11 import com.framsticks.parsers.Schema;12 10 13 import org.apache.commons.configuration.Configuration;14 11 import org.apache.log4j.Logger; 15 12 … … 17 14 import java.io.StringWriter; 18 15 import java.util.List; 16 17 import javax.annotation.OverridingMethodsMustInvokeSuper; 19 18 20 19 /** … … 31 30 } 32 31 33 @Override34 public void configure(Configuration config) {35 super.configure(config);36 try {37 schema = new Schema(Schema.getDefaultDefinitionAsStream());38 } catch (Exception e) {39 log.error("failed to load schema: " + e);40 }41 this.registry = schema.getRegistry();42 Package.register(this.getRegistry());32 // @Override 33 // public void configure(Configuration config) { 34 // super.configure(config); 35 // try { 36 // schema = Schema.load(Schema.getDefaultDefinitionAsStream()); 37 // } catch (Exception e) { 38 // log.error("failed to load schema: " + e); 39 // } 40 // this.registry = schema.getRegistry(); 41 // Package.register(this.getRegistry()); 43 42 44 registry.putInfoIntoCache(FramsClass.build()45 .idAndName("ModelBuilderRoot")46 .param(Param.build().id("model").type("o Model").name("model"))47 .param(Param.build().id("genotype").type("s 1").name("genotype"))48 .finish()49 );50 root = new Node(Param.build().type("o ModelBuilderRoot").id(name).name("Instance"), PropertiesAccess.createPropertiesMap());51 }43 // registry.putInfoIntoCache(FramsClass.build() 44 // .idAndName("ModelBuilderRoot") 45 // .param(Param.build().id("model").type("o Model").name("model")) 46 // .param(Param.build().id("genotype").type("s 1").name("genotype")) 47 // .finish() 48 // ); 49 // root = new Node(Param.build().type("o ModelBuilderRoot").id(name).name("Instance"), PropertiesAccess.createPropertiesMap()); 50 // } 52 51 53 52 @Override 54 protected void run() { 53 @OverridingMethodsMustInvokeSuper 54 protected void firstTask() { 55 55 assert isActive(); 56 super.firstTask(); 56 57 57 58 try { -
java/main/src/main/java/com/framsticks/gui/Browser.java
r85 r88 2 2 3 3 import com.framsticks.core.*; 4 import com.framsticks.observers.Endpoint; 5 import com.framsticks.observers.Observer; 4 import com.framsticks.params.annotations.AutoAppendAnnotation; 5 import com.framsticks.params.annotations.FramsClassAnnotation; 6 import com.framsticks.params.annotations.ParamAnnotation; 6 7 import com.framsticks.util.Logging; 8 import com.framsticks.util.dispatching.AbstractJoinable; 7 9 import com.framsticks.util.dispatching.Dispatcher; 10 import com.framsticks.util.dispatching.Dispatching; 8 11 import com.framsticks.util.dispatching.Future; 9 10 import org.apache.commons.configuration.Configuration; 11 import org.apache.commons.lang.ArrayUtils; 12 import com.framsticks.util.dispatching.Joinable; 13 import com.framsticks.util.dispatching.JoinableCollection; 14 import com.framsticks.util.dispatching.JoinableParent; 15 import com.framsticks.util.dispatching.JoinableState; 16 17 import javax.swing.*; 18 12 19 import org.apache.log4j.Logger; 13 14 import javax.swing.*;15 20 16 21 import java.awt.Dimension; 17 22 import java.util.ArrayList; 18 import java.util.HashSet;19 23 import java.util.List; 20 import java.util. Set;24 import java.util.Map; 21 25 import com.framsticks.util.dispatching.RunAt; 22 26 … … 24 28 * @author Piotr Sniegowski 25 29 */ 26 public class Browser extends Observer { 30 @FramsClassAnnotation 31 public class Browser extends AbstractJoinable implements Dispatcher<Browser>, Entity, JoinableParent { 27 32 28 33 private static final Logger log = Logger.getLogger(Browser.class.getName()); 29 34 30 protected final Set<Frame> frames = new HashSet<Frame>(); 35 protected JoinableCollection<Frame> frames = new JoinableCollection<Frame>().setObservableName("frames"); 36 protected JoinableCollection<Instance> instances = new JoinableCollection<Instance>().setObservableName("instances"); 37 31 38 protected MainFrame mainFrame; 32 39 public List<PanelProvider> panelProviders = new ArrayList<PanelProvider>(); 33 40 protected Dimension defaultFrameDimension; 34 41 42 String name; 43 35 44 public void addFrame(Frame frame) { 36 45 frames.add(frame); … … 38 47 39 48 public Browser() { 49 setName("browser"); 40 50 JPopupMenu.setDefaultLightWeightPopupEnabled(false); 41 51 addPanelProvider(new StandardPanelProvider()); 42 } 43 44 @Override 45 public void configure(Configuration config) { 46 super.configure(config); 47 48 defaultFrameDimension = new Dimension(config.getInteger("size.width", 1000), config.getInteger("size.height", 500)); 49 50 for (String name : config.getStringArray("panel_providers")) { 51 try { 52 Class<?> c = Class.forName(name); 53 if (ArrayUtils.indexOf(c.getInterfaces(), PanelProvider.class) == -1) { 54 continue; 55 } 56 PanelProvider p = (PanelProvider)c.newInstance(); 57 addPanelProvider(p); 58 } catch (Exception e) { 59 log.error("failed to load PanelProvider " + name + ": " + e); 60 } 61 } 62 63 // for (final String path : config.getStringArray("resolve_paths")) { 64 // invokeLater() 65 // autoResolvePath(path, new Future<Path>() { 66 // @Override 67 // public void result(Path p, Exception e) { 68 // Logging.log(log, "auto resolve path", path, e); 69 // } 70 // }); 71 // } 72 } 73 52 53 mainFrame = new MainFrame(Browser.this); 54 addFrame(mainFrame); 55 } 56 57 @AutoAppendAnnotation 74 58 public void addPanelProvider(PanelProvider panelProvider) { 75 59 log.debug("added panel provider of type: " + panelProvider.getClass().getCanonicalName()); … … 77 61 } 78 62 63 @AutoAppendAnnotation 64 public void addInstance(Instance instance) { 65 log.info("adding instance: " + instance); 66 instances.add(instance); 67 } 68 79 69 public void autoResolvePath(final String path, final Future<Path> future) { 80 final Instance i = endpoints.get("localhost").getInstance();70 final Instance i = instances.get("localhost"); 81 71 i.invokeLater(new RunAt<Instance>() { 82 72 @Override … … 110 100 } 111 101 112 @Override 113 public void run() { 114 super.run(); 115 102 protected void firstTask() { 116 103 assert isActive(); 104 log.info("executing first task"); 117 105 118 106 try { … … 135 123 javax.swing.JFrame.setDefaultLookAndFeelDecorated(true); 136 124 137 mainFrame = new MainFrame(Browser.this);138 addFrame(mainFrame);139 125 140 126 for (Frame f : frames) { … … 142 128 } 143 129 144 for (final Endpoint e : getEndpoints().values()) {145 e.invokeLater(new RunAt<Instance>() {130 for (final Instance i : instances) { 131 i.invokeLater(new RunAt<Instance>() { 146 132 @Override 147 133 public void run() { 148 final Path p = e.getInstance().getRootPath();134 final Path p = i.getRootPath(); 149 135 invokeLater(new RunAt<Browser>() { 150 136 @Override 151 137 public void run() { 152 mainFrame.addRootPath( (BrowserEndpoint) e,p);138 mainFrame.addRootPath(p); 153 139 } 154 140 }); … … 158 144 159 145 for (Frame f : frames) { 160 f. setVisible(true);146 f.getSwing().setVisible(true); 161 147 } 162 148 … … 169 155 //assert instance.isActive(); 170 156 171 172 /* 173 final TreeNode parentTreeNode = (TreeNode) child.getParent().getUserObject(); 174 if (parentTreeNode == null) { 175 Dispatching.invokeDispatch(this, manager, new Runnable() { 176 @Override 177 public void run() { 178 createTreeNodeForChild(child); 179 } 180 }); 181 return; 182 } 183 log.debug(child.getClass().getSimpleName() + " created: " + child); 184 185 186 invokeLater(new Runnable() { 157 /* 158 final TreeNode parentTreeNode = (TreeNode) child.getParent().getUserObject(); 159 if (parentTreeNode == null) { 160 Dispatching.invokeDispatch(this, manager, new Runnable() { 161 @Override 162 public void run() { 163 createTreeNodeForChild(child); 164 } 165 }); 166 return; 167 } 168 log.debug(child.getClass().getSimpleName() + " created: " + child); 169 170 171 invokeLater(new Runnable() { 172 @Override 173 public void run() { 174 parentTreeNode.getOrCreateChildTreeNodeFor(child); 175 } 176 }); 177 */ 178 } 179 180 @Override 181 protected void joinableStart() { 182 Dispatching.use(frames, this); 183 Dispatching.use(instances, this); 184 185 invokeLater(new RunAt<Browser>() { 187 186 @Override 188 187 public void run() { 189 parentTreeNode.getOrCreateChildTreeNodeFor(child);188 firstTask(); 190 189 } 191 190 }); 192 */ 193 } 194 195 196 @Override 197 protected Endpoint createEndpoint() { 198 return new BrowserEndpoint(); 199 } 200 201 @Override 202 public Dispatcher<Entity> createDefaultDispatcher() { 203 return SwingDispatcher.getInstance(); 191 } 192 193 /** 194 * @return the instances 195 */ 196 public Map<String, Instance> getInstances() { 197 return instances.getObservables(); 204 198 } 205 199 … … 211 205 } 212 206 207 /** 208 * @return the name 209 */ 210 @ParamAnnotation 211 public String getName() { 212 return name; 213 } 214 215 /** 216 * @param name the name to set 217 */ 218 @ParamAnnotation 219 public void setName(String name) { 220 this.name = name; 221 } 222 223 @Override 224 public boolean isActive() { 225 return SwingDispatcher.getInstance().isActive(); 226 } 227 228 @Override 229 public void invokeLater(RunAt<? extends Browser> runnable) { 230 SwingDispatcher.getInstance().invokeLater(runnable); 231 } 232 233 @Override 234 protected void joinableJoin() throws InterruptedException { 235 Dispatching.join(frames); 236 Dispatching.join(instances); 237 // super.join(); 238 } 239 240 @Override 241 protected void joinableInterrupt() { 242 Dispatching.drop(frames, this); 243 Dispatching.drop(instances, this); 244 } 245 246 @Override 247 public void childChangedState(Joinable joinable, JoinableState state) { 248 if (joinable == frames) { 249 proceedToState(state); 250 } 251 252 } 253 254 @Override 255 protected void joinableFinish() { 256 // TODO Auto-generated method stub 257 258 } 259 260 @Override 261 public String toString() { 262 return getName(); 263 } 264 265 266 // @Override 267 // public boolean isDone() { 268 // return frames.isDone() && instances.isDone(); 269 // } 213 270 } -
java/main/src/main/java/com/framsticks/gui/Frame.java
r85 r88 1 1 package com.framsticks.gui; 2 2 3 import com.framsticks.core.Entity; 3 4 import com.framsticks.core.Instance; 4 5 import com.framsticks.core.Path; … … 6 7 import com.framsticks.gui.view.TreeCellRenderer; 7 8 import com.framsticks.util.dispatching.Dispatcher; 9 import com.framsticks.util.dispatching.JoinableCollection; 8 10 import com.framsticks.util.lang.ScopeEnd; 9 11 import com.framsticks.util.swing.KeyboardModifier; 12 import com.framsticks.util.swing.MenuConstructor; 13 10 14 import org.apache.log4j.Logger; 11 15 … … 28 32 */ 29 33 @SuppressWarnings("serial") 30 public class Frame extends J Frame implementsDispatcher<Frame> {34 public class Frame extends JoinableCollection<Instance> implements Entity, Dispatcher<Frame> { 31 35 32 36 private static final Logger log = Logger.getLogger(Frame.class.getName()); … … 34 38 protected final Browser browser; 35 39 36 protected final Dimension screenDimension = Toolkit.getDefaultToolkit() 37 .getScreenSize(); 38 39 final protected CardLayout cardPanelLayout = new CardLayout(); 40 protected final JPanel cardPanel = new JPanel(); 41 40 protected final Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); 41 42 protected CardLayout cardPanelLayout; 43 protected JPanel cardPanel; 44 45 protected final String title; 46 protected JFrame swing; 42 47 protected JScrollPane treeScrollPane; 43 48 protected JTree tree; … … 63 68 protected JMenu helpMenu; 64 69 65 protected final Map<BrowserEndpoint, EndpointAtFrame> endpoints = new HashMap<BrowserEndpoint, EndpointAtFrame>(); 66 protected final Map<Instance, EndpointAtFrame> endpointsByInstance = new HashMap<Instance, EndpointAtFrame>(); 70 protected final Map<Instance, InstanceAtFrame> instancesAtFrames = new HashMap<Instance, InstanceAtFrame>(); 67 71 68 72 public Frame(String title, Browser browser) { 69 super(title); 73 this.title = title; 74 this.browser = browser; 75 } 76 77 public void configure() { 78 swing = new JFrame(title); 79 swing.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); 80 swing.addWindowListener(new WindowAdapter() { 81 @Override 82 public void windowClosing(WindowEvent e) { 83 log.info("received closing"); 84 joinableFinish(); 85 } 86 }); 70 87 /** this is done to remove the current value label from above the slider, 71 88 * because it cannot put to work properly with floating-point value sliders, 72 89 * nor it can be removed in normal way through JSlider methods */ 73 90 UIManager.put("Slider.paintValue", false); 74 this.browser = browser;75 91 log.debug("creating " + this); 76 } 77 78 public void configure() { 79 80 Container contentPane = this.getContentPane(); 92 93 statusBar = new JLabel("not connected"); 94 95 Container contentPane = swing.getContentPane(); 81 96 contentPane.setLayout(new BorderLayout()); 82 97 … … 95 110 treePopupMenu.add(new JMenuItem("Refresh")); 96 111 treePopupMenu.add(new JMenuItem("Open in new frame as root")); 97 addNodeActionToTreePopupMenu("Copy path to clipboard", 98 new NodeAction() { 99 @Override 100 public void actionPerformed(TreeNode treeNode) { 101 Path path = treeNode.getInstancePath(); 102 StringSelection selection = new StringSelection(path 103 .toString()); 104 getToolkit().getSystemClipboard().setContents( 105 selection, selection); 106 } 107 }); 112 addNodeActionToTreePopupMenu("Copy path to clipboard", new NodeAction() { 113 @Override 114 public void actionPerformed(TreeNode treeNode) { 115 Path path = treeNode.getInstancePath(); 116 StringSelection selection = new StringSelection(path.toString()); 117 swing.getToolkit().getSystemClipboard().setContents(selection, selection); 118 } 119 }); 108 120 //this.add(createMenuItem("Add to favourites", null)); 109 121 //this.add(createMenuItem("Remove from favourites", null)); … … 171 183 }); 172 184 173 new KeyboardModifier(tree, JComponent.WHEN_FOCUSED) 174 .join(KeyStroke.getKeyStroke('h'), KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)) 175 .join(KeyStroke.getKeyStroke('j'), KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)) 176 .join(KeyStroke.getKeyStroke('k'), KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)) 177 .join(KeyStroke.getKeyStroke('l'), KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0)) 178 ; 185 new KeyboardModifier(tree, JComponent.WHEN_FOCUSED).join(KeyStroke.getKeyStroke('h'), KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)).join(KeyStroke.getKeyStroke('j'), KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)).join(KeyStroke.getKeyStroke('k'), KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)).join(KeyStroke.getKeyStroke('l'), KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0)); 179 186 180 187 tree.setCellRenderer(new TreeCellRenderer()); … … 214 221 leftPanel.setLayout(new BorderLayout()); 215 222 //leftPanel.add(new ViewerTest(), BorderLayout.PAGE_START); 216 // JPanel leftTopPanel = createLeftTopPanel();217 // if (leftTopPanel != null) {218 // leftPanel.add(leftTopPanel, BorderLayout.PAGE_START);219 // }223 // JPanel leftTopPanel = createLeftTopPanel(); 224 // if (leftTopPanel != null) { 225 // leftPanel.add(leftTopPanel, BorderLayout.PAGE_START); 226 // } 220 227 leftPanel.add(treePanel, BorderLayout.CENTER); 221 228 leftPanel.setBackground(Color.WHITE); 222 229 leftPanel.setForeground(Color.WHITE); 223 230 231 cardPanel = new JPanel(); 224 232 cardPanel.setName("card"); 225 233 JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, cardPanel); … … 236 244 mainPanelLayout.show(mainPanel, "browser"); 237 245 246 cardPanelLayout = new CardLayout(); 238 247 cardPanel.setLayout(cardPanelLayout); 239 248 240 this.pack();249 swing.pack(); 241 250 tree.requestFocusInWindow(); 242 251 243 log.debug("frame configured"); 252 log.debug("frame configured: " + this); 253 254 new MenuConstructor(fileMenu).add(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK), new AbstractAction("Close") { 255 @Override 256 public void actionPerformed(ActionEvent actionEvent) { 257 interrupt(); 258 } 259 }); 244 260 245 261 } … … 249 265 } 250 266 251 public void addRootPath( BrowserEndpoint endpoint,Path path) {252 assert isActive(); 253 assert !endpoints.containsKey(endpoint);254 255 EndpointAtFrame e = new EndpointAtFrame(endpoint, this); 256 endpoint.getInstance().addListener(e);257 endpoints.put(endpoint,e);258 endpointsByInstance.put(endpoint.getInstance(), e);267 public void addRootPath(Path path) { 268 assert isActive(); 269 Instance instance = path.getInstance(); 270 assert browser.getInstances().containsValue(instance); 271 272 InstanceAtFrame e = new InstanceAtFrame(instance, this); 273 instance.addListener(e); 274 instancesAtFrames.put(instance, e); 259 275 TreeNode node = new TreeNode(e, path); 260 276 e.rootTreeNode = node; … … 299 315 } 300 316 301 302 317 private void showPopup(MouseEvent e) { 303 318 assert isActive(); … … 314 329 } 315 330 331 /** 332 * @return the swing 333 */ 334 public JFrame getSwing() { 335 return swing; 336 } 337 316 338 public TreeNode getCurrentlyPoppedTreeNode() { 317 339 assert isActive(); 318 340 return currentlyPoppedTreeNode; 319 341 } 320 321 342 322 343 public void clear() { … … 342 363 public void selectTreeNode(final TreeNode treeNode) { 343 364 assert isActive(); 344 /* final Panel panel = treeNode.getOrCreatePanel();345 if (panel == null) {346 347 }348 panel.setCurrentTreeNode(treeNode);349 treeNode.updateData();350 showPanel(panel);*/365 /* final Panel panel = treeNode.getOrCreatePanel(); 366 if (panel == null) { 367 return; 368 } 369 panel.setCurrentTreeNode(treeNode); 370 treeNode.updateData(); 371 showPanel(panel);*/ 351 372 } 352 373 … … 359 380 return null; 360 381 } 361 return (TreeNode) treePath.getLastPathComponent();382 return (TreeNode) treePath.getLastPathComponent(); 362 383 } 363 384 … … 373 394 public void goTo(Path path) { 374 395 assert isActive(); 375 final TreePath treePath = endpointsByInstance.get(path.getInstance()).getTreePath(path, false);396 final TreePath treePath = instancesAtFrames.get(path.getInstance()).getTreePath(path, false); 376 397 log.info("go to path: " + path + "(" + treePath + ")"); 377 398 … … 388 409 } 389 410 390 391 411 public void addNode(TreeNode child, DefaultMutableTreeNode parent) { 392 412 assert isActive(); … … 399 419 @Override 400 420 public String toString() { 401 return getTitle() + "@" + browser.getName(); 402 } 421 return title + "@" + browser.getName(); 422 } 423 424 @Override 425 protected void joinableInterrupt() { 426 assert isActive(); 427 super.joinableInterrupt(); 428 429 invokeLater(new RunAt<Frame>() { 430 @Override 431 public void run() { 432 finish(); 433 } 434 }); 435 } 436 437 @Override 438 protected void joinableFinish() { 439 assert isActive(); 440 log.debug("disposing frame " + this); 441 swing.dispose(); 442 } 443 444 // @Override 445 // public boolean isDone() { 446 // return super.isDone() && !swing.isDisplayable(); 447 // } 448 449 450 @Override 451 public String getName() { 452 return title; 453 } 454 403 455 404 456 } -
java/main/src/main/java/com/framsticks/gui/MainFrame.java
r84 r88 28 28 */ 29 29 public MainFrame(final Browser browser) { 30 super(" Framsticks Network Client", browser);30 super("framsticks", browser); 31 31 log.debug("creating main frame"); 32 32 33 statusBar = new JLabel("not connected");34 33 } 35 34 … … 234 233 private void setFrameProperties() { 235 234 assert isActive(); 236 s etMinimumSize(this.getPreferredSize());237 s etSize(this.getPreferredSize());238 s etMaximumSize(screenDimension);239 s etDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);240 241 s etIconImage(ImageProvider.loadImage(ImageProvider.LOGO)235 swing.setMinimumSize(swing.getPreferredSize()); 236 swing.setSize(swing.getPreferredSize()); 237 swing.setMaximumSize(screenDimension); 238 swing.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 239 240 swing.setIconImage(ImageProvider.loadImage(ImageProvider.LOGO) 242 241 .getImage()); 243 242 244 243 245 addWindowListener(new WindowAdapter() {244 swing.addWindowListener(new WindowAdapter() { 246 245 public void windowClosing(WindowEvent e) { 247 246 assert isActive(); … … 252 251 */ 253 252 onWindowClosing(); 254 dispose();253 swing.dispose(); 255 254 } 256 255 }); -
java/main/src/main/java/com/framsticks/gui/MultiPanel.java
r84 r88 24 24 for (Panel p : panels) { 25 25 assert p.getClassName().equals(getClassName()); 26 assert p.get EndpointAtFrame() == getEndpointAtFrame();26 assert p.getInstanceAtFrame() == getInstanceAtFrame(); 27 27 tabbedPane.add(p.getTitle(), p); 28 28 } -
java/main/src/main/java/com/framsticks/gui/Panel.java
r84 r88 15 15 16 16 public static class Parameters { 17 public final EndpointAtFrame endpoint;17 public final InstanceAtFrame instanceAtFrame; 18 18 public final CompositeParam param; 19 19 public final FramsClass framsClass; 20 20 21 public Parameters( EndpointAtFrame endpoint, CompositeParam param, FramsClass framsClass) {22 this. endpoint = endpoint;21 public Parameters(InstanceAtFrame instanceAtFrame, CompositeParam param, FramsClass framsClass) { 22 this.instanceAtFrame = instanceAtFrame; 23 23 this.param = param; 24 24 this.framsClass = framsClass; … … 29 29 30 30 protected TreeNode currentTreeNode; 31 protected final EndpointAtFrame endpoint;31 protected final InstanceAtFrame instanceAtFrame; 32 32 protected final Frame frame; 33 33 protected final String className; … … 37 37 38 38 public Panel(Parameters parameters) { 39 this. endpoint = parameters.endpoint;40 this.frame = parameters. endpoint.getFrame();39 this.instanceAtFrame = parameters.instanceAtFrame; 40 this.frame = parameters.instanceAtFrame.getFrame(); 41 41 this.framsClass = parameters.framsClass; 42 42 this.param = parameters.param; … … 57 57 } 58 58 59 public final EndpointAtFrame getEndpointAtFrame() {60 return endpoint;59 public final InstanceAtFrame getInstanceAtFrame() { 60 return instanceAtFrame; 61 61 } 62 62 -
java/main/src/main/java/com/framsticks/gui/StandardPanelProvider.java
r84 r88 22 22 } 23 23 // if (param instanceof ListParam) { 24 // return new ListPanel( endpoint);24 // return new ListPanel(); 25 25 // } 26 26 return null; -
java/main/src/main/java/com/framsticks/gui/TreeNode.java
r85 r88 41 41 42 42 final protected Frame frame; 43 final protected EndpointAtFrame endpoint;43 final protected InstanceAtFrame instanceAtFrame; 44 44 45 45 final protected Map<EventParam, Subscription<?>> userSubscriptions = new HashMap<>(); … … 51 51 protected Path path; 52 52 53 public TreeNode( EndpointAtFrame endpoint, final Path path) {54 this.frame = endpoint.getFrame();53 public TreeNode(InstanceAtFrame instanceAtFrame, final Path path) { 54 this.frame = instanceAtFrame.getFrame(); 55 55 assert frame.isActive(); 56 56 this.paramId = path.getLastElement(); … … 58 58 log.debug("creating treenode " + name + ": " + path); 59 59 this.path = path; 60 this. endpoint = endpoint;60 this.instanceAtFrame = instanceAtFrame; 61 61 62 62 iconName = TreeCellRenderer.findIconName(name, path.getTextual()); … … 171 171 } 172 172 log.debug("update: treenode for " + p); 173 TreeNode childNode = new TreeNode( endpoint, childPath);173 TreeNode childNode = new TreeNode(instanceAtFrame, childPath); 174 174 175 175 frame.addNode(childNode, TreeNode.this); … … 336 336 337 337 CompositeParam param = path.getTop().getParam(); 338 panel = endpoint.findPanel(param.computeAccessId());338 panel = instanceAtFrame.findPanel(param.computeAccessId()); 339 339 if (panel != null) { 340 340 log.debug("found prepared panel for: " + path); … … 353 353 @Override 354 354 public void run() { 355 panel = endpoint.preparePanel(param, framsClass);355 panel = instanceAtFrame.preparePanel(param, framsClass); 356 356 fillPanelWithValues(); 357 357 } … … 503 503 final Map<ValueControl, Object> changes = localChanges; 504 504 localChanges = null; 505 endpoint.getEndpoint().invokeLater(new RunAt<Instance>() {505 instanceAtFrame.getInstance().invokeLater(new RunAt<Instance>() { 506 506 @Override 507 507 public void run() { … … 509 509 final ValueControl key = e.getKey(); 510 510 final Path p = path; 511 endpoint.getEndpoint().getInstance().storeValue(p, e.getKey().getParam(), e.getValue(), new StateFunctor() {511 instanceAtFrame.getInstance().storeValue(p, e.getKey().getParam(), e.getValue(), new StateFunctor() { 512 512 @Override 513 513 public void call(Exception e) { -
java/main/src/main/java/com/framsticks/hosting/InstanceClient.java
r85 r88 10 10 import com.framsticks.parsers.Savers; 11 11 import com.framsticks.core.LocalInstance; 12 import com.framsticks.util.dispatching.AbstractJoinable; 13 import com.framsticks.util.dispatching.Dispatching; 12 14 import com.framsticks.util.dispatching.Future; 15 import com.framsticks.util.dispatching.Joinable; 16 import com.framsticks.util.dispatching.JoinableParent; 17 import com.framsticks.util.dispatching.JoinableState; 13 18 14 19 import java.net.Socket; … … 21 26 * @author Piotr Sniegowski 22 27 */ 23 public class InstanceClient implements RequestHandler{28 public class InstanceClient extends AbstractJoinable implements RequestHandler, JoinableParent { 24 29 25 30 protected final LocalInstance instance; … … 29 34 this.instance = instance; 30 35 connection = new ServerConnection(socket, this); 31 connection.start();32 36 } 33 37 … … 36 40 return instance + "|" + connection.toString(); 37 41 } 38 39 42 40 43 @Override … … 94 97 95 98 } 99 100 @Override 101 protected void joinableStart() { 102 Dispatching.use(connection, this); 103 } 104 105 @Override 106 protected void joinableInterrupt() { 107 Dispatching.drop(connection, this); 108 } 109 110 @Override 111 protected void joinableFinish() { 112 } 113 114 @Override 115 protected void joinableJoin() throws InterruptedException { 116 Dispatching.join(connection); 117 } 118 119 @Override 120 public void childChangedState(Joinable joinable, JoinableState state) { 121 proceedToState(state); 122 } 123 96 124 } -
java/main/src/main/java/com/framsticks/hosting/ServerInstance.java
r87 r88 4 4 import com.framsticks.params.ConstructionException; 5 5 import com.framsticks.params.FramsClass; 6 import com.framsticks.params.Param;7 6 import com.framsticks.core.LocalInstance; 7 import com.framsticks.util.dispatching.Dispatching; 8 8 import com.framsticks.util.dispatching.Future; 9 import com.framsticks.util.dispatching.Joinable; 10 import com.framsticks.util.dispatching.JoinableParent; 11 import com.framsticks.util.dispatching.JoinableState; 9 12 10 import org.apache.commons.configuration.Configuration;11 13 import org.apache.log4j.Logger; 12 14 … … 14 16 * @author Piotr Sniegowski 15 17 */ 16 public class ServerInstance extends LocalInstance {18 public class ServerInstance extends LocalInstance implements JoinableParent { 17 19 18 20 private final static Logger log = Logger.getLogger(ServerInstance.class.getName()); … … 24 26 25 27 @Override 26 protected void run() {27 super. run();28 protected void firstTask() { 29 super.firstTask(); 28 30 assert hosted != null; 29 hosted.start();31 Dispatching.use(hosted, this); 30 32 } 31 33 32 @Override33 public void configure(Configuration config) {34 super.configure(config);34 // @Override 35 // public void configure(Configuration config) { 36 // super.configure(config); 35 37 36 Configuration hostedConfig = config.subset("hosted.entity");37 hosted = Program.configureEntity(hostedConfig);38 if (hosted == null) {39 log.fatal("failed to create hosted entity");40 return;41 }42 hosted.setName("hosted");43 hosted.configure(hostedConfig);44 root = new Node(Param.build().name("root").id("root").type("o" + hosted.getClass().getCanonicalName()), hosted);45 }38 // Configuration hostedConfig = config.subset("hosted.entity"); 39 // hosted = Program.configureEntity(hostedConfig); 40 // if (hosted == null) { 41 // log.fatal("failed to create hosted entity"); 42 // return; 43 // } 44 // hosted.setName("hosted"); 45 // hosted.configure(hostedConfig); 46 // root = new Node(Param.build().name("root").id("root").type("o" + hosted.getClass().getCanonicalName()), hosted); 47 // } 46 48 47 49 @Override … … 93 95 } 94 96 97 @Override 98 public void childChangedState(Joinable joinable, JoinableState state) { 99 proceedToState(state); 100 101 } 102 103 @Override 104 protected void joinableInterrupt() { 105 Dispatching.drop(hosted, this); 106 } 107 108 @Override 109 protected void joinableFinish() { 110 111 } 112 95 113 } -
java/main/src/main/java/com/framsticks/leftovers/FavouritesXMLFactory.java
r87 r88 3 3 import java.io.BufferedWriter; 4 4 import java.io.File; 5 import java.io.FileInputStream; 6 import java.io.FileNotFoundException; 5 7 import java.io.FileOutputStream; 6 8 import java.io.IOException; 9 import java.io.InputStream; 7 10 import java.io.OutputStreamWriter; 8 11 import java.nio.file.Files; … … 26 29 import org.xml.sax.SAXException; 27 30 31 import com.framsticks.util.FramsticksException; 28 32 import com.framsticks.util.io.Encoding; 29 33 … … 36 40 private static final String TYPE_MARK = "type"; 37 41 38 protected Node readDocument(String filename) { 42 public static Node readDocument(InputStream stream) { 43 DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); 44 try { 45 DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); 46 Document doc = docBuilder.parse(stream); 47 doc.getDocumentElement().normalize(); 48 return doc.getFirstChild(); 49 } catch (ParserConfigurationException | SAXException | IOException e) { 50 throw new FramsticksException().cause(e); 51 } 52 } 53 54 public static Node readDocument(String filename) { 39 55 File file = new File(filename); 40 56 if (!file.exists()) { 41 return null; 42 } 43 DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory 44 .newInstance(); 57 throw new FramsticksException().msg("file does not exist"); 58 } 45 59 try { 46 DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); 47 Document doc = docBuilder.parse(file); 48 doc.getDocumentElement().normalize(); 49 return doc.getFirstChild(); 50 51 } catch (ParserConfigurationException | SAXException | IOException e) { 52 log.error(e); 53 return null; 60 return readDocument(new FileInputStream(file)); 61 } catch (FileNotFoundException e) { 62 throw new FramsticksException().cause(e); 54 63 } 55 64 } -
java/main/src/main/java/com/framsticks/params/FramsClass.java
r87 r88 3 3 import com.framsticks.params.annotations.FramsClassAnnotation; 4 4 import com.framsticks.params.annotations.ParamAnnotation; 5 import com.framsticks.util.FramsticksException; 5 6 // import com.framsticks.util.FramsticksException; 6 7 … … 26 27 @Immutable 27 28 @FramsClassAnnotation(id = "class", name = "class") 28 public finalclass FramsClass {29 public class FramsClass { 29 30 30 31 private final static Logger log = Logger.getLogger(FramsClass.class); … … 54 55 } 55 56 56 public FramsClass( String id, String name, String description, List<Param> params, List<Group> groups) {57 public FramsClass(FramsClassBuilder builder) { 57 58 58 this.id = id;59 this.name = name;60 this.description = description;61 this.groups = groups;62 this.paramList = params;59 this.id = builder.getId(); 60 this.name = builder.getName(); 61 this.description = builder.getDescription(); 62 this.groups = builder.groups; 63 this.paramList = builder.params; 63 64 64 for (Param param : param s) {65 for (Param param : paramList) { 65 66 paramEntryMap.put(param.getId(), param); 66 67 try { … … 133 134 public <T extends Param> T castedParam(@Nonnull final Param param, @Nonnull final Class<T> type, Object name) { 134 135 if (param == null) { 135 return null;136 //throw new FramsticksException().msg("param is missing").arg("name", name).arg("in", this);136 // return null; 137 throw new FramsticksException().msg("param is missing").arg("name", name).arg("in", this); 137 138 } 138 139 if (!type.isInstance(param)) { 139 return null;140 //throw new FramsticksException().msg("wrong type of param").arg("actual", param.getClass()).arg("requested", type).arg("in", this);140 // return null; 141 throw new FramsticksException().msg("wrong type of param").arg("actual", param.getClass()).arg("requested", type).arg("in", this); 141 142 } 142 143 return type.cast(param); -
java/main/src/main/java/com/framsticks/params/FramsClassBuilder.java
r87 r88 21 21 import com.framsticks.parsers.FileSource; 22 22 import com.framsticks.parsers.Loaders; 23 import com.framsticks.util.Builder; 24 import com.framsticks.util.FramsticksException; 23 25 import com.framsticks.util.lang.Strings; 24 26 25 27 @FramsClassAnnotation(id = "class", name = "class") 26 public class FramsClassBuilder {28 public class FramsClassBuilder implements Builder<FramsClass> { 27 29 private static final Logger log = 28 30 Logger.getLogger(FramsClassBuilder.class); … … 163 165 } 164 166 165 public static Map<Class<?>, FramsClass> synchronizedCacheForBasedOnForJavaClass = Collections.synchronizedMap(new HashMap<Class<?>, FramsClass>());167 public static final Map<Class<?>, FramsClass> synchronizedCacheForBasedOnForJavaClass = Collections.synchronizedMap(new HashMap<Class<?>, FramsClass>()); 166 168 167 169 public FramsClass forClass(Class<?> javaClass) throws ConstructionException { … … 171 173 } 172 174 173 log. info("building for class " + javaClass);175 log.debug("building for class " + javaClass); 174 176 175 177 FramsClassAnnotation fca = javaClass.getAnnotation(FramsClassAnnotation.class); … … 184 186 185 187 for (ParamCandidate pc : candidates.values()) { 186 param(Param.build().id(pc.getId()).name(pc.getName()).type(getParamTypeForNativeType(pc.getType())).flags(pc.getFlags())); 188 String type = getParamTypeForNativeType(pc.getType()); 189 if (type == null) { 190 throw new FramsticksException().msg("failed to find type for param candidate").arg("candidate", pc); 191 } 192 param(Param.build().id(pc.getId()).name(pc.getName()).type(type).flags(pc.getFlags())); 187 193 } 188 194 … … 233 239 234 240 public FramsClass finish() { 235 return new FramsClass( id, name, description, params, groups);241 return new FramsClass(this); 236 242 } 237 243 … … 244 250 public FramsClassBuilder param(ParamBuilder builder) { 245 251 return append(builder.finish()); 252 } 253 254 @AutoAppendAnnotation 255 public FramsClassBuilder group(GroupBuilder builder) { 256 return group(builder.finish()); 246 257 } 247 258 -
java/main/src/main/java/com/framsticks/params/Param.java
r87 r88 53 53 group = builder.getGroup(); 54 54 flags = builder.getFlags(); 55 extra = 0;55 extra = builder.getExtra(); 56 56 } 57 57 -
java/main/src/main/java/com/framsticks/params/ParamBuilder.java
r87 r88 4 4 import com.framsticks.params.annotations.ParamAnnotation; 5 5 import com.framsticks.params.types.*; 6 import com.framsticks.util.Builder; 6 7 import com.framsticks.util.FramsticksException; 7 8 import com.framsticks.util.lang.Strings; … … 23 24 24 25 @FramsClassAnnotation(name = "prop", id = "prop") 25 public class ParamBuilder {26 public class ParamBuilder implements Builder<Param> { 26 27 private final static Logger log = Logger.getLogger(ParamBuilder.class.getName()); 27 28 … … 63 64 private Object def; 64 65 66 private Integer extra; 67 65 68 String containedTypeName; 69 70 protected Class<?> storageType; 66 71 67 72 protected FramsClassBuilder classBuilder; … … 83 88 * @return the min 84 89 */ 90 @ParamAnnotation 85 91 public Object getMin() { 86 92 return min; … … 90 96 * @return the max 91 97 */ 98 @ParamAnnotation 92 99 public Object getMax() { 93 100 return max; … … 97 104 * @return the def 98 105 */ 106 @ParamAnnotation 99 107 public Object getDef() { 100 108 return def; … … 135 143 public Param finish() { 136 144 try { 145 if (paramType == null) { 146 throw new FramsticksException().msg("trying to finish incomplete param"); 147 } 148 137 149 return paramType.getConstructor(ParamBuilder.class).newInstance(this); 138 } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {150 } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | FramsticksException e) { 139 151 throw new FramsticksException().msg("failed to create param").cause(e).arg("name", name); 140 152 } … … 219 231 public ParamBuilder type(String type) { 220 232 // typeString = type; 233 assert type != null; 221 234 222 235 log.trace("parsing type: " + type); … … 352 365 } 353 366 367 @ParamAnnotation(id = "xtra") 368 public Integer getExtra() { 369 return extra; 370 } 371 354 372 /** 355 373 * @return the paramType … … 359 377 } 360 378 379 @ParamAnnotation(id = "xtra") 380 public ParamBuilder extra(Integer extra) { 381 this.extra = extra; 382 return this; 383 } 384 385 @ParamAnnotation 361 386 public ParamBuilder min(Object min) { 362 387 this.min = min; … … 364 389 } 365 390 391 @ParamAnnotation 366 392 public ParamBuilder max(Object max) { 367 393 this.max = max; … … 369 395 } 370 396 397 @ParamAnnotation 371 398 public ParamBuilder def(Object def) { 372 399 this.def = def; … … 374 401 } 375 402 376 // public Class<?> getStorageType() {377 // assert param != null;378 // return param.getStorageType();379 // }380 403 381 404 public Param build(String line) throws Exception { … … 435 458 } 436 459 437 public ParamBuilder defaultDef(Object def) {460 public ParamBuilder fillDef(Object def) { 438 461 if (this.def == null) { 439 462 return def(def); … … 442 465 } 443 466 467 public ParamBuilder fillStorageType(Class<?> storageType) { 468 if (this.storageType == null) { 469 this.storageType = storageType; 470 } 471 return this; 472 } 473 474 475 public Class<?> getStorageType() { 476 return storageType; 477 } 444 478 } 479 -
java/main/src/main/java/com/framsticks/params/ParamCandidate.java
r86 r88 132 132 return; 133 133 } 134 if ( field.has()) {134 if (isPublic(field)) { 135 135 if (setter.has()) { 136 136 throw new ConstructionException().msg("setter and field coexist"); … … 138 138 } 139 139 140 if ( getter.get() == null) {141 throw new ConstructionException().msg("missing getter ");140 if (!getter.has() && !field.has()) { 141 throw new ConstructionException().msg("missing getter or field"); 142 142 } 143 143 } catch (ConstructionException e) { … … 211 211 @Override 212 212 public String toString() { 213 return id ;213 return id + "(" + type.toString() + ")"; 214 214 } 215 215 -
java/main/src/main/java/com/framsticks/params/PrimitiveParam.java
r87 r88 2 2 3 3 import com.framsticks.util.FramsticksException; 4 import com.framsticks.util.Misc; 4 5 import com.framsticks.util.lang.Numbers; 5 6 … … 26 27 public PrimitiveParam(ParamBuilder builder) { 27 28 super(builder); 28 min = builder.getMin(); 29 max = builder.getMax(); 30 def = builder.getDef(); 29 Class<?> storageType = Misc.returnNotNull(builder.getStorageType(), Object.class); 30 min = tryCastAndReturn(builder.getMin(), storageType); 31 max = tryCastAndReturn(builder.getMax(), storageType); 32 def = tryCastAndReturn(builder.getDef(), storageType); 31 33 } 32 34 -
java/main/src/main/java/com/framsticks/params/ReflectionAccess.java
r87 r88 6 6 import java.util.Collections; 7 7 import java.util.HashMap; 8 import java.util.LinkedList; 9 import java.util.List; 8 10 import java.util.Map; 9 11 … … 37 39 public static class Backend { 38 40 39 protected static Map<Pair<Class<?>, FramsClass>, Backend> synchronizedCache = Collections.synchronizedMap(new HashMap<Pair<Class<?>, FramsClass>, Backend>());41 protected static final Map<Pair<Class<?>, FramsClass>, Backend> synchronizedCache = Collections.synchronizedMap(new HashMap<Pair<Class<?>, FramsClass>, Backend>()); 40 42 41 43 public static class ReflectedValueParam { … … 53 55 54 56 protected final Map<ValueParam, ReflectedValueParam> params; 55 protected final Map<Class<?>,Method> autoAppendMethods;57 protected final List<Method> autoAppendMethods; 56 58 57 59 /** 58 60 * @param params 59 61 */ 60 public Backend(Map<ValueParam, ReflectedValueParam> params, Map<Class<?>,Method> autoAppendMethods) {62 public Backend(Map<ValueParam, ReflectedValueParam> params, List<Method> autoAppendMethods) { 61 63 // this.params = Collections.unmodifiableMap(params); 62 64 this.params = params; … … 140 142 } 141 143 142 Map<Class<?>, Method> autoAppendMethods = new HashMap<>();144 List<Method> autoAppendMethods = new LinkedList<>(); 143 145 144 146 Class<?> javaClass = reflectedClass; … … 154 156 throw new ConstructionException().msg("invalid number of arguments in AutoAppend marked method").arg("method", m).arg("arguments", args.length); 155 157 } 156 autoAppendMethods. put(args[0],m);158 autoAppendMethods.add(m); 157 159 } 158 160 … … 327 329 public boolean tryAutoAppend(Object value) { 328 330 assert object != null; 329 for (M ap.Entry<Class<?>, Method> a : backend.autoAppendMethods.entrySet()) {330 if ( a.getKey().isAssignableFrom(value.getClass())) {331 for (Method m : backend.autoAppendMethods) { 332 if (m.getParameterTypes()[0].isAssignableFrom(value.getClass())) { 331 333 try { 332 a.getValue().invoke(object, value);334 m.invoke(object, value); 333 335 return true; 334 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {335 throw new FramsticksException().msg("failed to auto append").cause(e).arg("value", value).arg("into object", object).arg("with method", a.getValue());336 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | FramsticksException e) { 337 throw new FramsticksException().msg("failed to auto append").cause(e).arg("value", value).arg("into object", object).arg("with method", m); 336 338 } 337 339 } -
java/main/src/main/java/com/framsticks/params/Registry.java
r87 r88 4 4 5 5 import com.framsticks.params.annotations.FramsClassAnnotation; 6 import com.framsticks.util.DoubleMap; 7 import com.framsticks.util.FramsticksException; 6 8 7 import java.util.Collections;8 import java.util.HashMap;9 import java.util.HashSet;10 import java.util.Map;11 9 import java.util.Set; 12 10 … … 16 14 public class Registry { 17 15 private static final Logger log = Logger.getLogger(Registry.class.getName()); 18 19 public static class DoubleSet<K1, K2, V> {20 protected final Map<K1, V> byId = new HashMap<>();21 protected final Map<K2, V> byName = new HashMap<>();22 protected final Set<V> values = new HashSet<>();23 24 public int size() {25 return values.size();26 }27 28 public void put(K1 id, K2 name, V value) {29 values.add(value);30 if (id != null) {31 byId.put(id, value);32 }33 if (name != null) {34 byName.put(name, value);35 }36 }37 38 public boolean containsValue(V value) {39 return values.contains(value);40 41 }42 43 public boolean containsKey(String identifier) {44 return byId.containsKey(identifier) || byName.containsKey(identifier);45 }46 47 public V get(String identifier) {48 if (byId.containsKey(identifier)) {49 return byId.get(identifier);50 }51 if (byName.containsKey(identifier)) {52 return byName.get(identifier);53 }54 return null;55 }56 57 public Set<V> getValues() {58 return Collections.unmodifiableSet(values);59 }60 }61 16 62 17 // protected void internalRegisterClass(FramsClass framsClass, @Nullable Class<?> javaClass) { … … 71 26 // } 72 27 // } 73 protected final Double Set<String, String, Class<?>> javaClasses = new DoubleSet<>();74 protected final Double Set<String, String, FramsClass> framsClasses = new DoubleSet<>();28 protected final DoubleMap<String, Class<?>> javaClasses = new DoubleMap<>(); 29 protected final DoubleMap<String, FramsClass> framsClasses = new DoubleMap<>(); 75 30 76 31 public void registerReflectedClass(String name, String id, Class<?> reflectedClass) { … … 78 33 } 79 34 35 public Registry registerAndBuild(Class<?> reflectedClass) { 36 register(reflectedClass); 37 putInfoIntoCache(FramsClass.build().forClass(reflectedClass)); 38 return this; 39 } 40 80 41 public Registry register(Class<?> reflectedClass) { 81 42 FramsClassAnnotation a = reflectedClass.getAnnotation(FramsClassAnnotation.class); 82 43 if (a == null) { 83 log.error("class is not annotated: " + reflectedClass); 84 return this; 44 throw new FramsticksException().msg("class is not annotated").arg("class", reflectedClass); 85 45 } 86 46 87 47 registerReflectedClass(FramsClassBuilder.getName(a, reflectedClass), FramsClassBuilder.getId(a, reflectedClass), reflectedClass); 88 89 48 return this; 90 49 } 91 50 92 51 public AccessInterface createAccess(String name, FramsClass framsClass) throws ConstructionException { 93 assert framsClasses.containsValue(framsClass);52 // assert framsClasses.containsValue(framsClass); 94 53 if (javaClasses.containsKey(name)) { 95 54 return new ReflectionAccess(javaClasses.get(name), framsClass); -
java/main/src/main/java/com/framsticks/params/types/BooleanParam.java
r87 r88 20 20 */ 21 21 public BooleanParam(ParamBuilder builder) { 22 super(builder. defaultDef(false));22 super(builder.fillDef(false).fillStorageType(Boolean.class)); 23 23 } 24 24 -
java/main/src/main/java/com/framsticks/params/types/DecimalParam.java
r87 r88 17 17 */ 18 18 public DecimalParam(ParamBuilder builder) { 19 super(builder. defaultDef(0));19 super(builder.fillDef(0).fillStorageType(Integer.class)); 20 20 } 21 21 -
java/main/src/main/java/com/framsticks/params/types/FloatParam.java
r87 r88 17 17 */ 18 18 public FloatParam(ParamBuilder builder) { 19 super(builder. defaultDef(0.0));19 super(builder.fillDef(0.0).fillStorageType(Double.class)); 20 20 } 21 21 -
java/main/src/main/java/com/framsticks/parsers/F0Parser.java
r87 r88 11 11 12 12 import com.framsticks.model.Model; 13 import com.framsticks.model.f0.Schema; 14 13 15 import static com.framsticks.params.SimpleAbstractAccess.*; 14 16 … … 49 51 Pair<String, String> p = Strings.splitIntoPair(line, ':', ""); 50 52 String classId = p.first.trim(); 51 FramsClass framsClass = schema.get Registry().getInfoFromCache(classId);53 FramsClass framsClass = schema.getFramsClass(classId); 52 54 if (framsClass == null) { 53 55 throw new Exception("unknown class id: " + classId); -
java/main/src/main/java/com/framsticks/parsers/F0Writer.java
r87 r88 2 2 3 3 import com.framsticks.model.Model; 4 import com.framsticks.model.f0.Schema; 4 5 import com.framsticks.params.*; 5 6 import com.framsticks.util.Misc; -
java/main/src/main/java/com/framsticks/parsers/Loaders.java
r87 r88 1 1 package com.framsticks.parsers; 2 3 import javax.annotation.Nonnull; 2 4 3 5 import com.framsticks.params.*; … … 11 13 // private static final Logger log = Logger.getLogger(Loaders.class.getName()); 12 14 13 public static FramsClass loadFramsClass(SourceInterface source) throws ConstructionException {15 public static @Nonnull FramsClass loadFramsClass(SourceInterface source) throws ConstructionException { 14 16 final MultiParamLoader loader = new MultiParamLoader(); 15 17 loader.setNewSource(source); -
java/main/src/main/java/com/framsticks/parsers/MultiParamLoader.java
r87 r88 43 43 protected AccessInterface lastAccessInterface; 44 44 45 protected static FramsClass emptyFramsClass = FramsClass.build().idAndName("<empty>").finish();45 protected static final FramsClass emptyFramsClass = FramsClass.build().idAndName("<empty>").finish(); 46 46 /** 47 47 * Empty Param representing unknown classes - used to omit unknown -
java/main/src/main/java/com/framsticks/parsers/XmlLoader.java
r87 r88 1 1 package com.framsticks.parsers; 2 2 3 import java.io.InputStream; 4 5 import javax.xml.parsers.DocumentBuilder; 6 import javax.xml.parsers.DocumentBuilderFactory; 7 8 import org.apache.log4j.Logger; 9 import org.w3c.dom.Document; 10 import org.w3c.dom.Element; 11 import org.w3c.dom.NamedNodeMap; 12 import org.w3c.dom.Node; 13 import org.w3c.dom.NodeList; 14 15 import com.framsticks.params.AccessInterface; 16 import com.framsticks.params.Registry; 17 import com.framsticks.util.FramsticksException; 18 3 19 public class XmlLoader { 20 private static final Logger log = Logger.getLogger(XmlLoader.class); 4 21 22 protected Registry registry = new Registry(); 23 24 /** 25 * 26 */ 27 public XmlLoader() { 28 } 29 30 /** 31 * @return the registry 32 */ 33 public Registry getRegistry() { 34 return registry; 35 } 36 37 boolean useLowerCase = false; 38 39 /** 40 * @param useLowerCase the useLowerCase to set 41 */ 42 public void setUseLowerCase(boolean useLowerCase) { 43 this.useLowerCase = useLowerCase; 44 } 45 46 public Object processElement(Element element) { 47 String name = element.getNodeName(); 48 if (useLowerCase) { 49 name = name.toLowerCase(); 50 } 51 if (name.equals("import")) { 52 String className = element.getAttribute("class"); 53 try { 54 registry.registerAndBuild(Class.forName(className)); 55 return null; 56 } catch (ClassNotFoundException e) { 57 throw new FramsticksException().msg("failed to import class").arg("name", name).cause(e); 58 } 59 } 60 61 AccessInterface access = registry.createAccess(name); 62 63 if (access == null) { 64 throw new FramsticksException().msg("failed to find access interface").arg("name", name); 65 } 66 Object object = access.createAccessee(); 67 assert object != null; 68 access.select(object); 69 70 NamedNodeMap attributes = element.getAttributes(); 71 for (int i = 0; i < attributes.getLength(); ++i) { 72 Node attributeNode = attributes.item(i); 73 access.set(attributeNode.getNodeName().toLowerCase(), attributeNode.getNodeValue()); 74 } 75 76 NodeList children = element.getChildNodes(); 77 log.debug("found " + children.getLength() + " children in " + object); 78 for (int i = 0; i < children.getLength(); ++i) { 79 Node childNode = children.item(i); 80 if (!(childNode instanceof Element)) { 81 continue; 82 } 83 Object childObject = processElement((Element) childNode); 84 if (childObject == null) { 85 continue; 86 } 87 88 if (!access.tryAutoAppend(childObject)) { 89 throw new FramsticksException().msg("failed to auto append").arg("child", childObject).arg("parent", object); 90 } 91 } 92 log.debug("loaded " + object); 93 94 return object; 95 } 96 97 public Object load(InputStream stream) { 98 try { 99 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 100 DocumentBuilder db = factory.newDocumentBuilder(); 101 102 Document document = db.parse(stream); 103 document.getDocumentElement().normalize(); 104 Element element = document.getDocumentElement(); 105 assert element != null; 106 107 return processElement(element); 108 109 } catch (Exception e) { 110 throw new FramsticksException().msg("failed to load").cause(e); 111 } 112 } 113 114 public <T> T load(InputStream stream, Class<T> type) { 115 registry.registerAndBuild(type); 116 117 Object object = load(stream); 118 if (type.isAssignableFrom(object.getClass())) { 119 return type.cast(object); 120 } 121 throw new FramsticksException().msg("invalid type has been loaded"); 122 } 5 123 } 124 -
java/main/src/main/java/com/framsticks/portals/Portal.java
r86 r88 1 1 package com.framsticks.portals; 2 2 3 import com.framsticks.observers.Observer; 3 4 import com.framsticks.core.AbstractInstanceListener; 5 import com.framsticks.core.Instance; 6 import com.framsticks.core.Path; 4 7 import com.framsticks.params.annotations.FramsClassAnnotation; 5 8 import com.framsticks.params.annotations.ParamAnnotation; 6 import com.framsticks.util.PeriodicTask; 9 import com.framsticks.util.Logging; 10 import com.framsticks.util.dispatching.Dispatching; 11 import com.framsticks.util.dispatching.Future; 12 import com.framsticks.util.dispatching.JoinableCollection; 13 import com.framsticks.util.dispatching.RunAt; 14 7 15 import org.apache.log4j.Logger; 8 16 … … 12 20 */ 13 21 @FramsClassAnnotation 14 public class Portal extends Observer{22 public class Portal extends JoinableCollection<Instance> { 15 23 16 24 private final static Logger log = Logger.getLogger(Portal.class.getName()); … … 22 30 } 23 31 24 @Override25 public void run() {26 super.run();27 new PeriodicTask<Portal>(this, 1000) {32 // @Override 33 // public void run() { 34 // super.run(); 35 // new PeriodicTask<Portal>(this, 1000) { 28 36 29 @Override30 public void run() {31 ++counter;32 log.debug("counter is now: " + counter);33 again();34 }35 };36 }37 // @Override 38 // public void run() { 39 // ++counter; 40 // log.debug("counter is now: " + counter); 41 // again(); 42 // } 43 // }; 44 // } 37 45 38 46 @Override 39 protected PortalEndpoint createEndpoint() { 40 return new PortalEndpoint(); 47 public void add(final Instance instance) { 48 super.add(instance); 49 instance.addListener(new AbstractInstanceListener() { 50 @Override 51 public void onRun(Exception e) { 52 assert Dispatching.isThreadSafe(); 53 54 super.onRun(e); 55 56 if (e != null) { 57 return; 58 } 59 final String path = "/simulator/genepools/groups/0/genotypes"; 60 instance.invokeLater(new RunAt<Instance>() { 61 @Override 62 public void run() { 63 instance.resolve(path, new Future<Path>() { 64 @Override 65 public void result(Path result, Exception e) { 66 Logging.log(log, "resolve", path, e); 67 } 68 }); 69 } 70 }); 71 } 72 }); 41 73 } 42 74 -
java/main/src/main/java/com/framsticks/remote/RemoteInstance.java
r87 r88 9 9 import com.framsticks.core.Path; 10 10 import com.framsticks.params.*; 11 import com.framsticks.params.annotations.FramsClassAnnotation; 12 import com.framsticks.params.annotations.ParamAnnotation; 11 13 import com.framsticks.params.types.EventParam; 12 14 import com.framsticks.parsers.MultiParamLoader; … … 15 17 import com.framsticks.util.dispatching.Dispatching; 16 18 import com.framsticks.util.dispatching.Future; 19 import com.framsticks.util.dispatching.Joinable; 20 import com.framsticks.util.dispatching.JoinableParent; 21 import com.framsticks.util.dispatching.JoinableState; 17 22 import com.framsticks.util.lang.Casting; 18 23 import com.framsticks.util.lang.Pair; 19 24 import com.framsticks.util.dispatching.RunAt; 20 25 21 import org.apache.commons.configuration.Configuration; 26 import java.util.*; 27 22 28 import org.apache.log4j.Logger; 23 24 import java.util.*;25 29 26 30 /** 27 31 * @author Piotr Sniegowski 28 32 */ 29 public class RemoteInstance extends Instance { 33 @FramsClassAnnotation 34 public class RemoteInstance extends Instance implements JoinableParent { 30 35 31 36 private final static Logger log = Logger.getLogger(RemoteInstance.class.getName()); … … 45 50 } 46 51 47 @Override 48 public void run() { 49 assert isActive(); 50 super.run(); 51 connection.connect(new StateFunctor() { 52 public RemoteInstance() { 53 } 54 55 @ParamAnnotation 56 public void setAddress(String address) { 57 setConnection(new ClientConnection(address)); 58 } 59 60 @ParamAnnotation 61 public String getAddress() { 62 return connection == null ? "<disconnected>" : connection.getAddress(); 63 } 64 65 public void setConnection(final ClientConnection connection) { 66 this.connection = connection; 67 this.connection.setConnectedFunctor(new StateFunctor() { 52 68 @Override 53 69 public void call(Exception e) { … … 60 76 public void call(Exception e) { 61 77 if (e != null) { 62 log.fatal("unsupported protocol version!\n minimal version is: " 63 + "nmanager protocol is: " 64 + connection.getProtocolVersion()); 65 connection.close(); 78 log.fatal("unsupported protocol version!\n minimal version is: " + "\nmanager protocol is: " + connection.getProtocolVersion()); 79 Dispatching.drop(connection, RemoteInstance.this); 66 80 fireRun(e); 67 81 return; … … 112 126 } 113 127 }); 114 } 115 116 public RemoteInstance() { 117 } 118 119 120 @Override 121 public void configure(Configuration config) { 122 super.configure(config); 123 connection = new ClientConnection(config.getString("address")); 124 } 125 126 public void setAddress(String address) { 127 setConnection(new ClientConnection(address)); 128 } 129 130 public void setConnection(ClientConnection connection) { 131 this.connection = connection; 128 132 129 } 133 130 … … 135 132 public String toString() { 136 133 assert Dispatching.isThreadSafe(); 137 return getConnection().getAddress();134 return "remote instance " + getName() + "(" + getAddress() + ")"; 138 135 } 139 136 … … 167 164 } 168 165 }); 169 */166 */ 170 167 } 171 168 … … 175 172 } 176 173 177 public void disconnect() {178 assert isActive();179 if (connection.isConnected()) {180 connection.close();181 }182 }174 // public void disconnect() { 175 // assert isActive(); 176 // if (connection.isConnected()) { 177 // Dispatching.stop(connection, this); 178 // } 179 // } 183 180 184 181 public final ClientConnection getConnection() { … … 247 244 assert response.getFiles().size() == 1; 248 245 assert path.isTheSame(response.getFiles().get(0).getPath()); 249 FramsClass framsClass = processFetchedInfo(response.getFiles().get(0)); 250 251 if (framsClass == null) { 246 FramsClass framsClass; 247 try { 248 framsClass = processFetchedInfo(response.getFiles().get(0)); 249 } catch (ConstructionException e) { 252 250 log.fatal("could not read class info"); 253 251 finishInfoRequest(name, null, new Exception("could not read class info")); 254 252 return; 255 253 } 254 256 255 CompositeParam thisParam = path.getTop().getParam(); 257 256 if (!thisParam.isMatchingContainedName(framsClass.getId())) { … … 335 334 } 336 335 337 338 336 assert path.size() >= 2; 339 337 FramsClass underFramsClass = getInfoFromCache(path.getUnder().getParam().getContainedTypeName()); 340 338 341 EventParam changedEvent = underFramsClass.getParamEntry(path.getTop().getParam().getId() + "_changed", EventParam.class); 342 if (changedEvent == null) { 339 EventParam changedEvent; 340 try { 341 changedEvent = underFramsClass.getParamEntry(path.getTop().getParam().getId() + "_changed", EventParam.class); 342 } catch (FramsticksException e) { 343 343 return; 344 344 } 345 345 346 log.debug("registering for " + changedEvent); 346 347 if (getSubscription(path) != null) { 347 348 return; … … 394 395 } 395 396 396 397 397 protected void reactToChange(final Path path, final ListChange listChange) { 398 398 assert isActive(); … … 416 416 } 417 417 418 419 418 CompositeParam childParam = Casting.tryCast(CompositeParam.class, access.getParam(listChange.getBestIdentifier())); 420 419 assert childParam != null; 421 420 switch (listChange.getAction()) { 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 421 case Add: { 422 final String p = path.getTextual() + "/" + childParam.getId(); 423 resolveAndFetch(p, new Future<Path>() { 424 @Override 425 public void result(Path result, Exception e) { 426 if (e != null) { 427 log.error("failed to add " + p + ": " + e); 428 return; 429 } 430 log.debug("added: " + result); 431 fireListChange(path, listChange); 432 } 433 }); 434 break; 435 } 436 case Remove: { 437 access.set(childParam, null); 438 fireListChange(path, listChange); 439 break; 440 } 441 case Modify: { 442 final String p = path.getTextual() + "/" + childParam.getId(); 443 resolveAndFetch(p, new Future<Path>() { 444 @Override 445 public void result(Path result, Exception e) { 446 if (e != null) { 447 log.error("failed to modify " + p + ": " + e); 448 return; 449 } 450 fireListChange(path, listChange); 451 } 452 }); 453 break; 454 } 456 455 } 457 456 } … … 473 472 }); 474 473 } 474 475 @Override 476 protected void joinableStart() { 477 Dispatching.use(connection, this); 478 super.joinableStart(); 479 } 480 481 @Override 482 protected void joinableInterrupt() { 483 Dispatching.drop(connection, this); 484 super.joinableInterrupt(); 485 } 486 487 @Override 488 protected void joinableFinish() { 489 super.joinableFinish(); 490 491 } 492 493 @Override 494 public void joinableJoin() throws InterruptedException { 495 Dispatching.join(connection); 496 super.joinableJoin(); 497 } 498 499 500 @Override 501 public void childChangedState(Joinable joinable, JoinableState state) { 502 proceedToState(state); 503 } 504 505 475 506 } -
java/main/src/main/java/com/framsticks/util/FramsticksException.java
r87 r88 50 50 b.append("(").append(d.build()).append(")"); 51 51 } 52 if (this.getCause() instanceof FramsticksException) {53 b.append(" caused by ").append(this.getCause().getMessage());52 if (this.getCause() != null) { 53 b.append(" caused by: [").append(this.getCause().getMessage()).append("]"); 54 54 } 55 55 return b.toString(); -
java/main/src/main/java/com/framsticks/util/Misc.java
r84 r88 1 1 package com.framsticks.util; 2 3 // import org.apache.log4j.Logger; 2 4 3 5 /** … … 5 7 */ 6 8 public class Misc { 9 // private static final Logger log = 10 // Logger.getLogger(Misc.class); 11 12 public static class WithType { 13 protected Object value; 14 15 /** 16 * @param value 17 */ 18 public WithType(Object value) { 19 this.value = value; 20 } 21 22 @Override 23 public String toString() { 24 if (value == null) { 25 return "null"; 26 } 27 return value + "(" + value.getClass() + ")"; 28 } 29 } 30 31 public static WithType withType(Object value) { 32 return new WithType(value); 33 } 34 7 35 public static boolean equals(Object a, Object b) { 36 // log.info("equality of " + withType(a) + " ? " + withType(b)); 8 37 if (a != null) { 9 38 return (b != null && a.equals(b)); … … 11 40 return b == null; 12 41 } 42 43 public static <T> T returnNotNull(T first, T second) { 44 if (first != null) { 45 return first; 46 } 47 return second; 48 } 49 50 public static <T> T throwIfNull(T value) { 51 if (value == null) { 52 throw new FramsticksException().msg("value should not be null"); 53 } 54 return value; 55 } 13 56 } -
java/main/src/main/java/com/framsticks/util/dispatching/AtOnceDispatcher.java
r85 r88 23 23 runnable.run(); 24 24 } 25 26 25 27 } -
java/main/src/main/java/com/framsticks/util/dispatching/Dispatcher.java
r85 r88 7 7 public boolean isActive(); 8 8 public void invokeLater(RunAt<? extends C> runnable); 9 9 10 } -
java/main/src/main/java/com/framsticks/util/dispatching/Dispatching.java
r85 r88 1 1 package com.framsticks.util.dispatching; 2 3 import org.apache.log4j.Logger; 2 4 3 5 import com.framsticks.util.StateFunctor; … … 7 9 */ 8 10 public abstract class Dispatching { 11 private static final Logger log = Logger.getLogger(Dispatching.class); 9 12 10 13 public static boolean isThreadSafe() { … … 31 34 32 35 // public static boolean assertInvokeLater(Dispatcher dispatcher, RunAt runnable) { 33 // 34 // 36 // dispatcher.invokeLater(runnable); 37 // return true; 35 38 // } 36 39 … … 44 47 } 45 48 49 public static void sleep(int milliseconds) { 50 try { 51 java.lang.Thread.sleep(milliseconds, 0); 52 } catch (InterruptedException e) { 53 54 } 55 } 56 57 @SuppressWarnings("unchecked") 58 public static void dispatcherGuardedInvoke(Joinable joinable, RunAt<?> runnable) { 59 if (joinable instanceof Dispatcher) { 60 invokeLaterOrNow(Dispatcher.class.cast(joinable), runnable); 61 return; 62 } 63 runnable.run(); 64 } 65 66 public static void use(final Joinable joinable, final JoinableParent owner) { 67 log.debug("using " + joinable + " by " + owner); 68 if (joinable.use(owner)) { 69 log.debug("started " + joinable); 70 } else { 71 log.debug("start of " + joinable + " already happened"); 72 } 73 } 74 75 76 public static void drop(final Joinable joinable, final JoinableParent owner) { 77 log.debug("droping " + joinable + " by " + owner); 78 if (joinable.drop(owner)) { 79 log.debug("stoped " + joinable); 80 } else { 81 log.debug("stop of " + joinable + " deferred"); 82 } 83 } 84 85 public static void join(Joinable joinable) throws InterruptedException { 86 log.debug("joining " + joinable); 87 try { 88 joinable.join(); 89 } catch (InterruptedException e) { 90 log.debug("failed to join " + joinable); 91 throw e; 92 } 93 log.debug("joined " + joinable); 94 } 95 96 public static void childChangedState(final JoinableParent parent, final Joinable joinable, final JoinableState state) { 97 dispatcherGuardedInvoke(joinable, new RunAt<Object>() { 98 @Override 99 public void run() { 100 log.debug("joinable " + joinable + " is notifying parent " + parent + " about change to " + state); 101 parent.childChangedState(joinable, state); 102 } 103 }); 104 } 105 106 public static void wait(Object object, long millis) { 107 try { 108 object.wait(millis); 109 } catch (InterruptedException e) { 110 } 111 } 112 113 public static void joinAbsolutely(Joinable joinable) { 114 log.info("joining absolutely " + joinable); 115 while (true) { 116 try { 117 Dispatching.join(joinable); 118 return; 119 } catch (InterruptedException e) { 120 // throw new FramsticksException().msg("failed to join").arg("dispatcher", dispatcher).cause(e); 121 } 122 log.info("waiting for " + joinable); 123 sleep(500); 124 } 125 } 126 127 128 129 46 130 } -
java/main/src/main/java/com/framsticks/util/dispatching/Thread.java
r85 r88 5 5 import java.util.LinkedList; 6 6 import java.util.ListIterator; 7 8 import javax.annotation.OverridingMethodsMustInvokeSuper; 9 10 import com.framsticks.params.annotations.ParamAnnotation; 7 11 import com.framsticks.util.dispatching.RunAt; 8 12 … … 10 14 * @author Piotr Sniegowski 11 15 */ 12 public class Thread<C> implements Dispatcher<C> {16 public class Thread<C> extends AbstractJoinable implements Dispatcher<C> { 13 17 14 18 private static final Logger log = Logger.getLogger(Thread.class.getName()); … … 27 31 } 28 32 29 public Thread(String s) { 30 this(); 31 thread.setName(s); 32 // thread.start(); 33 @OverridingMethodsMustInvokeSuper 34 protected void firstTask() { 33 35 } 34 36 35 public Thread( String s,java.lang.Thread thread) {37 public Thread(java.lang.Thread thread) { 36 38 this.thread = thread; 37 thread.setName(s);38 39 } 39 40 40 public Thread<C> start() { 41 @Override 42 protected void joinableStart() { 41 43 thread.start(); 42 return this;43 44 } 44 45 … … 49 50 50 51 protected void routine() { 52 log.debug("starting thread " + this); 53 firstTask(); 51 54 while (!java.lang.Thread.interrupted()) { 52 55 Task<? extends C> task; … … 76 79 } catch (Exception e) { 77 80 log.error("error in thread: " + e); 78 e.printStackTrace();79 81 } 80 82 } 83 log.debug("finishing thread " + this); 84 finish(); 81 85 } 82 86 … … 124 128 } 125 129 126 public void interrupt() { 130 @Override 131 protected void joinableInterrupt() { 127 132 thread.interrupt(); 128 133 } 129 134 130 public void join() throws InterruptedException { 131 thread.join(); 135 @Override 136 protected void joinableJoin() throws InterruptedException { 137 thread.join(500); 138 log.debug("joined " + this); 132 139 } 133 140 141 @ParamAnnotation 134 142 public void setName(String name) { 135 143 thread.setName(name); 144 } 136 145 146 @ParamAnnotation 147 public String getName() { 148 return thread.getName(); 137 149 } 138 150 … … 140 152 return java.lang.Thread.interrupted(); 141 153 } 154 155 @Override 156 public String toString() { 157 return getName(); 158 } 159 160 @Override 161 protected void joinableFinish() { 162 } 163 142 164 } -
java/main/src/main/resources/configs/framsticks.xml
r87 r88 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 <framsticks> 3 <com.framsticks.gui.Browser> 4 <size>1500 800</size> 5 <endpoint> 6 <com.framsticks.remote.RemoteInstance> 7 <name>localhost:9009</name> 8 <address>localhost:9009</address> 9 </com.framsticks.remote.RemoteInstance> 10 </endpoint> 11 </com.framsticks.gui.Browser> 12 </framsticks> 2 <Framsticks> 3 <import class="com.framsticks.gui.Browser" /> 4 <import class="com.framsticks.remote.RemoteInstance" /> 5 <Browser> 6 <RemoteInstance name="localhost:9009" address="localhost:9009" /> 7 </Browser> 8 <!-- <Browser name="other"> --> 9 <!-- <RemoteInstance name="localhost:9009" address="localhost:9009" /> --> 10 <!-- </Browser> --> 11 </Framsticks> -
java/main/src/main/resources/configs/log4j.properties
r84 r88 29 29 30 30 log4j.logger.com.framsticks=INFO 31 # log4j.logger.com.framsticks.util.dispatching.Dispatching=DEBUG 32 # log4j.logger.com.framsticks.util.dispatching.AbstractJoinable=DEBUG 33 # log4j.logger.com.framsticks.util.dispatching.JoinableCollection=DEBUG 34 35 # log4j.logger.com.framsticks.gui=DEBUG 31 36 # log4j.logger.com.framsticks.gui.controls.SliderControl=TRACE 32 37 # log4j.logger.com.framsticks.gui.EndpointAtFrame=DEBUG -
java/main/src/test/java/com/framsticks/gui/BrowserTest.java
r87 r88 3 3 import javax.swing.JFrame; 4 4 5 import org.apache.commons.configuration.PropertiesConfiguration;6 5 import org.apache.log4j.Logger; 7 6 import org.fest.swing.edt.FailOnThreadViolationRepaintManager; … … 16 15 import com.framsticks.remote.RemoteInstance; 17 16 import com.framsticks.test.TestConfiguration; 17 import com.framsticks.util.dispatching.Dispatching; 18 import com.framsticks.util.dispatching.JoinableMonitor; 19 // import com.framsticks.util.dispatching.Dispatching; 18 20 19 21 import static org.fest.assertions.Assertions.*; … … 25 27 private static final Logger log = Logger.getLogger(BrowserTest.class); 26 28 29 JoinableMonitor monitor; 27 30 Browser browser; 28 31 Robot robot; … … 37 40 38 41 browser = new Browser(); 39 browser.configure(new PropertiesConfiguration());42 monitor = new JoinableMonitor(browser); 40 43 41 44 RemoteInstance localhost = new RemoteInstance(); … … 43 46 localhost.setAddress("localhost:9009"); 44 47 45 browser.add EndpointForInstance(localhost);48 browser.addInstance(localhost); 46 49 47 browser.start();50 monitor.use(); 48 51 // robot.waitForIdle(); 49 52 frame = new FrameFixture(robot, … … 51 54 @Override 52 55 protected JFrame executeInEDT() throws Throwable { 53 return browser.getMainFrame() ;56 return browser.getMainFrame().getSwing(); 54 57 } 55 58 })); … … 86 89 clickAndExpandPath(tree, "localhost/simulator/genepools/groups"); 87 90 clickAndExpandPath(tree, "localhost/simulator/genepools/groups/Genotypes"); 91 92 93 94 95 96 88 97 // tree.clickPath("localhost/simulator/genepools/groups/Genotypes/genotypes"); 89 98 // robot.waitForIdle(); … … 97 106 } 98 107 99 public void sleep(int seconds) {100 try {101 Thread.sleep(seconds * 1000, 0);102 } catch (InterruptedException e) {103 e.printStackTrace();104 }105 }106 108 107 109 @AfterClass 108 110 public void tearDown() { 109 // frame.close(); 110 frame.cleanUp(); 111 log.info("before close"); 112 113 monitor.drop(); 114 115 Dispatching.joinAbsolutely(browser); 116 // frame.cleanUp(); 117 // log.info("before close"); 118 // browser.interrupt(); 119 120 // try { 121 // // frame.close(); 122 // } catch (Throwable t) { 123 // log.error("caught ", t); 124 // } 125 // log.info("after close"); 126 // // frame.close(); 127 // // frame.cleanUp(); 128 129 130 131 // Dispatching.join(browser); 111 132 } 112 133 -
java/main/src/test/java/com/framsticks/params/ParamBuilderTest.java
r87 r88 20 20 builderFramsClass = FramsClass.build().forClass(ParamBuilder.class); 21 21 22 assertThat(builderFramsClass.getParamCount()).isEqualTo( 6);22 assertThat(builderFramsClass.getParamCount()).isEqualTo(10); 23 23 assertThat(builderFramsClass.getName()).isEqualTo("prop"); 24 24 assertThat(builderFramsClass.getId()).isEqualTo("prop"); -
java/main/src/test/java/com/framsticks/parsers/F0ParserTest.java
r87 r88 5 5 import com.framsticks.model.*; 6 6 import com.framsticks.model.Package; 7 import com.framsticks.model.f0.Schema; 7 8 import com.framsticks.params.*; 8 9 import com.framsticks.params.types.FloatParam; … … 29 30 @BeforeClass 30 31 public void setUp() throws Exception { 31 schema = new Schema(Schema.getDefaultDefinitionAsStream());32 schema = Schema.load(Schema.getDefaultDefinitionAsStream()); 32 33 Package.register(schema.getRegistry()); 33 34 } … … 35 36 @Test 36 37 public void primitiveParam() { 37 FramsClass joint = schema.get Registry().getInfoFromCache("j");38 FramsClass joint = schema.getFramsClass("j"); 38 39 PrimitiveParam<?> dx = joint.getParamEntry("dx", PrimitiveParam.class); 39 40 assertThat(dx).isInstanceOf(FloatParam.class); … … 47 48 @Test 48 49 public void readF0() throws IOException, ParseException { 50 assertThat(schema.getFramsClass("p")).isInstanceOf(FramsClass.class); 51 assertThat(schema.getRegistry().getInfoFromCache("p").getParamEntry("as", FloatParam.class).getDef(Double.class)).isEqualTo(0.25, delta(0.0)); 52 49 53 accesses = new F0Parser(schema, F0ParserTest.class.getResourceAsStream("/parsers/f0_example.txt")).parse(); 50 54 … … 75 79 assertThat(model.getJoints().get(0).part1).isEqualTo(0); 76 80 assertThat(model.getJoints().get(0).part2).isEqualTo(1); 81 assertThat(model.getNeuroDefs().size()).isEqualTo(6); 77 82 assertThat(model.getNeuroDefs().get(0).part).isEqualTo(1); 78 83 assertThat(model.getNeuroDefs().get(0).joint).isEqualTo(-1); … … 89 94 public void print() throws Exception { 90 95 ListSink sink = new ListSink(); 96 97 91 98 new F0Writer(schema, model, sink).write(); 92 99 -
java/main/src/test/java/com/framsticks/test/TestConfiguration.java
r84 r88 11 11 12 12 @BeforeClass 13 public staticvoid setUpConfiguration() {13 public void setUpConfiguration() { 14 14 PropertyConfigurator.configure(TestConfiguration.class.getResource("/log4j.properties")); 15 log.info(" logging configured");15 log.info("testing " + this.getClass()); 16 16 } 17 17 -
java/main/src/test/resources/configs/test.xml
r87 r88 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 <framsticks> 3 <instance class="com.framsticks.gui.Browser"> 4 <!-- <size>1500 800</size> --> 5 <endpoint class="com.framsticks.remote.RemoteInstance"> 6 <name>localhost:9009</name> 7 <address>localhost:9009</address> 8 </endpoint> 9 </instance> 10 </framsticks> 2 <Framsticks> 3 <import class="com.framsticks.gui.Browser" /> 4 <import class="com.framsticks.remote.RemoteInstance" /> 5 <Browser name="browser"> 6 <RemoteInstance name="localhost:9009" address="localhost:9009" /> 7 </Browser> 8 </Framsticks> -
java/main/src/test/resources/log4j.properties
r86 r88 27 27 28 28 log4j.logger.com.framsticks=INFO 29 # log4j.logger.com.framsticks.util.dispatching.JoinableMonitor=DEBUG 30 # log4j.logger.com.framsticks.util.dispatching.Dispatching=DEBUG 31 # log4j.logger.com.framsticks.parsers.XmlLoader=DEBUG 29 32 # log4j.logger.com.framsticks.parsers.MultiParamLoader=TRACE 30 33 # log4j.logger.com.framsticks.gui.controls.SliderControl=TRACE
Note: See TracChangeset
for help on using the changeset viewer.