Changeset 105
- Timestamp:
- 09/10/13 21:11:41 (11 years ago)
- Location:
- java/main
- Files:
-
- 19 added
- 13 deleted
- 118 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/pom.xml
r102 r105 57 57 </dependency> 58 58 <dependency> 59 <groupId> commons-lang</groupId>60 <artifactId>commons-lang </artifactId>61 <version> 2.3</version>59 <groupId>org.apache.commons</groupId> 60 <artifactId>commons-lang3</artifactId> 61 <version>3.1</version> 62 62 </dependency> 63 63 <dependency> -
java/main/src/main/java/com/framsticks/communication/ClientSideManagedConnection.java
r103 r105 9 9 import com.framsticks.communication.queries.UseRequest; 10 10 import com.framsticks.communication.queries.VersionRequest; 11 import com.framsticks.core.Path;12 11 import com.framsticks.params.ListSource; 12 import com.framsticks.structure.Path; 13 13 import com.framsticks.util.*; 14 14 import com.framsticks.util.dispatching.AtOnceDispatcher; 15 15 import com.framsticks.util.dispatching.Dispatcher; 16 16 import com.framsticks.util.dispatching.Dispatching; 17 import com.framsticks.util.dispatching. ExceptionResultHandler;17 import com.framsticks.util.dispatching.FutureHandler; 18 18 import com.framsticks.util.dispatching.Future; 19 import com.framsticks.util.dispatching.FutureHandler;20 19 import com.framsticks.util.dispatching.JoinableState; 21 20 import com.framsticks.util.lang.Casting; … … 195 194 } 196 195 197 private void sendNextUseRequest(final Iterator<String> featuresIterator, final Future <Void> future) {196 private void sendNextUseRequest(final Iterator<String> featuresIterator, final FutureHandler<Void> future) { 198 197 if (!featuresIterator.hasNext()) { 199 198 future.pass(null); … … 214 213 } 215 214 216 private void sendQueryVersion(final int version, final Future <Void> future) {215 private void sendQueryVersion(final int version, final FutureHandler<Void> future) { 217 216 send(new VersionRequest().version(version), new ClientSideResponseFuture(future) { 218 217 @Override … … 335 334 } 336 335 337 final Future <File> future = new Future<File>() {336 final FutureHandler<File> future = new FutureHandler<File>() { 338 337 339 338 protected void send(final File result) { … … 415 414 } 416 415 417 protected final Exception ResultHandler closeOnFailure = new ExceptionResultHandler() {416 protected final ExceptionHandler closeOnFailure = new ExceptionHandler() { 418 417 419 418 @Override … … 428 427 startClientConnection(this); 429 428 430 sendQueryVersion(1, new Future Handler<Void>(closeOnFailure) {429 sendQueryVersion(1, new Future<Void>(closeOnFailure) { 431 430 432 431 @Override … … 451 450 protected final Map<String, EventListener<File>> registeredListeners = new HashMap<>(); 452 451 453 public <C> void addListener(String path, final EventListener<File> listener, final Dispatcher<C> dispatcher, final Future <Void> future) {452 public <C> void addListener(String path, final EventListener<File> listener, final Dispatcher<C> dispatcher, final FutureHandler<Void> future) { 454 453 send(new RegisterRequest().path(path), dispatcher, new ClientSideResponseFuture(future) { 455 454 @Override … … 463 462 } 464 463 465 public <C> void removeListener(EventListener<File> listener, final Dispatcher<C> dispatcher, final Future <Void> future) {464 public <C> void removeListener(EventListener<File> listener, final Dispatcher<C> dispatcher, final FutureHandler<Void> future) { 466 465 String eventPath = null; 467 466 synchronized (registeredListeners) { -
java/main/src/main/java/com/framsticks/communication/ClientSideRawConnection.java
r97 r105 2 2 3 3 import com.framsticks.params.annotations.FramsClassAnnotation; 4 import com.framsticks.util. dispatching.ExceptionResultHandler;4 import com.framsticks.util.ExceptionHandler; 5 5 import com.framsticks.util.dispatching.RunAt; 6 6 … … 23 23 } 24 24 25 public void send(final String line, Exception ResultHandler handler) {25 public void send(final String line, ExceptionHandler handler) { 26 26 27 27 senderThread.dispatch(new RunAt<ClientSideRawConnection>(handler) { -
java/main/src/main/java/com/framsticks/communication/ClientSideResponseFuture.java
r98 r105 1 1 package com.framsticks.communication; 2 2 3 import com.framsticks.util.ExceptionHandler; 3 4 import com.framsticks.util.FramsticksException; 4 import com.framsticks.util.dispatching.ExceptionResultHandler; 5 import com.framsticks.util.dispatching.FutureHandler; 5 import com.framsticks.util.dispatching.Future; 6 6 7 public abstract class ClientSideResponseFuture extends Future Handler<Response> {7 public abstract class ClientSideResponseFuture extends Future<Response> { 8 8 9 public ClientSideResponseFuture(Exception ResultHandler handler) {9 public ClientSideResponseFuture(ExceptionHandler handler) { 10 10 super(handler); 11 11 } -
java/main/src/main/java/com/framsticks/communication/Connection.java
r102 r105 5 5 import com.framsticks.params.annotations.FramsClassAnnotation; 6 6 import com.framsticks.params.annotations.ParamAnnotation; 7 import com.framsticks.util.ExceptionHandler; 7 8 import com.framsticks.util.FramsticksException; 8 9 import com.framsticks.util.io.Encoding; … … 25 26 import com.framsticks.util.dispatching.Dispatcher; 26 27 import com.framsticks.util.dispatching.Dispatching; 27 import com.framsticks.util.dispatching.ExceptionResultHandler;28 28 import com.framsticks.util.dispatching.Joinable; 29 29 import com.framsticks.util.dispatching.JoinableCollection; … … 35 35 36 36 @FramsClassAnnotation 37 public abstract class Connection extends AbstractJoinable implements JoinableParent, Exception ResultHandler {37 public abstract class Connection extends AbstractJoinable implements JoinableParent, ExceptionHandler { 38 38 39 39 protected final static Logger log = LogManager.getLogger(Connection.class); … … 52 52 protected final Set<ConnectionListener> listeners = new HashSet<>(); 53 53 54 protected Exception ResultHandler exceptionHandler = ThrowExceptionHandler.getInstance();54 protected ExceptionHandler exceptionHandler = ThrowExceptionHandler.getInstance(); 55 55 56 56 /** … … 301 301 * @return the handler 302 302 */ 303 public Exception ResultHandler getExceptionHandler() {303 public ExceptionHandler getExceptionHandler() { 304 304 return exceptionHandler; 305 305 } … … 308 308 * @param handler the handler to set 309 309 */ 310 public void setExceptionHandler(Exception ResultHandler handler) {310 public void setExceptionHandler(ExceptionHandler handler) { 311 311 this.exceptionHandler = handler; 312 312 } … … 346 346 } 347 347 348 public final void sendFile(final String header, final File file, final Integer id, Exception ResultHandler handler) {348 public final void sendFile(final String header, final File file, final Integer id, ExceptionHandler handler) { 349 349 senderThread.dispatch(new RunAt<Connection>(handler) { 350 350 @Override -
java/main/src/main/java/com/framsticks/communication/File.java
r101 r105 1 1 package com.framsticks.communication; 2 2 3 import java.util.ArrayList;4 import java.util.List;5 3 6 4 import javax.annotation.Nonnull; … … 31 29 } 32 30 33 public static List<File> single(File file) {34 List<File> result = new ArrayList<File>();35 result.add(file);36 return result;37 }38 39 31 @Override 40 32 public String toString() { -
java/main/src/main/java/com/framsticks/communication/RequestHandler.java
r98 r105 2 2 3 3 import com.framsticks.communication.queries.ApplicationRequest; 4 import com.framsticks.util. dispatching.ExceptionResultHandler;4 import com.framsticks.util.ExceptionHandler; 5 5 6 6 /** 7 7 * @author Piotr Sniegowski 8 8 */ 9 public interface RequestHandler extends Exception ResultHandler {9 public interface RequestHandler extends ExceptionHandler { 10 10 public void handle(ApplicationRequest request, ServerSideResponseFuture responseCallback); 11 11 } -
java/main/src/main/java/com/framsticks/communication/Response.java
r96 r105 1 1 package com.framsticks.communication; 2 2 3 import java.util.Arrays; 3 4 import java.util.List; 4 5 … … 10 11 protected final String comment; 11 12 protected final List<File> files; 13 14 public Response(boolean ok, String comment, File... files) { 15 this(ok, comment, (files.length == 0 ? null : Arrays.asList(files))); 16 } 12 17 13 18 public Response(boolean ok, String comment, List<File> files) { -
java/main/src/main/java/com/framsticks/communication/ServerSideManagedConnection.java
r103 r105 46 46 if (request instanceof ProtocolRequest) { 47 47 if (request instanceof VersionRequest) { 48 responseCallback.pass(new Response(true, null , null));48 responseCallback.pass(new Response(true, null)); 49 49 return; 50 50 } … … 53 53 if (feature.equals("request_id")) { 54 54 requestIdEnabled = true; 55 responseCallback.pass(new Response(true, null , null));55 responseCallback.pass(new Response(true, null)); 56 56 return; 57 57 } 58 58 if (feature.equals("call_empty_result")) { 59 responseCallback.pass(new Response(true, null , null));59 responseCallback.pass(new Response(true, null)); 60 60 return; 61 61 } 62 62 if (feature.equals("needfile_id")) { 63 responseCallback.pass(new Response(true, null , null));63 responseCallback.pass(new Response(true, null)); 64 64 return; 65 65 } 66 responseCallback.pass(new Response(false, "unknown feature: " + feature , null));66 responseCallback.pass(new Response(false, "unknown feature: " + feature)); 67 67 return; 68 68 } … … 70 70 } 71 71 log.error("unhandled request: {}", request); 72 responseCallback.pass(new Response(false, "unhandled" , null));72 responseCallback.pass(new Response(false, "unhandled")); 73 73 } 74 74 … … 120 120 e.arg("id", id.get()).arg("line", line); 121 121 log.error("error: ", e); 122 respond(new Response(false, "invalid input: " + e.getMsg() , null), id.get());122 respond(new Response(false, "invalid input: " + e.getMsg()), id.get()); 123 123 return; 124 124 } -
java/main/src/main/java/com/framsticks/communication/ServerSideResponseFuture.java
r99 r105 2 2 3 3 import com.framsticks.util.FramsticksException; 4 import com.framsticks.util.dispatching.Future ;4 import com.framsticks.util.dispatching.FutureHandler; 5 5 6 6 /** 7 7 * @author Piotr Sniegowski 8 8 */ 9 public abstract class ServerSideResponseFuture extends Future <Response> {9 public abstract class ServerSideResponseFuture extends FutureHandler<Response> { 10 10 11 11 @Override 12 12 public final void handle(FramsticksException e) { 13 result(new Response(false, e.getClass().getCanonicalName() + ": " + e.getMessage() , null));13 result(new Response(false, e.getClass().getCanonicalName() + ": " + e.getMessage())); 14 14 } 15 15 -
java/main/src/main/java/com/framsticks/communication/queries/NeedFile.java
r101 r105 2 2 3 3 import com.framsticks.communication.File; 4 import com.framsticks.util.dispatching.Future ;4 import com.framsticks.util.dispatching.FutureHandler; 5 5 import com.framsticks.util.lang.Strings; 6 6 … … 9 9 protected final String suggestedName; 10 10 protected final String description; 11 protected final Future <File> future;11 protected final FutureHandler<File> future; 12 12 13 13 /** … … 16 16 * @param future 17 17 */ 18 public NeedFile(String suggestedName, String description, Future <File> future) {18 public NeedFile(String suggestedName, String description, FutureHandler<File> future) { 19 19 this.suggestedName = suggestedName; 20 20 this.description = description; … … 39 39 * @return the future 40 40 */ 41 public Future <File> getFuture() {41 public FutureHandler<File> getFuture() { 42 42 return future; 43 43 } -
java/main/src/main/java/com/framsticks/communication/queries/RegisterRequest.java
r99 r105 1 1 package com.framsticks.communication.queries; 2 2 3 import com.framsticks. core.Path;3 import com.framsticks.structure.Path; 4 4 import com.framsticks.util.lang.Pair; 5 5 -
java/main/src/main/java/com/framsticks/dumping/LoadStream.java
r100 r105 2 2 3 3 import com.framsticks.communication.File; 4 import com.framsticks.core.TreeOperations;5 import com.framsticks.core.Path;6 4 import com.framsticks.params.ListSource; 7 import com.framsticks.core.Tree; 5 import com.framsticks.structure.Path; 6 import com.framsticks.structure.Tree; 7 import com.framsticks.structure.TreeOperations; 8 8 import com.framsticks.util.*; 9 import com.framsticks.util.dispatching.Future ;9 import com.framsticks.util.dispatching.FutureHandler; 10 10 import com.framsticks.util.lang.Pair; 11 11 import com.framsticks.util.lang.Strings; … … 28 28 protected final Path mountPath; 29 29 protected final BufferedReader stream; 30 protected final Future <Path> future;30 protected final FutureHandler<Path> future; 31 31 protected final Stopwatch stopwatch = new Stopwatch(); 32 32 33 33 34 public LoadStream(Path mountPath, BufferedReader stream, Tree tree, Future <Path> future) {34 public LoadStream(Path mountPath, BufferedReader stream, Tree tree, FutureHandler<Path> future) { 35 35 this.tree = tree; 36 36 this.mountPath = mountPath; -
java/main/src/main/java/com/framsticks/dumping/SaveStream.java
r102 r105 1 1 package com.framsticks.dumping; 2 2 3 import static com.framsticks.core.TreeOperations.*;4 3 import static com.framsticks.params.AccessOperations.*; 5 import com.framsticks.core.Node;6 import com.framsticks.core.Path;7 4 import com.framsticks.params.Access; 8 5 import com.framsticks.params.CompositeParam; … … 11 8 import com.framsticks.params.Sink; 12 9 import com.framsticks.parsers.Savers; 13 import com.framsticks.core.Tree; 10 import com.framsticks.structure.Node; 11 import com.framsticks.structure.Path; 12 import com.framsticks.structure.Tree; 14 13 import com.framsticks.util.*; 15 14 import com.framsticks.util.dispatching.Dispatching; 16 import com.framsticks.util.dispatching.Future ;15 import com.framsticks.util.dispatching.FutureHandler; 17 16 18 17 import org.apache.logging.log4j.Logger; … … 22 21 import java.util.HashSet; 23 22 import java.util.Set; 23 24 import static com.framsticks.structure.TreeOperations.*; 24 25 import static com.framsticks.util.lang.Containers.filterInstanceof; 25 26 … … 33 34 protected final Sink sink; 34 35 protected final Tree tree; 35 protected final Future <Void> future;36 protected final FutureHandler<Void> future; 36 37 protected final Stopwatch stopwatch = new Stopwatch(); 37 38 protected final Set<FramsClass> storedInfo = new HashSet<FramsClass>(); … … 39 40 private int dispatched = 0; 40 41 41 public SaveStream(Sink sink, Tree tree, Path root, Future <Void> future) {42 public SaveStream(Sink sink, Tree tree, Path root, FutureHandler<Void> future) { 42 43 assert Dispatching.isThreadSafe(); 43 44 this.sink = sink; -
java/main/src/main/java/com/framsticks/experiment/Experiment.java
r103 r105 7 7 import org.apache.logging.log4j.LogManager; 8 8 9 import com.framsticks.core.ListChange;10 9 import com.framsticks.params.EventListener; 11 10 import com.framsticks.params.ParamFlags; … … 16 15 import com.framsticks.params.types.ProcedureParam; 17 16 import com.framsticks.remote.RemoteTree; 17 import com.framsticks.structure.messages.ListChange; 18 import com.framsticks.util.ExceptionHandler; 18 19 import com.framsticks.util.FramsticksException; 19 20 import com.framsticks.util.dispatching.AbstractJoinable; … … 22 23 import com.framsticks.util.dispatching.DispatcherSetable; 23 24 import com.framsticks.util.dispatching.Dispatching; 24 import com.framsticks.util.dispatching.ExceptionResultHandler;25 25 import com.framsticks.util.dispatching.Joinable; 26 26 import com.framsticks.util.dispatching.JoinableCollection; … … 30 30 31 31 @FramsClassAnnotation 32 public class Experiment extends AbstractJoinable implements Dispatcher<Experiment>, DispatcherSetable<Experiment>, JoinableParent, Exception ResultHandler {32 public class Experiment extends AbstractJoinable implements Dispatcher<Experiment>, DispatcherSetable<Experiment>, JoinableParent, ExceptionHandler { 33 33 private static final Logger log = LogManager.getLogger(Experiment.class); 34 34 -
java/main/src/main/java/com/framsticks/experiment/NetLoadSaveLogic.java
r103 r105 5 5 import org.apache.logging.log4j.LogManager; 6 6 7 import com.framsticks.core.ListChange;8 import com.framsticks.core.Message;9 7 import com.framsticks.params.EventListener; 10 8 import com.framsticks.params.MessageLogger; 11 9 import com.framsticks.params.annotations.FramsClassAnnotation; 12 10 import com.framsticks.params.annotations.ParamAnnotation; 11 import com.framsticks.structure.messages.ListChange; 12 import com.framsticks.structure.messages.Message; 13 import com.framsticks.util.dispatching.FutureHandler; 13 14 import com.framsticks.util.dispatching.Future; 14 import com.framsticks.util.dispatching.FutureHandler;15 15 16 16 @FramsClassAnnotation … … 50 50 51 51 log.debug("issuing netsave to: {}", simulator); 52 simulator.netsave(netJavaClass, new Future Handler<NF>(simulator) {52 simulator.netsave(netJavaClass, new Future<NF>(simulator) { 53 53 54 54 @Override … … 68 68 } 69 69 log.debug("issuing netload to: {}", simulator); 70 netload(simulator, new Future Handler<NF>(simulator) {70 netload(simulator, new Future<NF>(simulator) { 71 71 72 72 @Override … … 77 77 } 78 78 79 simulator.netload(net, new Future Handler<Object>(this) {79 simulator.netload(net, new Future<Object>(this) { 80 80 81 81 @Override … … 90 90 } 91 91 92 public abstract void netload(Simulator simulator, Future <NF> net);92 public abstract void netload(Simulator simulator, FutureHandler<NF> net); 93 93 94 94 public abstract void netsave(Simulator simulator, NF net); -
java/main/src/main/java/com/framsticks/experiment/Simulator.java
r103 r105 4 4 import com.framsticks.communication.queries.NeedFile; 5 5 import com.framsticks.communication.queries.NeedFileAcceptor; 6 import com.framsticks.core.ListChange;7 import com.framsticks.core.Path;8 import com.framsticks.core.Tree;9 import com.framsticks.core.ValueChange;10 6 import com.framsticks.params.AccessOperations; 11 7 import com.framsticks.params.CastFailure; … … 19 15 import com.framsticks.params.types.ProcedureParam; 20 16 import com.framsticks.remote.RemoteTree; 17 import com.framsticks.structure.Path; 18 import com.framsticks.structure.Tree; 19 import com.framsticks.structure.messages.ListChange; 20 import com.framsticks.structure.messages.ValueChange; 21 import com.framsticks.util.ExceptionHandler; 21 22 import com.framsticks.util.FramsticksException; 22 23 import com.framsticks.util.dispatching.AbstractJoinable; 23 24 import com.framsticks.util.dispatching.Dispatcher; 24 25 import com.framsticks.util.dispatching.Dispatching; 25 import com.framsticks.util.dispatching. ExceptionResultHandler;26 import com.framsticks.util.dispatching.FutureHandler; 26 27 import com.framsticks.util.dispatching.Future; 27 import com.framsticks.util.dispatching.FutureHandler;28 28 import com.framsticks.util.dispatching.Joinable; 29 29 import com.framsticks.util.dispatching.JoinableParent; … … 35 35 import org.apache.logging.log4j.LogManager; 36 36 import org.apache.logging.log4j.Logger; 37 import static com.framsticks.core.TreeOperations.*; 37 import static com.framsticks.params.ParamsUtil.arguments; 38 import static com.framsticks.params.ParamsUtil.getParam; 39 import static com.framsticks.structure.TreeOperations.*; 38 40 39 41 @FramsClassAnnotation 40 public final class Simulator extends AbstractJoinable implements Dispatcher<Simulator>, JoinableParent, UniqueObject, Exception ResultHandler {42 public final class Simulator extends AbstractJoinable implements Dispatcher<Simulator>, JoinableParent, UniqueObject, ExceptionHandler { 41 43 42 44 private static final Logger log = LogManager.getLogger(Simulator.class); … … 69 71 public void action(ValueChange argument) { 70 72 try { 71 boolean running = simulatorClass.getParamEntry("running", BooleanParam.class).reassign(argument.value, null).getValue();73 boolean running = getParam(simulatorClass, "running", BooleanParam.class).reassign(argument.value, null).getValue(); 72 74 log.debug("running state of {} changed: {}", Simulator.this, running); 73 75 if (!running) { … … 80 82 }; 81 83 82 addListener(simulatorPath, simulatorClass.getParamEntry("running_changed", EventParam.class), runningListener, ValueChange.class, new FutureHandler<Void>(this) {84 addListener(simulatorPath, getParam(simulatorClass, "running_changed", EventParam.class), runningListener, ValueChange.class, new Future<Void>(this) { 83 85 @Override 84 86 protected void result(Void result) { … … 160 162 public void start() { 161 163 log.debug("starting simulator {}", this); 162 call(simulatorPath, "start", new Object[] {}, Object.class, FutureHandler.doNothing(Object.class, this));164 call(simulatorPath, "start", arguments(), Object.class, Future.doNothing(Object.class, this)); 163 165 } 164 166 … … 199 201 protected final AtomicInteger netloadIdCounter = new AtomicInteger(); 200 202 201 public <N> void netload(final N net, final Future <Object> future) {203 public <N> void netload(final N net, final FutureHandler<Object> future) { 202 204 final String netloadId = "NetLoadSaveLogic" + netloadIdCounter.getAndIncrement(); 203 205 … … 231 233 simulatorPath.getTree().addNeedFileAcceptor(Integer.MIN_VALUE, acceptor.get()); 232 234 233 call(simulatorPath, get FramsClass(simulatorPath).getParamEntry("netload_id", ProcedureParam.class), new Object[] { netloadId }, Object.class, new FutureHandler<Object>(future) {235 call(simulatorPath, getParam(simulatorPath, "netload_id", ProcedureParam.class), arguments(netloadId), Object.class, new Future<Object>(future) { 234 236 235 237 @Override 236 238 protected void result(Object result) { 237 log.debug(" upload of {} done", file);239 log.debug("netload of {} done", file); 238 240 future.pass(result); 239 241 } … … 242 244 } 243 245 244 public <N> void netsave(Class<N> netJavaClass, final Future <N> futureNet) {245 call(simulatorPath, get FramsClass(simulatorPath).getParamEntry("netsave", ProcedureParam.class), new Object[] { }, netJavaClass, new FutureHandler<N>(futureNet) {246 public <N> void netsave(Class<N> netJavaClass, final FutureHandler<N> futureNet) { 247 call(simulatorPath, getParam(simulatorPath, "netsave", ProcedureParam.class), arguments(), netJavaClass, new Future<N>(futureNet) { 246 248 247 249 @Override 248 250 protected void result(N net) { 249 log.debug(" downloadof {} done", net);251 log.debug("netsave of {} done", net); 250 252 futureNet.pass(net); 251 253 } 252 254 }); 253 254 255 } 255 256 } -
java/main/src/main/java/com/framsticks/experiment/SimulatorConnector.java
r102 r105 6 6 7 7 import com.framsticks.communication.Address; 8 import com.framsticks.core.Path;9 8 import com.framsticks.params.annotations.FramsClassAnnotation; 10 9 import com.framsticks.params.annotations.ParamAnnotation; 11 10 import com.framsticks.remote.RemoteTree; 11 import com.framsticks.structure.Path; 12 12 import com.framsticks.util.AutoAttacher; 13 13 import com.framsticks.util.Misc; 14 14 import com.framsticks.util.dispatching.Dispatcher; 15 15 import com.framsticks.util.dispatching.Dispatching; 16 import com.framsticks.util.dispatching.Future Handler;16 import com.framsticks.util.dispatching.Future; 17 17 import com.framsticks.util.lang.Casting; 18 18 import com.framsticks.util.lang.Strings; 19 19 20 import static com.framsticks. core.TreeOperations.*;20 import static com.framsticks.structure.TreeOperations.*; 21 21 22 22 @FramsClassAnnotation … … 46 46 Dispatching.dispatchLog(remoteTree, log, Level.DEBUG, "first task in remote tree"); 47 47 48 tryGet(remoteTree, "/simulator", new Future Handler<Path>(experiment) {48 tryGet(remoteTree, "/simulator", new Future<Path>(experiment) { 49 49 50 50 @Override -
java/main/src/main/java/com/framsticks/experiment/WorkPackageLogic.java
r103 r105 8 8 import org.apache.logging.log4j.LogManager; 9 9 10 import com.framsticks.core.Message;11 import com.framsticks.core.ValueChange;12 10 import com.framsticks.params.EventListener; 13 11 import com.framsticks.params.MessageLogger; … … 15 13 import com.framsticks.params.annotations.FramsClassAnnotation; 16 14 import com.framsticks.params.annotations.ParamAnnotation; 15 import com.framsticks.structure.messages.Message; 16 import com.framsticks.structure.messages.ValueChange; 17 import com.framsticks.util.dispatching.FutureHandler; 17 18 import com.framsticks.util.dispatching.Future; 18 import com.framsticks.util.dispatching.FutureHandler;19 19 20 20 @FramsClassAnnotation(order = {"netLoadSaveLogic", "newestTaskScheduled", "newestResultReceived"}) … … 47 47 48 48 @Override 49 public void netload(final Simulator simulator, final Future <WP> netFuture) {49 public void netload(final Simulator simulator, final FutureHandler<WP> netFuture) { 50 50 assert experiment.isActive(); 51 51 log.debug("providing netload file for {}", simulator); 52 52 53 findNextPackage(new Future Handler<WP> (netFuture) {53 findNextPackage(new Future<WP> (netFuture) { 54 54 55 55 @Override … … 106 106 107 107 108 protected void findNextPackage(final Future <WP> future) {108 protected void findNextPackage(final FutureHandler<WP> future) { 109 109 if (!queuedPackages.isEmpty()) { 110 110 WP workPackage = queuedPackages.pollFirst(); … … 113 113 } 114 114 115 generateNextPackage(new Future Handler<WP>(experiment) {115 generateNextPackage(new Future<WP>(experiment) { 116 116 117 117 @Override … … 127 127 } 128 128 129 protected abstract void generateNextPackage(Future <WP> future);129 protected abstract void generateNextPackage(FutureHandler<WP> future); 130 130 protected abstract void returnPackage(WP workPackage); 131 131 -
java/main/src/main/java/com/framsticks/gui/Browser.java
r102 r105 4 4 import com.framsticks.communication.queries.NeedFile; 5 5 import com.framsticks.communication.queries.NeedFileAcceptor; 6 import com.framsticks.core.*;7 6 import com.framsticks.gui.console.Console; 8 7 import com.framsticks.gui.console.DirectConsole; … … 16 15 import com.framsticks.parsers.FileSource; 17 16 import com.framsticks.remote.RemoteTree; 17 import com.framsticks.structure.Path; 18 import com.framsticks.structure.Tree; 19 import com.framsticks.util.ExceptionHandler; 18 20 import com.framsticks.util.FramsticksException; 19 21 import com.framsticks.util.dispatching.AbstractJoinable; 20 22 import com.framsticks.util.dispatching.Dispatcher; 21 23 import com.framsticks.util.dispatching.Dispatching; 22 import com.framsticks.util.dispatching.ExceptionResultHandler; 23 import com.framsticks.util.dispatching.Future; 24 import com.framsticks.util.dispatching.FutureHandler; 24 25 import com.framsticks.util.dispatching.Joinable; 25 26 import com.framsticks.util.dispatching.JoinableCollection; … … 54 55 */ 55 56 @FramsClassAnnotation 56 public class Browser extends AbstractJoinable implements Dispatcher<Browser>, JoinableParent, Exception ResultHandler {57 public class Browser extends AbstractJoinable implements Dispatcher<Browser>, JoinableParent, ExceptionHandler { 57 58 58 59 private static final Logger log = LogManager.getLogger(Browser.class); … … 213 214 file = new File("", new FileSource(filename)); 214 215 } catch (IOException e) { 215 needFile.getFuture().handle(new FramsticksException().msg("failed to open cho osedfile").arg("filename", filename).cause(e));216 needFile.getFuture().handle(new FramsticksException().msg("failed to open chosen file").arg("filename", filename).cause(e)); 216 217 } 217 218 if (file != null) { … … 239 240 } 240 241 241 public void autoResolvePath(final String path, final Future <Path> future) {242 public void autoResolvePath(final String path, final FutureHandler<Path> future) { 242 243 // final Tree i = trees.get("localhost"); 243 244 // i.dispatch(new RunAt<Tree>(future) { … … 277 278 protected void runAt() { 278 279 279 for (final Tree i: trees) {280 i.dispatch(new RunAt<Tree>(this) {280 for (final Tree tree : trees) { 281 tree.dispatch(new RunAt<Tree>(this) { 281 282 @Override 282 283 protected void runAt() { 283 final Path p = Path.to( i, "/");284 final Path p = Path.to(tree, "/"); 284 285 log.debug("adding path: {}", p); 285 286 dispatch(new RunAt<Browser>(this) { -
java/main/src/main/java/com/framsticks/gui/Frame.java
r102 r105 39 39 import org.apache.logging.log4j.LogManager; 40 40 41 import com.framsticks.core.Path;42 import com.framsticks.core.Tree;43 41 import com.framsticks.gui.tree.AbstractNode; 44 42 import com.framsticks.gui.tree.MetaNode; … … 46 44 import com.framsticks.gui.tree.TreeModel; 47 45 import com.framsticks.gui.tree.TreeNode; 46 import com.framsticks.structure.Path; 47 import com.framsticks.structure.Tree; 48 48 import com.framsticks.util.dispatching.Dispatching; 49 import com.framsticks.util.dispatching.Future Handler;49 import com.framsticks.util.dispatching.Future; 50 50 import com.framsticks.util.dispatching.Joinable; 51 51 import com.framsticks.util.dispatching.JoinableCollection; … … 269 269 if (!tree.getAssignedRoot().isResolved()) { 270 270 log.debug("root not yet assigned, geting root"); 271 tree.get(path, new Future Handler<Path>(this) {271 tree.get(path, new Future<Path>(this) { 272 272 273 273 @Override … … 329 329 public void updatePanelIfIsLeadSelection(Path path) { 330 330 assert isActive(); 331 TreePath treePath = treeModel.convertToTreePath(path , true);331 TreePath treePath = treeModel.convertToTreePath(path); 332 332 if (treePath == null) { 333 333 return; -
java/main/src/main/java/com/framsticks/gui/FrameJoinable.java
r101 r105 13 13 import org.apache.logging.log4j.LogManager; 14 14 15 import com.framsticks.util.ExceptionHandler; 15 16 import com.framsticks.util.FramsticksException; 16 import com.framsticks.util.dispatching.ExceptionResultHandler;17 17 import com.framsticks.util.dispatching.RunAt; 18 18 import com.framsticks.util.dispatching.ThrowExceptionHandler; 19 19 20 public abstract class FrameJoinable extends SwingJoinable<JFrame> implements Exception ResultHandler {20 public abstract class FrameJoinable extends SwingJoinable<JFrame> implements ExceptionHandler { 21 21 private static final Logger log = 22 22 LogManager.getLogger(FrameJoinable.class); -
java/main/src/main/java/com/framsticks/gui/ModifiablePanel.java
r101 r105 9 9 import java.awt.event.ActionEvent; 10 10 import java.awt.event.ActionListener; 11 import static com.framsticks.core.TreeOperations.*; 11 12 import static com.framsticks.structure.TreeOperations.*; 12 13 13 14 /** -
java/main/src/main/java/com/framsticks/gui/MultiPanel.java
r100 r105 1 1 package com.framsticks.gui; 2 2 3 import com.framsticks.core.Path;4 3 import com.framsticks.params.Access; 4 import com.framsticks.structure.Path; 5 5 6 6 import javax.swing.*; -
java/main/src/main/java/com/framsticks/gui/ObjectPanel.java
r101 r105 1 1 package com.framsticks.gui; 2 2 3 import com.framsticks.core.Path;4 3 import com.framsticks.gui.controls.Control; 5 4 import com.framsticks.gui.controls.ControlOwner; … … 16 15 import java.util.HashMap; 17 16 import java.util.Map; 17 18 import static com.framsticks.structure.TreeOperations.*; 18 19 import static com.framsticks.util.lang.Containers.filterInstanceof; 19 20 21 import com.framsticks.structure.Path; 20 22 import com.framsticks.util.FramsticksException; 21 23 22 import static com.framsticks.core.TreeOperations.*;23 24 24 25 @SuppressWarnings("serial") -
java/main/src/main/java/com/framsticks/gui/PopupMenuEntryProvider.java
r97 r105 3 3 import javax.swing.JPopupMenu; 4 4 5 import com.framsticks. core.Path;5 import com.framsticks.structure.Path; 6 6 7 7 public interface PopupMenuEntryProvider { -
java/main/src/main/java/com/framsticks/gui/StandardPanelProvider.java
r100 r105 19 19 public TreePanel providePanel(TreePanel.Parameters parameters) { 20 20 if (parameters.param instanceof ObjectParam) { 21 return new ObjectPanel(parameters, CollectionUtils.select(parameters.framsClass.getParam Entries(), new NotPredicate(new InstanceofPredicate(CompositeParam.class))));21 return new ObjectPanel(parameters, CollectionUtils.select(parameters.framsClass.getParams(), new NotPredicate(new InstanceofPredicate(CompositeParam.class)))); 22 22 } 23 // if (param instanceof ListParam) {24 // return new ListPanel();25 // }26 23 return null; 27 24 } -
java/main/src/main/java/com/framsticks/gui/StatusBar.java
r101 r105 13 13 14 14 import com.framsticks.gui.controls.Control; 15 import com.framsticks.util.ExceptionHandler; 15 16 import com.framsticks.util.FramsticksException; 16 17 import com.framsticks.util.dispatching.Dispatcher; 17 18 import com.framsticks.util.dispatching.Dispatching; 18 import com.framsticks.util.dispatching.ExceptionResultHandler;19 19 import com.framsticks.util.dispatching.RunAt; 20 20 21 public class StatusBar implements Exception ResultHandler {21 public class StatusBar implements ExceptionHandler { 22 22 private static final Logger log = LogManager.getLogger(StatusBar.class); 23 23 24 24 protected JTextField statusBar; 25 25 protected JPanel swing; 26 protected Exception ResultHandler exceptionHandler;26 protected ExceptionHandler exceptionHandler; 27 27 protected final Dispatcher<?> dispatcher; 28 28 … … 86 86 * @return the exceptionHandler 87 87 */ 88 public Exception ResultHandler getExceptionHandler() {88 public ExceptionHandler getExceptionHandler() { 89 89 return exceptionHandler; 90 90 } … … 93 93 * @param exceptionHandler the exceptionHandler to set 94 94 */ 95 public void setExceptionHandler(Exception ResultHandler exceptionHandler) {95 public void setExceptionHandler(ExceptionHandler exceptionHandler) { 96 96 this.exceptionHandler = exceptionHandler; 97 97 } -
java/main/src/main/java/com/framsticks/gui/TreeAtFrame.java
r101 r105 4 4 import org.apache.logging.log4j.LogManager; 5 5 6 import com.framsticks.core.SideNoteKey;7 import com.framsticks.core.Tree;8 import com.framsticks.core.Node;9 import com.framsticks.core.Path;10 import static com.framsticks.core.TreeOperations.*;11 6 import com.framsticks.gui.controls.ValueControl; 12 7 import com.framsticks.params.CompositeParam; … … 15 10 16 11 import java.util.*; 12 import static com.framsticks.params.ParamsUtil.getParam; 13 import static com.framsticks.structure.TreeOperations.*; 17 14 18 19 20 import com.framsticks.util.dispatching.FutureHandler; 15 import com.framsticks.structure.Node; 16 import com.framsticks.structure.Path; 17 import com.framsticks.structure.SideNoteKey; 18 import com.framsticks.structure.Tree; 19 import com.framsticks.util.dispatching.Future; 21 20 22 21 /** … … 114 113 115 114 for (final Map.Entry<String, Object> e : userChanges.changes.entrySet()) { 116 set(path, getParam(path, e.getKey(), PrimitiveParam.class), e.getValue(), new Future Handler<Integer>(frame) {115 set(path, getParam(path, e.getKey(), PrimitiveParam.class), e.getValue(), new Future<Integer>(frame) { 117 116 @Override 118 117 protected void result(Integer flag) { -
java/main/src/main/java/com/framsticks/gui/TreePanel.java
r101 r105 1 1 package com.framsticks.gui; 2 2 3 import com.framsticks.core.Path; 4 import com.framsticks.core.Tree; 5 import static com.framsticks.core.TreeOperations.*; 3 import static com.framsticks.structure.TreeOperations.*; 4 6 5 import com.framsticks.gui.tree.AbstractNode; 7 6 import com.framsticks.gui.tree.TreeNode; … … 9 8 import com.framsticks.params.CompositeParam; 10 9 import com.framsticks.params.FramsClass; 10 import com.framsticks.structure.Path; 11 import com.framsticks.structure.Tree; 11 12 import com.framsticks.util.lang.Casting; 12 13 -
java/main/src/main/java/com/framsticks/gui/console/Console.java
r100 r105 15 15 import com.framsticks.gui.FrameJoinable; 16 16 import com.framsticks.params.annotations.FramsClassAnnotation; 17 import com.framsticks.util.ExceptionHandler; 17 18 import com.framsticks.util.FramsticksException; 18 19 import com.framsticks.util.dispatching.Dispatching; 19 import com.framsticks.util.dispatching.ExceptionResultHandler;20 20 import com.framsticks.util.dispatching.Joinable; 21 21 import com.framsticks.util.dispatching.JoinableParent; … … 89 89 } 90 90 91 protected Exception ResultHandler getExceptionHandler() {92 return new Exception ResultHandler() {91 protected ExceptionHandler getExceptionHandler() { 92 return new ExceptionHandler() { 93 93 94 94 @Override -
java/main/src/main/java/com/framsticks/gui/console/ManagedConsole.java
r102 r105 10 10 import com.framsticks.communication.Response; 11 11 import com.framsticks.communication.queries.ApplicationRequest; 12 import com.framsticks.core.Path; 13 import static com.framsticks.core.TreeOperations.*; 12 13 import static com.framsticks.structure.TreeOperations.*; 14 14 15 import com.framsticks.gui.SwingDispatcher; 15 16 import com.framsticks.params.CompositeParam; … … 18 19 import com.framsticks.params.types.ListParam; 19 20 import com.framsticks.remote.RemoteTree; 21 import com.framsticks.structure.Path; 20 22 import com.framsticks.util.FramsticksException; 21 23 import com.framsticks.util.dispatching.Dispatching; 22 import com.framsticks.util.dispatching.Future Handler;24 import com.framsticks.util.dispatching.Future; 23 25 import com.framsticks.util.dispatching.RunAt; 24 26 import com.framsticks.util.lang.Casting; … … 98 100 // final Iterator<String> iterator = Path.splitPath(textual); 99 101 100 tryGet(tree, textual, new Future Handler<Path>(this) {102 tryGet(tree, textual, new Future<Path>(this) { 101 103 102 104 @Override … … 143 145 144 146 if (path.getTop().getParam() instanceof ListParam) { 145 tree.get(path, new Future Handler<Path>(ManagedConsole.this) {147 tree.get(path, new Future<Path>(ManagedConsole.this) { 146 148 @Override 147 149 protected void result(Path result) { -
java/main/src/main/java/com/framsticks/gui/controls/Control.java
r101 r105 1 1 package com.framsticks.gui.controls; 2 3 // import java.awt.BorderLayout;4 5 2 6 3 import javax.swing.JPanel; 7 4 8 import com.framsticks.core.Path;9 5 import com.framsticks.params.ParamFlags; 10 6 import com.framsticks.params.Param; 7 import com.framsticks.structure.Path; 8 import com.framsticks.util.ExceptionHandler; 11 9 import com.framsticks.util.FramsticksException; 12 10 import com.framsticks.util.Misc; 13 import com.framsticks.util.dispatching.ExceptionResultHandler;14 11 15 12 /** … … 17 14 */ 18 15 @SuppressWarnings("serial") 19 public abstract class Control extends JPanel implements Exception ResultHandler {16 public abstract class Control extends JPanel implements ExceptionHandler { 20 17 21 18 public static final int LINE_HEIGHT = 36; -
java/main/src/main/java/com/framsticks/gui/controls/ControlOwner.java
r101 r105 2 2 3 3 4 import com.framsticks.core.Path;5 4 import com.framsticks.gui.Frame; 6 import com.framsticks.util.dispatching.ExceptionResultHandler; 5 import com.framsticks.structure.Path; 6 import com.framsticks.util.ExceptionHandler; 7 7 8 public interface ControlOwner extends Exception ResultHandler {8 public interface ControlOwner extends ExceptionHandler { 9 9 10 10 public Path getCurrentPath(); -
java/main/src/main/java/com/framsticks/gui/controls/EventControl.java
r101 r105 10 10 11 11 12 import com.framsticks.core.Path;13 import com.framsticks.core.SideNoteKey;14 12 import com.framsticks.gui.Frame; 15 13 import com.framsticks.gui.Gui; … … 17 15 import com.framsticks.params.EventListener; 18 16 import com.framsticks.params.types.EventParam; 17 import com.framsticks.structure.Path; 18 import com.framsticks.structure.SideNoteKey; 19 19 import com.framsticks.util.FramsticksUnsupportedOperationException; 20 20 import com.framsticks.util.dispatching.Dispatching; 21 import com.framsticks.util.dispatching.Future Handler;21 import com.framsticks.util.dispatching.Future; 22 22 import com.framsticks.util.dispatching.RunAt; 23 23 import com.framsticks.util.lang.Pair; 24 24 25 import static com.framsticks. core.TreeOperations.*;25 import static com.framsticks.structure.TreeOperations.*; 26 26 27 27 /** … … 59 59 removeSideNote(path, listenerKey); 60 60 refreshState(); 61 path.getTree().removeListener(path, getParam(), listener, Future Handler.doNothing(Void.class, owner.getFrame()));61 path.getTree().removeListener(path, getParam(), listener, Future.doNothing(Void.class, owner.getFrame())); 62 62 return; 63 63 } … … 79 79 }; 80 80 81 path.getTree().addListener(path, getParam(), newListener, Object.class, new FutureHandler<Void>(owner.getFrame()) {81 addListener(path, getParam(), newListener, Object.class, new Future<Void>(owner.getFrame()) { 82 82 83 83 @Override -
java/main/src/main/java/com/framsticks/gui/controls/ProcedureControl.java
r103 r105 1 1 package com.framsticks.gui.controls; 2 2 3 import com.framsticks.core.Path;4 3 import com.framsticks.gui.Frame; 5 4 import com.framsticks.gui.Gui; 6 5 import com.framsticks.params.Param; 7 6 import com.framsticks.params.types.ProcedureParam; 8 import com.framsticks.util.dispatching.FutureHandler; 7 import com.framsticks.structure.Path; 8 import com.framsticks.util.dispatching.Future; 9 9 10 10 import javax.swing.*; … … 73 73 assert path.getTree().isActive(); 74 74 75 path.getTree().call(path, param, arguments, Object.class, new Future Handler<Object>(frame) {75 path.getTree().call(path, param, arguments, Object.class, new Future<Object>(frame) { 76 76 77 77 @Override -
java/main/src/main/java/com/framsticks/gui/table/ListPanel.java
r101 r105 44 44 } 45 45 } else { 46 for (Param param : framsClass.getParam Entries()) {46 for (Param param : framsClass.getParams()) { 47 47 if (provider.getMaximumColumnNumber() != null && tableModel.getColumnCount() >= provider.getMaximumColumnNumber()) { 48 48 break; -
java/main/src/main/java/com/framsticks/gui/table/ProcedureColumn.java
r102 r105 1 1 package com.framsticks.gui.table; 2 2 3 4 import com.framsticks.core.Path;5 3 import com.framsticks.gui.controls.ProcedureControl; 6 4 import com.framsticks.params.CompositeParam; 7 5 import com.framsticks.params.types.ProcedureParam; 6 import com.framsticks.structure.Path; 7 8 import static com.framsticks.params.ParamsUtil.arguments; 8 9 9 10 public class ProcedureColumn extends Column { … … 38 39 return 0; 39 40 } 40 ProcedureControl.callProcedure(path, getParam(), new Object[] {}, tableModel.getFrame());41 ProcedureControl.callProcedure(path, getParam(), arguments(), tableModel.getFrame()); 41 42 return 0; 42 43 } -
java/main/src/main/java/com/framsticks/gui/tree/TreeModel.java
r103 r105 14 14 import org.apache.logging.log4j.LogManager; 15 15 16 import com.framsticks.core.ListChange;17 import com.framsticks.core.Node;18 import com.framsticks.core.Path;19 import com.framsticks.core.SideNoteKey;20 import com.framsticks.core.TreeOperations;21 import com.framsticks.core.ValueChange;22 16 import com.framsticks.gui.Frame; 23 17 import com.framsticks.params.Access; … … 29 23 import com.framsticks.params.ValueParam; 30 24 import com.framsticks.params.types.EventParam; 31 import com.framsticks.util.FramsticksException; 25 import com.framsticks.structure.Node; 26 import com.framsticks.structure.Path; 27 import com.framsticks.structure.SideNoteKey; 28 import com.framsticks.structure.TreeOperations; 29 import com.framsticks.structure.messages.ListChange; 30 import com.framsticks.structure.messages.ValueChange; 32 31 import com.framsticks.util.Misc; 33 32 import com.framsticks.util.FramsticksUnsupportedOperationException; 34 import com.framsticks.util.dispatching.Future Handler;33 import com.framsticks.util.dispatching.Future; 35 34 import com.framsticks.util.lang.Casting; 36 35 37 import static com.framsticks. core.TreeOperations.*;36 import static com.framsticks.structure.TreeOperations.*; 38 37 39 38 public class TreeModel implements javax.swing.tree.TreeModel { … … 42 41 43 42 protected List<TreeModelListener> listeners = new LinkedList<>(); 44 45 43 46 44 protected final Frame frame; … … 208 206 } 209 207 210 public TreePath convertToTreePath(Path path , boolean forceComplete) {208 public TreePath convertToTreePath(Path path) { 211 209 assert frame.isActive(); 212 210 … … 271 269 return; 272 270 } 273 path.getTree().get(path, new Future Handler<Path>(frame) {271 path.getTree().get(path, new Future<Path>(frame) { 274 272 @Override 275 273 protected void result(Path result) { 276 final TreePath treePath = convertToTreePath(result , true);274 final TreePath treePath = convertToTreePath(result); 277 275 278 276 … … 358 356 359 357 log.debug("reacting to change {} in {}", listChange, listPath); 360 final TreePath treeListPath = convertToTreePath(listPath, true); 361 if (treeListPath == null) { 362 throw new FramsticksException().msg("path was not fully converted").arg("path", listPath); 363 } 358 final TreePath treeListPath = convertToTreePath(listPath); 364 359 365 360 if ((listChange.getAction().equals(ListChange.Action.Modify)) && (listChange.getPosition() == -1)) { … … 387 382 } 388 383 389 listPath.getTree().get(childPath, new Future Handler<Path>(frame) {384 listPath.getTree().get(childPath, new Future<Path>(frame) { 390 385 @Override 391 386 protected void result(Path result) { … … 394 389 } 395 390 assert frame.isActive(); 396 final TreePath treePath = Misc.throwIfNull(frame.getTreeModel().convertToTreePath(result , true));391 final TreePath treePath = Misc.throwIfNull(frame.getTreeModel().convertToTreePath(result)); 397 392 398 393 // treeModel.nodeStructureChanged(treePath); … … 420 415 case Modify: { 421 416 Path childPath = listPath.appendParam(access.prepareParamFor(id)).tryResolveIfNeeded(); 422 listPath.getTree().get(childPath, new Future Handler<Path>(frame) {417 listPath.getTree().get(childPath, new Future<Path>(frame) { 423 418 @Override 424 419 protected void result(Path result) { -
java/main/src/main/java/com/framsticks/gui/tree/TreeNode.java
r101 r105 8 8 import org.apache.logging.log4j.Logger; 9 9 10 import com.framsticks.core.Node;11 import com.framsticks.core.Path;12 import com.framsticks.core.SideNoteKey;13 import com.framsticks.core.Tree;14 10 import com.framsticks.gui.Frame; 15 11 import com.framsticks.gui.ImageProvider; … … 19 15 import com.framsticks.params.CompositeParam; 20 16 import com.framsticks.params.EventListener; 21 import com.framsticks.params.FramsClass;22 17 import com.framsticks.params.ValueParam; 23 18 import com.framsticks.params.types.EventParam; 24 19 import com.framsticks.params.types.ObjectParam; 25 20 import com.framsticks.params.types.StringParam; 21 import com.framsticks.structure.Node; 22 import com.framsticks.structure.Path; 23 import com.framsticks.structure.SideNoteKey; 24 import com.framsticks.structure.Tree; 26 25 import com.framsticks.util.FramsticksException; 27 import com.framsticks.util.dispatching.Future Handler;26 import com.framsticks.util.dispatching.Future; 28 27 import com.framsticks.util.lang.Casting; 29 28 import com.framsticks.util.lang.Containers; 30 29 import com.framsticks.util.swing.TooltipConstructor; 31 30 32 import static com.framsticks. core.TreeOperations.*;31 import static com.framsticks.structure.TreeOperations.*; 33 32 34 33 public class TreeNode extends AbstractNode { … … 69 68 if (path.getTop().getParam() instanceof ObjectParam) { 70 69 Access access = bindAccess(path); 71 FramsClass framsClass = access.getFramsClass(); 72 for (EventParam eventParam : Containers.filterInstanceof(framsClass.getParamEntries(), EventParam.class)) { 70 for (EventParam eventParam : Containers.filterInstanceof(access.getParams(), EventParam.class)) { 73 71 if (!eventParam.getId().endsWith("_changed")) { 74 72 continue; 75 73 } 76 74 String valueId = eventParam.getId().substring(0, eventParam.getId().length() - 8); 77 final ValueParam valueParam = Casting.tryCast(ValueParam.class, framsClass.getParam(valueId));75 final ValueParam valueParam = Casting.tryCast(ValueParam.class, access.getParam(valueId)); 78 76 if (valueParam == null) { 79 77 continue; … … 249 247 250 248 renderer.setToolTipText(new TooltipConstructor() 251 .append("frams", access.get Id())249 .append("frams", access.getTypeId()) 252 250 .append("java", child.getClass().getCanonicalName()) 253 251 .append("access", access.getClass().getSimpleName()) … … 271 269 272 270 protected <A> void tryAddListener(final Path path, final EventParam eventParam, Class<A> argumentType, final EventListener<A> listener) { 273 getTree().addListener(path, eventParam, listener, argumentType, new FutureHandler<Void>(getFrame()) {271 addListener(path, eventParam, listener, argumentType, new Future<Void>(getFrame()) { 274 272 @SuppressWarnings("unchecked") 275 273 @Override -
java/main/src/main/java/com/framsticks/hosting/Cli.java
r103 r105 9 9 import com.framsticks.communication.Response; 10 10 import com.framsticks.communication.ServerSideResponseFuture; 11 import com.framsticks.core.Path;12 import com.framsticks.core.Tree;13 11 import com.framsticks.params.EventListener; 14 12 import com.framsticks.params.annotations.FramsClassAnnotation; 15 13 import com.framsticks.params.annotations.ParamAnnotation; 16 14 import com.framsticks.params.types.EventParam; 17 import com.framsticks.util.dispatching.FutureHandler; 15 import com.framsticks.structure.Path; 16 import com.framsticks.structure.Tree; 17 import com.framsticks.structure.TreeOperations; 18 import com.framsticks.util.dispatching.Future; 18 19 import com.framsticks.util.dispatching.ThrowExceptionHandler; 19 20 … … 69 70 70 71 // SyncedFuture handler = new SyncedFuture<Void>(ThrowExceptionHandler.getInstance()); 71 path.getTree().addListener(path, param, event.listener, Object.class, FutureHandler.doNothing(Void.class, ThrowExceptionHandler.getInstance()));72 TreeOperations.addListener(path, param, event.listener, Object.class, Future.doNothing(Void.class, ThrowExceptionHandler.getInstance())); 72 73 73 74 events.put(event.id, event); 74 responseFuture.pass(new Response(true, event.pathToEvent , null));75 responseFuture.pass(new Response(true, event.pathToEvent)); 75 76 // handler 76 77 } -
java/main/src/main/java/com/framsticks/hosting/CliEvent.java
r103 r105 1 1 package com.framsticks.hosting; 2 2 3 import com.framsticks.core.Path;4 3 import com.framsticks.params.EventListener; 5 4 import com.framsticks.params.annotations.FramsClassAnnotation; … … 7 6 import com.framsticks.params.types.EventParam; 8 7 import com.framsticks.params.types.ProcedureParam; 9 import com.framsticks.util.dispatching.FutureHandler; 8 import com.framsticks.structure.Path; 9 import com.framsticks.util.dispatching.Future; 10 10 import com.framsticks.util.dispatching.ThrowExceptionHandler; 11 11 … … 32 32 33 33 //it should happen now 34 path.getTree().removeListener(path, param, listener, Future Handler.doNothing(Void.class, ThrowExceptionHandler.getInstance()));34 path.getTree().removeListener(path, param, listener, Future.doNothing(Void.class, ThrowExceptionHandler.getInstance())); 35 35 cli.events.remove(id); 36 36 } -
java/main/src/main/java/com/framsticks/hosting/ClientAtServer.java
r103 r105 1 1 package com.framsticks.hosting; 2 2 3 import static com.framsticks.structure.TreeOperations.*; 3 4 import static com.framsticks.util.lang.Strings.assureNotEmpty; 4 5 … … 10 11 import com.framsticks.communication.queries.RegisterRequest; 11 12 import com.framsticks.communication.queries.SetRequest; 12 import com.framsticks.core.LocalTree;13 import com.framsticks.core.Tree;14 import com.framsticks.core.Path;15 13 import com.framsticks.params.*; 16 14 import com.framsticks.params.types.EventParam; 17 15 import com.framsticks.params.types.ProcedureParam; 18 16 import com.framsticks.parsers.Savers; 17 import com.framsticks.structure.LocalTree; 18 import com.framsticks.structure.Path; 19 import com.framsticks.structure.Tree; 20 import com.framsticks.util.ExceptionHandler; 19 21 import com.framsticks.util.FramsticksException; 20 22 import com.framsticks.util.Misc; 21 23 import com.framsticks.util.dispatching.AbstractJoinable; 22 24 import com.framsticks.util.dispatching.Dispatching; 23 import com.framsticks.util.dispatching.ExceptionResultHandler; 24 import com.framsticks.util.dispatching.FutureHandler; 25 import com.framsticks.util.dispatching.Future; 25 26 import com.framsticks.util.dispatching.Joinable; 26 27 import com.framsticks.util.dispatching.JoinableParent; … … 29 30 import com.framsticks.util.lang.Strings; 30 31 31 import static com.framsticks.core.TreeOperations.*;32 32 import static com.framsticks.params.AccessOperations.*; 33 import static com.framsticks.params.ParamsUtil.getParam; 33 34 34 35 import java.net.Socket; … … 37 38 * @author Piotr Sniegowski 38 39 */ 39 public class ClientAtServer extends AbstractJoinable implements RequestHandler, JoinableParent, Exception ResultHandler {40 public class ClientAtServer extends AbstractJoinable implements RequestHandler, JoinableParent, ExceptionHandler { 40 41 41 42 protected final Server server; … … 126 127 protected void handleInTree(final Tree tree, final ApplicationRequest request, final ServerSideResponseFuture responseCallback, final String usedPrefix) { 127 128 128 tryGet(tree, request.getActualPath(), new Future Handler<Path>(responseCallback) {129 tryGet(tree, request.getActualPath(), new Future<Path>(responseCallback) { 129 130 @Override 130 131 protected void result(final Path path) { … … 142 143 throw new FramsticksException().msg("mismatch objects during fetch").arg("path", path); 143 144 } 144 responseCallback.pass(new Response(true, "", File.single(printToFile(path.getTextual(), access))));145 responseCallback.pass(new Response(true, "", printToFile(path.getTextual(), access))); 145 146 146 147 return; … … 149 150 if (request instanceof SetRequest) { 150 151 SetRequest setRequest = (SetRequest) request; 151 tree.set(path, access.getFramsClass().getParamEntry(setRequest.getField(), PrimitiveParam.class), setRequest.getValue(), new FutureHandler<Integer>(responseCallback) {152 tree.set(path, getParam(access, setRequest.getField(), PrimitiveParam.class), setRequest.getValue(), new Future<Integer>(responseCallback) { 152 153 @Override 153 154 protected void result(Integer flag) { 154 responseCallback.pass(new Response(true, FlagsUtil.write(SetStateFlags.class, flag, null), null)); 155 155 responseCallback.pass(new Response(true, FlagsUtil.write(SetStateFlags.class, flag, null))); 156 156 } 157 157 }); … … 161 161 if (request instanceof CallRequest) { 162 162 final CallRequest callRequest = (CallRequest) request; 163 tree.call(path, access.getFramsClass().getParamEntry(callRequest.getProcedure(), ProcedureParam.class), callRequest.getArguments().toArray(), Object.class, new FutureHandler<Object>(responseCallback) {163 tree.call(path, getParam(access, callRequest.getProcedure(), ProcedureParam.class), callRequest.getArguments().toArray(), Object.class, new Future<Object>(responseCallback) { 164 164 @Override 165 protected void result(Object result) { 166 ListSink sink = new ListSink(); 167 sink.print("Result:").breakLine(); 168 sink.print("value:"); 169 sink.print("["); 170 if (result != null) { 171 sink.print(result); 165 protected void result(final Object result) { 166 if (result == null) { 167 responseCallback.pass(new Response(true, "")); 168 return; 172 169 } 173 sink.print("]"); 174 175 responseCallback.pass(new Response(true, "", File.single(new File("", new ListSource(sink.getOut()))))); 170 final Object wrapped = AccessOperations.wrapValueInResultIfPrimitive(result); 171 final File file = AccessOperations.convert(File.class, wrapped, tree.getRegistry()); 172 responseCallback.pass(new Response(true, "", file)); 173 176 174 } 177 175 }); … … 184 182 throw new FramsticksException().msg("info should be available"); 185 183 } 186 responseCallback.pass(new Response(true, null, File.single(new File(path.getTextual(), new ListSource(Savers.saveFramsClass(new ListSink(), framsClass).getOut())))));184 responseCallback.pass(new Response(true, null, new File(path.getTextual(), new ListSource(Savers.saveFramsClass(new ListSink(), framsClass).getOut())))); 187 185 return; 188 186 } … … 191 189 RegisterRequest register = (RegisterRequest) request; 192 190 193 cliObject.addListener(path, access.getFramsClass().getParamEntry(register.getEventName(), EventParam.class), usedPrefix, responseCallback);191 cliObject.addListener(path, getParam(access, register.getEventName(), EventParam.class), usedPrefix, responseCallback); 194 192 return; 195 193 } -
java/main/src/main/java/com/framsticks/hosting/Server.java
r102 r105 5 5 import org.apache.logging.log4j.LogManager; 6 6 7 import com.framsticks.core.Tree;8 7 import com.framsticks.params.ParamFlags; 9 8 import com.framsticks.params.annotations.AutoAppendAnnotation; 10 9 import com.framsticks.params.annotations.FramsClassAnnotation; 11 10 import com.framsticks.params.annotations.ParamAnnotation; 11 import com.framsticks.structure.Tree; 12 12 import com.framsticks.util.FramsticksException; 13 13 import com.framsticks.util.dispatching.AbstractJoinable; -
java/main/src/main/java/com/framsticks/model/Part.java
r90 r105 12 12 public class Part extends BasePart implements ModelComponent { 13 13 14 @ParamAnnotation 15 public double r x, ry, rz;14 @ParamAnnotation(id = "rx") 15 public double rotationX; 16 16 17 @ParamAnnotation(id = "ry") 18 public double rotationY; 17 19 18 public Point3d getRotation() { return new Point3d(rx, ry, rz); } 19 public void setRotation(Point3d r) { rx = r.x; ry = r.y; rz = r.z; } 20 @ParamAnnotation(id = "rz") 21 public double rotationZ; 22 23 public Point3d getRotation() { return new Point3d(rotationX, rotationY, rotationZ); } 24 public void setRotation(Point3d r) { rotationX = r.x; rotationY = r.y; rotationZ = r.z; } 20 25 21 26 @ParamAnnotation(id = "dn") -
java/main/src/main/java/com/framsticks/model/f0/VisualHints.java
r88 r105 8 8 /** don't draw class name label below the neuron. */ 9 9 public static final int DONT_SHOW_CLASS = 2; 10 10 11 11 /** draw the neuron at the first part when attached to joint (default is in the middle). */ 12 12 public static final int AT_FIRST_PART = 4; 13 13 14 14 /** draw the neuron at the second part when attached to joint (default is in the middle). */ 15 15 public static final int AT_SECOND_PART = 8; 16 16 17 17 /** use effector color for this neuro unit. */ 18 18 public static final int EFFECTOR_CLASS = 16; 19 19 20 20 /** use receptor color for this neuro unit. */ 21 21 public static final int RECEPTOR_CLASS = 32; 22 22 23 23 /** The Constant V1_BEND_MUSCLE. */ 24 24 public static final int V1_BEND_MUSCLE = 64; 25 25 26 26 /** The Constant V1_ROT_MUSCLE. */ 27 27 public static final int V1_ROT_MUSCLE = 128; -
java/main/src/main/java/com/framsticks/params/Access.java
r102 r105 14 14 * surname with my personal data) 15 15 */ 16 public interface Access {16 public interface Access extends ParamCollection { 17 17 18 Param getParam(int i);18 String getTypeId(); 19 19 20 Param getParam(String id);20 Object call(String id, Object... arguments); 21 21 22 String getId(); 23 24 int getParamCount(); 25 26 Object call(String id, Object[] arguments); 27 28 Object call(ProcedureParam param, Object[] arguments); 22 Object call(ProcedureParam param, Object... arguments); 29 23 30 24 <T> T get(int i, Class<T> type); … … 57 51 Object createAccessee(); 58 52 59 Iterable<Param> getParams();60 61 53 FramsClass getFramsClass(); 62 54 -
java/main/src/main/java/com/framsticks/params/AccessOperations.java
r103 r105 6 6 import javax.annotation.Nullable; 7 7 8 import org.apache.commons.lang3.ClassUtils; 8 9 import org.apache.logging.log4j.Logger; 9 10 import org.apache.logging.log4j.LogManager; … … 12 13 import com.framsticks.params.types.ListParam; 13 14 import com.framsticks.parsers.MultiParamLoader; 15 import com.framsticks.structure.messages.Result; 14 16 import com.framsticks.util.FramsticksException; 15 17 import com.framsticks.util.FramsticksUnsupportedOperationException; … … 114 116 first.set(false); 115 117 if (rootAccess != null) { 116 if (name.equals(rootAccess.get Id())) {118 if (name.equals(rootAccess.getTypeId())) { 117 119 needAdd.set(false); 118 120 currentAccess.set(rootAccess); … … 224 226 if (access instanceof ObjectAccess) { 225 227 ObjectAccess objectAccess = (ObjectAccess) access; 226 FramsClass framsClass = access.getFramsClass();227 assert framsClass != null;228 228 boolean headerNeeded = true; 229 229 // sink.print(framsClass.getId()).print(":").breakLine(); 230 for (PrimitiveParam<?> p : filterInstanceof( framsClass.getParamEntries(), PrimitiveParam.class)) {230 for (PrimitiveParam<?> p : filterInstanceof(access.getParams(), PrimitiveParam.class)) { 231 231 232 232 Object value = objectAccess.get(p, Object.class); … … 236 236 237 237 if (headerNeeded) { 238 sink.print( framsClass.getId()).print(":").breakLine();238 sink.print(access.getTypeId()).print(":").breakLine(); 239 239 headerNeeded = false; 240 240 } 241 241 242 sink.print(p.getId()).print(":"); 243 p.save(sink, value); 242 String stringValue = p.serialize(value); 243 244 sink.print(p.getId()).print(":").print(stringValue); 245 // p.save(sink, stringValue); 244 246 sink.breakLine(); 245 247 } … … 414 416 } 415 417 418 public static Object wrapValueInResultIfPrimitive(Object object) { 419 Class<?> javaClass = object.getClass(); 420 if (ClassUtils.isPrimitiveOrWrapper(javaClass)) { 421 return new Result(object); 422 } 423 if (javaClass.equals(String.class)) { 424 return new Result(object); 425 } 426 return object; 427 } 416 428 417 429 /** -
java/main/src/main/java/com/framsticks/params/ArrayListAccess.java
r101 r105 48 48 49 49 @Override 50 public String get Id() {51 return "l " + elementAccess.get Id();50 public String getTypeId() { 51 return "l " + elementAccess.getTypeId(); 52 52 } 53 53 -
java/main/src/main/java/com/framsticks/params/FramsClass.java
r100 r105 3 3 import com.framsticks.params.annotations.FramsClassAnnotation; 4 4 import com.framsticks.params.annotations.ParamAnnotation; 5 import com.framsticks.util.FramsticksException;6 5 import com.framsticks.util.lang.Containers; 7 6 import com.framsticks.util.lang.Strings; … … 10 9 import java.util.*; 11 10 12 import javax.annotation.Nonnull;13 11 import javax.annotation.concurrent.Immutable; 14 12 … … 30 28 @Immutable 31 29 @FramsClassAnnotation(id = "class", name = "class") 32 public class FramsClass {30 public class FramsClass implements ParamCollection { 33 31 34 32 private final static Logger log = LogManager.getLogger(FramsClass.class); … … 55 53 56 54 @ParamAnnotation(id = "props", name = "props") 57 public List<Param> getParam Entries() {55 public List<Param> getParams() { 58 56 return Collections.unmodifiableList(paramList); 59 57 } … … 135 133 } 136 134 137 public @Nonnull <T extends Param> T castedParam(@Nonnull final Param param, @Nonnull final Class<T> type, Object name) {138 if (param == null) {139 // return null;140 throw new FramsticksException().msg("param is missing").arg("name", name).arg("in", this);141 }142 if (!type.isInstance(param)) {143 // return null;144 throw new FramsticksException().msg("wrong type of param").arg("actual", param.getClass()).arg("requested", type).arg("in", this);145 }146 return type.cast(param);147 }148 149 /**150 * Gets the param entry.151 *152 * @param i153 * the offset of parameter154 * @return the param entry155 */156 public @Nonnull <T extends Param> T getParamEntry(final int i, @Nonnull final Class<T> type) {157 return castedParam(getParam(i), type, i);158 }159 160 /**161 * Gets the param entry.162 *163 * @param id164 * the getId of parameter165 * @return the param entry166 */167 public @Nonnull <T extends Param> T getParamEntry(@Nonnull final String id, @Nonnull final Class<T> type) {168 return castedParam(getParam(id), type, id);169 }170 171 135 public Param getParam(int i) { 172 136 if (i < 0 || i >= paramList.size()) { -
java/main/src/main/java/com/framsticks/params/ListAccess.java
r102 r105 19 19 public ListAccess(Access elementAccess) { 20 20 this.elementAccess = elementAccess; 21 this.containedTypeName = elementAccess.get Id();21 this.containedTypeName = elementAccess.getTypeId(); 22 22 paramBuilder = elementAccess.buildParam(new ParamBuilder()); 23 23 } … … 51 51 52 52 @Override 53 public Object call(String id, Object []arguments) {53 public Object call(String id, Object... arguments) { 54 54 throw new InvalidOperationException().msg("list access does not support calling methods").arg("id", id).arg("access", this); 55 55 } 56 56 57 57 @Override 58 public Object call(ProcedureParam param, Object []arguments) {58 public Object call(ProcedureParam param, Object... arguments) { 59 59 throw new InvalidOperationException().msg("list access does not support calling methods").arg("param", param).arg("access", this); 60 60 } -
java/main/src/main/java/com/framsticks/params/MessageLogger.java
r103 r105 1 1 package com.framsticks.params; 2 2 3 import com.framsticks. core.Message;3 import com.framsticks.structure.messages.Message; 4 4 5 5 public class MessageLogger extends EventListeners<Message> { -
java/main/src/main/java/com/framsticks/params/Param.java
r102 r105 85 85 } 86 86 87 public boolean isNumeric() {88 return false;89 }90 91 public abstract Class<?> getStorageType();92 93 87 public boolean hasFlag(int flag) { 94 88 return (flags & flag) != 0; -
java/main/src/main/java/com/framsticks/params/ParamCandidate.java
r102 r105 79 79 protected final OneTime<Method> adder = new OneTime<>("adder"); 80 80 protected final OneTime<Method> remover = new OneTime<>("remover"); 81 protected final OneTime<Class<? extends Param>> paramType = new OneTime<>("paramType"); 82 81 83 protected int flags = 0; 82 84 … … 262 264 } 263 265 266 // public static <T extends Param> boolean isParamAnnorationOfTypeOrUnspecified(ParamAnnotation paramAnnotation, Class<T> paramType) { 267 // return paramAnnotation.paramType().equals(Param.class) || paramAnnotation.paramType().equals(paramType); 268 // } 269 270 // public static <T extends Param> boolean isParamAnnorationOfType(ParamAnnotation paramAnnotation, Class<T> paramType) { 271 // return paramAnnotation.paramType().equals(paramType); 272 // } 273 264 274 void add(ParamAnnotation paramAnnotation, Member member, String name) { 265 275 this.name.set(name); 266 276 annotations.add(paramAnnotation); 267 277 flags |= paramAnnotation.flags(); 278 if (!paramAnnotation.paramType().equals(Param.class)) { 279 paramType.set(paramAnnotation.paramType()); 280 } 268 281 if (member instanceof Field) { 269 282 field.set((Field) member); … … 273 286 if (member instanceof Method) { 274 287 Method m = (Method) member; 275 if (!paramAnnotation.paramType().equals(Param.class)) { 276 if (paramAnnotation.paramType().equals(ProcedureParam.class)) { 277 caller.set(m); 278 return; 279 } 280 throw new ConstructionException().msg("explicit set of paramType different than ProcedureParam is not yet supported").arg("name", name).arg("method", m).arg("in", this); 288 if (paramAnnotation.paramType().equals(ProcedureParam.class)) { 289 caller.set(m); 290 return; 281 291 } 282 292 Type[] ps = m.getGenericParameterTypes(); … … 392 402 protected static final Map<Class<?>, Set> setsCache = Collections.synchronizedMap(new IdentityHashMap<Class<?>, Set>()); 393 403 394 public static Set getAllCandidates( Class<?> javaClass) throws ConstructionException {404 public static Set getAllCandidates(final Class<?> javaClass) throws ConstructionException { 395 405 Set result = setsCache.get(javaClass); 396 406 if (result != null) { … … 399 409 400 410 List<Class<?>> javaClasses = new LinkedList<>(); 401 while (javaClass != null) { 402 javaClasses.add(0, javaClass); 403 javaClass = javaClass.getSuperclass(); 411 Class<?> jc = javaClass; 412 while (jc != null) { 413 javaClasses.add(0, jc); 414 jc = jc.getSuperclass(); 404 415 } 405 416 … … 473 484 // throw new ConstructionException().msg("void is not a valid type"); 474 485 // } 486 475 487 476 488 if (type instanceof ParameterizedType) { … … 562 574 } 563 575 564 565 576 public ParamBuilder induceParamType(ParamBuilder builder) { 566 577 Method method = getCaller(); 567 578 if (method == null) { 579 if (paramType.has()) { 580 return builder.type(paramType.get()); 581 } 568 582 return induceParamType(builder, getType()); 569 583 } -
java/main/src/main/java/com/framsticks/params/ParamsUtil.java
r101 r105 3 3 import java.util.ArrayList; 4 4 import java.util.List; 5 import java.util.Map; 6 7 import javax.annotation.Nonnull; 5 8 6 9 import com.framsticks.util.FramsticksException; … … 29 32 Object object = a.getSelected(); 30 33 if (!type.isInstance(object)) { 31 throw new FramsticksException().msg("extracted object is of invalid type").arg("object", object).arg("desired", type).arg("actual", object.getClass()).arg(" framsclass", a.getFramsClass());34 throw new FramsticksException().msg("extracted object is of invalid type").arg("object", object).arg("desired", type).arg("actual", object.getClass()).arg("access", a); 32 35 } 33 36 result.add(type.cast(object)); … … 88 91 } 89 92 93 public static Object[] arguments(Object... args) { 94 return args; 95 } 96 97 public static Param getParam(ParamCollection collection, int i) { 98 return collection.getParam(i); 99 } 100 101 public static Param getParam(ParamCollection collection, String id) { 102 return collection.getParam(id); 103 } 104 105 public static @Nonnull <T extends Param> T castedParam(ParamCollection collection, @Nonnull final Param param, @Nonnull final Class<T> type, Object name) { 106 if (param == null) { 107 // return null; 108 throw new FramsticksException().msg("param is missing").arg("name", name).arg("in", collection); 109 } 110 if (!type.isInstance(param)) { 111 // return null; 112 throw new FramsticksException().msg("wrong type of param").arg("actual", param.getClass()).arg("requested", type).arg("in", collection); 113 } 114 return type.cast(param); 115 } 116 117 /** 118 * Gets the param entry. 119 * 120 * @param i 121 * the offset of parameter 122 * @return the param entry 123 */ 124 public static @Nonnull <T extends Param> T getParam(ParamCollection collection, final int i, @Nonnull final Class<T> type) { 125 return castedParam(collection, collection.getParam(i), type, i); 126 } 127 128 /** 129 * Gets the param entry. 130 * 131 * @param id 132 * the getId of parameter 133 * @return the param entry 134 */ 135 public static @Nonnull <T extends Param> T getParam(ParamCollection collection, @Nonnull final String id, @Nonnull final Class<T> type) { 136 return castedParam(collection, collection.getParam(id), type, id); 137 } 138 139 public static final String SERIALIZED = "@Serialized:"; 140 141 public static class SerializationContext { 142 protected final StringBuilder builder = new StringBuilder(); 143 protected final ArrayList<Object> objects = new ArrayList<>(); 144 145 protected void appendString(String value) { 146 builder.append('"').append(value).append('"'); 147 } 148 149 protected boolean serializeInternal(Object value) { 150 if (value == null) { 151 builder.append("null"); 152 return true; 153 } 154 /** indexOf is not used here, because it uses equals() internally, which results in StackOverflowError */ 155 Class<?> type = value.getClass(); 156 if (type.equals(String.class)) { 157 String stringValue = (String) value; 158 appendString(stringValue); 159 return stringValue.startsWith(SERIALIZED); 160 } 161 if (type.equals(Boolean.class)) { 162 builder.append(((Boolean) value) ? "1" : "0"); 163 return false; 164 } 165 if (type.equals(Double.class) || type.equals(Integer.class)) { 166 builder.append(value.toString()); 167 return false; 168 } 169 170 for (int i = 0; i < objects.size(); ++i) { 171 if (objects.get(i) == value) { 172 builder.append("^").append(i); 173 return true; 174 } 175 } 176 177 if (List.class.isAssignableFrom(type)) { 178 objects.add(value); 179 List<?> list = (List<?>) value; 180 boolean placeComma = false; 181 builder.append("["); 182 for (Object element : list) { 183 if (placeComma) { 184 builder.append(","); 185 } else { 186 placeComma = true; 187 } 188 serializeInternal(element); 189 } 190 builder.append("]"); 191 return true; 192 } 193 if (Map.class.isAssignableFrom(type)) { 194 objects.add(value); 195 Map<?, ?> map = (Map<?, ?>) value; 196 boolean placeComma = false; 197 builder.append("{"); 198 for (Map.Entry<?, ?> entry : map.entrySet()) { 199 if (placeComma) { 200 builder.append(","); 201 } else { 202 placeComma = true; 203 } 204 if (!(entry.getKey() instanceof String)) { 205 throw new FramsticksException().msg("non string keys are not allowed in serialization").arg("key type", entry.getKey().getClass()); 206 } 207 appendString((String) entry.getKey()); 208 builder.append(":"); 209 serializeInternal(entry.getValue()); 210 } 211 builder.append("}"); 212 return true; 213 } 214 throw new FramsticksException().msg("invalid type for serialization").arg("type", type); 215 } 216 217 public String serialize(Object value) { 218 if (value instanceof String) { 219 String stringValue = (String) value; 220 if (!stringValue.startsWith(SERIALIZED)) { 221 return stringValue; 222 } 223 } 224 boolean complex = serializeInternal(value); 225 return (complex ? SERIALIZED : "") + builder.toString(); 226 } 227 228 } 229 230 231 public static <T> String serialize(T value) { 232 return new SerializationContext().serialize(value); 233 } 234 235 public static <T> T deserialize(String value, Class<T> type) { 236 return null; 237 } 238 90 239 } -
java/main/src/main/java/com/framsticks/params/PrimitiveParam.java
r102 r105 3 3 import com.framsticks.util.FramsticksException; 4 4 import com.framsticks.util.Misc; 5 import com.framsticks.util.lang.Casting; 5 6 import com.framsticks.util.lang.Numbers; 7 import com.framsticks.util.lang.Strings; 6 8 7 9 import javax.annotation.concurrent.Immutable; … … 33 35 } 34 36 35 public void save(Sink sink, Object value) {36 sink.print(value);37 }37 // public void save(Sink sink, Object value) { 38 // sink.print(value); 39 // } 38 40 39 41 protected <T> T tryCastAndReturn(Object value, Class<T> type) { … … 97 99 } 98 100 101 @Override 102 public <T> String serialize(T value) { 103 return Strings.toStringNullProof(value); 104 } 105 106 @Override 107 public <T> T deserialize(String text, T currentValue, Class<T> type) { 108 try { 109 return Casting.nullOrThrowCast(type, reassign(text, currentValue).getValue()); 110 } catch (CastFailure e) { 111 return null; 112 } 113 } 99 114 } -
java/main/src/main/java/com/framsticks/params/PropertiesAccess.java
r101 r105 1 1 package com.framsticks.params; 2 3 import java.util.HashMap;4 import java.util.Map;5 2 6 3 import com.framsticks.params.types.EventParam; 7 4 import com.framsticks.params.types.ProcedureParam; 8 9 5 10 6 /** … … 18 14 public class PropertiesAccess extends SimpleAbstractAccess { 19 15 20 p ublic Map<String, Object>properties;16 protected PropertiesObject properties; 21 17 22 18 @Override 23 public Map<String, Object> createAccessee() { 24 return PropertiesAccess.createPropertiesMap(); 25 } 26 27 public static Map<String, Object> createPropertiesMap() { 28 return new HashMap<String, Object>(); 19 public PropertiesObject createAccessee() { 20 return new PropertiesObject(framsClass.getId()); 29 21 } 30 22 … … 43 35 assert properties != null; 44 36 assert param != null; 45 Object object = properties.get(param.getId()); 46 if (object != null) { 47 try { 48 return type.cast(object); 49 } catch (ClassCastException e) { 50 throw (ClassCastException) new ClassCastException("property " + param + " type is " + object.getClass().getName() + ", not " + type.getName()).initCause(e); 51 } 37 Object object = properties.get(param.getId(), Object.class); 38 if (object == null) { 39 return null; 52 40 } 53 41 try { 54 return param.getDef(type);42 return type.cast(object); 55 43 } catch (ClassCastException e) { 56 throw (ClassCastException) new ClassCastException(" default value of property " + param + " is not of type" + type.getName()).initCause(e);44 throw (ClassCastException) new ClassCastException("property " + param + " type is " + object.getClass().getName() + ", not " + type.getName()).initCause(e); 57 45 } 58 59 46 } 60 47 61 48 @Override 62 49 protected <T> void internalSet(ValueParam param, T value) { 63 properties. put(param.getId(), value);50 properties.set(param.getId(), value); 64 51 } 65 52 … … 73 60 * the properties with parameters values 74 61 */ 75 @SuppressWarnings("unchecked")76 62 @Override 77 63 public PropertiesAccess select(Object object) { 78 properties = ParamsUtil.selectObjectForAccess(this, object, Map.class);64 properties = ParamsUtil.selectObjectForAccess(this, object, PropertiesObject.class); 79 65 return this; 80 66 } … … 82 68 /** covariant */ 83 69 @Override 84 public Map<String, Object>getSelected() {70 public PropertiesObject getSelected() { 85 71 return properties; 86 72 } … … 97 83 98 84 @Override 99 public Object call(String id, Object []arguments) {85 public Object call(String id, Object... arguments) { 100 86 throw new InvalidOperationException().msg("properties access does not support calling methods").arg("id", id); 101 87 } 102 88 103 89 @Override 104 public Object call(ProcedureParam param, Object []arguments) {90 public Object call(ProcedureParam param, Object... arguments) { 105 91 throw new InvalidOperationException().msg("properties access does not support calling methods").arg("param", param); 106 92 } -
java/main/src/main/java/com/framsticks/params/ReflectionAccess.java
r101 r105 131 131 132 132 @Override 133 public Object call(String id, Object []arguments) {133 public Object call(String id, Object... arguments) { 134 134 try { 135 135 try { … … 151 151 152 152 @Override 153 public Object call(ProcedureParam param, Object []arguments) {153 public Object call(ProcedureParam param, Object... arguments) { 154 154 return call(param.getId(), arguments); 155 155 } … … 162 162 163 163 try { 164 for (ValueParam p : filterInstanceof(framsClass.getParam Entries(), ValueParam.class)) {164 for (ValueParam p : filterInstanceof(framsClass.getParams(), ValueParam.class)) { 165 165 setValue(p, p.getDef(Object.class)); 166 166 } -
java/main/src/main/java/com/framsticks/params/ReflectionAccessBackend.java
r101 r105 81 81 82 82 try { 83 for (final ProcedureParam pp : filterInstanceof(framsClass.getParam Entries(), ProcedureParam.class)) {83 for (final ProcedureParam pp : filterInstanceof(framsClass.getParams(), ProcedureParam.class)) { 84 84 if (!candidates.containsKey(pp.getId())) { 85 85 log.trace("java class does implement method {}", pp); … … 99 99 } 100 100 101 for (final EventParam ep : filterInstanceof(framsClass.getParam Entries(), EventParam.class)) {101 for (final EventParam ep : filterInstanceof(framsClass.getParams(), EventParam.class)) { 102 102 if (!candidates.containsKey(ep.getId())) { 103 103 log.trace("java class does not implement the event param {}", ep); … … 125 125 } 126 126 127 for (final ValueParam vp : filterInstanceof(framsClass.getParam Entries(), ValueParam.class)) {127 for (final ValueParam vp : filterInstanceof(framsClass.getParams(), ValueParam.class)) { 128 128 if (!candidates.containsKey(vp.getId())) { 129 129 throw new ConstructionException().msg("missing candidate for param").arg("param", vp); … … 228 228 } 229 229 if (!a.isPrimitive()) { 230 return a.equals(b);230 return b.isAssignableFrom(a);//equals(b); 231 231 } 232 232 -
java/main/src/main/java/com/framsticks/params/SimpleAbstractAccess.java
r102 r105 1 1 package com.framsticks.params; 2 3 4 5 2 6 3 import com.framsticks.params.types.ObjectParam; … … 36 33 37 34 @Override 38 public String get Id() {35 public String getTypeId() { 39 36 return framsClass.getId(); 40 37 } … … 62 59 @Override 63 60 public <T> T get(int i, Class<T> type) { 64 return get( framsClass.getParamEntry(i, ValueParam.class), type);61 return get(ParamsUtil.getParam(framsClass, i, ValueParam.class), type); 65 62 } 66 63 67 64 @Override 68 65 public <T> T get(String id, Class<T> type) { 69 return get( framsClass.getParamEntry(id, ValueParam.class), type);66 return get(ParamsUtil.getParam(framsClass, id, ValueParam.class), type); 70 67 } 71 68 72 69 @Override 73 70 public <T> int set(int i, T value) { 74 return set( framsClass.getParamEntry(i, ValueParam.class), value);71 return set(ParamsUtil.getParam(framsClass, i, ValueParam.class), value); 75 72 } 76 73 77 74 @Override 78 75 public <T> int set(String id, T value) { 79 return set( framsClass.getParamEntry(id, ValueParam.class), value);76 return set(ParamsUtil.getParam(framsClass, id, ValueParam.class), value); 80 77 } 81 78 … … 107 104 @Override 108 105 public Iterable<Param> getParams() { 109 return framsClass.getParam Entries();106 return framsClass.getParams(); 110 107 } 111 108 … … 122 119 @Override 123 120 public ParamBuilder buildParam(ParamBuilder builder) { 124 return builder.name(get Id()).type(ObjectParam.class).containedTypeName(getId());121 return builder.name(getTypeId()).type(ObjectParam.class).containedTypeName(getTypeId()); 125 122 } 126 123 -
java/main/src/main/java/com/framsticks/params/SimplePrimitive.java
r103 r105 1 1 package com.framsticks.params; 2 2 3 import com.framsticks. core.ValueChange;3 import com.framsticks.structure.messages.ValueChange; 4 4 import com.framsticks.util.lang.Strings; 5 5 -
java/main/src/main/java/com/framsticks/params/SimpleUniqueList.java
r103 r105 5 5 import java.util.Map; 6 6 7 import com.framsticks. core.ListChange;7 import com.framsticks.structure.messages.ListChange; 8 8 9 9 public class SimpleUniqueList<T extends UniqueObject> implements Iterable<T> { -
java/main/src/main/java/com/framsticks/params/UniqueListAccess.java
r103 r105 140 140 141 141 @Override 142 public String get Id() {143 return "l " + elementAccess.get Id() + " " + uidName;142 public String getTypeId() { 143 return "l " + elementAccess.getTypeId() + " " + uidName; 144 144 } 145 145 -
java/main/src/main/java/com/framsticks/params/ValueParam.java
r87 r105 1 1 package com.framsticks.params; 2 3 2 4 3 import javax.annotation.concurrent.Immutable; … … 23 22 public abstract <T> T getDef(Class<T> type); 24 23 24 public abstract Class<?> getStorageType(); 25 26 public boolean isNumeric() { 27 return false; 28 } 29 30 public abstract <T> String serialize(T value); 31 32 public abstract <T> T deserialize(String text, T currentValue, Class<T> type); 33 25 34 } -
java/main/src/main/java/com/framsticks/params/types/ArrayListParam.java
r100 r105 49 49 // List<?> list; 50 50 // if (oldValue == null) { 51 // 51 // list = new ArrayList<Object>(); 52 52 // } else { 53 // 54 // 55 // 56 // 53 // list = Casting.tryCast(List.class, oldValue); 54 // if (list == null) { 55 // throw new CastFailure(); 56 // } 57 57 // } 58 58 // Containers.resizeList(list, size); … … 61 61 } 62 62 // if (oldValue != null) { 63 // 63 // return new ReassignResult<List<?>>(Casting.throwCast(List.class, oldValue)); 64 64 // } 65 65 return new ReassignResult<List<?>>(Casting.throwCast(List.class, newValue)); … … 70 70 return "l " + getContainedTypeName(); 71 71 } 72 73 // return (value == null) ? "0" : Integer.toString(Casting.throwCast(List.class, value).size()); 72 74 } -
java/main/src/main/java/com/framsticks/params/types/BooleanParam.java
r102 r105 7 7 import com.framsticks.params.PrimitiveParam; 8 8 import com.framsticks.params.ReassignResult; 9 import com.framsticks.params.Sink;10 9 import com.framsticks.util.lang.Numbers; 11 10 … … 58 57 59 58 @Override 60 public void save(Sink sink,Object value) {59 public String serialize(Object value) { 61 60 assert value instanceof Boolean; 62 sink.print(((Boolean)value) ? "1" : "0");61 return ((Boolean)value) ? "1" : "0"; 63 62 } 64 63 } -
java/main/src/main/java/com/framsticks/params/types/EventParam.java
r99 r105 24 24 25 25 @Override 26 public Class<?> getStorageType() {27 return Void.TYPE;28 }29 30 @Override31 26 public String getFramsTypeName() { 32 27 return eventArgumentTypeName != null ? "e " + eventArgumentTypeName : "e"; -
java/main/src/main/java/com/framsticks/params/types/ListParam.java
r87 r105 16 16 } 17 17 18 @Override 19 public <T> String serialize(T value) { 20 return null; 21 } 22 23 @Override 24 public <T> T deserialize(String text, T currentValue, Class<T> type) { 25 return null; 26 } 18 27 } -
java/main/src/main/java/com/framsticks/params/types/ObjectParam.java
r100 r105 5 5 import com.framsticks.params.CompositeParam; 6 6 import com.framsticks.params.ParamBuilder; 7 import com.framsticks.params.ParamsUtil; 7 8 import com.framsticks.params.ReassignResult; 8 9 … … 50 51 } 51 52 53 @Override 54 public <T> String serialize(T value) { 55 return ParamsUtil.serialize(value); 56 } 57 58 @Override 59 public <T> T deserialize(String text, T currentValue, Class<T> type) { 60 return ParamsUtil.deserialize(text, type); 61 } 52 62 53 63 } -
java/main/src/main/java/com/framsticks/params/types/ProcedureParam.java
r99 r105 52 52 } 53 53 54 @Override55 public Class<?> getStorageType() {56 return Void.TYPE;57 }58 59 54 public @Nullable ValueParam getResultType() { 60 55 return resultType; -
java/main/src/main/java/com/framsticks/params/types/StringParam.java
r102 r105 5 5 import com.framsticks.params.PrimitiveParam; 6 6 import com.framsticks.params.ReassignResult; 7 import com.framsticks.params.Sink;8 7 9 8 import javax.annotation.concurrent.Immutable; … … 49 48 50 49 @Override 51 public void save(Sink sink,Object value) {50 public String serialize(Object value) { 52 51 assert value instanceof String; 53 String s = (String) value;54 sink.print((s.contains(SEPARATOR) ? (s = "~" + SEPARATOR + s + "~") : s));52 String s = (String) value; 53 return (s.contains(SEPARATOR) ? (s = "~" + SEPARATOR + s + "~") : s); 55 54 } 56 55 } -
java/main/src/main/java/com/framsticks/params/types/UniversalParam.java
r87 r105 3 3 import com.framsticks.params.CastFailure; 4 4 import com.framsticks.params.ParamBuilder; 5 import com.framsticks.params.ParamsUtil; 5 6 import com.framsticks.params.PrimitiveParam; 6 7 import com.framsticks.params.ReassignResult; … … 37 38 } 38 39 40 @Override 41 public <T> String serialize(T value) { 42 return ParamsUtil.serialize(value); 43 } 44 45 @Override 46 public <T> T deserialize(String text, T currentValue, Class<T> type) { 47 return ParamsUtil.deserialize(text, type); 48 } 49 39 50 } -
java/main/src/main/java/com/framsticks/parsers/AccessStash.java
r103 r105 18 18 public AccessStash add(Access access) { 19 19 /**TODO: by id or by name? rather by id, because from file is always lowercase*/ 20 accesses.put(access.get Id(), access);20 accesses.put(access.getTypeId(), access); 21 21 return this; 22 22 } -
java/main/src/main/java/com/framsticks/parsers/F0Parser.java
r101 r105 233 233 throw (new Exception("tried to set a read-only attribute \"" 234 234 + currentParam.getId() 235 + "\" in class \"" + access.get Id() + "\""));235 + "\" in class \"" + access.getTypeId() + "\"")); 236 236 } 237 237 } … … 258 258 + param.getId() 259 259 + "\" in class \"" 260 + access.get Id()260 + access.getTypeId() 261 261 + "\" to value which exceeds " + name + " (" 262 262 + value -
java/main/src/main/java/com/framsticks/parsers/F0Writer.java
r102 r105 38 38 } 39 39 StringBuilder line = new StringBuilder(); 40 line.append(access.get Id()).append(":");40 line.append(access.getTypeId()).append(":"); 41 41 boolean placeComma = false; 42 42 boolean contiguous = true; -
java/main/src/main/java/com/framsticks/parsers/Savers.java
r102 r105 19 19 20 20 save(framsClassAccess, sink); 21 for (Param p : framsClass.getParam Entries()) {21 for (Param p : framsClass.getParams()) { 22 22 save(paramAccess.select(p), sink); 23 23 } -
java/main/src/main/java/com/framsticks/parsers/XmlLoader.java
r102 r105 27 27 import com.framsticks.util.FramsticksException; 28 28 import com.framsticks.util.lang.Strings; 29 import static com.framsticks.params.ParamsUtil.getParam; 29 30 30 31 public class XmlLoader { … … 110 111 for (int i = 0; i < attributes.getLength(); ++i) { 111 112 Node attributeNode = attributes.item(i); 112 PrimitiveParam<?> param = access.getFramsClass().getParamEntry(mangleAttribute(attributeNode.getNodeName()), PrimitiveParam.class);113 PrimitiveParam<?> param = getParam(access, mangleAttribute(attributeNode.getNodeName()), PrimitiveParam.class); 113 114 if (param.hasFlag(ParamFlags.READONLY)) { 114 115 throw new FramsticksException().msg("cannot configure readonly param").arg("param", param).arg("in", access); -
java/main/src/main/java/com/framsticks/remote/RecursiveFetcher.java
r100 r105 1 1 package com.framsticks.remote; 2 2 3 import static com.framsticks.core.TreeOperations.*;4 3 5 import com.framsticks.core.Node;6 import com.framsticks.core.Path;7 4 import com.framsticks.params.Access; 8 5 import com.framsticks.params.CompositeParam; 9 import com.framsticks.params.FramsClass; 10 import com.framsticks.core.Tree; 6 import com.framsticks.structure.Node; 7 import com.framsticks.structure.Path; 8 import com.framsticks.structure.Tree; 9 import com.framsticks.util.dispatching.FutureHandler; 11 10 import com.framsticks.util.dispatching.Future; 12 import com.framsticks.util.dispatching.FutureHandler;13 11 import com.framsticks.util.dispatching.ThrowExceptionHandler; 14 12 import com.framsticks.util.FramsticksException; … … 17 15 import org.apache.logging.log4j.Logger; 18 16 import org.apache.logging.log4j.LogManager; 17 18 import static com.framsticks.structure.TreeOperations.*; 19 19 import static com.framsticks.util.lang.Containers.filterInstanceof; 20 20 import com.framsticks.util.dispatching.RunAt; … … 28 28 29 29 protected final Tree tree; 30 protected final Future <Void> future;30 protected final FutureHandler<Void> future; 31 31 protected int dispatched; 32 32 protected final Stopwatch stopwatch = new Stopwatch(); 33 33 34 public RecursiveFetcher(Tree tree, final Path path, Future <Void> future) {34 public RecursiveFetcher(Tree tree, final Path path, FutureHandler<Void> future) { 35 35 this.tree = tree; 36 36 this.future = future; … … 51 51 } else { 52 52 Access access = bindAccess(path); 53 FramsClass framsClass = access.getFramsClass();54 assert framsClass != null;55 53 for (CompositeParam p : filterInstanceof(access.getParams(), CompositeParam.class)) { 56 54 Object child = access.get(p, Object.class); … … 67 65 } 68 66 ++dispatched; 69 tree.get(childPath, new Future Handler<Path>(Logging.logger(log, "resolve", RecursiveFetcher.this)) {67 tree.get(childPath, new Future<Path>(Logging.logger(log, "resolve", RecursiveFetcher.this)) { 70 68 @Override 71 69 protected void result(Path result) { … … 83 81 84 82 protected void fetch(final Path path) { 85 tree.get(path, new Future <Path>() {83 tree.get(path, new FutureHandler<Path>() { 86 84 87 85 @Override -
java/main/src/main/java/com/framsticks/remote/RemoteTree.java
r103 r105 6 6 import com.framsticks.communication.queries.InfoRequest; 7 7 import com.framsticks.communication.queries.SetRequest; 8 import com.framsticks.core.AbstractTree;9 import com.framsticks.core.ListChange;10 import com.framsticks.core.Path;11 import com.framsticks.core.ValueChange;12 8 import com.framsticks.params.*; 13 9 import com.framsticks.params.EventListener; … … 17 13 import com.framsticks.params.types.ProcedureParam; 18 14 import com.framsticks.parsers.Loaders; 15 import com.framsticks.structure.AbstractTree; 16 import com.framsticks.structure.Path; 17 import com.framsticks.structure.messages.ListChange; 18 import com.framsticks.structure.messages.ValueChange; 19 19 import com.framsticks.util.*; 20 20 import com.framsticks.util.dispatching.AtOnceDispatcher; 21 21 import com.framsticks.util.dispatching.Dispatching; 22 22 import com.framsticks.util.dispatching.DispatchingFuture; 23 import com.framsticks.util.dispatching. ExceptionResultHandler;23 import com.framsticks.util.dispatching.FutureHandler; 24 24 import com.framsticks.util.dispatching.Future; 25 import com.framsticks.util.dispatching.FutureHandler;26 25 import com.framsticks.util.dispatching.Joinable; 27 26 import com.framsticks.util.dispatching.JoinableParent; … … 29 28 import com.framsticks.util.dispatching.ThrowExceptionHandler; 30 29 import com.framsticks.util.dispatching.RunAt; 31 import static com.framsticks.core.TreeOperations.*; 30 31 import static com.framsticks.structure.TreeOperations.*; 32 32 33 33 import java.util.*; … … 80 80 } 81 81 82 protected Exception ResultHandler pathRemoveHandler(final Path path, final ExceptionResultHandler handler) {83 return new Exception ResultHandler() {82 protected ExceptionHandler pathRemoveHandler(final Path path, final ExceptionHandler handler) { 83 return new ExceptionHandler() { 84 84 85 85 @Override … … 114 114 // } 115 115 116 protected final Map<String, Set<Future <FramsClass>>> infoRequests = new HashMap<String, Set<Future<FramsClass>>>();116 protected final Map<String, Set<FutureHandler<FramsClass>>> infoRequests = new HashMap<String, Set<FutureHandler<FramsClass>>>(); 117 117 118 118 … … 124 124 * */ 125 125 @Override 126 public void info(final Path path, final Future <FramsClass> future) {126 public void info(final Path path, final FutureHandler<FramsClass> future) { 127 127 128 128 final String name = path.getTop().getParam().getContainedTypeName(); … … 134 134 135 135 log.debug("issuing info request for {}", name); 136 final Set<Future <FramsClass>> futures = new HashSet<Future<FramsClass>>();136 final Set<FutureHandler<FramsClass>> futures = new HashSet<FutureHandler<FramsClass>>(); 137 137 futures.add(future); 138 138 infoRequests.put(name, futures); 139 139 140 final Future <FramsClass> compositeFuture = DispatchingFuture.create(this, new Future<FramsClass>() {140 final FutureHandler<FramsClass> compositeFuture = DispatchingFuture.create(this, new FutureHandler<FramsClass>() { 141 141 142 142 @Override … … 144 144 assert isActive(); 145 145 infoRequests.remove(name); 146 for (Future <FramsClass> f : futures) {146 for (FutureHandler<FramsClass> f : futures) { 147 147 f.handle(exception); 148 148 } … … 154 154 putInfoIntoCache(framsClass); 155 155 infoRequests.remove(name); 156 for (Future <FramsClass> f : futures) {156 for (FutureHandler<FramsClass> f : futures) { 157 157 f.pass(framsClass); 158 158 } … … 183 183 184 184 @Override 185 public void get(final Path path, final Future <Path> future) {186 assert isActive(); 187 final Exception ResultHandler remover = pathRemoveHandler(path, future);185 public void get(final Path path, final FutureHandler<Path> future) { 186 assert isActive(); 187 final ExceptionHandler remover = pathRemoveHandler(path, future); 188 188 189 189 log.trace("fetching values for {}", path); 190 findInfo(path, new Future Handler<FramsClass>(remover) {190 findInfo(path, new Future<FramsClass>(remover) { 191 191 @Override 192 192 protected void result(FramsClass result) { … … 204 204 205 205 @Override 206 public void set(final Path path, final PrimitiveParam<?> param, final Object value, final Future <Integer> future) {206 public void set(final Path path, final PrimitiveParam<?> param, final Object value, final FutureHandler<Integer> future) { 207 207 assert isActive(); 208 208 final Integer flag = bindAccess(path).set(param, value); … … 267 267 268 268 @Override 269 public <R> void call(@Nonnull final Path path, @Nonnull final ProcedureParam procedure, @Nonnull Object[] arguments, final Class<R> resultType, final Future <R> future) {269 public <R> void call(@Nonnull final Path path, @Nonnull final ProcedureParam procedure, @Nonnull Object[] arguments, final Class<R> resultType, final FutureHandler<R> future) { 270 270 assert isActive(); 271 271 assert path.isResolved(); … … 294 294 protected final Map<EventListener<?>, EventListener<File>> proxyListeners = new IdentityHashMap<>(); 295 295 296 public <A> void addListener(Path path, EventParam param, final EventListener<A> listener, final Class<A> argumentType, final Future <Void> future) {296 public <A> void addListener(Path path, EventParam param, final EventListener<A> listener, final Class<A> argumentType, final FutureHandler<Void> future) { 297 297 assert isActive(); 298 298 assert path.isResolved(); … … 322 322 } 323 323 324 public void removeListener(Path path, EventParam param, EventListener<?> listener, Future <Void> future) {324 public void removeListener(Path path, EventParam param, EventListener<?> listener, FutureHandler<Void> future) { 325 325 assert isActive(); 326 326 EventListener<File> proxyListener = proxyListeners.get(listener); -
java/main/src/main/java/com/framsticks/running/ExternalProcess.java
r103 r105 14 14 import org.apache.logging.log4j.LogManager; 15 15 16 import com.framsticks.core.ValueChange;17 16 import com.framsticks.params.EventListener; 18 17 import com.framsticks.params.EventListeners; … … 21 20 import com.framsticks.params.annotations.FramsClassAnnotation; 22 21 import com.framsticks.params.annotations.ParamAnnotation; 22 import com.framsticks.structure.messages.ValueChange; 23 23 import com.framsticks.util.FramsticksException; 24 24 import com.framsticks.util.dispatching.AbstractJoinable; -
java/main/src/main/java/com/framsticks/running/LoggingOutputListener.java
r101 r105 4 4 import org.apache.logging.log4j.LogManager; 5 5 6 import com.framsticks.core.ValueChange;7 6 import com.framsticks.params.EventListener; 8 7 import com.framsticks.params.annotations.FramsClassAnnotation; 8 import com.framsticks.structure.messages.ValueChange; 9 9 10 10 @FramsClassAnnotation -
java/main/src/main/java/com/framsticks/test/PrimeExperiment.java
r103 r105 8 8 import org.apache.logging.log4j.LogManager; 9 9 10 import com.framsticks.core.ValueChange;11 10 import com.framsticks.experiment.Experiment; 12 11 import com.framsticks.experiment.WorkPackageLogic; … … 15 14 import com.framsticks.params.annotations.FramsClassAnnotation; 16 15 import com.framsticks.params.annotations.ParamAnnotation; 16 import com.framsticks.params.types.ProcedureParam; 17 import com.framsticks.structure.messages.ValueChange; 17 18 import com.framsticks.test.prime.ExpParams; 18 19 import com.framsticks.test.prime.PrimePackage; 19 20 import com.framsticks.util.FramsticksException; 20 import com.framsticks.util.dispatching.Future ;21 import com.framsticks.util.dispatching.FutureHandler; 21 22 22 23 @FramsClassAnnotation … … 33 34 protected int nextWaitNumber = 1; 34 35 protected List<PrimePackage> waitingPackages = new LinkedList<>(); 35 protected List<Integer> primes = new LinkedList<>();36 // protected List<Integer> primes = new LinkedList<>(); 36 37 37 38 protected final EventListeners<ValueChange> primesListeners = new EventListeners<>(); … … 50 51 51 52 @Override 52 protected void generateNextPackage(Future <PrimePackage> future) {53 protected void generateNextPackage(FutureHandler<PrimePackage> future) { 53 54 assert isActive(); 54 55 if (task.state.current_number > task.params.to_number) { … … 84 85 return; 85 86 } 86 log.info("experiment is done, {} primes found", primes.size());87 log.debug("primes: {}", primes);87 log.info("experiment is done, {} primes found", getPrimes().size()); 88 log.debug("primes: {}", getPrimes()); 88 89 } 89 90 }; 91 } 92 93 public List<Integer> getPrimes() { 94 return task.state.getResultList(); 90 95 } 91 96 … … 98 103 } 99 104 100 primes.addAll(result.state.getResultList());105 getPrimes().addAll(result.state.getResultList()); 101 106 nextWaitNumber = result.params.to_number + 1; 102 107 … … 141 146 @ParamAnnotation 142 147 public String getDescription() { 143 return primes.size() + " found in range " + new ExpParams(task.params.from_number, nextWaitNumber - 1);148 return getPrimes().size() + " found in range " + new ExpParams(task.params.from_number, nextWaitNumber - 1); 144 149 } 145 150 … … 154 159 } 155 160 161 @ParamAnnotation(paramType = ProcedureParam.class) 162 public PrimePackage experimentNetsave() { 163 return task; 164 } 165 156 166 } -
java/main/src/main/java/com/framsticks/test/TestClass.java
r103 r105 6 6 import org.apache.logging.log4j.LogManager; 7 7 8 import com.framsticks.core.ListChange;9 import com.framsticks.core.ValueChange;10 8 import com.framsticks.params.EventListener; 11 9 import com.framsticks.params.SimplePrimitive; … … 15 13 import com.framsticks.params.annotations.ParamAnnotation; 16 14 import com.framsticks.params.types.ProcedureParam; 15 import com.framsticks.structure.messages.ListChange; 16 import com.framsticks.structure.messages.ValueChange; 17 17 18 18 @FramsClassAnnotation( … … 135 135 } 136 136 137 137 138 } -
java/main/src/main/java/com/framsticks/test/prime/ExpState.java
r102 r105 4 4 import java.util.List; 5 5 6 import org.apache.commons.lang .StringUtils;6 import org.apache.commons.lang3.StringUtils; 7 7 8 8 import com.framsticks.params.annotations.FramsClassAnnotation; -
java/main/src/main/java/com/framsticks/util/FramsticksException.java
r98 r105 4 4 import java.util.List; 5 5 6 import com.framsticks.util.dispatching.ExceptionResultHandler;7 6 import com.framsticks.util.lang.Delimeted; 8 7 import com.framsticks.util.lang.Pair; … … 77 76 78 77 79 public static Exception ResultHandler addArgumentHandler(final ExceptionResultHandler innerHandler, final String header, final Object argument) {80 return new Exception ResultHandler() {78 public static ExceptionHandler addArgumentHandler(final ExceptionHandler innerHandler, final String header, final Object argument) { 79 return new ExceptionHandler() { 81 80 @Override 82 81 public void handle(FramsticksException exception) { -
java/main/src/main/java/com/framsticks/util/Logging.java
r100 r105 3 3 import org.apache.logging.log4j.Logger; 4 4 5 import com.framsticks.util.dispatching.ExceptionResultHandler;6 5 7 6 /** … … 20 19 } 21 20 22 public static Exception ResultHandler logger(final Logger logger, final String action, final Object subject) {23 return new Exception ResultHandler() {21 public static ExceptionHandler logger(final Logger logger, final String action, final Object subject) { 22 return new ExceptionHandler() { 24 23 @Override 25 24 public void handle(FramsticksException e) { -
java/main/src/main/java/com/framsticks/util/dispatching/BufferedDispatcher.java
r102 r105 92 92 93 93 public void createThreadIfNeeded() { 94 if (targetDispatcher != null) { 95 return; 94 synchronized (this) { 95 if (targetDispatcher != null) { 96 return; 97 } 96 98 } 97 99 this.setTargetDispatcher(new Thread<C>().setName(parent.getName())); … … 104 106 105 107 @Override 106 protected void joinableStart() {108 protected synchronized void joinableStart() { 107 109 Dispatching.use(targetDispatcher, this); 108 110 } 109 111 110 112 @Override 111 protected void joinableInterrupt() {113 protected synchronized void joinableInterrupt() { 112 114 Dispatching.drop(targetDispatcher, this); 113 115 … … 121 123 122 124 @Override 123 protected void joinableJoin() throws InterruptedException {125 protected synchronized void joinableJoin() throws InterruptedException { 124 126 Dispatching.join(targetDispatcher); 125 127 } -
java/main/src/main/java/com/framsticks/util/dispatching/Dispatching.java
r102 r105 7 7 import org.apache.logging.log4j.LogManager; 8 8 9 import com.framsticks.util.ExceptionHandler; 9 10 import com.framsticks.util.FramsticksException; 10 11 import com.framsticks.util.Misc; … … 141 142 } 142 143 143 public interface Query<T> extends Exception ResultHandler {144 public interface Query<T> extends ExceptionHandler { 144 145 T get(); 145 146 } 146 147 147 148 public static abstract class QueryHandler<T> implements Query<T> { 148 Exception ResultHandler handler;149 ExceptionHandler handler; 149 150 150 151 /** 151 152 * @param handler 152 153 */ 153 public QueryHandler(Exception ResultHandler handler) {154 public QueryHandler(ExceptionHandler handler) { 154 155 this.handler = handler; 155 156 } … … 244 245 245 246 protected final double timeOut; 246 protected final Exception ResultHandler handler;247 protected final ExceptionHandler handler; 247 248 248 249 /** 249 250 * @param timeOut 250 251 */ 251 public Waiter(double timeOut, Exception ResultHandler handler) {252 public Waiter(double timeOut, ExceptionHandler handler) { 252 253 this.timeOut = timeOut; 253 254 this.handler = handler; … … 273 274 } 274 275 275 public <T> Future <T> passInFuture(Class<T> type) {276 return new Future Handler<T>(handler) {276 public <T> FutureHandler<T> passInFuture(Class<T> type) { 277 return new Future<T>(handler) { 277 278 @Override 278 279 protected void result(T result) { -
java/main/src/main/java/com/framsticks/util/dispatching/DispatchingExceptionHandler.java
r100 r105 1 1 package com.framsticks.util.dispatching; 2 2 3 import com.framsticks.util.ExceptionHandler; 3 4 import com.framsticks.util.FramsticksException; 4 5 5 public class DispatchingExceptionHandler implements Exception ResultHandler {6 public class DispatchingExceptionHandler implements ExceptionHandler { 6 7 7 8 protected final Dispatcher<?> dispatcher; 8 protected final Exception ResultHandler handler;9 protected final ExceptionHandler handler; 9 10 10 11 /** … … 12 13 * @param handler 13 14 */ 14 public DispatchingExceptionHandler(Dispatcher<?> dispatcher, Exception ResultHandler handler) {15 public DispatchingExceptionHandler(Dispatcher<?> dispatcher, ExceptionHandler handler) { 15 16 this.dispatcher = dispatcher; 16 17 this.handler = handler; -
java/main/src/main/java/com/framsticks/util/dispatching/DispatchingFuture.java
r100 r105 3 3 import com.framsticks.util.FramsticksException; 4 4 5 public class DispatchingFuture<C, T> extends Future <T> {5 public class DispatchingFuture<C, T> extends FutureHandler<T> { 6 6 7 7 protected final Dispatcher<? super C> dispatcher; 8 protected final Future <T> future;8 protected final FutureHandler<T> future; 9 9 10 10 /** … … 12 12 * @param future 13 13 */ 14 public DispatchingFuture(Dispatcher<? super C> dispatcher, Future <T> future) {14 public DispatchingFuture(Dispatcher<? super C> dispatcher, FutureHandler<T> future) { 15 15 this.dispatcher = dispatcher; 16 16 this.future = future; … … 37 37 } 38 38 39 public static <Ca, Ta> Future <Ta> create(Dispatcher<Ca> dispatcher, Future<Ta> future) {39 public static <Ca, Ta> FutureHandler<Ta> create(Dispatcher<Ca> dispatcher, FutureHandler<Ta> future) { 40 40 return new DispatchingFuture<Ca, Ta>(dispatcher, future); 41 41 } -
java/main/src/main/java/com/framsticks/util/dispatching/Future.java
r97 r105 1 1 package com.framsticks.util.dispatching; 2 2 3 import com.framsticks.util.ExceptionHandler; 3 4 import com.framsticks.util.FramsticksException; 4 5 5 /** 6 * @author Piotr Sniegowski 7 */ 8 public abstract class Future<T> implements ExceptionResultHandler { 6 public abstract class Future<T> extends FutureHandler<T> { 9 7 10 protected abstract void result(T result);8 protected final ExceptionHandler handler; 11 9 12 public final void pass(T result) { 13 try { 14 result(result); 15 } catch (FramsticksException e) { 16 handle(e); 17 } 10 public Future(ExceptionHandler handler) { 11 assert handler != null; 12 this.handler = handler; 18 13 } 19 14 15 @Override 16 public final void handle(FramsticksException exception) { 17 handler.handle(exception); 18 } 19 20 public static <T> Future<T> doNothing(Class<T> type, ExceptionHandler handler) { 21 return new Future<T>(handler) { 22 23 @Override 24 protected void result(T result) { 25 26 } 27 }; 28 } 20 29 21 30 } -
java/main/src/main/java/com/framsticks/util/dispatching/FutureHandler.java
r99 r105 1 1 package com.framsticks.util.dispatching; 2 2 3 import com.framsticks.util.ExceptionHandler; 3 4 import com.framsticks.util.FramsticksException; 4 5 5 public abstract class FutureHandler<T> extends Future<T> { 6 /** 7 * @author Piotr Sniegowski 8 */ 9 public abstract class FutureHandler<T> implements ExceptionHandler { 6 10 7 protected final ExceptionResultHandler handler;11 protected abstract void result(T result); 8 12 9 public FutureHandler(ExceptionResultHandler handler) { 10 assert handler != null; 11 this.handler = handler; 13 public final void pass(T result) { 14 try { 15 result(result); 16 } catch (FramsticksException e) { 17 handle(e); 18 } 12 19 } 13 14 @Override15 public final void handle(FramsticksException exception) {16 handler.handle(exception);17 }18 19 public static <T> FutureHandler<T> doNothing(Class<T> type, ExceptionResultHandler handler) {20 return new FutureHandler<T>(handler) {21 22 @Override23 protected void result(T result) {24 25 }26 };27 }28 29 20 } -
java/main/src/main/java/com/framsticks/util/dispatching/IgnoreExceptionHandler.java
r99 r105 1 1 package com.framsticks.util.dispatching; 2 2 3 import com.framsticks.util.ExceptionHandler; 3 4 import com.framsticks.util.FramsticksException; 4 5 5 public class IgnoreExceptionHandler implements Exception ResultHandler {6 public class IgnoreExceptionHandler implements ExceptionHandler { 6 7 7 8 private static final IgnoreExceptionHandler instance = new IgnoreExceptionHandler(); -
java/main/src/main/java/com/framsticks/util/dispatching/Monitor.java
r102 r105 104 104 } 105 105 106 protected Exception Handler taskExceptionHandler;106 protected ExceptionDispatcherHandler taskExceptionHandler; 107 107 108 108 /** 109 109 * @return the taskExceptionHandler 110 110 */ 111 public Exception Handler getTaskExceptionHandler() {111 public ExceptionDispatcherHandler getTaskExceptionHandler() { 112 112 return taskExceptionHandler; 113 113 } … … 116 116 * @param taskExceptionHandler the taskExceptionHandler to set 117 117 */ 118 public void setTaskExceptionHandler(Exception Handler taskExceptionHandler) {118 public void setTaskExceptionHandler(ExceptionDispatcherHandler taskExceptionHandler) { 119 119 this.taskExceptionHandler = taskExceptionHandler; 120 120 } -
java/main/src/main/java/com/framsticks/util/dispatching/RunAt.java
r97 r105 1 1 package com.framsticks.util.dispatching; 2 2 3 import com.framsticks.util.ExceptionHandler; 3 4 import com.framsticks.util.FramsticksException; 4 5 5 public abstract class RunAt<C> implements Exception ResultHandler, Runnable {6 public abstract class RunAt<C> implements ExceptionHandler, Runnable { 6 7 7 protected final Exception ResultHandler handler;8 protected final ExceptionHandler handler; 8 9 9 public RunAt(Exception ResultHandler handler) {10 public RunAt(ExceptionHandler handler) { 10 11 assert handler != null; 11 12 this.handler = handler; -
java/main/src/main/java/com/framsticks/util/dispatching/Thread.java
r102 r105 46 46 log.debug("starting thread {}", this); 47 47 assert getMonitor() != null; 48 ExceptionHandler exceptionHandler = getMonitor().getTaskExceptionHandler();49 48 while (!java.lang.Thread.interrupted()) { 50 49 RunAt<? extends C> runnable; … … 64 63 runnable.run(); 65 64 } catch (Exception e) { 65 final ExceptionDispatcherHandler exceptionHandler = getMonitor().getTaskExceptionHandler(); 66 66 if (exceptionHandler != null) { 67 67 if (exceptionHandler.handle(this, e)) { … … 122 122 // @Override 123 123 // public String toString() { 124 // 124 // return getName(); 125 125 // } 126 126 -
java/main/src/main/java/com/framsticks/util/dispatching/ThrowExceptionHandler.java
r97 r105 1 1 package com.framsticks.util.dispatching; 2 2 3 import com.framsticks.util.ExceptionHandler; 3 4 import com.framsticks.util.FramsticksException; 4 5 5 public class ThrowExceptionHandler implements Exception ResultHandler {6 public class ThrowExceptionHandler implements ExceptionHandler { 6 7 7 8 private static final ThrowExceptionHandler instance = new ThrowExceptionHandler(); -
java/main/src/main/resources/bash-gui-runner.xml
r101 r105 2 2 <Framsticks> 3 3 <import class="com.framsticks.gui.Browser" /> 4 <import class="com.framsticks. core.LocalTree" />4 <import class="com.framsticks.structure.LocalTree" /> 5 5 <import class="com.framsticks.running.LoggingOutputListener" /> 6 6 <import class="com.framsticks.running.FramsServer" /> -
java/main/src/main/resources/framsticks.xml
r101 r105 6 6 <import class="com.framsticks.model.ModelBuilder" /> 7 7 <import class="com.framsticks.model.f0.SchemaBuilder" /> 8 <import class="com.framsticks. core.LocalTree" />8 <import class="com.framsticks.structure.LocalTree" /> 9 9 <import class="com.framsticks.hosting.Server" /> 10 10 <import class="com.framsticks.test.TestClass" /> -
java/main/src/main/resources/prime.xml
r103 r105 3 3 <import class="com.framsticks.hosting.Server" /> 4 4 <import class="com.framsticks.test.PrimeExperiment" /> 5 <!-- <import class="com.framsticks.experiment.Simulator" /> -->6 5 <import class="com.framsticks.experiment.SimulatorConnector" /> 7 <import class="com.framsticks. core.LocalTree" />6 <import class="com.framsticks.structure.LocalTree" /> 8 7 <Server port="9007"> 9 8 <LocalTree name="prime-local-tree"> 10 <PrimeExperiment maxNumber="3000 0">9 <PrimeExperiment maxNumber="3000"> 11 10 <SimulatorConnector address="localhost:9100" /> 12 11 <SimulatorConnector address="localhost:9101" /> … … 16 15 </Server> 17 16 </Framsticks> 18 -
java/main/src/test/java/com/framsticks/core/ListChangeTest.java
r102 r105 6 6 import org.testng.annotations.Test; 7 7 8 import com.framsticks.core.ListChange.Action;9 8 import static com.framsticks.params.AccessOperations.*; 10 9 import com.framsticks.params.FramsClass; … … 12 11 import com.framsticks.params.ListSource; 13 12 import com.framsticks.params.ReflectionAccess; 13 import com.framsticks.structure.messages.ListChange; 14 import com.framsticks.structure.messages.ListChange.Action; 14 15 import com.framsticks.test.TestConfiguration; 15 16 -
java/main/src/test/java/com/framsticks/core/LocalTreeTest.java
r100 r105 12 12 import com.framsticks.model.f0.Schema; 13 13 import com.framsticks.model.f0.SchemaBuilder; 14 import com.framsticks.structure.LocalTree; 15 import com.framsticks.structure.Path; 16 import com.framsticks.structure.Tree; 17 import com.framsticks.structure.TreeOperations; 14 18 import com.framsticks.test.TestConfiguration; 15 19 import com.framsticks.util.dispatching.Dispatching; … … 20 24 import com.framsticks.params.types.FloatParam; 21 25 22 import static com.framsticks.core.TreeOperations.*;23 26 24 27 25 28 import static org.fest.assertions.Assertions.*; 29 import static com.framsticks.params.ParamsUtil.getParam; 30 import static com.framsticks.structure.TreeOperations.*; 26 31 27 32 @Test … … 75 80 assertThat(access.get("se", Double.class)).isEqualTo(1.0); 76 81 77 assertThat( bindAccess(tree, "/parts/2").getFramsClass().getParamEntry("m", FloatParam.class).getDef(Double.class)).isEqualTo(1.0);78 assertThat( bindAccess(tree, "/parts/2").getFramsClass().getParamEntry("m", FloatParam.class).getMax(Double.class)).isEqualTo(999.0);82 assertThat(getParam(bindAccess(tree, "/parts/2"), "m", FloatParam.class).getDef(Double.class)).isEqualTo(1.0); 83 assertThat(getParam(bindAccess(tree, "/parts/2"), "m", FloatParam.class).getMax(Double.class)).isEqualTo(999.0); 79 84 assertThat(bindAccess(tree, "/parts/2")).isInstanceOf(ReflectionAccess.class); 80 85 assertThat(Path.to(tree, "/neurodefs").getTopObject()).isInstanceOf(ArrayList.class); -
java/main/src/test/java/com/framsticks/core/PathTest.java
r99 r105 11 11 import org.testng.annotations.Test; 12 12 13 import com.framsticks.structure.Path; 13 14 import com.framsticks.test.TestConfiguration; 14 15 import com.framsticks.util.lang.Pair; -
java/main/src/test/java/com/framsticks/gui/LocalTreeBrowserTest.java
r100 r105 5 5 import org.testng.annotations.Test; 6 6 7 import com.framsticks.core.Tree;8 import com.framsticks.core.LocalTree;9 7 import com.framsticks.model.Model; 10 8 import com.framsticks.params.types.FloatParam; 11 9 import com.framsticks.parsers.XmlLoader; 10 import com.framsticks.structure.LocalTree; 11 import com.framsticks.structure.Tree; 12 12 import com.framsticks.util.dispatching.RunAt; 13 13 14 import static com.framsticks.core.TreeOperations.*; 14 import static com.framsticks.params.ParamsUtil.getParam; 15 import static com.framsticks.structure.TreeOperations.*; 15 16 16 17 @Test … … 45 46 @Override 46 47 protected void runAt() { 47 assertThat( bindAccess(tree, "/parts/2").getFramsClass().getParamEntry("m", FloatParam.class).getMax(Double.class)).isEqualTo(999.0);48 assertThat(getParam(bindAccess(tree, "/parts/2"), "m", FloatParam.class).getMax(Double.class)).isEqualTo(999.0); 48 49 } 49 50 }); -
java/main/src/test/java/com/framsticks/gui/ProcedureBrowserTest.java
r103 r105 7 7 import org.testng.annotations.Test; 8 8 9 import com.framsticks.core.Path;10 import com.framsticks.core.Tree;11 import com.framsticks.core.LocalTree;12 import com.framsticks.core.ValueChange;13 9 import com.framsticks.params.Access; 14 10 import com.framsticks.params.EventListener; 15 import com.framsticks.params.FramsClass;16 11 import com.framsticks.params.ReflectionAccess; 17 12 import com.framsticks.params.types.EventParam; 18 13 import com.framsticks.params.types.StringParam; 19 14 import com.framsticks.parsers.XmlLoader; 15 import com.framsticks.structure.LocalTree; 16 import com.framsticks.structure.Path; 17 import com.framsticks.structure.Tree; 18 import com.framsticks.structure.messages.ValueChange; 20 19 import com.framsticks.test.TestClass; 21 import com.framsticks.util.dispatching.Future Handler;20 import com.framsticks.util.dispatching.Future; 22 21 // import com.framsticks.util.dispatching.Dispatching; 23 22 import com.framsticks.util.dispatching.RunAt; 24 import static com.framsticks.core.TreeOperations.*; 23 import static com.framsticks.params.ParamsUtil.getParam; 24 import static com.framsticks.structure.TreeOperations.*; 25 25 26 26 @Test … … 53 53 @Override 54 54 protected void runAt() { 55 assertThat( bindAccess(tree, "/").getFramsClass().getParam("history")).isInstanceOf(StringParam.class);55 assertThat(getParam(bindAccess(tree, "/"), "history")).isInstanceOf(StringParam.class); 56 56 } 57 57 }); … … 64 64 Access access = bindAccess(tree, "/"); 65 65 assertThat(access).isInstanceOf(ReflectionAccess.class); 66 FramsClass framsClass = access.getFramsClass(); 67 assertThat(framsClass.getParam(0).getId()).isEqualTo("name"); 68 assertThat(framsClass.getParam(1).getId()).isEqualTo("history"); 69 assertThat(framsClass.getParam(2).getId()).isEqualTo("history_changed"); 70 assertThat(framsClass.getParam(3).getId()).isEqualTo("appendHistory"); 71 assertThat(framsClass.getParam(4).getId()).isEqualTo("resetHistory"); 66 assertThat(getParam(access, 0).getId()).isEqualTo("name"); 67 assertThat(getParam(access, 1).getId()).isEqualTo("history"); 68 assertThat(getParam(access, 2).getId()).isEqualTo("history_changed"); 69 assertThat(getParam(access, 3).getId()).isEqualTo("appendHistory"); 70 assertThat(getParam(access, 4).getId()).isEqualTo("resetHistory"); 72 71 73 72 assertThat(access.get("history", String.class)).isEqualTo("initial|"); … … 96 95 assertThat(access.get("history", String.class)).isEqualTo("initial|Żółw|"); 97 96 98 tree.addListener(Path.to(tree, "/"), access.getFramsClass().getParamEntry("history_changed", EventParam.class), listener, ValueChange.class, FutureHandler.doNothing(Void.class, failOnException));97 tree.addListener(Path.to(tree, "/"), getParam(access, "history_changed", EventParam.class), listener, ValueChange.class, Future.doNothing(Void.class, failOnException)); 99 98 } 100 99 }); … … 109 108 assertThat(access.get("history", String.class)).isEqualTo(""); 110 109 111 tree.removeListener(Path.to(tree, "/"), access.getFramsClass().getParamEntry("history_changed", EventParam.class), listener, FutureHandler.doNothing(Void.class, failOnException));110 tree.removeListener(Path.to(tree, "/"), getParam(access, "history_changed", EventParam.class), listener, Future.doNothing(Void.class, failOnException)); 112 111 } 113 112 }); -
java/main/src/test/java/com/framsticks/gui/console/TrackConsoleTest.java
r101 r105 3 3 import org.testng.annotations.Test; 4 4 5 import com.framsticks.core.Path;6 5 import com.framsticks.gui.GuiTest; 7 6 import com.framsticks.remote.RemoteTree; 7 import com.framsticks.structure.Path; 8 8 import com.framsticks.util.dispatching.Dispatching; 9 9 import com.framsticks.util.dispatching.Dispatching.Waiter; 10 import com.framsticks.util.dispatching.Future Handler;10 import com.framsticks.util.dispatching.Future; 11 11 import com.framsticks.util.dispatching.Joinable; 12 12 import com.framsticks.util.dispatching.JoinableCollection; 13 13 14 import static com.framsticks. core.TreeOperations.*;14 import static com.framsticks.structure.TreeOperations.*; 15 15 16 16 @Test … … 41 41 final Waiter waiter = produceWaiter(1.0); 42 42 43 tryGet(tree, "/simulator/genepools/groups/0", new Future Handler<Path>(failOnException) {43 tryGet(tree, "/simulator/genepools/groups/0", new Future<Path>(failOnException) { 44 44 45 45 @Override -
java/main/src/test/java/com/framsticks/hosting/ServerTest.java
r103 r105 8 8 import org.testng.annotations.Test; 9 9 10 import com.framsticks.core.ListChange;11 import com.framsticks.core.LocalTree;12 import com.framsticks.core.Path;13 import com.framsticks.core.Result;14 import com.framsticks.core.TreeOperations;15 import com.framsticks.core.ValueChange;16 10 import com.framsticks.core.XmlBasedTest; 17 11 import com.framsticks.remote.RemoteTree; 12 import com.framsticks.structure.LocalTree; 13 import com.framsticks.structure.Path; 14 import com.framsticks.structure.Tree; 15 import com.framsticks.structure.TreeOperations; 16 import com.framsticks.structure.messages.ListChange; 17 import com.framsticks.structure.messages.Result; 18 import com.framsticks.structure.messages.ValueChange; 18 19 19 20 import com.framsticks.test.TestClass; 20 import com.framsticks.core.Tree;21 21 import com.framsticks.params.FramsClass; 22 22 import com.framsticks.params.Access; … … 29 29 import com.framsticks.params.types.ProcedureParam; 30 30 import com.framsticks.util.dispatching.Dispatching.Waiter; 31 import com.framsticks.util.dispatching.Future Handler;31 import com.framsticks.util.dispatching.Future; 32 32 import com.framsticks.util.dispatching.RunAt; 33 33 34 import static com.framsticks. core.TreeOperations.*;34 import static com.framsticks.params.ParamsUtil.arguments; 35 35 36 36 import static org.fest.assertions.Assertions.*; 37 import static com.framsticks.params.ParamsUtil.getParam; 38 import static com.framsticks.structure.TreeOperations.*; 37 39 38 40 @Test … … 72 74 final Waiter waiter = produceWaiter(1.0); 73 75 74 TreeOperations.tryGet(remote, "/testClass", new Future Handler<Path>(failOnException) {76 TreeOperations.tryGet(remote, "/testClass", new Future<Path>(failOnException) { 75 77 @Override 76 78 protected void result(Path path) { … … 88 90 final Waiter waiter = produceWaiter(1.0); 89 91 90 TreeOperations.tryGet(remote, "/testClass", new Future Handler<Path>(failOnException) {92 TreeOperations.tryGet(remote, "/testClass", new Future<Path>(failOnException) { 91 93 @Override 92 94 protected void result(Path path) { … … 105 107 final Waiter waiter = produceWaiter(2.0); 106 108 107 set(remotePath, remoteTestFramsClass.getParamEntry("name", PrimitiveParam.class), "new name", new FutureHandler<Integer>(failOnException) {109 set(remotePath, getParam(remoteTestFramsClass, "name", PrimitiveParam.class), "new name", new Future<Integer>(failOnException) { 108 110 @Override 109 111 protected void result(Integer flags) { … … 132 134 }; 133 135 134 TreeOperations.tryGet(remote, "/cli/events", new Future Handler<Path>(failOnException) {136 TreeOperations.tryGet(remote, "/cli/events", new Future<Path>(failOnException) { 135 137 @Override 136 138 protected void result(Path path) { … … 139 141 }); 140 142 141 addListener(remotePath, remoteTestFramsClass.getParamEntry("history_changed", EventParam.class), listener, ValueChange.class, produceWaiter(1.0).passInFuture(Void.class));143 addListener(remotePath, getParam(remoteTestFramsClass, "history_changed", EventParam.class), listener, ValueChange.class, produceWaiter(1.0).passInFuture(Void.class)); 142 144 } 143 145 … … 146 148 final Waiter waiter = produceWaiter(2.0); 147 149 148 call(remotePath, remoteTestFramsClass.getParamEntry("resetHistory", ProcedureParam.class), new Object[] {}, Object.class, produceWaiter(2.0).passInFuture(Object.class));149 150 call(remotePath, remoteTestFramsClass.getParamEntry("appendHistory", ProcedureParam.class), new Object[] {"next word"}, Result.class, new FutureHandler<Result>(failOnException) {150 call(remotePath, getParam(remoteTestFramsClass, "resetHistory", ProcedureParam.class), arguments(), Object.class, produceWaiter(2.0).passInFuture(Object.class)); 151 152 call(remotePath, getParam(remoteTestFramsClass, "appendHistory", ProcedureParam.class), arguments("next word"), Result.class, new Future<Result>(failOnException) { 151 153 @Override 152 154 protected void result(final Result result) { … … 167 169 @Test(dependsOnMethods = "callMethod") 168 170 public void deregisterListener() { 169 removeListener(remotePath, remoteTestFramsClass.getParamEntry("history_changed", EventParam.class), listener, produceWaiter(1.0).passInFuture(Void.class));171 removeListener(remotePath, getParam(remoteTestFramsClass, "history_changed", EventParam.class), listener, produceWaiter(1.0).passInFuture(Void.class)); 170 172 171 173 assertThat(listenerArguments).isEqualTo(Arrays.asList("", "next word|")); … … 183 185 }; 184 186 185 addListener(remotePath, remoteTestFramsClass.getParamEntry("children_changed", EventParam.class), childListener, ListChange.class, produceWaiter(1.0).passInFuture(Void.class));187 addListener(remotePath, getParam(remoteTestFramsClass, "children_changed", EventParam.class), childListener, ListChange.class, produceWaiter(1.0).passInFuture(Void.class)); 186 188 } 187 189 … … 189 191 public void createChild() { 190 192 final Waiter waiter = produceWaiter(2.0); 191 call(remotePath, "createChild", new Object[] { "a child" }, Object.class, produceWaiter(2.0).passInFuture(Object.class));192 call(remotePath, "createChild", new Object[] { "another child" }, Object.class, produceWaiter(2.0).passInFuture(Object.class));193 194 tryGet(remote, "/testClass/children/c0", new Future Handler<Path>(failOnException) {193 call(remotePath, "createChild", arguments("a child"), Object.class, produceWaiter(2.0).passInFuture(Object.class)); 194 call(remotePath, "createChild", arguments("another child"), Object.class, produceWaiter(2.0).passInFuture(Object.class)); 195 196 tryGet(remote, "/testClass/children/c0", new Future<Path>(failOnException) { 195 197 196 198 @Override 197 199 protected void result(Path result) { 198 set(result, get FramsClass(result).getParamEntry("name", StringParam.class), "new_name", new FutureHandler<Integer>(failOnException) {200 set(result, getParam(result, "name", StringParam.class), "new_name", new Future<Integer>(failOnException) { 199 201 200 202 @Override … … 209 211 @Test(dependsOnMethods = "createChild") 210 212 public void deregisterChildListener() { 211 removeListener(remotePath, remoteTestFramsClass.getParamEntry("children_changed", EventParam.class), childListener, produceWaiter(1.0).passInFuture(Void.class));213 removeListener(remotePath, getParam(remoteTestFramsClass, "children_changed", EventParam.class), childListener, produceWaiter(1.0).passInFuture(Void.class)); 212 214 } 213 215 -
java/main/src/test/java/com/framsticks/model/CreatureTest.java
r87 r105 11 11 12 12 import static org.fest.assertions.Assertions.*; 13 import static com.framsticks.params.ParamsUtil.getParam; 13 14 14 15 @Test … … 27 28 assertThat(framsClass.getParam("name")).describedAs("name").isInstanceOf(StringParam.class); 28 29 assertThat(framsClass.getParam("parts")).describedAs("parts").isInstanceOf(ArrayListParam.class); 29 partsParam = framsClass.getParamEntry("parts", ArrayListParam.class);30 partsParam = getParam(framsClass, "parts", ArrayListParam.class); 30 31 assertThat(partsParam).describedAs("partsParam").isNotNull(); 31 32 assertThat(partsParam).isInstanceOf(ArrayListParam.class); -
java/main/src/test/java/com/framsticks/model/ModelPackageTest.java
r101 r105 15 15 16 16 import static org.fest.assertions.Assertions.*; 17 import static com.framsticks.params.ParamsUtil.getParam; 17 18 18 19 @Test … … 41 42 Object defaultValue = args[1]; 42 43 43 ValueParam param = framsClass.getParamEntry(paramName, ValueParam.class);44 ValueParam param = getParam(framsClass, paramName, ValueParam.class); 44 45 assertThat(param.getDef(Object.class)).isEqualTo(defaultValue); 45 46 -
java/main/src/test/java/com/framsticks/model/f0/SchemaTest.java
r97 r105 11 11 12 12 import static org.fest.assertions.Assertions.*; 13 import static com.framsticks.params.ParamsUtil.getParam; 13 14 14 15 public class SchemaTest extends TestConfiguration { … … 23 24 24 25 assertThat(schema.getNeuroClass("|").getName()).isEqualTo("Bend muscle"); 25 assertThat( schema.getNeuroClass("VEye").getParam("p")).isInstanceOf(FloatParam.class);26 assertThat( schema.getNeuroClass("VEye").getParamEntry("p", FloatParam.class).getMax(Double.class)).isEqualTo(10.0, delta(0.0));26 assertThat(getParam(schema.getNeuroClass("VEye"), "p")).isInstanceOf(FloatParam.class); 27 assertThat(getParam(schema.getNeuroClass("VEye"), "p", FloatParam.class).getMax(Double.class)).isEqualTo(10.0, delta(0.0)); 27 28 28 29 FramsClass partClass = schema.getFramsClass("p"); 29 30 assertThat(partClass).isNotNull(); 30 assertThat( partClass.getParamEntry("as", FloatParam.class).getDef(Double.class)).isEqualTo(0.25, delta(0.0));31 assertThat(getParam(partClass, "as", FloatParam.class).getDef(Double.class)).isEqualTo(0.25, delta(0.0)); 31 32 assertThat(partClass.getGroupCount()).isEqualTo(3); 32 33 assertThat(partClass.getGroup(1).getName()).isEqualTo("Other properties"); -
java/main/src/test/java/com/framsticks/params/FramsClassBuilderTest.java
r103 r105 6 6 import org.testng.annotations.Test; 7 7 8 import com.framsticks.core.ValueChange;9 8 import com.framsticks.params.types.EventParam; 10 9 import com.framsticks.params.types.ProcedureParam; 11 10 import com.framsticks.params.types.StringParam; 12 11 import com.framsticks.parsers.Savers; 12 import com.framsticks.structure.messages.ValueChange; 13 13 import com.framsticks.test.TestClass; 14 14 import com.framsticks.test.TestConfiguration; … … 16 16 17 17 import static org.fest.assertions.Assertions.*; 18 import static com.framsticks.params.ParamsUtil.arguments; 19 import static com.framsticks.params.ParamsUtil.getParam; 18 20 19 21 @Test … … 43 45 assertThat(framsClass.getParam("resetHistory")).isInstanceOf(ProcedureParam.class); 44 46 45 ProcedureParam appendHistory = framsClass.getParamEntry("appendHistory", ProcedureParam.class); 47 48 ProcedureParam appendHistory = getParam(framsClass, "appendHistory", ProcedureParam.class); 46 49 assertThat(appendHistory.getArgumentsType().size()).isEqualTo(1); 47 50 assertThat(appendHistory.getArgumentsType().get(0).getId()).isEqualTo("arg0"); … … 111 114 112 115 assertThat(access.get("history", String.class)).isEqualTo("initial|first|"); 113 Object result = access.call("appendHistory", new Object[] {"second"});116 Object result = access.call("appendHistory", arguments("second")); 114 117 115 118 assertThat(result).isInstanceOf(Integer.class); … … 117 120 assertThat(access.get("history", String.class)).isEqualTo("initial|first|second|"); 118 121 119 result = access.call("resetHistory" , null);122 result = access.call("resetHistory"); 120 123 assertThat(result).isNull(); 121 124 … … 136 139 }; 137 140 138 final EventParam eventParam = access.getFramsClass().getParamEntry("history_changed", EventParam.class);141 final EventParam eventParam = getParam(access, "history_changed", EventParam.class); 139 142 access.reg(eventParam, listener); 140 143 … … 142 145 final String addition = "test"; 143 146 144 access.call("appendHistory", new Object[] { addition });147 access.call("appendHistory", arguments(addition)); 145 148 146 149 String expected = currentHistory + addition + "|"; -
java/main/src/test/java/com/framsticks/params/ParamBuilderTest.java
r103 r105 9 9 import com.framsticks.test.TestConfiguration; 10 10 import static org.fest.assertions.Assertions.*; 11 import static com.framsticks.params.ParamsUtil.getParam; 11 12 12 13 @Test … … 24 25 assertThat(builderFramsClass.getName()).isEqualTo("prop"); 25 26 assertThat(builderFramsClass.getId()).isEqualTo("prop"); 26 assertThat( builderFramsClass.getParamEntry("flags", ValueParam.class).getDef(Object.class)).isEqualTo(new Integer(0));27 assertThat( builderFramsClass.getParamEntry("id", Param.class)).isInstanceOf(StringParam.class);27 assertThat(getParam(builderFramsClass, "flags", ValueParam.class).getDef(Object.class)).isEqualTo(new Integer(0)); 28 assertThat(getParam(builderFramsClass, "id", Param.class)).isInstanceOf(StringParam.class); 28 29 } 29 30 -
java/main/src/test/java/com/framsticks/parsers/F0ParserTest.java
r101 r105 17 17 import static org.fest.assertions.Assertions.*; 18 18 import static org.fest.assertions.Delta.*; 19 import static com.framsticks.params.ParamsUtil.getParam; 19 20 20 21 /** … … 48 49 public void primitiveParam() { 49 50 FramsClass joint = schema.getFramsClass("j"); 50 PrimitiveParam<?> dx = joint.getParamEntry("dx", PrimitiveParam.class);51 PrimitiveParam<?> dx = getParam(joint, "dx", PrimitiveParam.class); 51 52 assertThat(dx).isInstanceOf(FloatParam.class); 52 53 assertThat(schema.getNeuroClasses().size()).isEqualTo(21); … … 54 55 assertThat(dx.getMin(Double.class)).isEqualTo(-2.0, delta(0.0)); 55 56 56 assertThat( schema.getRegistry().getFramsClass("n").getParamEntry("d", StringParam.class).getDef(String.class)).isEqualTo("N");57 assertThat(getParam(schema.getRegistry().getFramsClass("n"), "d", StringParam.class).getDef(String.class)).isEqualTo("N"); 57 58 } 58 59 … … 60 61 public void readF0() throws IOException, ParseException { 61 62 assertThat(schema.getFramsClass("p")).isInstanceOf(FramsClass.class); 62 assertThat( schema.getRegistry().getFramsClass("p").getParamEntry("as", FloatParam.class).getDef(Double.class)).isEqualTo(0.25, delta(0.0));63 assertThat(getParam(schema.getRegistry().getFramsClass("p"), "as", FloatParam.class).getDef(Double.class)).isEqualTo(0.25, delta(0.0)); 63 64 64 65 accesses = new F0Parser(schema, F0ParserTest.class.getResourceAsStream("/parsers/f0_example.txt")).parse(); … … 91 92 92 93 assertThat(model.getParts().get(1).getPosition().x).isEqualTo(2.0, delta(0.0)); 93 assertThat(model.getParts().get(2).getPosition().sub(new Point3d(2.27236, -0.0792596, -0.958924)).length()). isLessThan(0.0001);94 assertThat(model.getParts().get(2).getPosition().sub(new Point3d(2.27236, -0.0792596, -0.958924)).length()).describedAs("position error").isLessThan(0.0001); 94 95 assertThat(model.getParts().get(2).getOrientation().y.sub(new Point3d(0.870277, -0.404792, 0.280644)).length()).isLessThan(0.0001); 95 96 -
java/main/src/test/java/com/framsticks/running/ExternalProcessTest.java
r101 r105 9 9 import org.testng.annotations.Test; 10 10 11 import com.framsticks.core.ValueChange;12 11 import com.framsticks.params.EventListener; 12 import com.framsticks.structure.messages.ValueChange; 13 13 import com.framsticks.test.TestConfiguration; 14 14 import com.framsticks.util.dispatching.Monitor; -
java/main/src/test/java/com/framsticks/test/TestConfiguration.java
r100 r105 10 10 import org.testng.annotations.*; 11 11 12 import com.framsticks.util.ExceptionHandler; 12 13 import com.framsticks.util.FramsticksException; 13 14 import com.framsticks.util.dispatching.Dispatcher; 14 15 import com.framsticks.util.dispatching.Dispatching; 15 16 import com.framsticks.util.dispatching.Dispatching.Waiter; 16 import com.framsticks.util.dispatching.ExceptionHandler; 17 import com.framsticks.util.dispatching.ExceptionResultHandler; 17 import com.framsticks.util.dispatching.ExceptionDispatcherHandler; 18 18 19 19 // import static org.fest.assertions.Assertions.*; … … 46 46 } 47 47 48 public Exception Handler createExceptionHandler() {49 return new Exception Handler() {48 public ExceptionDispatcherHandler createExceptionHandler() { 49 return new ExceptionDispatcherHandler() { 50 50 @Override 51 51 public boolean handle(Dispatcher<?> dispatcher, Throwable throwable) { … … 98 98 } 99 99 100 public final Exception ResultHandler failOnException = new ExceptionResultHandler() {100 public final ExceptionHandler failOnException = new ExceptionHandler() { 101 101 @Override 102 102 public void handle(FramsticksException e) { -
java/main/src/test/resources/configs/LocalTreeBrowserTest.xml
r99 r105 2 2 <Browser> 3 3 <import class="com.framsticks.model.ModelBuilder" /> 4 <import class="com.framsticks. core.LocalTree" />4 <import class="com.framsticks.structure.LocalTree" /> 5 5 <!-- <import class="com.framsticks.model.ModelPackage" /> --> 6 6 <LocalTree name="model"> -
java/main/src/test/resources/configs/ProcedureBrowserTest.xml
r99 r105 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <Browser> 3 <import class="com.framsticks. core.LocalTree" />3 <import class="com.framsticks.structure.LocalTree" /> 4 4 <import class="com.framsticks.test.TestClass" /> 5 5 <LocalTree name="test"> -
java/main/src/test/resources/configs/ServerTest.xml
r102 r105 3 3 <import class="com.framsticks.hosting.Server" /> 4 4 <import class="com.framsticks.remote.RemoteTree" /> 5 <import class="com.framsticks. core.LocalTree" />5 <import class="com.framsticks.structure.LocalTree" /> 6 6 <import class="com.framsticks.test.TestClass" /> 7 7 <import class="com.framsticks.running.LoggingOutputListener" />
Note: See TracChangeset
for help on using the changeset viewer.