Changeset 97
- Timestamp:
- 07/06/13 03:51:11 (11 years ago)
- Location:
- java/main
- Files:
-
- 43 added
- 21 deleted
- 71 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/pom.xml
r96 r97 117 117 <version>2.9</version> 118 118 <configuration> 119 <forkedProcessTimeoutInSeconds>60</forkedProcessTimeoutInSeconds> 119 120 <useFile>false</useFile> 120 121 </configuration> … … 156 157 </configuration> 157 158 </plugin> 158 159 <plugin> 160 <groupId>org.codehaus.mojo</groupId> 161 <artifactId>appassembler-maven-plugin</artifactId> 162 <version>1.3.1</version> 163 <configuration> 164 <programs> 165 <program> 166 <mainClass>com.framsticks.core.Framsticks</mainClass> 167 <name>framsticks</name> 168 </program> 169 </programs> 170 </configuration> 171 </plugin> 159 172 </plugins> 160 173 </build> -
java/main/src/main/java/com/framsticks/communication/Connection.java
r96 r97 1 1 package com.framsticks.communication; 2 2 3 import com.framsticks.params.annotations.AutoAppendAnnotation; 4 import com.framsticks.params.annotations.FramsClassAnnotation; 5 import com.framsticks.params.annotations.ParamAnnotation; 3 6 import com.framsticks.util.FramsticksException; 4 7 import com.framsticks.util.io.Encoding; 5 import com.framsticks.util.lang.Pair; 8 import com.framsticks.util.lang.Strings; 9 10 import org.apache.log4j.Level; 6 11 import org.apache.log4j.Logger; 7 12 import java.io.BufferedReader; … … 12 17 import java.net.Socket; 13 18 import java.net.SocketTimeoutException; 19 import java.util.Collection; 20 import java.util.HashSet; 21 import java.util.Set; 14 22 15 23 import com.framsticks.util.dispatching.AbstractJoinable; … … 21 29 import com.framsticks.util.dispatching.RunAt; 22 30 import com.framsticks.util.dispatching.Thread; 23 31 import com.framsticks.util.dispatching.ThrowExceptionHandler; 32 33 @FramsClassAnnotation 24 34 public abstract class Connection extends AbstractJoinable implements JoinableParent { 25 35 26 36 protected final static Logger log = Logger.getLogger(Connection.class); 27 37 28 pr otectedPrintWriter output = null;29 pr otectedBufferedReader input = null;38 private PrintWriter output = null; 39 private BufferedReader input = null; 30 40 31 41 protected Socket socket = null; 32 42 33 public boolean requestIdEnabled = false; 34 35 protected int protocolVersion = -1; 36 37 public String getAddress() { 38 return address; 39 } 40 protected final String address; 41 protected final String description; 43 protected Address address; 44 protected String description = "connection"; 42 45 43 46 protected final Thread<Connection> senderThread = new Thread<>(); 44 47 protected final Thread<Connection> receiverThread = new Thread<>(); 45 48 protected final JoinableCollection<Thread<Connection>> threads = new JoinableCollection<>(); 46 47 protected void setUpThreadNames(String name) { 48 } 49 protected final Set<ConnectionListener> listeners = new HashSet<>(); 49 50 50 51 /** 51 52 * 52 53 */ 53 public Connection(String address, String description) { 54 this.address = address; 55 this.description = description; 56 threads.setObservableName(address + " connection threads"); 54 public Connection() { 57 55 threads.add(senderThread); 58 56 threads.add(receiverThread); 59 57 58 } 59 60 protected void updateNames() { 61 if (address == null) { 62 return; 63 } 60 64 senderThread.setName(description + " thread " + address + " sender"); 61 65 receiverThread.setName(description + " thread " + address + " receiver"); 66 threads.setObservableName(address + " connection threads"); 67 } 68 69 public void setDescription(String description) { 70 this.description = description; 71 updateNames(); 72 } 73 74 @AutoAppendAnnotation 75 public Connection setAddress(Address address) { 76 this.address = address; 77 updateNames(); 78 return this; 79 } 80 81 @ParamAnnotation 82 public Connection setAddress(String address) { 83 return setAddress(new Address(address)); 62 84 } 63 85 64 86 public synchronized boolean isConnected() { 65 87 return socket != null && socket.isConnected(); 66 }67 68 69 // protected static final String ARGUMENT_PATTERN_FRAGMENT = "((?:\\S+)|(?:\\\"[^\"]*\\\"))";70 // protected static final Pattern REQUEST_ID_ENABLED_PATTERN = Pattern.compile("^\\s*([0-9]+)(?:\\s+" + ARGUMENT_PATTERN_FRAGMENT + ")?$");71 // protected static final Pattern REQUEST_ID_DISABLED_PATTERN = Pattern.compile("^\\s*" + ARGUMENT_PATTERN_FRAGMENT + "?$");72 73 // // protected final Pair<String, String> breakLine(String line)74 // protected final Pair<Integer, String> parseRest(String rest) {75 // Matcher matcher = (requestIdEnabled ? REQUEST_ID_ENABLED_PATTERN : REQUEST_ID_DISABLED_PATTERN).matcher(rest);76 // if (!matcher.matches()) {77 // log.fatal("unmatched first line of input: '" + rest + "'");78 // return null;79 // }80 // return new Pair<Integer, String>(requestIdEnabled ? Integer.parseInt(matcher.group(1)) : null, matcher.group(requestIdEnabled ? 2 : 1));81 // }82 83 protected final Pair<Integer, CharSequence> takeRequestId(CharSequence line) {84 return Request.takeRequestId(requestIdEnabled, line);85 88 } 86 89 … … 105 108 ++iterator; 106 109 bufferStart = iterator; 107 return lineBuffer.toString(); 110 String line = lineBuffer.toString(); 111 112 synchronized (listeners) { 113 for (ConnectionListener l : listeners) { 114 l.connectionIncomming(line); 115 } 116 } 117 118 return line; 108 119 } 109 120 final int length = readChars - bufferStart; … … 131 142 } 132 143 144 protected void putLine(String line) { 145 synchronized (listeners) { 146 for (ConnectionListener l : listeners) { 147 l.connectionOutgoing(line); 148 } 149 } 150 output.println(line); 151 } 152 153 protected void flushOut() { 154 output.flush(); 155 } 156 157 protected abstract void processNextInputBatch(); 158 159 protected final void processInputBatchesUntilClosed() { 160 while (isRunning() && isConnected()) { 161 try { 162 processNextInputBatch(); 163 } catch (Exception e) { 164 log.log(isRunning() ? Level.ERROR : Level.DEBUG, "caught exception: ", e); 165 break; 166 } 167 } 168 } 169 133 170 protected abstract void receiverThreadRoutine(); 134 171 135 172 // @SuppressWarnings("NN_NAKED_NOTIFY") 136 173 protected void setupStreams() { 137 174 try { … … 146 183 } 147 184 148 /**149 * Returns Query associated with query getId.150 *151 * @return Query associated with query getId.152 */153 public int getProtocolVersion() {154 return protocolVersion;155 }156 185 157 186 … … 187 216 @Override 188 217 public String getName() { 189 return description + " " + address;218 return address != null ? description + " " + address : description; 190 219 } 191 220 … … 194 223 Dispatching.use(threads, this); 195 224 196 senderThread.dispatch(new RunAt<Connection>( ) {225 senderThread.dispatch(new RunAt<Connection>(ThrowExceptionHandler.getInstance()) { 197 226 @Override 198 p ublic void run() {227 protected void runAt() { 199 228 synchronized (Connection.this) { 200 229 while (state.equals(JoinableState.RUNNING) && output == null) { … … 205 234 }); 206 235 207 receiverThread.dispatch(new RunAt<Connection>( ) {236 receiverThread.dispatch(new RunAt<Connection>(ThrowExceptionHandler.getInstance()) { 208 237 @Override 209 p ublic void run() {238 protected void runAt() { 210 239 receiverThreadRoutine(); 240 interrupt(); 241 finish(); 211 242 } 212 243 }); … … 215 246 @Override 216 247 protected void joinableInterrupt() { 217 protocolVersion = -1;218 248 Dispatching.drop(threads, this); 219 249 finish(); … … 226 256 } 227 257 258 protected static void startClientConnection(Connection connection) { 259 while (connection.isRunning() && !connection.isConnected()) { 260 log.debug("connecting to " + connection.address); 261 try { 262 connection.socket = new Socket(connection.getAddressObject().getHostName(), connection.getAddressObject().getPort()); 263 } catch (IOException e) { 264 log.info(connection + " failed to connect (retrying): " + e); 265 Dispatching.sleep(0.5); 266 } 267 } 268 269 log.debug(connection + " connected"); 270 try { 271 connection.socket.setSoTimeout(500); 272 connection.setupStreams(); 273 } catch (Exception e) { 274 throw new FramsticksException().msg("failed to initialize socket").cause(e).arg("connection", connection); 275 } 276 } 277 278 /** 279 * @return the address 280 */ 281 @ParamAnnotation 282 public String getAddress() { 283 return Strings.toStringNullProof(address, "?"); 284 } 285 286 public Address getAddressObject() { 287 return address; 288 } 289 290 291 /** 292 * @return the listeners 293 */ 294 public Collection<ConnectionListener> getListeners() { 295 return listeners; 296 } 297 298 public static <T extends Connection> T to(T connection, Address address) { 299 connection.setAddress(address); 300 return connection; 301 } 302 228 303 } -
java/main/src/main/java/com/framsticks/communication/RequestHandler.java
r85 r97 7 7 */ 8 8 public interface RequestHandler { 9 public void handle(ApplicationRequest request, ResponseCallback<?>responseCallback);9 public void handle(ApplicationRequest request, ServerSideResponseFuture responseCallback); 10 10 } -
java/main/src/main/java/com/framsticks/communication/Subscription.java
r96 r97 4 4 5 5 import com.framsticks.communication.queries.RegistrationRequest; 6 import com.framsticks.util.dispatching.AtOnceDispatcher; 6 7 import com.framsticks.util.dispatching.Dispatcher; 7 8 import com.framsticks.util.dispatching.Dispatching; 8 9 import com.framsticks.util.dispatching.RunAt; 9 import com.framsticks.util. FramsticksException;10 import com.framsticks.util.StateFunctor; 10 import com.framsticks.util.dispatching.ThrowExceptionHandler; 11 11 12 import org.apache.log4j.Logger; 12 13 … … 19 20 private final static Logger log = Logger.getLogger(Subscription.class); 20 21 21 private final Client Connection connection;22 private final ClientSideManagedConnection connection; 22 23 private final String path; 23 24 private final String registeredPath; … … 26 27 private EventCallback eventCallback; 27 28 28 public Subscription(Client Connection connection, String path, String registeredPath, Dispatcher<C> dispatcher) {29 public Subscription(ClientSideManagedConnection connection, String path, String registeredPath, Dispatcher<C> dispatcher) { 29 30 this.connection = connection; 30 31 this.path = path; … … 46 47 } 47 48 48 public void unsubscribe(final StateFunctor stateFunctor) {49 public void unsubscribe(final ClientSideResponseFuture future) { 49 50 //@todo remove that /cli/ prefix, when registeredPath will be a fully qualified path 50 connection.send(new RegistrationRequest().register(false).path(registeredPath), new ResponseCallback<Connection>() { 51 connection.send(new RegistrationRequest().register(false).path(registeredPath), AtOnceDispatcher.getInstance(), new ClientSideResponseFuture(future) { 52 51 53 @Override 52 public void process(Response response) { 53 if (!response.getOk()) { 54 log.error("failed to unsunscribe " + this + ": " + response.getComment()); 55 stateFunctor.handle(new FramsticksException().msg("unsubscription failed").arg("comment", response.getComment())); 56 return; 57 } 54 protected void processOk(Response response) { 58 55 assert response.hasFiles(); 59 56 log.debug("unsunscribed " + this); 60 stateFunctor.call();57 future.pass(response); 61 58 } 62 59 }); … … 76 73 77 74 public void dispatchCall(final List<File> files) { 78 Dispatching.dispatchIfNotActive(dispatcher, new RunAt<C>() { 75 //TODO TEH 76 Dispatching.dispatchIfNotActive(dispatcher, new RunAt<C>(ThrowExceptionHandler.getInstance()) { 79 77 @Override 80 p ublic void run() {78 protected void runAt() { 81 79 eventCallback.call(files); 82 80 } -
java/main/src/main/java/com/framsticks/communication/SubscriptionCallback.java
r85 r97 1 1 package com.framsticks.communication; 2 3 import com.framsticks.util.FramsticksException; 4 import com.framsticks.util.dispatching.ExceptionResultHandler; 2 5 3 6 /** 4 7 * @author Piotr Sniegowski 5 8 */ 6 public interface SubscriptionCallback<C> { 7 EventCallback subscribed(Subscription<? super C> subscription); 9 public abstract class SubscriptionCallback<C> implements ExceptionResultHandler { 10 public abstract EventCallback subscribed(Subscription<? super C> subscription); 11 12 @Override 13 public void handle(FramsticksException exception) { 14 throw exception; 15 } 16 8 17 } -
java/main/src/main/java/com/framsticks/communication/util/LoggingStateCallback.java
r96 r97 1 1 package com.framsticks.communication.util; 2 2 3 import com.framsticks.communication. StateCallback;4 import com.framsticks. util.FramsticksException;3 import com.framsticks.communication.ClientSideResponseFuture; 4 import com.framsticks.communication.Response; 5 5 6 6 import org.apache.log4j.Logger; … … 9 9 * @author Piotr Sniegowski 10 10 */ 11 public class LoggingStateCallback <C> extends StateCallback<C>{11 public class LoggingStateCallback extends ClientSideResponseFuture { 12 12 13 13 protected final Logger logger; … … 15 15 16 16 public LoggingStateCallback(Logger logger, String message) { 17 super(null); 17 18 this.logger = logger; 18 19 this.message = message; 19 20 } 20 21 22 // @Override 23 // public void handle(FramsticksException e) { 24 // logger.error("failed to " + message + " with " + e); 25 // } 26 21 27 @Override 22 p ublic void handle(FramsticksExceptione) {23 logger. error("failed to " + message + " with " +e);28 protected void processOk(Response response) { 29 logger.debug(message); 24 30 } 25 31 26 @Override27 public void callImpl() {28 logger.debug(message);29 }30 32 } -
java/main/src/main/java/com/framsticks/communication/util/LoggingSubscriptionCallback.java
r85 r97 9 9 * @author Piotr Sniegowski 10 10 */ 11 public class LoggingSubscriptionCallback<C> implements SubscriptionCallback<C> {11 public class LoggingSubscriptionCallback<C> extends SubscriptionCallback<C> { 12 12 13 13 protected final Logger logger; -
java/main/src/main/java/com/framsticks/core/Framsticks.java
r96 r97 29 29 public static void main(final String[] args) { 30 30 31 new Monitor(loadConfiguration(Framsticks.class.getResourceAsStream("/configs/framsticks.xml"))).use().waitFor().drop().join(); 31 String config = "/configs/framsticks.xml"; 32 if (args.length != 0) { 33 config = args[0]; 34 } 35 36 new Monitor(loadConfiguration(Framsticks.class.getResourceAsStream(config))).use().waitFor().drop().join(); 32 37 33 38 log.debug("exiting main"); -
java/main/src/main/java/com/framsticks/core/Path.java
r96 r97 23 23 // private final static Logger log = Logger.getLogger(Path.class.getName()); 24 24 25 final Instance instance;25 final Tree tree; 26 26 final String textual; 27 27 final LinkedList<Node> nodes; 28 28 29 protected static Object getKnownChild( Instance instance, AccessInterface access, CompositeParam param) {29 protected static Object getKnownChild(Tree tree, AccessInterface access, CompositeParam param) { 30 30 Object child = access.get(param, Object.class); 31 31 if (child == null) { … … 33 33 } 34 34 try { 35 instance.prepareAccess(param);35 tree.prepareAccess(param); 36 36 return child; 37 37 } catch (FramsticksException e) { … … 41 41 42 42 /** 43 * @param instance43 * @param tree 44 44 * @param textual 45 45 * @param nodes 46 46 */ 47 Path( Instance instance, String textual, LinkedList<Node> nodes) {48 this. instance = instance;47 Path(Tree tree, String textual, LinkedList<Node> nodes) { 48 this.tree = tree; 49 49 this.textual = textual; 50 50 this.nodes = nodes; … … 53 53 public Path appendNode(Node node) { 54 54 assert isResolved(); 55 return new PathBuilder(). instance(instance).textual(textual + ((size() == 1) ? "" : "/") + node.getParam().getId()).add(nodes).add(node).finish();55 return new PathBuilder().tree(tree).textual(textual + ((size() == 1) ? "" : "/") + node.getParam().getId()).add(nodes).add(node).finish(); 56 56 } 57 57 … … 63 63 public static class PathBuilder { 64 64 65 Instance instance;65 Tree tree; 66 66 String textual; 67 67 final LinkedList<Node> nodes = new LinkedList<Node>(); 68 68 69 69 public Path finish() { 70 assert instance != null;70 assert tree != null; 71 71 assert textual != null; 72 return new Path( instance, textual, nodes);72 return new Path(tree, textual, nodes); 73 73 } 74 74 … … 77 77 } 78 78 79 public PathBuilder instance(Instance instance) {80 this. instance = instance;79 public PathBuilder tree(Tree tree) { 80 this.tree = tree; 81 81 return this; 82 82 } … … 130 130 } 131 131 132 public PathBuilder resolve(@Nonnull Instance instance, String textual) {132 public PathBuilder resolve(@Nonnull Tree tree, String textual) { 133 133 134 134 assert nodes.isEmpty(); 135 assert instance.isActive();136 this. instance = instance;137 138 nodes.add( instance.getRoot());139 Node current = instance.getRoot();135 assert tree.isActive(); 136 this.tree = tree; 137 138 nodes.add(tree.getRoot()); 139 Node current = tree.getRoot(); 140 140 141 141 StringBuilder b = new StringBuilder(); 142 142 Iterator<String> i = splitPath(textual); 143 143 while (i.hasNext() && current.getObject() != null) { 144 AccessInterface access = instance.prepareAccess(current.getParam());144 AccessInterface access = tree.prepareAccess(current.getParam()); 145 145 if (access == null) { 146 146 break; … … 155 155 b.append("/").append(e); 156 156 access.select(current.getObject()); 157 current = new Node(c, getKnownChild( instance, access, c));157 current = new Node(c, getKnownChild(tree, access, c)); 158 158 nodes.add(current); 159 159 } … … 170 170 public Path appendResolution(Object object) { 171 171 assert !isResolved(); 172 Path result = new PathBuilder().textual(textual). instance(instance).add(nodes).setLast(object).finish();172 Path result = new PathBuilder().textual(textual).tree(tree).add(nodes).setLast(object).finish(); 173 173 assert size() == result.size(); 174 174 return result; … … 193 193 194 194 public String toString() { 195 return instance + textual + (!isResolved() ? "!" : ""); 195 return tree + textual + (!isResolved() ? "!" : ""); 196 } 197 198 public String getFullTextual() { 199 return tree.getName() + textual; 196 200 } 197 201 … … 216 220 } 217 221 218 public final @Nonnull Instance getInstance() {219 assert Dispatching.isThreadSafe(); 220 return instance;222 public final @Nonnull Tree getTree() { 223 assert Dispatching.isThreadSafe(); 224 return tree; 221 225 } 222 226 … … 233 237 */ 234 238 public Path tryFindResolution() { 235 assert instance.isActive();239 assert tree.isActive(); 236 240 assert !isResolved(); 237 241 if (size() == 1) { 238 return Path.build().resolve( instance, "/").finish();//appendResolution(instance.root.object);239 } 240 Object child = getKnownChild( instance, InstanceUtils.bindAccess(instance, getUnder()), getTop().getParam());242 return Path.build().resolve(tree, "/").finish(); 243 } 244 Object child = getKnownChild(tree, TreeOperations.bindAccess(tree, getUnder()), getTop().getParam()); 241 245 if (child == null) { 242 246 return this; … … 247 251 public boolean matches(Path p) { 248 252 assert Dispatching.isThreadSafe(); 249 assert instance == p.instance;253 assert tree == p.tree; 250 254 Iterator<Node> a = nodes.iterator(); 251 255 Iterator<Node> b = p.nodes.iterator(); … … 264 268 } 265 269 266 public final boolean isOwner(Instance instance) { 267 return this.instance == instance; 268 } 269 270 // public void setInstance(Instance instance) { 271 // this.instance = instance; 272 // } 270 public final boolean isOwner(Tree tree) { 271 return this.tree == tree; 272 } 273 273 274 274 @SuppressWarnings("unchecked") … … 284 284 } 285 285 286 public static Path to(@Nonnull Instance instance, String textual) {287 return Path.build().resolve( instance, textual).finish();286 public static Path to(@Nonnull Tree tree, String textual) { 287 return Path.build().resolve(tree, textual).finish(); 288 288 } 289 289 } -
java/main/src/main/java/com/framsticks/diagnostics/Diagnostics.java
r96 r97 11 11 import org.apache.log4j.Logger; 12 12 13 import com.framsticks.core.Abstract InstanceListener;14 import com.framsticks.core. Instance;13 import com.framsticks.core.AbstractTreeListener; 14 import com.framsticks.core.Tree; 15 15 import com.framsticks.core.Path; 16 16 import com.framsticks.dumping.PrintWriterSink; … … 19 19 import com.framsticks.remote.RecursiveFetcher; 20 20 import com.framsticks.util.FramsticksException; 21 import com.framsticks.util.Logging;22 21 import com.framsticks.util.PeriodicTask; 23 import com.framsticks.util.StateFunctor; 22 import com.framsticks.util.dispatching.ExceptionResultHandler; 23 import com.framsticks.util.dispatching.FutureHandler; 24 24 import com.framsticks.util.dispatching.JoinableCollection; 25 import com.framsticks.util.dispatching.ThrowExceptionHandler; 25 26 import com.framsticks.util.io.Encoding; 26 27 … … 28 29 * @author Piotr Sniegowski 29 30 */ 30 public class Diagnostics extends JoinableCollection< Instance> {31 public class Diagnostics extends JoinableCollection<Tree> { 31 32 private static final Logger log = Logger.getLogger(Diagnostics.class); 32 33 … … 41 42 42 43 44 43 45 @Override 44 46 @AutoAppendAnnotation 45 public void add(final Instance instance) {46 super.add( instance);47 public void add(final Tree tree) { 48 super.add(tree); 47 49 48 instance.addListener(new AbstractInstanceListener() {50 tree.addListener(new AbstractTreeListener() { 49 51 @Override 50 52 public void onRun(Exception e) { … … 54 56 55 57 if (dumpsInterval != null) { 56 new PeriodicTask<Instance>(instance, dumpsInterval * 1000) { 58 new PeriodicTask<Tree>(ThrowExceptionHandler.getInstance(), tree, dumpsInterval * 1000) { 59 protected final ExceptionResultHandler repeater = new ExceptionResultHandler() { 60 61 @Override 62 public void handle(FramsticksException exception) { 63 log.error("caught error during diagnostics fetching (repeating): " + exception); 64 again(); 65 } 66 67 }; 57 68 @Override 58 p ublic void run() {69 protected void runAt() { 59 70 60 71 log.info("starting periodic dump"); 61 new RecursiveFetcher(instance, Path.to(instance, "/"), new StateFunctor() { 62 @Override 63 public void handle(FramsticksException e) { 64 Logging.log(log, "recursively fetch", instance, e); 65 again(); 66 } 72 new RecursiveFetcher(tree, Path.to(tree, "/"), new FutureHandler<Void>(repeater) { 67 73 68 74 @Override 69 p ublic void call() {70 log.info(" instance resolved, saving");75 protected void result(Void result) { 76 log.info("tree resolved, saving"); 71 77 try { 72 final String fileName = dumpsPath + "/" + instance + "_" + new SimpleDateFormat(dumpsFormat).format(new Date()) + ".param";78 final String fileName = dumpsPath + "/" + tree + "_" + new SimpleDateFormat(dumpsFormat).format(new Date()) + ".param"; 73 79 File file = new File(fileName); 74 new SaveStream(new PrintWriterSink(new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), Encoding.getFramsticksCharset()))), instance, Path.to(instance, "/"), new StateFunctor() { 75 @Override 76 public void handle(FramsticksException e) { 77 Logging.log(log, "periodic dump in " + fileName + " of", instance, e); 78 again(); 79 } 80 new SaveStream(new PrintWriterSink(new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), Encoding.getFramsticksCharset()))), tree, Path.to(tree, "/"), new FutureHandler<Void>(repeater) { 80 81 81 82 @Override 82 p ublic void call() {83 protected void result(Void result) { 83 84 again(); 84 85 } 85 86 }); 86 } catch (IOException ex) { 87 log.info("failed to initiate dump: " + ex); 88 again(); 87 } catch (IOException e) { 88 throw new FramsticksException().msg("failed to initiate dump").cause(e); 89 89 } 90 91 90 } 92 91 }); -
java/main/src/main/java/com/framsticks/dumping/LoadStream.java
r96 r97 2 2 3 3 import com.framsticks.communication.File; 4 import com.framsticks.core. InstanceUtils;4 import com.framsticks.core.TreeOperations; 5 5 import com.framsticks.core.Path; 6 6 import com.framsticks.params.ListSource; 7 import com.framsticks.core. Instance;7 import com.framsticks.core.Tree; 8 8 import com.framsticks.util.*; 9 9 import com.framsticks.util.dispatching.Future; … … 24 24 private final static Logger log = Logger.getLogger(LoadStream.class.getName()); 25 25 26 protected final Instance instance;26 protected final Tree tree; 27 27 protected final Path mountPath; 28 28 protected final BufferedReader stream; … … 31 31 32 32 33 public LoadStream(Path mountPath, BufferedReader stream, Instance instance, Future<Path> future) {34 this. instance = instance;33 public LoadStream(Path mountPath, BufferedReader stream, Tree tree, Future<Path> future) { 34 this.tree = tree; 35 35 this.mountPath = mountPath; 36 36 this.stream = stream; … … 59 59 if (line.equals("ok")) { 60 60 if (query.first.equals("get")) { 61 Path path = InstanceUtils.createIfNeeded(instance, query.second);62 InstanceUtils.processFetchedValues(path, files);61 Path path = TreeOperations.createIfNeeded(tree, query.second); 62 TreeOperations.processFetchedValues(path, files); 63 63 } else if (query.first.equals("info")) { 64 64 assert files.size() == 1; 65 InstanceUtils.processFetchedInfo(instance, files.get(0));65 TreeOperations.processFetchedInfo(tree, files.get(0)); 66 66 } else { 67 67 assert false; … … 87 87 } 88 88 log.info("loaded in: " + stopwatch); 89 future.pass(Path.to( instance, mountPath.getTextual()));89 future.pass(Path.to(tree, mountPath.getTextual())); 90 90 } 91 91 -
java/main/src/main/java/com/framsticks/dumping/SaveStream.java
r96 r97 1 1 package com.framsticks.dumping; 2 2 3 import static com.framsticks.core. InstanceUtils.*;3 import static com.framsticks.core.TreeOperations.*; 4 4 import com.framsticks.core.Node; 5 5 import com.framsticks.core.Path; … … 10 10 import com.framsticks.params.SinkInterface; 11 11 import com.framsticks.parsers.Savers; 12 import com.framsticks.core. Instance;12 import com.framsticks.core.Tree; 13 13 import com.framsticks.util.*; 14 14 import com.framsticks.util.dispatching.Dispatching; 15 import com.framsticks.util.dispatching.Future; 16 import com.framsticks.util.dispatching.ThrowExceptionHandler; 17 15 18 import org.apache.log4j.Logger; 16 19 import com.framsticks.util.dispatching.RunAt; … … 28 31 29 32 protected final SinkInterface sink; 30 protected final Instance instance;31 protected final StateFunctor stateFunctor;33 protected final Tree tree; 34 protected final Future<Void> future; 32 35 protected final Stopwatch stopwatch = new Stopwatch(); 33 36 protected final Set<FramsClass> storedInfo = new HashSet<FramsClass>(); … … 35 38 private int dispatched = 0; 36 39 37 public SaveStream(SinkInterface sink, Instance instance, Path root, StateFunctor stateFunctor) {40 public SaveStream(SinkInterface sink, Tree tree, Path root, Future<Void> future) { 38 41 assert Dispatching.isThreadSafe(); 39 42 this.sink = sink; 40 this. instance = instance;41 this. stateFunctor = stateFunctor;43 this.tree = tree; 44 this.future = future; 42 45 dispatchWrite(root); 43 46 } … … 45 48 protected void dispatchWrite(final Path path) { 46 49 ++dispatched; 47 instance.dispatch(new RunAt<Instance>() { 50 //TODO TEH 51 tree.dispatch(new RunAt<Tree>(ThrowExceptionHandler.getInstance()) { 48 52 @Override 49 p ublic void run() {53 protected void runAt() { 50 54 write(path); 51 55 } … … 54 58 55 59 protected void finished() { 56 assert instance.isActive();60 assert tree.isActive(); 57 61 log.info("stored in " + stopwatch); 58 stateFunctor.call();62 future.pass(null); 59 63 } 60 64 61 65 public void write(final Path path) { 62 assert instance.isActive();66 assert tree.isActive(); 63 67 if (!path.isResolved()) { 64 68 log.debug("path " + path + " is not resolved - skipping"); -
java/main/src/main/java/com/framsticks/gui/Browser.java
r96 r97 2 2 3 3 import com.framsticks.core.*; 4 import com.framsticks.gui.console.Console; 5 import com.framsticks.gui.console.TrackConsole; 4 6 import com.framsticks.params.annotations.AutoAppendAnnotation; 5 7 import com.framsticks.params.annotations.FramsClassAnnotation; 6 8 import com.framsticks.params.annotations.ParamAnnotation; 9 import com.framsticks.remote.RemoteTree; 10 import com.framsticks.util.FramsticksException; 7 11 import com.framsticks.util.dispatching.AbstractJoinable; 8 12 import com.framsticks.util.dispatching.Dispatcher; 9 13 import com.framsticks.util.dispatching.Dispatching; 14 import com.framsticks.util.dispatching.ExceptionResultHandler; 10 15 import com.framsticks.util.dispatching.Future; 16 import com.framsticks.util.dispatching.FutureHandler; 11 17 import com.framsticks.util.dispatching.Joinable; 12 18 import com.framsticks.util.dispatching.JoinableCollection; … … 19 25 20 26 import java.awt.Dimension; 27 import java.awt.Toolkit; 28 import java.awt.datatransfer.StringSelection; 29 import java.awt.event.ActionEvent; 21 30 import java.util.ArrayList; 31 import java.util.LinkedList; 22 32 import java.util.List; 23 33 import com.framsticks.util.dispatching.RunAt; … … 27 37 */ 28 38 @FramsClassAnnotation 29 public class Browser extends AbstractJoinable implements Dispatcher<Browser>, JoinableParent { 30 31 private static final Logger log = Logger.getLogger(Browser.class.getName()); 32 33 protected JoinableCollection<Frame> frames = new JoinableCollection<Frame>().setObservableName("frames"); 34 protected JoinableCollection<Instance> instances = new JoinableCollection<Instance>().setObservableName("instances"); 35 36 protected MainFrame mainFrame; 37 public List<PanelProvider> panelProviders = new ArrayList<PanelProvider>(); 39 public class Browser extends AbstractJoinable implements Dispatcher<Browser>, JoinableParent, ExceptionResultHandler { 40 41 private static final Logger log = Logger.getLogger(Browser.class); 42 43 protected final JoinableCollection<Frame> frames = new JoinableCollection<Frame>().setObservableName("frames"); 44 protected final JoinableCollection<Tree> trees = new JoinableCollection<Tree>().setObservableName("trees"); 45 protected final JoinableCollection<Console> consoles = new JoinableCollection<Console>().setObservableName("consoles"); 46 47 protected final List<PopupMenuEntryProvider> popupMenuEntryProviders = new LinkedList<>(); 48 49 protected final MainFrame mainFrame; 50 protected final List<PanelProvider> panelProviders = new ArrayList<PanelProvider>(); 38 51 protected Dimension defaultFrameDimension; 39 52 … … 51 64 mainFrame = new MainFrame(Browser.this); 52 65 addFrame(mainFrame); 66 67 addPopupMenuEntryProvider(new PopupMenuEntryProvider() { 68 @Override 69 public void provide(JPopupMenu menu, Path path) { 70 menu.add(new JMenuItem(path.getFullTextual())); 71 menu.addSeparator(); 72 } 73 }); 74 75 addPopupMenuEntryProvider(new PopupMenuEntryProvider() { 76 @SuppressWarnings("serial") 77 @Override 78 public void provide(JPopupMenu menu, final Path path) { 79 menu.add(new AbstractAction("Copy path to clipboard") { 80 @Override 81 public void actionPerformed(ActionEvent e) { 82 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(path.getFullTextual()), null); 83 } 84 }); 85 } 86 }); 87 88 addPopupMenuEntryProvider(new PopupMenuEntryProvider() { 89 @SuppressWarnings("serial") 90 @Override 91 public void provide(JPopupMenu menu, final Path path) { 92 if (!(path.getTree() instanceof RemoteTree)) { 93 return; 94 } 95 final RemoteTree remoteTree = (RemoteTree) path.getTree(); 96 menu.add(new AbstractAction("Open tracking console") { 97 @Override 98 public void actionPerformed(ActionEvent e) { 99 consoles.add(new TrackConsole().setConnection(remoteTree.getConnection())); 100 } 101 }); 102 } 103 }); 104 // addNodeActionToTreePopupMenu("", new NodeAction() ) 105 53 106 } 54 107 … … 60 113 61 114 @AutoAppendAnnotation 62 public void addInstance(Instance instance) { 63 log.info("adding instance: " + instance); 64 instances.add(instance); 115 public void addPopupMenuEntryProvider(PopupMenuEntryProvider popupMenuEntryProvider) { 116 popupMenuEntryProviders.add(popupMenuEntryProvider); 117 } 118 119 @AutoAppendAnnotation 120 public void addTree(Tree tree) { 121 log.info("adding tree: " + tree); 122 trees.add(tree); 65 123 } 66 124 67 125 public void autoResolvePath(final String path, final Future<Path> future) { 68 final Instance i = instances.get("localhost");69 i.dispatch(new RunAt< Instance>() {70 @Override 71 p ublic void run() {72 InstanceUtils.resolveAndFetch(i, path, new Future<Path>(future) {126 final Tree i = trees.get("localhost"); 127 i.dispatch(new RunAt<Tree>(future) { 128 @Override 129 protected void runAt() { 130 TreeOperations.resolveAndGet(i, path, new FutureHandler<Path>(future) { 73 131 @Override 74 132 protected void result(final Path p) { 75 133 future.pass(p); 76 mainFrame.dispatch(new RunAt<Frame>( ) {134 mainFrame.dispatch(new RunAt<Frame>(future) { 77 135 @Override 78 p ublic void run() {136 protected void runAt() { 79 137 mainFrame.goTo(p); 80 138 } … … 93 151 } 94 152 95 protected void initializeGUI() {96 assert isActive();97 log.debug("executing first task");98 99 try {100 boolean found = false;101 // for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {102 // log.info("look and feel available: " + info.getName());103 // if ("Nimbus".equals(info.getName())) {104 // UIManager.setLookAndFeel(info.getClassName());105 // found = true;106 // break;107 // }108 // }109 if (!found) {110 UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");111 }112 } catch (Exception ex) {113 log.warn("failed loading Look&Feel: ", ex);114 }115 116 javax.swing.JFrame.setDefaultLookAndFeelDecorated(true);117 118 119 for (Frame f : frames) {120 f.configure();121 }122 123 for (final Instance i : instances) {124 i.dispatch(new RunAt<Instance>() {125 @Override126 public void run() {127 final Path p = Path.to(i, "/");128 dispatch(new RunAt<Browser>() {129 @Override130 public void run() {131 mainFrame.addRootPath(p);132 }133 });134 }135 });136 }137 138 for (Frame f : frames) {139 f.getSwing().setVisible(true);140 }141 142 // autoResolvePath("/simulator/genepools/groups/0", null);143 // autoResolvePath("/", null);144 }145 146 153 public void createTreeNodeForChild(final Path path) { 147 154 assert !isActive(); 148 //assert instance.isActive();155 //assert tree.isActive(); 149 156 150 157 /* … … 174 181 protected void joinableStart() { 175 182 Dispatching.use(frames, this); 176 Dispatching.use(instances, this); 177 178 dispatch(new RunAt<Browser>() { 179 @Override 180 public void run() { 181 initializeGUI(); 182 } 183 }); 184 } 185 186 /** 187 * @return the instances 188 */ 189 public JoinableCollection<Instance> getInstances() { 190 return instances; 183 Dispatching.use(trees, this); 184 Dispatching.use(consoles, this); 185 186 dispatch(new RunAt<Browser>(this) { 187 @Override 188 protected void runAt() { 189 190 for (final Tree i : trees) { 191 i.dispatch(new RunAt<Tree>(this) { 192 @Override 193 protected void runAt() { 194 final Path p = Path.to(i, "/"); 195 dispatch(new RunAt<Browser>(this) { 196 @Override 197 protected void runAt() { 198 mainFrame.addRootPath(p); 199 } 200 }); 201 } 202 }); 203 } 204 } 205 }); 206 } 207 208 /** 209 * @return the tree 210 */ 211 public JoinableCollection<Tree> getTrees() { 212 return trees; 191 213 } 192 214 … … 227 249 protected void joinableJoin() throws InterruptedException { 228 250 Dispatching.join(frames); 229 Dispatching.join(instances); 251 Dispatching.join(trees); 252 Dispatching.join(consoles); 230 253 // super.join(); 231 254 } … … 233 256 @Override 234 257 protected void joinableInterrupt() { 258 Dispatching.drop(consoles, this); 235 259 Dispatching.drop(frames, this); 236 Dispatching.drop( instances, this);260 Dispatching.drop(trees, this); 237 261 } 238 262 … … 255 279 } 256 280 281 @Override 282 public void handle(FramsticksException exception) { 283 mainFrame.handle(exception); 284 } 257 285 258 286 // @Override 259 287 // public boolean isDone() { 260 // return frames.isDone() && instances.isDone();288 // return frames.isDone() && trees.isDone(); 261 289 // } 262 290 } -
java/main/src/main/java/com/framsticks/gui/Frame.java
r96 r97 1 1 package com.framsticks.gui; 2 2 3 import com.framsticks.core.Instance; 4 import com.framsticks.core.Path; 5 import com.framsticks.gui.view.*; 6 import com.framsticks.gui.view.TreeCellRenderer; 7 import com.framsticks.util.dispatching.Dispatcher; 8 import com.framsticks.util.dispatching.JoinableCollection; 9 import com.framsticks.util.lang.ScopeEnd; 10 import com.framsticks.util.swing.KeyboardModifier; 11 import com.framsticks.util.swing.MenuConstructor; 12 13 import org.apache.log4j.Logger; 14 15 import javax.swing.*; 3 import java.awt.BorderLayout; 4 import java.awt.CardLayout; 5 import java.awt.Color; 6 import java.awt.Container; 7 import java.awt.Dimension; 8 import java.awt.Toolkit; 9 import java.awt.event.ActionEvent; 10 import java.awt.event.KeyEvent; 11 import java.awt.event.MouseAdapter; 12 import java.awt.event.MouseEvent; 13 import java.util.HashMap; 14 import java.util.Map; 15 16 import javax.swing.AbstractAction; 17 import javax.swing.BorderFactory; 18 import javax.swing.JComponent; 19 import javax.swing.JMenu; 20 import javax.swing.JMenuBar; 21 import javax.swing.JMenuItem; 22 import javax.swing.JPanel; 23 import javax.swing.JPopupMenu; 24 import javax.swing.JScrollPane; 25 import javax.swing.JSplitPane; 26 import javax.swing.JTree; 27 import javax.swing.KeyStroke; 28 import javax.swing.ToolTipManager; 29 import javax.swing.UIManager; 16 30 import javax.swing.event.TreeModelEvent; 17 31 import javax.swing.event.TreeModelListener; 18 32 import javax.swing.event.TreeSelectionEvent; 19 33 import javax.swing.event.TreeSelectionListener; 20 import javax.swing.tree.*; 21 22 import java.awt.*; 23 import java.awt.datatransfer.StringSelection; 24 import java.awt.event.*; 25 import java.util.HashMap; 26 import java.util.Map; 34 import javax.swing.tree.DefaultMutableTreeNode; 35 import javax.swing.tree.DefaultTreeModel; 36 import javax.swing.tree.DefaultTreeSelectionModel; 37 import javax.swing.tree.TreePath; 38 import javax.swing.tree.TreeSelectionModel; 39 40 import org.apache.log4j.Logger; 41 42 import com.framsticks.core.Path; 43 import com.framsticks.core.Tree; 44 import com.framsticks.gui.view.TreeCellRenderer; 45 import com.framsticks.util.FramsticksException; 46 import com.framsticks.util.dispatching.Dispatching; 47 import com.framsticks.util.dispatching.ExceptionResultHandler; 48 import com.framsticks.util.dispatching.Joinable; 49 import com.framsticks.util.dispatching.JoinableCollection; 50 import com.framsticks.util.dispatching.JoinableParent; 51 import com.framsticks.util.dispatching.JoinableState; 27 52 import com.framsticks.util.dispatching.RunAt; 53 import com.framsticks.util.lang.ScopeEnd; 54 import com.framsticks.util.swing.KeyboardModifier; 55 import com.framsticks.util.swing.MenuConstructor; 28 56 29 57 /** … … 31 59 */ 32 60 @SuppressWarnings("serial") 33 public class Frame extends JoinableCollection<Instance> implements Dispatcher<Frame>{61 public class Frame extends FrameJoinable implements JoinableParent { 34 62 35 63 private static final Logger log = Logger.getLogger(Frame.class.getName()); … … 42 70 protected JPanel cardPanel; 43 71 44 protected final String title;45 protected JFrame swing;46 72 protected JScrollPane treeScrollPane; 47 protected JTree tree;73 protected JTree jtree; 48 74 protected DefaultTreeModel treeModel; 49 75 protected javax.swing.tree.MutableTreeNode rootNode; 50 //final Instance instance;51 76 protected JPanel treePanel; 52 77 protected JPopupMenu treePopupMenu; … … 54 79 55 80 TreeNode currentlyPoppedTreeNode; 56 protected JLabel statusBar;57 81 protected JPanel mainPanel; 58 82 protected JPanel leftPanel; … … 67 91 protected JMenu helpMenu; 68 92 69 protected final Map< Instance, InstanceAtFrame> instancesAtFrames = new HashMap<Instance, InstanceAtFrame>();70 71 public Frame(String title, Browser browser) { 72 this.title = title;93 protected final Map<Tree, TreeAtFrame> treeAtFrames = new HashMap<Tree, TreeAtFrame>(); 94 protected JoinableCollection<Tree> trees = new JoinableCollection<Tree>(); 95 96 public Frame(Browser browser) { 73 97 this.browser = browser; 74 98 } 75 99 76 public void configure() { 77 swing = new JFrame(title); 78 swing.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); 79 swing.addWindowListener(new WindowAdapter() { 80 @Override 81 public void windowClosing(WindowEvent e) { 82 log.info("received closing"); 83 interrupt(); 84 } 85 }); 100 protected void initializeGui() { 101 super.initializeGui(); 86 102 /** this is done to remove the current value label from above the slider, 87 103 * because it cannot put to work properly with floating-point value sliders, … … 90 106 log.debug("creating " + this); 91 107 92 statusBar = new JLabel("not connected"); 93 94 Container contentPane = swing.getContentPane(); 95 contentPane.setLayout(new BorderLayout()); 96 108 109 Container contentPane = getSwing().getContentPane(); 97 110 treePopupMenu = new JPopupMenu("title"); 98 111 treePopupMenu.setName("popup"); 99 treePopupMenuHeader = new JMenuItem();100 treePopupMenuHeader.setForeground(Color.BLUE);101 treePopupMenu.add(treePopupMenuHeader);102 treePopupMenu.addSeparator();103 //TODO: add to favourites104 //TODO: remove from favourites105 //TODO: open in new window as root106 //TODO: refresh107 //TODO: open in console108 109 treePopupMenu.add(new JMenuItem("Refresh"));110 treePopupMenu.add(new JMenuItem("Open in new frame as root"));111 addNodeActionToTreePopupMenu("Copy path to clipboard", new NodeAction() {112 @Override113 public void actionPerformed(TreeNode treeNode) {114 Path path = treeNode.getInstancePath();115 StringSelection selection = new StringSelection(path.toString());116 swing.getToolkit().getSystemClipboard().setContents(selection, selection);117 }118 });119 //this.add(createMenuItem("Add to favourites", null));120 //this.add(createMenuItem("Remove from favourites", null));121 112 122 113 treePanel = new JPanel(); … … 147 138 }); 148 139 149 tree = new JTree(treeModel);150 tree.setName("tree");151 tree.setRootVisible(false);152 tree.setExpandsSelectedPaths(true);153 tree.setSelectionModel(new DefaultTreeSelectionModel());154 ToolTipManager.sharedInstance().registerComponent( tree);155 156 tree.addTreeSelectionListener(new TreeSelectionListener() {140 jtree = new JTree(treeModel); 141 jtree.setName("tree"); 142 jtree.setRootVisible(false); 143 jtree.setExpandsSelectedPaths(true); 144 jtree.setSelectionModel(new DefaultTreeSelectionModel()); 145 ToolTipManager.sharedInstance().registerComponent(jtree); 146 147 jtree.addTreeSelectionListener(new TreeSelectionListener() { 157 148 @Override 158 149 public void valueChanged(TreeSelectionEvent e) { … … 161 152 }); 162 153 163 tree.setExpandsSelectedPaths(true);164 tree.setEditable(false);165 tree.setDoubleBuffered(true);166 tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);167 tree.setShowsRootHandles(true);168 tree.setRowHeight(26);169 tree.setDoubleBuffered(true);170 tree.addMouseListener(new MouseAdapter() {154 jtree.setExpandsSelectedPaths(true); 155 jtree.setEditable(false); 156 jtree.setDoubleBuffered(true); 157 jtree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); 158 jtree.setShowsRootHandles(true); 159 jtree.setRowHeight(26); 160 jtree.setDoubleBuffered(true); 161 jtree.addMouseListener(new MouseAdapter() { 171 162 @Override 172 163 public void mousePressed(MouseEvent e) { … … 182 173 }); 183 174 184 new KeyboardModifier( tree, JComponent.WHEN_FOCUSED).join(KeyStroke.getKeyStroke('h'), KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)).join(KeyStroke.getKeyStroke('j'), KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)).join(KeyStroke.getKeyStroke('k'), KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)).join(KeyStroke.getKeyStroke('l'), KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));185 186 tree.setCellRenderer(new TreeCellRenderer());187 188 treeScrollPane = new JScrollPane( tree);175 new KeyboardModifier(jtree, JComponent.WHEN_FOCUSED).join(KeyStroke.getKeyStroke('h'), KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)).join(KeyStroke.getKeyStroke('j'), KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)).join(KeyStroke.getKeyStroke('k'), KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)).join(KeyStroke.getKeyStroke('l'), KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0)); 176 177 jtree.setCellRenderer(new TreeCellRenderer()); 178 179 treeScrollPane = new JScrollPane(jtree); 189 180 treeScrollPane.setBorder(BorderFactory.createEmptyBorder()); 190 181 … … 215 206 contentPane.add(menuBar, BorderLayout.NORTH); 216 207 contentPane.add(mainPanel, BorderLayout.CENTER); 217 contentPane.add(statusBar, BorderLayout.SOUTH);218 208 219 209 leftPanel = new JPanel(); … … 246 236 cardPanel.setLayout(cardPanelLayout); 247 237 248 swing.pack();249 tree.requestFocusInWindow();238 getSwing().pack(); 239 jtree.requestFocusInWindow(); 250 240 251 241 log.debug("frame configured: " + this); … … 266 256 public void addRootPath(Path path) { 267 257 assert isActive(); 268 Instance instance = path.getInstance();269 assert browser.get Instances().contains(instance);270 271 InstanceAtFrame e = new InstanceAtFrame(instance, this);272 instance.addListener(e);273 instancesAtFrames.put(instance, e);258 Tree tree = path.getTree(); 259 assert browser.getTrees().contains(tree); 260 261 TreeAtFrame e = new TreeAtFrame(tree, this); 262 tree.addListener(e); 263 treeAtFrames.put(tree, e); 274 264 TreeNode node = new TreeNode(e, path); 275 265 e.rootTreeNode = node; 276 266 treeModel.insertNodeInto(node, rootNode, rootNode.getChildCount()); 277 tree.expandPath(new TreePath(rootNode)); 278 } 279 280 @Override 281 public boolean isActive() { 282 return SwingDispatcher.instance.isActive(); 283 } 284 285 @Override 286 public void dispatch(RunAt<? extends Frame> runnable) { 287 SwingDispatcher.getInstance().dispatch(runnable); 288 } 289 290 public Action addActionToTreePopupMenu(Action action) { 291 assert isActive(); 292 treePopupMenu.add(action); 293 return action; 294 } 295 296 public Action addNodeActionToTreePopupMenu(String title, final NodeAction nodeAction) { 297 assert isActive(); 298 return addActionToTreePopupMenu(new AbstractAction(title) { 299 @Override 300 public void actionPerformed(ActionEvent e) { 301 TreeNode treeNode = getCurrentlyPoppedTreeNode(); 302 if (treeNode == null) { 303 return; 304 } 305 nodeAction.actionPerformed(treeNode); 306 } 307 }); 308 } 267 jtree.expandPath(new TreePath(rootNode)); 268 } 269 309 270 310 271 public void showPanel(Panel panel) { … … 319 280 return; 320 281 } 321 currentlyPoppedTreeNode = findTreeNodeByTreePath( tree.getPathForLocation(e.getX(), e.getY()));282 currentlyPoppedTreeNode = findTreeNodeByTreePath(jtree.getPathForLocation(e.getX(), e.getY())); 322 283 if (currentlyPoppedTreeNode == null) { 323 284 return; 324 285 } 286 287 Path path = currentlyPoppedTreeNode.getTreePath(); 288 treePopupMenu.removeAll(); 289 290 for (PopupMenuEntryProvider provider : browser.popupMenuEntryProviders) { 291 provider.provide(treePopupMenu, path); 292 } 293 // treePopupMenuHeader.setText(path.getTree().getName() + path.getTextual()); 325 294 treePopupMenu.show(e.getComponent(), e.getX(), e.getY()); 326 295 //currentlyPoppedPanel.getNode().getFramsClass().getName() 327 //treePopupMenuHeader.setText(currentlyPoppedTreeNode.getNode().getPath());328 }329 330 /**331 * @return the swing332 */333 public JFrame getSwing() {334 return swing;335 296 } 336 297 … … 344 305 cardPanel.removeAll(); 345 306 cardPanel.updateUI(); 346 tree.setEnabled(false);307 jtree.setEnabled(false); 347 308 } 348 309 349 310 public ScopeEnd startChange(final DefaultMutableTreeNode node) { 350 311 assert isActive(); 351 final TreePath selection = tree.getSelectionPath();312 final TreePath selection = jtree.getSelectionPath(); 352 313 return new ScopeEnd() { 353 314 @Override … … 355 316 assert isActive(); 356 317 treeModel.nodeChanged(node); 357 tree.setSelectionPath(selection);318 jtree.setSelectionPath(selection); 358 319 } 359 320 }; … … 391 352 } 392 353 354 protected final ExceptionResultHandler dialogHandler = new ExceptionResultHandler() { 355 356 @Override 357 public void handle(FramsticksException exception) { 358 //TODO TEH 359 throw exception; 360 361 } 362 }; 363 393 364 public void goTo(Path path) { 394 365 assert isActive(); 395 final TreePath treePath = instancesAtFrames.get(path.getInstance()).getTreePath(path, false);366 final TreePath treePath = treeAtFrames.get(path.getTree()).getTreePath(path, false); 396 367 log.info("go to path: " + path + "(" + treePath + ")"); 397 368 398 new RunAt<Frame>(this) {399 @Override 400 p ublic void run() {369 this.dispatch(new RunAt<Frame>(dialogHandler) { 370 @Override 371 protected void runAt() { 401 372 log.info("executed"); 402 tree.setSelectionPath(treePath);403 tree.makeVisible(treePath);404 assert tree.isVisible(treePath);405 } 406 } ;373 jtree.setSelectionPath(treePath); 374 jtree.makeVisible(treePath); 375 assert jtree.isVisible(treePath); 376 } 377 }); 407 378 408 379 } … … 422 393 423 394 @Override 395 protected void joinableStart() { 396 super.joinableStart(); 397 Dispatching.use(trees, this); 398 } 399 400 @Override 424 401 protected void joinableInterrupt() { 425 assert isActive();402 Dispatching.drop(trees, this); 426 403 super.joinableInterrupt(); 427 428 dispatch(new RunAt<Frame>() {429 @Override430 public void run() {431 finish();432 }433 });434 404 } 435 405 436 406 @Override 437 407 protected void joinableFinish() { 438 assert isActive(); 439 log.debug("disposing frame " + this); 440 swing.dispose(); 441 } 442 443 // @Override 444 // public boolean isDone() { 445 // return super.isDone() && !swing.isDisplayable(); 446 // } 447 448 449 @Override 450 public String getName() { 451 return title; 452 } 453 408 super.joinableFinish(); 409 } 410 411 @Override 412 protected void joinableJoin() throws InterruptedException { 413 Dispatching.join(trees); 414 super.joinableJoin(); 415 } 416 417 @Override 418 public void childChangedState(Joinable joinable, JoinableState state) { 419 if (joinable == trees) { 420 proceedToState(state); 421 } 422 } 454 423 455 424 } -
java/main/src/main/java/com/framsticks/gui/Gui.java
r90 r97 45 45 46 46 public static Control createComponentForText(PrimitiveParam<?> valueParam) { 47 if (valueParam.getM in(Object.class) != null) {48 return new Text AreaControl(valueParam);47 if (valueParam.getMax(Object.class) != null) { 48 return new TextFieldControl(valueParam); 49 49 } 50 return new TextFieldControl(valueParam); 50 return new TextAreaControl(valueParam); 51 52 53 // if (valueParam.getMin(Object.class) != null) { 54 // return new TextAreaControl(valueParam); 55 // } 56 // return new TextFieldControl(valueParam); 51 57 } 52 58 … … 64 70 return new SliderControl(decimalParam); 65 71 } 66 return createComponentForText(decimalParam);72 return new TextFieldControl(decimalParam); 67 73 } 68 74 if (param instanceof FloatParam) { … … 71 77 return new SliderControl(floatParam); 72 78 } 73 return createComponentForText(floatParam);79 return new TextFieldControl(floatParam); 74 80 } 75 81 if (param instanceof StringParam) { 76 return createComponentForText((StringParam) param);82 return createComponentForText((StringParam) param); 77 83 } 78 84 if (param instanceof ProcedureParam) { 79 return new ProcedureControl((ProcedureParam) param);85 return new ProcedureControl((ProcedureParam) param); 80 86 } 81 87 if (param instanceof BinaryParam) { 82 return createComponentForText((BinaryParam)param);88 return new TextFieldControl((BinaryParam) param); 83 89 } 84 90 if (param instanceof ColorParam) { 85 return createComponentForText((ColorParam) param);91 return new TextFieldControl((ColorParam) param); 86 92 } 87 93 if (param instanceof UniversalParam) { 88 return new TextAreaControl((UniversalParam) param);94 return new TextAreaControl((UniversalParam) param); 89 95 } 90 96 if (param instanceof EventParam) { 91 return new EventControl((EventParam) param);97 return new EventControl((EventParam) param); 92 98 } 93 99 return null; -
java/main/src/main/java/com/framsticks/gui/MainFrame.java
r88 r97 1 1 package com.framsticks.gui; 2 2 3 import com.framsticks.gui.windows.console.ConsoleFrame;4 import com.framsticks.util.swing.MenuConstructor;5 import org.apache.log4j.Logger;6 7 import javax.swing.*;8 import javax.swing.border.TitledBorder;9 import java.awt.*;10 3 import java.awt.event.ActionEvent; 11 import java.awt.event.ActionListener;12 4 import java.awt.event.KeyEvent; 13 5 import java.awt.event.WindowAdapter; 14 6 import java.awt.event.WindowEvent; 7 8 import javax.swing.AbstractAction; 9 import javax.swing.JButton; 10 import javax.swing.KeyStroke; 11 import javax.swing.WindowConstants; 12 13 import org.apache.log4j.Logger; 14 15 import com.framsticks.util.swing.MenuConstructor; 15 16 16 17 /** … … 28 29 */ 29 30 public MainFrame(final Browser browser) { 30 super("framsticks", browser); 31 super(browser); 32 setTitle("framsticks"); 31 33 log.debug("creating main frame"); 32 34 … … 35 37 36 38 @Override 37 p ublic void configure() {38 super. configure();39 protected void initializeGui() { 40 super.initializeGui(); 39 41 40 42 new MenuConstructor(fileMenu) … … 42 44 @Override 43 45 public void actionPerformed(ActionEvent actionEvent) { 44 showConsoleFrame();46 // showConsoleFrame(); 45 47 } 46 48 }) … … 145 147 // } 146 148 147 public void setSimulationRunning(final boolean run) { 148 assert isActive(); 149 /* 150 remoteInstance.invokeLater(new Runnable() { 151 @Override 152 public void run() { 153 remoteInstance.setRunning(run); 154 } 155 }); 156 */ 157 } 158 159 /** 160 * Creates panel with start, step, stop buttons. 161 */ 162 @Override 163 protected JPanel createLeftTopPanel() { 164 assert isActive(); 165 Dimension buttonDimension = new Dimension(45, 45); 166 167 JPanel panel = new JPanel(); 168 169 stop = new JButton(ImageProvider.loadImage(ImageProvider.SIM_STOP)); 170 stop.addActionListener(new ActionListener() { 171 172 public void actionPerformed(ActionEvent e) { 173 setSimulationRunning(false); 174 } 175 176 }); 177 178 stop.setPreferredSize(buttonDimension); 179 stop.setToolTipText("Simulation Stop"); 180 stop.setEnabled(false); 181 182 step = new JButton(ImageProvider.loadImage(ImageProvider.SIM_STEP)); 183 /* 184 step.addActionListener(new ActionListener() { 185 186 public void actionPerformed(ActionEvent e) { 187 connection.send(new CallQuery().setMethod("step").setPath("/simulator")); 188 } 189 190 }); 191 */ 192 193 step.setPreferredSize(buttonDimension); 194 step.setToolTipText("Simulation Step"); 195 196 start = new JButton(ImageProvider.loadImage(ImageProvider.SIM_START)); 197 start.addActionListener(new ActionListener() { 198 199 public void actionPerformed(ActionEvent e) { 200 setSimulationRunning(true); 201 } 202 203 }); 204 205 start.setPreferredSize(buttonDimension); 206 start.setToolTipText("Start Simulation"); 207 208 JPanel buttonPanel = new JPanel(); 209 buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS)); 210 buttonPanel.add(Box.createHorizontalStrut(5)); 211 buttonPanel.add(stop); 212 buttonPanel.add(Box.createHorizontalStrut(10)); 213 buttonPanel.add(step); 214 buttonPanel.add(Box.createHorizontalStrut(10)); 215 buttonPanel.add(start); 216 buttonPanel.add(Box.createHorizontalStrut(5)); 217 218 buttonPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory 219 .createRaisedBevelBorder(), "Simulation Control", 220 TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION 221 )); 222 223 panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS)); 224 panel.add(Box.createHorizontalGlue()); 225 panel.add(buttonPanel); 226 panel.add(Box.createHorizontalGlue()); 227 return panel; 228 } 149 150 // /** 151 // * Creates panel with start, step, stop buttons. 152 // */ 153 // @Override 154 // protected JPanel createLeftTopPanel() { 155 // assert isActive(); 156 // Dimension buttonDimension = new Dimension(45, 45); 157 158 // JPanel panel = new JPanel(); 159 160 // stop = new JButton(ImageProvider.loadImage(ImageProvider.SIM_STOP)); 161 // stop.addActionListener(new ActionListener() { 162 163 // public void actionPerformed(ActionEvent e) { 164 // setSimulationRunning(false); 165 // } 166 167 // }); 168 169 // stop.setPreferredSize(buttonDimension); 170 // stop.setToolTipText("Simulation Stop"); 171 // stop.setEnabled(false); 172 173 // step = new JButton(ImageProvider.loadImage(ImageProvider.SIM_STEP)); 174 // /* 175 // step.addActionListener(new ActionListener() { 176 177 // public void actionPerformed(ActionEvent e) { 178 // connection.send(new CallQuery().setMethod("step").setPath("/simulator")); 179 // } 180 181 // }); 182 // */ 183 184 // step.setPreferredSize(buttonDimension); 185 // step.setToolTipText("Simulation Step"); 186 187 // start = new JButton(ImageProvider.loadImage(ImageProvider.SIM_START)); 188 // start.addActionListener(new ActionListener() { 189 190 // public void actionPerformed(ActionEvent e) { 191 // setSimulationRunning(true); 192 // } 193 194 // }); 195 196 // start.setPreferredSize(buttonDimension); 197 // start.setToolTipText("Start Simulation"); 198 199 // JPanel buttonPanel = new JPanel(); 200 // buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS)); 201 // buttonPanel.add(Box.createHorizontalStrut(5)); 202 // buttonPanel.add(stop); 203 // buttonPanel.add(Box.createHorizontalStrut(10)); 204 // buttonPanel.add(step); 205 // buttonPanel.add(Box.createHorizontalStrut(10)); 206 // buttonPanel.add(start); 207 // buttonPanel.add(Box.createHorizontalStrut(5)); 208 209 // buttonPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory 210 // .createRaisedBevelBorder(), "Simulation Control", 211 // TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION 212 // )); 213 214 // panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS)); 215 // panel.add(Box.createHorizontalGlue()); 216 // panel.add(buttonPanel); 217 // panel.add(Box.createHorizontalGlue()); 218 // return panel; 219 // } 229 220 230 221 /** … … 233 224 private void setFrameProperties() { 234 225 assert isActive(); 235 swing.setMinimumSize(swing.getPreferredSize());236 swing.setSize(swing.getPreferredSize());237 swing.setMaximumSize(screenDimension);238 swing.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);239 240 swing.setIconImage(ImageProvider.loadImage(ImageProvider.LOGO)226 getSwing().setMinimumSize(getSwing().getPreferredSize()); 227 getSwing().setSize(getSwing().getPreferredSize()); 228 getSwing().setMaximumSize(screenDimension); 229 getSwing().setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 230 231 getSwing().setIconImage(ImageProvider.loadImage(ImageProvider.LOGO) 241 232 .getImage()); 242 233 243 234 244 swing.addWindowListener(new WindowAdapter() {235 getSwing().addWindowListener(new WindowAdapter() { 245 236 public void windowClosing(WindowEvent e) { 246 237 assert isActive(); … … 251 242 */ 252 243 onWindowClosing(); 253 swing.dispose();244 getSwing().dispose(); 254 245 } 255 246 }); 256 247 } 257 248 258 public ConsoleFrame showConsoleFrame() {259 assert isActive();260 /*261 ConsoleFrame consoleFrame = new ConsoleFrame(connection);262 consoleFrame.show(MainFrame.this);263 return consoleFrame;264 */265 return null;266 }249 // public ConsoleFrame showConsoleFrame() { 250 // assert isActive(); 251 // /* 252 // ConsoleFrame consoleFrame = new ConsoleFrame(connection); 253 // consoleFrame.show(MainFrame.this); 254 // return consoleFrame; 255 // */ 256 // return null; 257 // } 267 258 268 259 /** … … 271 262 private void disconnect() { 272 263 assert isActive(); 273 //remoteInstance.disconnect();274 264 browser.clear(); 275 265 onWindowClosing(); 276 statusBar.setText("You are disconnected");266 // statusBar.setText("You are disconnected"); 277 267 } 278 268 -
java/main/src/main/java/com/framsticks/gui/ModifiablePanel.java
r84 r97 39 39 40 40 applyButton = new JButton("Apply"); 41 applyButton.setName("apply"); 42 41 43 applyButton.addActionListener(new ActionListener() { 42 44 public void actionPerformed(ActionEvent e) { -
java/main/src/main/java/com/framsticks/gui/MultiPanel.java
r88 r97 24 24 for (Panel p : panels) { 25 25 assert p.getClassName().equals(getClassName()); 26 assert p.get InstanceAtFrame() == getInstanceAtFrame();26 assert p.getTreeAtFrame() == getTreeAtFrame(); 27 27 tabbedPane.add(p.getTitle(), p); 28 28 } -
java/main/src/main/java/com/framsticks/gui/ObjectPanel.java
r90 r97 17 17 import java.util.Map; 18 18 import static com.framsticks.util.lang.Containers.filterInstanceof; 19 20 import com.framsticks.util.FramsticksException; 19 21 import com.framsticks.util.dispatching.RunAt; 20 22 … … 70 72 public void pullValuesFromLocalToUser(AccessInterface access) { 71 73 assert currentTreeNode != null; 72 assert currentTreeNode.path.get Instance().isActive();74 assert currentTreeNode.path.getTree().isActive(); 73 75 log.debug("refreshing components"); 74 76 … … 78 80 } 79 81 80 frame.dispatch(new RunAt<Frame>( ) {82 frame.dispatch(new RunAt<Frame>(frame) { 81 83 @Override 82 p ublic void run() {84 protected void runAt() { 83 85 if (currentTreeNode.localChanges != null) { 84 86 for (Map.Entry<ValueControl, Object> e : currentTreeNode.localChanges.entrySet()) { … … 111 113 } 112 114 115 @Override 116 public void handle(FramsticksException exception) { 117 frame.handle(exception); 118 } 119 113 120 // public void updateValue() { 114 121 // //assert panel.getFrame().isActive(); -
java/main/src/main/java/com/framsticks/gui/Panel.java
r88 r97 15 15 16 16 public static class Parameters { 17 public final InstanceAtFrame instanceAtFrame;17 public final TreeAtFrame treeAtFrame; 18 18 public final CompositeParam param; 19 19 public final FramsClass framsClass; 20 20 21 public Parameters( InstanceAtFrame instanceAtFrame, CompositeParam param, FramsClass framsClass) {22 this. instanceAtFrame = instanceAtFrame;21 public Parameters(TreeAtFrame treeAtFrame, CompositeParam param, FramsClass framsClass) { 22 this.treeAtFrame = treeAtFrame; 23 23 this.param = param; 24 24 this.framsClass = framsClass; … … 29 29 30 30 protected TreeNode currentTreeNode; 31 protected final InstanceAtFrame instanceAtFrame;31 protected final TreeAtFrame treeAtFrame; 32 32 protected final Frame frame; 33 33 protected final String className; … … 37 37 38 38 public Panel(Parameters parameters) { 39 this. instanceAtFrame = parameters.instanceAtFrame;40 this.frame = parameters. instanceAtFrame.getFrame();39 this.treeAtFrame = parameters.treeAtFrame; 40 this.frame = parameters.treeAtFrame.getFrame(); 41 41 this.framsClass = parameters.framsClass; 42 42 this.param = parameters.param; … … 57 57 } 58 58 59 public final InstanceAtFrame getInstanceAtFrame() {60 return instanceAtFrame;59 public final TreeAtFrame getTreeAtFrame() { 60 return treeAtFrame; 61 61 } 62 62 -
java/main/src/main/java/com/framsticks/gui/SwingDispatcher.java
r90 r97 3 3 import com.framsticks.util.dispatching.Dispatcher; 4 4 import com.framsticks.util.dispatching.Task; 5 import com.framsticks.util.dispatching.ThrowExceptionHandler; 5 6 6 7 import javax.swing.*; … … 21 22 22 23 public SwingDispatcher() { 23 dispatch(new RunAt<C>( ) {24 dispatch(new RunAt<C>(ThrowExceptionHandler.getInstance()) { 24 25 @Override 25 p ublic void run() {26 protected void runAt() { 26 27 Thread.currentThread().setName("gui"); 27 28 } -
java/main/src/main/java/com/framsticks/gui/TreeNode.java
r96 r97 1 1 package com.framsticks.gui; 2 2 3 import com.framsticks.communication.Connection;4 3 import com.framsticks.communication.Subscription; 5 4 import com.framsticks.communication.util.LoggingStateCallback; 6 import com.framsticks.core.Instance; 7 import com.framsticks.core.InstanceUtils; 5 import com.framsticks.core.Mode; 6 import com.framsticks.core.Tree; 7 import com.framsticks.core.TreeOperations; 8 8 import com.framsticks.core.ListChange; 9 9 import com.framsticks.core.Path; … … 18 18 import com.framsticks.util.lang.Holder; 19 19 import com.framsticks.util.swing.TooltipConstructor; 20 import com.framsticks.util.dispatching.Future; 21 import com.framsticks.util.AbstractStateFunctor; 20 import com.framsticks.util.dispatching.ExceptionResultHandler; 21 import com.framsticks.util.dispatching.FutureHandler; 22 import com.framsticks.util.FramsticksException; 22 23 import com.framsticks.util.Logging; 23 24 import org.apache.log4j.Logger; … … 31 32 import static com.framsticks.util.lang.Containers.filterInstanceof; 32 33 import com.framsticks.util.swing.TreeNodeUtils; 33 import static com.framsticks.core. InstanceUtils.*;34 import static com.framsticks.core.TreeOperations.*; 34 35 35 36 /** … … 37 38 */ 38 39 @SuppressWarnings("serial") 39 public class TreeNode extends DefaultMutableTreeNode implements NodeListener {40 public class TreeNode extends DefaultMutableTreeNode implements NodeListener, ExceptionResultHandler { 40 41 41 42 private static final Logger log = Logger.getLogger(TreeNode.class.getName()); … … 44 45 45 46 final protected Frame frame; 46 final protected InstanceAtFrame instanceAtFrame;47 final protected TreeAtFrame treeAtFrame; 47 48 48 49 final protected Map<EventParam, Subscription<?>> userSubscriptions = new HashMap<>(); … … 50 51 protected String tooltip; 51 52 protected String name; 52 protected final String paramId;53 protected final CompositeParam param; 53 54 protected String iconName; 54 55 protected Path path; 55 56 56 public TreeNode( InstanceAtFrame instanceAtFrame, final Path path) {57 this.frame = instanceAtFrame.getFrame();58 assert frame.isActive(); 59 this.param Id = path.getLastElement();60 this.name = this.param Id;57 public TreeNode(TreeAtFrame treeAtFrame, final Path path) { 58 this.frame = treeAtFrame.getFrame(); 59 assert frame.isActive(); 60 this.param = path.getTop().getParam(); 61 this.name = this.param.getId(); 61 62 log.debug("creating treenode " + name + ": " + path); 62 63 this.path = path; 63 this. instanceAtFrame = instanceAtFrame;64 this.treeAtFrame = treeAtFrame; 64 65 65 66 iconName = TreeCellRenderer.findIconName(name, path.getTextual()); 66 67 tooltip = "?"; 67 path.get Instance().dispatch(new RunAt<Instance>() {68 @Override 69 p ublic void run() {68 path.getTree().dispatch(new RunAt<Tree>(this) { 69 @Override 70 protected void runAt() { 70 71 updateDescriptions(path); 71 72 } … … 74 75 75 76 public void fetch(final Path p) { 76 assert p.get Instance().isActive();77 assert p.getTree().isActive(); 77 78 log.debug("fetching: " + p); 78 p.get Instance().fetchValues(p, new AbstractStateFunctor() {79 @Override 80 p ublic void call() {81 // reactForFetchResult(p, e); 79 p.getTree().get(p, Mode.FETCH, new FutureHandler<Object>(this) { 80 @Override 81 protected void result(Object result) { 82 82 83 } 83 84 }); … … 85 86 86 87 protected void reactForFetchResult(final Path p, Exception e) { 87 assert p.get Instance().isActive();88 assert p.getTree().isActive(); 88 89 if (Logging.log(log, "fetch", TreeNode.this, e)) { 89 frame.dispatch(new RunAt<Frame>( ) {90 frame.dispatch(new RunAt<Frame>(this) { 90 91 @Override 91 p ublic void run() {92 protected void runAt() { 92 93 log.debug("removing node from tree: " + p); 93 94 frame.treeModel.removeNodeFromParent(TreeNode.this); … … 97 98 } 98 99 updateChildren(p); 99 frame.dispatch(new RunAt<Frame>( ) {100 @Override 101 p ublic void run() {100 frame.dispatch(new RunAt<Frame>(this) { 101 @Override 102 protected void runAt() { 102 103 //TODO maybe this should be called from some better place 103 104 useOrCreatePanel(); … … 109 110 assert !frame.isActive(); 110 111 /** TODO those two actions could be merged into single closure */ 111 frame.dispatch(new RunAt<Frame>( ) {112 @Override 113 p ublic void run() {112 frame.dispatch(new RunAt<Frame>(this) { 113 @Override 114 protected void runAt() { 114 115 updatePath(newPath); 115 116 } … … 140 141 */ 141 142 protected void updateChildren(final Path p) { 142 assert p.get Instance().isActive();143 assert p.getTree().isActive(); 143 144 log.debug("updating children of " + this); 144 AccessInterface access = InstanceUtils.bindAccess(p.getInstance(), p.getTop()); 145 if (access == null) { 146 return; 147 } 145 AccessInterface access = TreeOperations.bindAccess(p.getTree(), p.getTop()); 148 146 final List<Path> childrenPaths = new LinkedList<Path>(); 149 147 /**Prepare path for each child.*/ … … 154 152 /**If some child were found, update in frame context.*/ 155 153 if (childrenPaths.size() > 0) { 156 frame.dispatch(new RunAt<Frame>( ) {154 frame.dispatch(new RunAt<Frame>(this) { 157 155 @Override 158 p ublic void run() {156 protected void runAt() { 159 157 // TreePath treePath = frame.startChange(); 160 158 updatePath(p); … … 173 171 } 174 172 log.debug("update: treenode for " + p); 175 TreeNode childNode = new TreeNode( instanceAtFrame, childPath);173 TreeNode childNode = new TreeNode(treeAtFrame, childPath); 176 174 177 175 frame.addNode(childNode, TreeNode.this); … … 191 189 final Path p = path; 192 190 193 p.get Instance().dispatch(new RunAt<Instance>() {194 @Override 195 p ublic void run() {191 p.getTree().dispatch(new RunAt<Tree>(this) { 192 @Override 193 protected void runAt() { 196 194 final Path updated = (p.isResolved()) ? p : p.tryFindResolution(); 197 195 if (updated.isResolved()) { … … 201 199 return; 202 200 } 203 p.get Instance().resolve(updated, new Future<Path>(Logging.logger(log, "resolve and select", TreeNode.this)) {201 p.getTree().resolve(updated, new FutureHandler<Path>(Logging.logger(log, "resolve and select", TreeNode.this)) { 204 202 @Override 205 203 protected void result(Path result) { … … 224 222 225 223 protected void updateDescriptions(Path p) { 226 assert p.get Instance().isActive();224 assert p.getTree().isActive(); 227 225 228 226 if (!p.isResolved()) { 229 227 return; 230 228 } 231 AccessInterface access = InstanceUtils.bindAccess(p); 232 233 final String tooltip = new TooltipConstructor() 234 .append("frams", access.getId()) 235 .append("java", p.getTopObject().getClass().getCanonicalName()) 236 .append("access", access.getClass().getSimpleName()) 237 .append("name", name) 238 .append("id", paramId) 239 .append("object", Integer.toHexString(System.identityHashCode(this))) 240 .build() 241 ; 229 AccessInterface access = TreeOperations.bindAccess(p); 230 231 final String tooltip = new TooltipConstructor().append("frams", access.getId()).append("java", p.getTopObject().getClass().getCanonicalName()).append("access", access.getClass().getSimpleName()).append("name", name).append("id", param.getId()).append("object", Integer.toHexString(System.identityHashCode(this))).build(); 242 232 243 233 StringParam nameParam = Casting.tryCast(StringParam.class, access.getParam("name")); 244 234 final String name = (nameParam != null ? access.get(nameParam, String.class) : path.getTop().getParam().getId()); 245 235 246 frame.dispatch(new RunAt<Frame>( ) {247 @Override 248 p ublic void run() {236 frame.dispatch(new RunAt<Frame>(this) { 237 @Override 238 protected void runAt() { 249 239 TreeNode.this.tooltip = tooltip; 250 240 TreeNode.this.name = name; … … 254 244 }); 255 245 } 256 257 /*258 public void updateData() {259 assert browser.isActive();260 final Node node = getNode();261 browser.manager.invokeLater(new Runnable() {262 @Override263 public void run() {264 node.fetchValues(new StateFunctor() {265 @Override266 public void call(Exception e) {267 if (e != null) {268 return;269 }270 browser.invokeLater(new Runnable() {271 @Override272 public void run() {273 assert browser.isActive();274 if (panel.getCurrentTreeNode() == TreeNode.this) {275 panel.refreshComponents();276 }277 278 browser.tree.repaint();279 panel.refreshComponents();280 }281 });282 }283 });284 }285 });286 }287 */288 246 289 247 public void showPanel() { … … 301 259 assert p.isResolved(); 302 260 panel.setCurrentTreeNode(this); 303 p.get Instance().dispatch(new RunAt<Instance>() {304 @Override 305 p ublic void run() {306 AccessInterface access = InstanceUtils.bindAccess(p);261 p.getTree().dispatch(new RunAt<Tree>(this) { 262 @Override 263 protected void runAt() { 264 AccessInterface access = TreeOperations.bindAccess(p); 307 265 panel.pullValuesFromLocalToUser(access); 308 266 309 frame.dispatch(new RunAt<Frame>( ) {267 frame.dispatch(new RunAt<Frame>(this) { 310 268 @Override 311 p ublic void run() {269 protected void runAt() { 312 270 showPanel(); 313 271 } … … 331 289 332 290 CompositeParam param = path.getTop().getParam(); 333 panel = instanceAtFrame.findPanel(param.computeAccessId());291 panel = treeAtFrame.findPanel(param.computeAccessId()); 334 292 if (panel != null) { 335 293 log.debug("found prepared panel for: " + path); … … 339 297 final Path p = path; 340 298 log.debug("preparing panel: " + p); 341 p.get Instance().dispatch(new RunAt<Instance>() {342 @Override 343 p ublic void run() {344 assert p.get Instance().isActive();299 p.getTree().dispatch(new RunAt<Tree>(this) { 300 @Override 301 protected void runAt() { 302 assert p.getTree().isActive(); 345 303 final CompositeParam param = p.getTop().getParam(); 346 final FramsClass framsClass = p.get Instance().getInfoFromCache(param.getContainedTypeName());347 frame.dispatch(new RunAt<Frame>( ) {304 final FramsClass framsClass = p.getTree().getInfoFromCache(param.getContainedTypeName()); 305 frame.dispatch(new RunAt<Frame>(this) { 348 306 @Override 349 p ublic void run() {350 panel = instanceAtFrame.preparePanel(param, framsClass);307 protected void runAt() { 308 panel = treeAtFrame.preparePanel(param, framsClass); 351 309 fillPanelWithValues(); 352 310 } … … 360 318 return tooltip; 361 319 } 362 363 364 365 320 366 321 /*public void subscribe(final EventParam eventParam) { … … 408 363 return; 409 364 } 410 userSubscriptions.get(eventParam).unsubscribe(new LoggingStateCallback <Connection>(log, "unsubscribed " + eventParam));365 userSubscriptions.get(eventParam).unsubscribe(new LoggingStateCallback(log, "unsubscribed " + eventParam)); 411 366 userSubscriptions.remove(eventParam); 412 367 } 413 368 414 /* 415 416 @Override 417 public void onChildChange(final Child child, ListChange.Action action) { 418 assert browser.manager.isActive(); 419 420 switch (action) { 421 case Remove: { 422 Dispatching.invokeDispatch(browser, browser.manager, new Runnable() { 423 @Override 424 public void run() { 425 assert browser.manager.isActive(); 426 final TreeNode treeNode = (TreeNode) child.getUserObject(); 427 if (treeNode == null) { 428 log.error("child " + child + " had no tree node attached"); 429 return; 430 } 431 browser.invokeLater(new Runnable() { 432 @Override 433 public void run() { 434 assert browser.isActive(); 435 TreePath path = browser.startChange(); 436 //assert treeNode.getParent() == TreeNode.this; 437 if (treeNode.getParent() != null) { 438 browser.treeModel.removeNodeFromParent(treeNode); 439 } 440 //remove(treeNode); 441 browser.markNodeChanged(TreeNode.this, path); 442 } 443 }); 444 } 445 }); 446 break; 447 } 448 } 449 450 } 451 */ 369 // @Override 370 // public void onChildChange(final Child child, ListChange.Action action) { 371 // assert browser.manager.isActive(); 372 373 // switch (action) { 374 // case Remove: { 375 // Dispatching.invokeDispatch(browser, browser.manager, new Runnable() { 376 // @Override 377 // public void run() { 378 // assert browser.manager.isActive(); 379 // final TreeNode treeNode = (TreeNode) child.getUserObject(); 380 // if (treeNode == null) { 381 // log.error("child " + child + " had no tree node attached"); 382 // return; 383 // } 384 // browser.invokeLater(new Runnable() { 385 // @Override 386 // public void run() { 387 // assert browser.isActive(); 388 // TreePath path = browser.startChange(); 389 // //assert treeNode.getParent() == TreeNode.this; 390 // if (treeNode.getParent() != null) { 391 // browser.treeModel.removeNodeFromParent(treeNode); 392 // } 393 // //remove(treeNode); 394 // browser.markNodeChanged(TreeNode.this, path); 395 // } 396 // }); 397 // } 398 // }); 399 // break; 400 // } 401 // } 402 403 // } 452 404 453 405 public String getName() { … … 486 438 } 487 439 488 public Path get InstancePath() {440 public Path getTreePath() { 489 441 assert frame.isActive(); 490 442 return path; … … 501 453 final Path p = path; 502 454 503 for (Map.Entry<ValueControl, Object> e : localChanges.entrySet()) {504 s toreValue(p, e.getKey().getParam(), e.getValue(), new AbstractStateFunctor() {455 for (Map.Entry<ValueControl, Object> e : changes.entrySet()) { 456 set(p, e.getKey().getParam(), e.getValue(), new FutureHandler<Integer>(this) { 505 457 @Override 506 p ublic void call() {458 protected void result(Integer flag) { 507 459 counter.set(counter.get() - 1); 508 460 if (counter.get() != 0) { … … 510 462 } 511 463 log.debug("applied changes for: " + p); 512 frame.dispatch(new RunAt<Frame>( ) {464 frame.dispatch(new RunAt<Frame>(this) { 513 465 @Override 514 p ublic void run() {466 protected void runAt() { 515 467 fillPanelWithValues(); 516 468 } 517 469 }); 518 470 } 471 519 472 }); 520 473 } 521 474 } 475 476 @Override 477 public void handle(FramsticksException exception) { 478 frame.handle(exception); 479 } 522 480 } -
java/main/src/main/java/com/framsticks/gui/controls/Control.java
r90 r97 6 6 import javax.swing.JPanel; 7 7 8 import com.framsticks.gui.Frame;9 8 import com.framsticks.params.Flags; 10 9 import com.framsticks.params.Param; 10 import com.framsticks.util.FramsticksException; 11 import com.framsticks.util.dispatching.ExceptionResultHandler; 11 12 12 13 /** … … 14 15 */ 15 16 @SuppressWarnings("serial") 16 public abstract class Control extends JPanel {17 public abstract class Control extends JPanel implements ExceptionResultHandler { 17 18 18 19 public static final int LINE_HEIGHT = 36; … … 20 21 // private static final Logger log = Logger.getLogger(Control.class.getName()); 21 22 22 protected Frame frame;23 23 protected final Param param; 24 24 protected ControlOwner owner; … … 36 36 } 37 37 38 public void setFrame(Frame frame) {39 this.frame = frame;40 }41 42 38 public void setOwner(ControlOwner owner) { 43 39 this.owner = owner; … … 53 49 return param.toString(); 54 50 } 51 52 @Override 53 public void handle(FramsticksException exception) { 54 owner.handle(exception); 55 } 55 56 } -
java/main/src/main/java/com/framsticks/gui/controls/ControlOwner.java
r90 r97 4 4 5 5 import com.framsticks.gui.TreeNode; 6 import com.framsticks.util.dispatching.ExceptionResultHandler; 6 7 7 public interface ControlOwner {8 public interface ControlOwner extends ExceptionResultHandler { 8 9 9 10 public JPanel getPanel(); -
java/main/src/main/java/com/framsticks/gui/controls/ProcedureControl.java
r96 r97 1 1 package com.framsticks.gui.controls; 2 2 3 import com.framsticks.core. Instance;3 import com.framsticks.core.Tree; 4 4 import com.framsticks.core.Path; 5 5 import com.framsticks.gui.Gui; … … 8 8 import com.framsticks.params.ValueParam; 9 9 import com.framsticks.params.types.ProcedureParam; 10 import com.framsticks.util.FramsticksException; 11 import com.framsticks.util.Logging; 12 import com.framsticks.util.dispatching.Future; 10 import com.framsticks.util.dispatching.ExceptionResultHandler; 11 import com.framsticks.util.dispatching.FutureHandler; 13 12 import com.framsticks.util.dispatching.RunAt; 13 import com.framsticks.util.dispatching.ThrowExceptionHandler; 14 14 15 15 import javax.swing.*; … … 58 58 59 59 log.debug("calling " + getParam() + " on " + treeNode); 60 final Path path = treeNode.get InstancePath();60 final Path path = treeNode.getTreePath(); 61 61 62 62 final List<Object> arguments = new LinkedList<Object>(); 63 63 for (Param arg : getParam().getArgumentsType()) { 64 arguments.add(((ValueControl) components.get(arg)).getCurrentValue()); 64 Object value = components.get(arg).getCurrentValue(); 65 arguments.add(value); 66 log.debug("argument " + arg + ": " + value); 65 67 } 68 //TODO FEH: make it show dialog 69 final ExceptionResultHandler handler = ThrowExceptionHandler.getInstance(); 66 70 67 path.get Instance().dispatch(new RunAt<Instance>() {71 path.getTree().dispatch(new RunAt<Tree>(handler) { 68 72 @Override 69 public void run() { 70 path.getInstance().call(path, getParam(), arguments.toArray(), new Future<Object>() { 71 72 @Override 73 public void handle(FramsticksException e) { 74 Logging.log(log, "call procedure", path, e); 75 } 73 protected void runAt() { 74 path.getTree().call(path, getParam(), arguments.toArray(), new FutureHandler<Object>(handler) { 76 75 77 76 @Override -
java/main/src/main/java/com/framsticks/gui/controls/SliderControl.java
r84 r97 104 104 105 105 JPanel sliderPanel = new JPanel(); 106 sliderPanel.setLayout(new BoxLayout(sliderPanel, BoxLayout.LINE_AXIS));106 // sliderPanel.setLayout(new BoxLayout(sliderPanel, BoxLayout.LINE_AXIS)); 107 107 108 108 -
java/main/src/main/java/com/framsticks/gui/controls/TextAreaControl.java
r87 r97 9 9 public class TextAreaControl extends TextControl { 10 10 11 // private static final Logger log = Logger.getLogger(TextAreaControl.class.getName()); 12 13 protected JTextArea textArea; 14 protected JScrollPane textScrollPane; 11 protected final JTextArea textArea; 12 protected final JScrollPane textScrollPane; 15 13 16 14 public TextAreaControl(PrimitiveParam<?> valueParam) { 17 15 super(valueParam); 18 16 textArea = new JTextArea(); 17 textArea.setName("value"); 19 18 textArea.setLineWrap(true); 20 19 textArea.setWrapStyleWord(true); -
java/main/src/main/java/com/framsticks/gui/controls/ValueControl.java
r90 r97 7 7 import com.framsticks.params.PrimitiveParam; 8 8 import com.framsticks.params.ReassignResult; 9 import com.framsticks.util.FramsticksException; 9 10 import com.framsticks.util.swing.TooltipConstructor; 10 11 … … 73 74 return res.getValue(); 74 75 } catch (CastFailure e) { 75 log.error("cast failure when setting param " + param + " to value " + candidate + ": " + e); 76 //TODO just throw here, but check where that function is being used 77 handle(new FramsticksException().msg("invalid value in control").arg("param", param).arg("value", candidate).cause(e)); 76 78 } 77 79 return oldValue; -
java/main/src/main/java/com/framsticks/hosting/Server.java
r96 r97 4 4 import org.apache.log4j.Logger; 5 5 6 import com.framsticks.core. Instance;6 import com.framsticks.core.Tree; 7 7 import com.framsticks.params.annotations.AutoAppendAnnotation; 8 8 import com.framsticks.params.annotations.FramsClassAnnotation; … … 17 17 import com.framsticks.util.dispatching.RunAt; 18 18 import com.framsticks.util.dispatching.Task; 19 import com.framsticks.util.dispatching.ThrowExceptionHandler; 19 20 20 21 import java.io.IOException; … … 32 33 33 34 protected ServerSocket acceptSocket; 34 protected Instance hosted;35 protected final JoinableCollection< InstanceClient> clients = new JoinableCollection<InstanceClient>();35 protected Tree hosted; 36 protected final JoinableCollection<ClientAtServer> clients = new JoinableCollection<ClientAtServer>(); 36 37 37 38 public static class Accept { … … 80 81 * @return the hosted 81 82 */ 82 public Instance getHosted() {83 public Tree getHosted() { 83 84 return hosted; 84 85 } 85 86 86 87 @AutoAppendAnnotation 87 public void setHosted( Instance hosted) {88 public void setHosted(Tree hosted) { 88 89 if (this.hosted != null) { 89 throw new FramsticksException().msg("hosted instance is already set").arg("current", this.hosted);90 throw new FramsticksException().msg("hosted tree is already set").arg("current", this.hosted); 90 91 } 91 92 this.hosted = hosted; … … 123 124 return; 124 125 } 125 acceptThread.dispatch(new RunAt<Accept>() { 126 //TODO TEH 127 acceptThread.dispatch(new RunAt<Accept>(ThrowExceptionHandler.getInstance()) { 126 128 @Override 127 p ublic void run() {129 protected void runAt() { 128 130 try { 129 131 log.debug("accepting"); … … 131 133 assert socket != null; 132 134 log.debug("accepted socket: " + socket.getInetAddress().getHostAddress()); 133 hosted.dispatch(new RunAt< Instance>() {135 hosted.dispatch(new RunAt<Tree>(this) { 134 136 @Override 135 p ublic void run() {136 InstanceClient client = new InstanceClient(Server.this, socket);137 protected void runAt() { 138 ClientAtServer client = new ClientAtServer(Server.this, socket); 137 139 clients.add(client); 138 140 log.info("client connected: " + client); … … 148 150 149 151 protected void tryBind(int when) { 150 acceptThread.dispatch(new Task<Accept>( when) {152 acceptThread.dispatch(new Task<Accept>(ThrowExceptionHandler.getInstance(), when) { 151 153 @Override 152 p ublic void run() {154 protected void runAt() { 153 155 try { 154 156 acceptSocket.bind(new InetSocketAddress(port)); -
java/main/src/main/java/com/framsticks/model/f0/Schema.java
r90 r97 35 35 } 36 36 37 pr otectedstatic Schema defaultSchema;37 private static Schema defaultSchema; 38 38 39 39 public synchronized static Schema getDefaultSchema() { -
java/main/src/main/java/com/framsticks/params/AccessInterface.java
r96 r97 56 56 void save(SinkInterface sink); 57 57 58 void load(SourceInterface stream) throws Exception;58 void load(SourceInterface stream); 59 59 60 60 /** -
java/main/src/main/java/com/framsticks/params/ListAccess.java
r96 r97 63 63 64 64 @Override 65 public void load(SourceInterface stream) throws Exception{65 public void load(SourceInterface stream) { 66 66 } 67 67 -
java/main/src/main/java/com/framsticks/params/ParamBuilder.java
r96 r97 504 504 } 505 505 506 private static Pattern addressPattern = Pattern.compile("^([^\\(]+)?\\(([^\\)]*)\\)$");506 private static Pattern signaturePattern = Pattern.compile("^([^\\(]+)?\\(([^\\)]*)\\)$"); 507 507 508 508 public ParamBuilder signature(String signature) { … … 513 513 return this; 514 514 } 515 Matcher matcher = addressPattern.matcher(signature);515 Matcher matcher = signaturePattern.matcher(signature); 516 516 if (!matcher.matches()) { 517 517 throw new FramsticksException().msg("invalid signature"); -
java/main/src/main/java/com/framsticks/params/SimpleAbstractAccess.java
r96 r97 1 1 package com.framsticks.params; 2 2 3 import java.io.IOException;4 3 import java.util.Collection; 5 4 … … 149 148 public void setMin(int i) { 150 149 PrimitiveParam<?> entry = framsClass.getParamEntry(i, PrimitiveParam.class); 151 if (entry == null) {152 return;153 }154 150 Object min = entry.getMin(entry.getStorageType()); 155 151 if (min != null) { … … 168 164 public void setMax(int i) { 169 165 PrimitiveParam<?> entry = framsClass.getParamEntry(i, PrimitiveParam.class); 170 if (entry == null) {171 return;172 }173 166 Object max = entry.getMax(entry.getStorageType()); 174 167 if (max != null) { … … 205 198 } 206 199 207 private Entry readEntry(SourceInterface source) 208 throws IOException { 200 private Entry readEntry(SourceInterface source) { 209 201 210 202 String line; … … 252 244 253 245 @Override 254 public void load(SourceInterface source) throws Exception{246 public void load(SourceInterface source) { 255 247 //TODO not clearing values, because get from manager gives only fields, not children 256 248 //this.clearValues(); -
java/main/src/main/java/com/framsticks/params/types/ProcedureParam.java
r96 r97 26 26 resultType = builder.getResultType(); 27 27 argumentsType = builder.getArgumentsType(); 28 assert argumentsType != null; 28 29 29 30 StringBuilder b = new StringBuilder().append("p"); … … 49 50 50 51 signatureString = b.toString(); 51 assert argumentsType != null;52 52 } 53 53 -
java/main/src/main/java/com/framsticks/parsers/F0Parser.java
r90 r97 19 19 import com.framsticks.params.PrimitiveParam; 20 20 import com.framsticks.util.FramsticksException; 21 import com.framsticks.util.io.Encoding; 21 22 import com.framsticks.util.lang.Containers; 22 23 import com.framsticks.util.lang.Pair; … … 85 86 public List<AccessInterface> parse() { 86 87 87 try (InputStreamReader reader = new InputStreamReader(is, "UTF-8")) {88 try (InputStreamReader reader = new InputStreamReader(is, Encoding.getDefaultCharset())) { 88 89 BufferedReader br = new BufferedReader(reader); 89 90 while (br.ready()) { -
java/main/src/main/java/com/framsticks/parsers/MultiParamLoader.java
r88 r97 4 4 import org.apache.log4j.Logger; 5 5 6 import java.io.FileNotFoundException;7 import java.io.IOException;8 6 import java.util.*; 9 7 … … 110 108 * Starts reading the file. 111 109 */ 112 public Status go() throws Exception{110 public Status go() { 113 111 log.trace("go"); 114 112 … … 159 157 continue; 160 158 } 161 log.warn("unknown line: " + currentLine); 159 160 // log.warn("unknown line: " + currentLine); 161 changeStatus(Status.OnError); 162 if (action == LoopAction.Break) { 163 break; 164 } 165 if (action == LoopAction.Continue) { 166 continue; 167 } 162 168 } 163 169 … … 170 176 * @throws Exception 171 177 */ 172 private LoopAction tryReadObject() throws Exception{178 private LoopAction tryReadObject() { 173 179 if (status == Status.BeforeObject 174 180 || (status == Status.BeforeUnknown && lastAccessInterface != null)) { … … 201 207 * Checks whether some additional file shouldn't be included. 202 208 */ 203 private LoopAction isIncludeLine(String line) throws FileNotFoundException{209 private LoopAction isIncludeLine(String line) { 204 210 try { 205 211 // found comment … … 374 380 * Returns from included file. 375 381 */ 376 private boolean returnFromIncluded() throws IOException{382 private boolean returnFromIncluded() { 377 383 if (fileStack.size() == 0) { 378 384 return false; -
java/main/src/main/java/com/framsticks/parsers/XmlLoader.java
r96 r97 64 64 AccessInterface access = registry.createAccess(name); 65 65 66 if (access == null) {67 throw new FramsticksException().msg("failed to find access interface").arg("name", name);68 }69 66 Object object = access.createAccessee(); 70 67 assert object != null; -
java/main/src/main/java/com/framsticks/portals/Portal.java
r96 r97 2 2 3 3 4 import com.framsticks.core.Abstract InstanceListener;5 import com.framsticks.core. Instance;6 import com.framsticks.core. InstanceUtils;4 import com.framsticks.core.AbstractTreeListener; 5 import com.framsticks.core.Tree; 6 import com.framsticks.core.TreeOperations; 7 7 import com.framsticks.core.Path; 8 8 import com.framsticks.params.annotations.FramsClassAnnotation; … … 10 10 import com.framsticks.util.Logging; 11 11 import com.framsticks.util.dispatching.Dispatching; 12 import com.framsticks.util.dispatching.Future ;12 import com.framsticks.util.dispatching.FutureHandler; 13 13 import com.framsticks.util.dispatching.JoinableCollection; 14 14 import com.framsticks.util.dispatching.RunAt; 15 import com.framsticks.util.dispatching.ThrowExceptionHandler; 15 16 16 17 import org.apache.log4j.Logger; … … 21 22 */ 22 23 @FramsClassAnnotation 23 public class Portal extends JoinableCollection< Instance> {24 public class Portal extends JoinableCollection<Tree> { 24 25 25 26 private final static Logger log = Logger.getLogger(Portal.class.getName()); … … 33 34 // @Override 34 35 // public void run() { 35 // 36 // 36 // super.run(); 37 // new PeriodicTask<Portal>(this, 1000) { 37 38 38 // 39 // 40 // 41 // 42 // 43 // 44 // 39 // @Override 40 // public void run() { 41 // ++counter; 42 // log.debug("counter is now: " + counter); 43 // again(); 44 // } 45 // }; 45 46 // } 46 47 47 48 @Override 48 public void add(final Instance instance) {49 super.add( instance);50 instance.addListener(new AbstractInstanceListener() {49 public void add(final Tree tree) { 50 super.add(tree); 51 tree.addListener(new AbstractTreeListener() { 51 52 @Override 52 53 public void onRun(Exception e) { … … 59 60 } 60 61 final String path = "/simulator/genepools/groups/0/genotypes"; 61 instance.dispatch(new RunAt<Instance>() {62 tree.dispatch(new RunAt<Tree>(ThrowExceptionHandler.getInstance()) { 62 63 @Override 63 p ublic void run() {64 InstanceUtils.resolve(instance, path, new Future<Path>(Logging.logger(log, "resolve", path)) {64 protected void runAt() { 65 TreeOperations.resolve(tree, path, new FutureHandler<Path>(Logging.logger(log, "resolve", path)) { 65 66 @Override 66 67 public void result(Path result) { -
java/main/src/main/java/com/framsticks/remote/RecursiveFetcher.java
r96 r97 1 1 package com.framsticks.remote; 2 2 3 import static com.framsticks.core.InstanceUtils.*; 3 import static com.framsticks.core.TreeOperations.*; 4 5 import com.framsticks.core.Mode; 4 6 import com.framsticks.core.Node; 5 7 import com.framsticks.core.Path; … … 7 9 import com.framsticks.params.CompositeParam; 8 10 import com.framsticks.params.FramsClass; 9 import com.framsticks.core. Instance;11 import com.framsticks.core.Tree; 10 12 import com.framsticks.util.dispatching.Future; 13 import com.framsticks.util.dispatching.FutureHandler; 14 import com.framsticks.util.dispatching.ThrowExceptionHandler; 11 15 import com.framsticks.util.FramsticksException; 12 16 import com.framsticks.util.Logging; 13 import com.framsticks.util.StateFunctor;14 17 import com.framsticks.util.Stopwatch; 15 18 import org.apache.log4j.Logger; … … 24 27 private final static Logger log = Logger.getLogger(RecursiveFetcher.class.getName()); 25 28 26 protected final Instance instance;27 protected final StateFunctor stateFunctor;29 protected final Tree tree; 30 protected final Future<Void> future; 28 31 protected int dispatched; 29 32 protected final Stopwatch stopwatch = new Stopwatch(); 30 33 31 public RecursiveFetcher( Instance instance, final Path path, StateFunctor stateFunctor) {32 this. instance = instance;33 this. stateFunctor = stateFunctor;34 public RecursiveFetcher(Tree tree, final Path path, Future<Void> future) { 35 this.tree = tree; 36 this.future = future; 34 37 dispatched = 1; 35 38 process(path); … … 37 40 38 41 protected void finished() { 39 assert instance.isActive();42 assert tree.isActive(); 40 43 log.info("recursively fetched in " + stopwatch); 41 stateFunctor.call();44 future.pass(null); 42 45 } 43 46 44 47 protected void process(final Path path) { 45 assert instance.isActive();48 assert tree.isActive(); 46 49 if (path == null || !path.isResolved()) { 47 50 log.warn("path " + path + " is not resolved - skipping"); … … 55 58 if (childPath.isResolved() && getInfoFromCache(childPath) != null) { 56 59 ++dispatched; 57 instance.dispatch(new RunAt<Instance>() {60 tree.dispatch(new RunAt<Tree>(ThrowExceptionHandler.getInstance()) { 58 61 @Override 59 p ublic void run() {62 protected void runAt() { 60 63 fetch(childPath); 61 64 } … … 64 67 } 65 68 ++dispatched; 66 instance.resolve(childPath, new Future<Path>(Logging.logger(log, "resolve", RecursiveFetcher.this)) {69 tree.resolve(childPath, new FutureHandler<Path>(Logging.logger(log, "resolve", RecursiveFetcher.this)) { 67 70 @Override 68 71 protected void result(Path result) { 69 assert instance.isActive();72 assert tree.isActive(); 70 73 fetch(result); 71 74 } … … 80 83 81 84 protected void fetch(final Path path) { 82 instance.fetchValues(path, new StateFunctor() { 85 tree.get(path, Mode.FETCH, new Future<Object>() { 86 83 87 @Override 84 88 public void handle(FramsticksException e) { … … 88 92 89 93 @Override 90 p ublic void call() {94 protected void result(Object object) { 91 95 process(path); 92 96 } -
java/main/src/main/java/com/framsticks/running/ExternalProcess.java
r96 r97 26 26 import com.framsticks.util.dispatching.RunAt; 27 27 import com.framsticks.util.dispatching.Thread; 28 import com.framsticks.util.dispatching.ThrowExceptionHandler; 28 29 import com.framsticks.util.io.Encoding; 29 30 … … 129 130 } 130 131 131 readerThread.dispatch(new RunAt<ExternalProcess>( ) {132 readerThread.dispatch(new RunAt<ExternalProcess>(ThrowExceptionHandler.getInstance()) { 132 133 133 134 @Override 134 p ublic void run() {135 protected void runAt() { 135 136 readerTask(); 136 137 } -
java/main/src/main/java/com/framsticks/test/TestClass.java
r96 r97 1 1 package com.framsticks.test; 2 3 import org.apache.log4j.Logger; 2 4 3 5 import com.framsticks.params.annotations.FramsClassAnnotation; … … 7 9 @FramsClassAnnotation(order = {"name", "history", "appendHistory", "resetHistory"}) 8 10 public class TestClass { 11 private static final Logger log = 12 Logger.getLogger(TestClass.class); 13 9 14 10 15 protected String name = "test"; 11 protected String history = " ";16 protected String history = "initial|"; 12 17 13 18 /** … … 45 50 @ParamAnnotation(paramType = ProcedureParam.class) 46 51 public int appendHistory(String line) { 52 log.debug("appending '" + line + "'"); 47 53 history = history + line + "|"; 48 54 return history.length(); … … 51 57 @ParamAnnotation(paramType = ProcedureParam.class) 52 58 public void resetHistory() { 59 log.debug("reseting"); 53 60 history = ""; 54 61 } -
java/main/src/main/java/com/framsticks/util/FramsticksException.java
r96 r97 35 35 } 36 36 37 public voidgetShortMessage(StringBuilder b) {37 public StringBuilder getShortMessage(StringBuilder b) { 38 38 if (message != null) { 39 39 b.append(message); … … 50 50 b.append("(").append(d.build()).append(")"); 51 51 } 52 return b; 52 53 } 53 54 -
java/main/src/main/java/com/framsticks/util/PeriodicTask.java
r96 r97 2 2 3 3 import com.framsticks.util.dispatching.Dispatcher; 4 import com.framsticks.util.dispatching.ExceptionResultHandler; 4 5 import com.framsticks.util.dispatching.Task; 5 6 import com.framsticks.util.dispatching.RunAt; … … 13 14 protected Dispatcher<? super C> dispatcher; 14 15 15 public PeriodicTask(Dispatcher<? super C> dispatcher, long period) { 16 public PeriodicTask(ExceptionResultHandler handler, Dispatcher<? super C> dispatcher, long period) { 17 super(handler); 16 18 this.period = period; 17 19 this.dispatcher = dispatcher; … … 21 23 22 24 public void again() { 23 dispatcher.dispatch(new Task<C>( period) {25 dispatcher.dispatch(new Task<C>(handler, period) { 24 26 @Override 25 p ublic void run() {26 PeriodicTask.this.run ();27 protected void runAt() { 28 PeriodicTask.this.runAt(); 27 29 } 28 30 }); -
java/main/src/main/java/com/framsticks/util/ResourceBuilder.java
r90 r97 35 35 36 36 @ParamAnnotation 37 public ResourceBuilder<T> 37 public ResourceBuilder<T> resource(String resource) { 38 38 this.resource = resource; 39 39 return stream(getClass().getResourceAsStream(resource)); -
java/main/src/main/java/com/framsticks/util/UnaryFunctor.java
r77 r97 5 5 */ 6 6 public interface UnaryFunctor <Ret, Arg> { 7 7 Ret call(Arg arg); 8 8 } -
java/main/src/main/java/com/framsticks/util/dispatching/AbstractJoinable.java
r96 r97 137 137 boolean start = false; 138 138 synchronized (this) { 139 assert !owners.contains(owner); 139 if (owners.contains(owner)) { 140 throw new FramsticksException().msg("owner is already using that joinable").arg("joinable", this).arg("owner", owner); 141 } 140 142 start = owners.isEmpty(); 141 143 log.debug(owner + " is using " + this); … … 164 166 } 165 167 if (stop) { 166 Dispatching.dispatcherGuardedInvoke(this, new RunAt<Object>( ) {168 Dispatching.dispatcherGuardedInvoke(this, new RunAt<Object>(ThrowExceptionHandler.getInstance()) { 167 169 @Override 168 p ublic void run() {170 protected void runAt() { 169 171 interrupt(); 170 172 } -
java/main/src/main/java/com/framsticks/util/dispatching/AtOnceDispatcher.java
r90 r97 21 21 @Override 22 22 public final void dispatch(RunAt<? extends C> runnable) { 23 runnable.run ();23 runnable.runAt(); 24 24 } 25 25 -
java/main/src/main/java/com/framsticks/util/dispatching/Dispatching.java
r96 r97 4 4 5 5 import com.framsticks.util.FramsticksException; 6 import com.framsticks.util.StateFunctor;7 6 8 7 /** … … 18 17 public static <C> void dispatchIfNotActive(Dispatcher<C> dispatcher, RunAt<? extends C> runnable) { 19 18 if (dispatcher.isActive()) { 20 runnable.run ();19 runnable.runAt(); 21 20 return; 22 21 } 23 22 dispatcher.dispatch(runnable); 24 }25 26 //TODO RunAt StateFunctor27 public static <C> void dispatchOk(Dispatcher<C> dispatcher, final StateFunctor stateFunctor) {28 dispatcher.dispatch(new RunAt<C>() {29 @Override30 public void run() {31 stateFunctor.call();32 }33 });34 23 } 35 24 … … 40 29 41 30 public static <P, C> void invokeDispatch(Dispatcher<P> dispatcher, final Dispatcher<C> finalDispatcher, final RunAt<C> runnable) { 42 dispatcher.dispatch(new RunAt<P>( ) {31 dispatcher.dispatch(new RunAt<P>(runnable) { 43 32 @Override 44 p ublic void run() {33 protected void runAt() { 45 34 finalDispatcher.dispatch(runnable); 46 35 } … … 49 38 50 39 public static void sleep(double seconds) { 40 log.debug("sleeping"); 51 41 try { 52 42 java.lang.Thread.sleep((long) (seconds * 1000)); … … 54 44 55 45 } 46 log.debug("slept"); 56 47 } 57 48 … … 62 53 return; 63 54 } 64 runnable.run ();55 runnable.runAt(); 65 56 } 66 57 … … 95 86 96 87 public static void childChangedState(final JoinableParent parent, final Joinable joinable, final JoinableState state) { 97 dispatcherGuardedInvoke(joinable, new RunAt<Object>( ) {88 dispatcherGuardedInvoke(joinable, new RunAt<Object>(ThrowExceptionHandler.getInstance()) { 98 89 @Override 99 p ublic void run() {90 protected void runAt() { 100 91 log.debug("joinable " + joinable + " is notifying parent " + parent + " about change to " + state); 101 92 parent.childChangedState(joinable, state); … … 140 131 */ 141 132 public QueryRunner(Query<T> query) { 133 //TODO TEH 134 super(ThrowExceptionHandler.getInstance()); 142 135 this.query = query; 143 136 } 144 137 145 138 @Override 146 p ublic void run() {139 protected void runAt() { 147 140 result = query.get(); 148 141 synchronized (this) { … … 206 199 public static <C> void synchronize(Dispatcher<C> dispatcher, double seconds) { 207 200 final Waiter waiter = new Waiter(seconds); 208 dispatcher.dispatch(new RunAt<C>( ) {201 dispatcher.dispatch(new RunAt<C>(ThrowExceptionHandler.getInstance()) { 209 202 @Override 210 p ublic void run() {203 protected void runAt() { 211 204 waiter.pass(); 212 205 } -
java/main/src/main/java/com/framsticks/util/dispatching/Future.java
r96 r97 7 7 */ 8 8 public abstract class Future<T> implements ExceptionResultHandler { 9 10 protected final ExceptionResultHandler handler;11 12 public Future(ExceptionResultHandler handler) {13 this.handler = handler;14 }15 16 public Future() {17 this.handler = null;18 }19 9 20 10 protected abstract void result(T result); … … 28 18 } 29 19 30 public static <T> void passOrHandle(Future<T> future, T value, FramsticksException e) {31 if (e != null) {32 future.handle(e);33 } else {34 future.pass(value);35 }36 }37 20 38 @Override39 public void handle(FramsticksException exception) {40 if (handler != null) {41 handler.handle(exception);42 return;43 }44 throw exception;45 }46 21 } -
java/main/src/main/java/com/framsticks/util/dispatching/JoinableCollection.java
r96 r97 1 1 package com.framsticks.util.dispatching; 2 2 3 import java.util.AbstractCollection; 4 import java.util.Collection; 3 5 import java.util.Collections; 4 6 import java.util.HashSet; … … 42 44 if (this.state.equals(JoinableState.RUNNING)) { 43 45 Dispatching.use(joinable, this); 46 } 47 } 48 49 public synchronized void remove(T joinable) { 50 if (this.state.ordinal() > JoinableState.RUNNING.ordinal()) { 51 throw new FramsticksException().msg("failed to remote joinable - collection is passed running state").arg("joinable", joinable).arg("collection", this); 52 } 53 if (!joinables.contains(joinable)) { 54 throw new FramsticksException().msg("joinable is not observed").arg("joinable", joinable).arg("in", this); 55 } 56 57 joinables.remove(joinable); 58 59 if (this.state.equals(JoinableState.RUNNING)) { 60 Dispatching.drop(joinable, this); 44 61 } 45 62 } … … 140 157 } 141 158 159 public Collection<T> asCollection() { 160 return new AbstractCollection<T>() { 161 162 @Override 163 public Iterator<T> iterator() { 164 return JoinableCollection.this.iterator(); 165 } 166 167 @Override 168 public int size() { 169 return JoinableCollection.this.size(); 170 } 171 172 @Override 173 public boolean add(T joinable) { 174 JoinableCollection.this.add(joinable); 175 return true; 176 } 177 178 @SuppressWarnings("unchecked") 179 @Override 180 public boolean remove(Object joinable) { 181 JoinableCollection.this.remove((T) joinable); 182 return true; 183 } 184 }; 185 } 186 142 187 } -
java/main/src/main/java/com/framsticks/util/dispatching/RunAt.java
r90 r97 1 1 package com.framsticks.util.dispatching; 2 2 3 public abstract class RunAt<C> implements java.lang.Runnable { 3 import com.framsticks.util.FramsticksException; 4 4 5 public RunAt() { 5 public abstract class RunAt<C> implements ExceptionResultHandler, Runnable { 6 7 protected final ExceptionResultHandler handler; 8 9 public RunAt(ExceptionResultHandler handler) { 10 assert handler != null; 11 this.handler = handler; 6 12 } 7 13 8 public RunAt(Dispatcher<? super C> dispatcher) { 9 dispatcher.dispatch(this); 14 protected abstract void runAt(); 15 16 public final void run() { 17 try { 18 runAt(); 19 } catch (FramsticksException e) { 20 handle(e); 21 } 10 22 } 23 24 25 26 @Override 27 public final void handle(FramsticksException exception) { 28 handler.handle(exception); 29 } 30 11 31 } -
java/main/src/main/java/com/framsticks/util/dispatching/Task.java
r96 r97 8 8 protected final long moment; 9 9 10 public Task() { 10 public Task(ExceptionResultHandler handler) { 11 super(handler); 11 12 moment = System.currentTimeMillis(); 12 13 } 13 14 14 public Task(long moment) { 15 public Task(ExceptionResultHandler handler, long moment) { 16 super(handler); 15 17 this.moment = System.currentTimeMillis() + moment; 16 18 } -
java/main/src/main/java/com/framsticks/util/dispatching/Thread.java
r96 r97 15 15 public class Thread<C> extends AbstractJoinable implements Dispatcher<C> { 16 16 17 private static final Logger log = Logger.getLogger(Thread.class .getName());17 private static final Logger log = Logger.getLogger(Thread.class); 18 18 19 19 protected final java.lang.Thread thread; … … 73 73 } 74 74 try { 75 task.run ();75 task.runAt(); 76 76 } catch (Exception e) { 77 77 if (exceptionHandler != null) { … … 119 119 public void dispatch(final RunAt<? extends C> runnable) { 120 120 if (!(runnable instanceof Task)) { 121 enqueueTask(new Task<C>( ) {121 enqueueTask(new Task<C>(runnable) { 122 122 @Override 123 p ublic void run() {124 runnable.run ();123 protected void runAt() { 124 runnable.runAt(); 125 125 } 126 126 }); -
java/main/src/main/java/com/framsticks/util/io/Encoding.java
r85 r97 7 7 protected static final Charset defaultCharset = Charset.forName("UTF-8"); 8 8 9 protected static final Charset framsticksCharset = Charset.forName("ISO-8859-1"); 9 protected static final Charset framsticksCharset = Charset.forName("UTF-8"); 10 //Charset.forName("ISO-8859-1"); 10 11 11 12 -
java/main/src/main/java/com/framsticks/util/lang/Strings.java
r96 r97 26 26 27 27 public static String toStringNullProof(Object object) { 28 return toStringNullProof(object, ""); 29 } 30 31 public static String toStringNullProof(Object object, String def) { 28 32 if (object == null) { 29 return "";33 return def; 30 34 } 31 35 return object.toString(); … … 56 60 return input.substring(0, 1).toLowerCase() + input.substring(1); 57 61 } 62 63 public static String commonPrefix(String a, String b) { 64 int length = Math.min(a.length(), b.length()); 65 int i = 0; 66 while ((i < length) && (a.charAt(i) == b.charAt(i))) { 67 ++i; 68 } 69 return a.substring(0, i); 70 } 71 58 72 } -
java/main/src/main/resources/configs/framsticks.xml
r96 r97 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <Framsticks> 3 <import class="com.framsticks.gui.Browser" /> 4 <import class="com.framsticks.remote.RemoteInstance" /> 5 <import class="com.framsticks.remote.SimulatorInstance" /> 6 <import class="com.framsticks.model.ModelPackage" /> 7 <import class="com.framsticks.model.ModelBuilder" /> 8 <import class="com.framsticks.model.f0.SchemaBuilder" /> 9 <import class="com.framsticks.core.ObjectInstance" /> 10 <import class="com.framsticks.hosting.Server" /> 11 <import class="com.framsticks.test.TestClass" /> 12 <Browser> 13 <SimulatorInstance name="localhost:9009" address="localhost:9009"> 14 <ModelPackage /> 15 </SimulatorInstance> 16 <ObjectInstance name="model"> 17 <ModelBuilder resource="/examples/f0_example.txt" /> 18 </ObjectInstance> 19 <ObjectInstance name="f0schema"> 20 <SchemaBuilder /> 21 </ObjectInstance> 22 <RemoteInstance name="remote" address="localhost:9007" /> 23 </Browser> 24 <Server name="server" port="9007"> 25 <ObjectInstance name="test"> 26 <TestClass /> 27 </ObjectInstance> 28 </Server> 3 <import class="com.framsticks.gui.console.ManagedConsole" /> 4 <import class="com.framsticks.remote.RemoteTree" /> 5 <ManagedConsole> 6 <RemoteTree name="remote" address="localhost:9009" /> 7 </ManagedConsole> 8 9 <!-- <import class="com.framsticks.gui.console.DirectConsole" /> --> 10 <!-- <import class="com.framsticks.communication.ClientSideRawConnection" /> --> 11 <!-- <DirectConsole> --> 12 <!-- <ClientSideRawConnection address="localhost:9009" /> --> 13 <!-- </DirectConsole> --> 14 15 <!-- <import class="com.framsticks.gui.Browser" /> --> 16 <!-- <import class="com.framsticks.remote.RemoteTree" /> --> 17 <!-- <import class="com.framsticks.remote.SimulatorTree" /> --> 18 <!-- <import class="com.framsticks.model.ModelPackage" /> --> 19 <!-- <import class="com.framsticks.model.ModelBuilder" /> --> 20 <!-- <import class="com.framsticks.model.f0.SchemaBuilder" /> --> 21 <!-- <import class="com.framsticks.core.ObjectTree" /> --> 22 <!-- <import class="com.framsticks.hosting.Server" /> --> 23 <!-- <import class="com.framsticks.test.TestClass" /> --> 24 <!-- <Browser> --> 25 <!-- <SimulatorTree name="localhost:9009" address="localhost:9009"> --> 26 <!-- <ModelPackage /> --> 27 <!-- </SimulatorTree> --> 28 <!-- <ObjectTree name="model"> --> 29 <!-- <ModelBuilder resource="/examples/f0_example.txt" /> --> 30 <!-- </ObjectTree> --> 31 <!-- <ObjectTree name="f0schema"> --> 32 <!-- <SchemaBuilder /> --> 33 <!-- </ObjectTree> --> 34 <!-- <RemoteTree name="remote" address="localhost:9007" /> --> 35 <!-- </Browser> --> 36 <!-- <Server name="server" port="9007"> --> 37 <!-- <ObjectTree name="test"> --> 38 <!-- <TestClass /> --> 39 <!-- </ObjectTree> --> 40 <!-- </Server> --> 29 41 </Framsticks> -
java/main/src/main/resources/configs/log4j.properties
r96 r97 31 31 # log4j.logger.com.framsticks.core.Framsticks=DEBUG 32 32 # log4j.logger.com.framsticks.gui.Frame=DEBUG 33 # log4j.logger.com.framsticks.core.ObjectInstance=DEBUG34 # log4j.logger.com.framsticks.core.Instance=DEBUG35 33 # log4j.logger.com.framsticks.gui.controls.ProcedureControl=DEBUG 36 34 # log4j.logger.com.framsticks.params.ReflectionAccess=TRACE … … 49 47 #log4j.logger.com.framsticks.gui.Browser=DEBUG 50 48 #log4j.logger.com.framsticks.gui.EndpointAtFrame=DEBUG 51 #log4j.logger.com.framsticks.remote.RemoteInstance=DEBUG52 49 #log4j.logger.com.framsticks.gui.TreeNode=DEBUG 53 50 #log4j.logger.com.framsticks.gui.components.CheckBox=DEBUG -
java/main/src/test/java/com/framsticks/dumping/StreamTest.java
r96 r97 16 16 // public void result(Path result, Exception e) { 17 17 // if (e != null) { 18 // log.error("failed to load file instance " + FileInstance.this + ": " + e);18 // log.error("failed to load file: " + e); 19 19 // fireRun(e); 20 20 // return; 21 21 // } 22 // log.info("loaded file instance " + FileInstance.this);22 // log.info("loaded file"); 23 23 // fireRun(null); 24 24 // } -
java/main/src/test/java/com/framsticks/gui/BrowserBaseTest.java
r96 r97 4 4 5 5 import org.apache.log4j.Logger; 6 import org.fest.swing.core.Robot;7 import org.fest.swing.edt.FailOnThreadViolationRepaintManager;8 6 import org.fest.swing.edt.GuiQuery; 9 7 import org.fest.swing.fixture.FrameFixture; … … 11 9 import org.testng.annotations.Test; 12 10 13 import com.framsticks.test.MonitorBasedTest; 11 12 import org.fest.swing.edt.GuiActionRunner; 13 14 14 import com.framsticks.util.dispatching.Joinable; 15 15 16 import static org.fest.assertions.Assertions.assertThat;17 import static org.fest.swing.edt.GuiActionRunner.executeInEDT;18 import static org.fest.swing.core.BasicRobot.robotWithNewAwtHierarchy;19 import org.fest.swing.edt.GuiActionRunner;20 21 16 @Test 22 public abstract class BrowserBaseTest extends MonitorBasedTest {17 public abstract class BrowserBaseTest extends GuiTest { 23 18 24 19 private static final Logger log = Logger.getLogger(BrowserTest.class); 25 20 26 21 protected Browser browser; 27 protected static Robot robot;28 22 protected FrameFixture frame; 29 23 protected JTreeFixture tree; 30 31 static {32 FailOnThreadViolationRepaintManager.install();33 assertThat(executeInEDT()).isTrue();34 35 robot = robotWithNewAwtHierarchy();36 }37 24 38 25 @Override … … 64 51 } 65 52 66 protected void waitForIdle() {67 robot.waitForIdle();68 }69 53 70 54 } -
java/main/src/test/java/com/framsticks/gui/BrowserTest.java
r96 r97 3 3 import static org.fest.assertions.Assertions.assertThat; 4 4 import static org.fest.swing.edt.GuiActionRunner.execute; 5 6 import java.awt.event.KeyEvent; 5 7 6 8 … … 10 12 11 13 import com.framsticks.model.ModelPackage; 12 import com.framsticks.remote.SimulatorInstance; 14 import com.framsticks.remote.SimulatorTree; 15 import com.framsticks.util.dispatching.Dispatching; 13 16 14 17 public class BrowserTest extends BrowserBaseTest { … … 16 19 private static final Logger log = Logger.getLogger(BrowserTest.class); 17 20 18 Simulator Instance localhost;21 SimulatorTree localhost; 19 22 20 23 @Override … … 22 25 browser = new Browser(); 23 26 24 localhost = new Simulator Instance();27 localhost = new SimulatorTree(); 25 28 localhost.setName("localhost"); 26 29 localhost.setAddress("localhost:9009"); 27 30 localhost.usePackage(new ModelPackage()); 28 31 29 browser.add Instance(localhost);32 browser.addTree(localhost); 30 33 31 34 } 32 35 33 @Test(timeOut = 10000)36 @Test(timeOut = 30000) 34 37 public void testShow() { 35 38 log.info("testing"); 36 39 tree.clickRow(0).expandRow(0); 37 40 robot.waitForIdle(); 41 38 42 tree.clickRow(1).expandRow(1); 39 43 robot.waitForIdle(); … … 47 51 }); 48 52 53 49 54 clickAndExpandPath("localhost/simulator/genepools"); 50 55 clickAndExpandPath("localhost/simulator/genepools/groups"); 51 56 clickAndExpandPath("localhost/simulator/genepools/groups/Genotypes"); 57 clickAndExpandPath("localhost/simulator/genepools/groups/Genotypes/genotypes"); 58 Dispatching.sleep(2.0); 59 clickAndExpandPath("localhost/simulator/genepools/groups/Genotypes/genotypes"); 60 robot.pressAndReleaseKey(KeyEvent.VK_J); 61 waitForIdle(); 62 Dispatching.sleep(2.0); 63 64 frame.panel("Genotype").panel("name").textBox("value").enterText("-Żółw"); 65 clickButton(frame.panel("Genotype").button("apply")); 66 67 Dispatching.sleep(1.0); 52 68 } 53 69 -
java/main/src/test/java/com/framsticks/gui/ProcedureBrowserTest.java
r96 r97 7 7 import org.testng.annotations.Test; 8 8 9 import com.framsticks.core. Instance;10 import com.framsticks.core.Object Instance;9 import com.framsticks.core.Tree; 10 import com.framsticks.core.ObjectTree; 11 11 import com.framsticks.params.AccessInterface; 12 12 import com.framsticks.params.FramsClass; … … 15 15 import com.framsticks.parsers.XmlLoader; 16 16 import com.framsticks.test.TestClass; 17 // import com.framsticks.util.dispatching.Dispatching; 17 18 import com.framsticks.util.dispatching.RunAt; 18 import static com.framsticks.core. InstanceUtils.*;19 import static com.framsticks.core.TreeOperations.*; 19 20 20 21 @Test 21 22 public class ProcedureBrowserTest extends BrowserBaseTest { 22 23 23 Object Instance instance;24 ObjectTree tree; 24 25 25 26 @Override … … 27 28 browser = new XmlLoader().load(Browser.class, getClass().getResourceAsStream("/configs/ProcedureBrowserTest.xml")); 28 29 29 assertThat(browser.get Instances().size()).isEqualTo(1);30 assertThat(browser.get Instances().get("test")).isInstanceOf(ObjectInstance.class);30 assertThat(browser.getTrees().size()).isEqualTo(1); 31 assertThat(browser.getTrees().get("test")).isInstanceOf(ObjectTree.class); 31 32 32 instance = (ObjectInstance) browser.getInstances().get("test");33 tree = (ObjectTree) browser.getTrees().get("test"); 33 34 } 34 35 35 36 @Test(timeOut = 10000) 36 37 public void testShow() { 37 instance.dispatch(new RunAt<Instance>() {38 tree.dispatch(new RunAt<Tree>(failOnException) { 38 39 @Override 39 p ublic void run() {40 assertThat( instance.getRootObject()).isInstanceOf(TestClass.class);40 protected void runAt() { 41 assertThat(tree.getRootObject()).isInstanceOf(TestClass.class); 41 42 } 42 43 }); … … 44 45 clickAndExpandPath("test"); 45 46 46 instance.dispatch(new RunAt<Instance>() {47 tree.dispatch(new RunAt<Tree>(failOnException) { 47 48 @Override 48 p ublic void run() {49 assertThat(bindAccess( instance, "/").getFramsClass().getParam("history")).isInstanceOf(StringParam.class);49 protected void runAt() { 50 assertThat(bindAccess(tree, "/").getFramsClass().getParam("history")).isInstanceOf(StringParam.class); 50 51 } 51 52 }); … … 53 54 // monitor.useFor(4.0); 54 55 55 instance.dispatch(new RunAt<Instance>() {56 tree.dispatch(new RunAt<Tree>(failOnException) { 56 57 @Override 57 p ublic void run() {58 AccessInterface access = bindAccess( instance, "/");58 protected void runAt() { 59 AccessInterface access = bindAccess(tree, "/"); 59 60 assertThat(access).isInstanceOf(ReflectionAccess.class); 60 61 FramsClass framsClass = access.getFramsClass(); … … 65 66 assertThat(framsClass.getParam(3).getId()).isEqualTo("resetHistory"); 66 67 67 assertThat(access.get("history", String.class)).isEqualTo(" ");68 assertThat(access.get("history", String.class)).isEqualTo("initial|"); 68 69 } 69 70 }); 70 71 71 72 // frame.panel("TestClass"); 72 JPanelFixture appendHistory = frame.panel("TestClass").panel("appendHistory"); 73 appendHistory.panel("arg0").textBox("value").enterText("argument"); 74 appendHistory.button("call").click(); 73 final JPanelFixture appendHistory = frame.panel("TestClass").panel("appendHistory"); 74 appendHistory.panel("arg0").textBox("value").enterText("Żółw"); 75 assertThat(appendHistory.panel("arg0").textBox("value").text()).isEqualTo("Żółw"); 76 clickButton(appendHistory.button("call")); 75 77 waitForIdle(); 76 78 77 instance.dispatch(new RunAt<Instance>() { 79 80 tree.dispatch(new RunAt<Tree>(failOnException) { 78 81 @Override 79 p ublic void run() {80 assertThat(bindAccess( instance, "/").get("history", String.class)).isEqualTo("argument|");82 protected void runAt() { 83 assertThat(bindAccess(tree, "/").get("history", String.class)).isEqualTo("initial|Żółw|"); 81 84 } 82 85 }); 83 86 84 frame.panel("TestClass").panel("resetHistory").button("call").click();87 clickButton(frame.panel("TestClass").panel("resetHistory").button("call")); 85 88 waitForIdle(); 86 89 87 instance.dispatch(new RunAt<Instance>() {90 tree.dispatch(new RunAt<Tree>(failOnException) { 88 91 @Override 89 p ublic void run() {90 assertThat(bindAccess( instance, "/").get("history", String.class)).isEqualTo("");92 protected void runAt() { 93 assertThat(bindAccess(tree, "/").get("history", String.class)).isEqualTo(""); 91 94 } 92 95 }); -
java/main/src/test/java/com/framsticks/hosting/ServerTest.java
r96 r97 4 4 import org.testng.annotations.Test; 5 5 6 import com.framsticks.core.ObjectInstance; 6 import com.framsticks.core.Mode; 7 import com.framsticks.core.ObjectTree; 7 8 import com.framsticks.core.Path; 8 9 import com.framsticks.core.XmlBasedTest; 9 import com.framsticks.remote.Remote Instance;10 import com.framsticks.remote.RemoteTree; 10 11 11 12 import com.framsticks.test.TestClass; 12 import com.framsticks.core. Instance;13 import com.framsticks.core.Tree; 13 14 import com.framsticks.params.FramsClass; 14 import com.framsticks.util.AbstractStateFunctor;15 15 import com.framsticks.util.dispatching.Dispatching; 16 16 import com.framsticks.params.AccessInterface; 17 import com.framsticks.params.PrimitiveParam; 17 18 import com.framsticks.params.PropertiesAccess; 18 import com.framsticks.params.ValueParam;19 19 import com.framsticks.params.types.ProcedureParam; 20 20 import com.framsticks.util.dispatching.Dispatching.Waiter; 21 import com.framsticks.util.dispatching.Future ;21 import com.framsticks.util.dispatching.FutureHandler; 22 22 import com.framsticks.util.dispatching.RunAt; 23 23 24 import static com.framsticks.core. InstanceUtils.*;24 import static com.framsticks.core.TreeOperations.*; 25 25 26 26 import static org.fest.assertions.Assertions.*; … … 29 29 public class ServerTest extends XmlBasedTest { 30 30 31 protected Remote Instance remote;31 protected RemoteTree remote; 32 32 protected FramsClass remoteTestFramsClass; 33 33 protected Path remotePath; 34 34 35 35 protected Server server; 36 protected Object Instance hosted;36 protected ObjectTree hosted; 37 37 protected TestClass hostedObject; 38 38 … … 46 46 assertThat(framsticks.size()).isEqualTo(2); 47 47 assertThat(framsticks.get("test")).isInstanceOf(Server.class); 48 assertThat(framsticks.get("remote")).isInstanceOf(Remote Instance.class);48 assertThat(framsticks.get("remote")).isInstanceOf(RemoteTree.class); 49 49 50 50 server = (Server) framsticks.get("test"); 51 remote = (Remote Instance) framsticks.get("remote");52 assertThat(server.getHosted()).isInstanceOf(Object Instance.class);53 hosted = (Object Instance) server.getHosted();51 remote = (RemoteTree) framsticks.get("remote"); 52 assertThat(server.getHosted()).isInstanceOf(ObjectTree.class); 53 hosted = (ObjectTree) server.getHosted(); 54 54 assertThat(hosted.getRootObject()).isInstanceOf(TestClass.class); 55 55 hostedObject = hosted.getRootObject(TestClass.class); … … 58 58 @Test(dependsOnMethods = "runServer") 59 59 public void fetchInfo() { 60 remote.dispatch(new RunAt< Instance>() {60 remote.dispatch(new RunAt<Tree>(failOnException) { 61 61 @Override 62 p ublic void run() {63 remote. fetchInfo(Path.to(remote, "/"), new Future<FramsClass>(failOnException()) {62 protected void runAt() { 63 remote.info(Path.to(remote, "/"), new FutureHandler<FramsClass>(failOnException) { 64 64 @Override 65 65 protected void result(FramsClass result) { … … 78 78 final Waiter waiter = produceWaiter(1.0); 79 79 80 remote.dispatch(new RunAt< Instance>() {80 remote.dispatch(new RunAt<Tree>(failOnException) { 81 81 @Override 82 p ublic void run() {82 protected void runAt() { 83 83 final Path path = Path.to(remote, "/"); 84 84 assertThat(path.isResolved()).isFalse(); 85 85 86 remote.resolve(path, new Future <Path>(failOnException()) {86 remote.resolve(path, new FutureHandler<Path>(failOnException) { 87 87 @Override 88 88 protected void result(final Path result) { 89 89 assertThat(result.isResolved()).isTrue(); 90 90 remotePath = result; 91 remote. fetchValues(result, new AbstractStateFunctor(failOnException()) {91 remote.get(result, Mode.FETCH, new FutureHandler<Object>(failOnException) { 92 92 @Override 93 p ublic void call() {93 protected void result(Object object) { 94 94 AccessInterface access = bindAccess(result); 95 95 assertThat(access).isInstanceOf(PropertiesAccess.class); … … 108 108 final Waiter waiter = produceWaiter(2.0); 109 109 110 s toreValue(remotePath, remoteTestFramsClass.getParamEntry("name", ValueParam.class), "new name", new AbstractStateFunctor(failOnException()) {110 set(remotePath, remoteTestFramsClass.getParamEntry("name", PrimitiveParam.class), "new name", new FutureHandler<Integer>(failOnException) { 111 111 @Override 112 public void call() { 112 protected void result(Integer flags) { 113 // assertThat(flags).isEqualTo(0); 113 114 /** And now check directly whether it was really set. */ 114 hosted.dispatch(new RunAt< Instance>() {115 hosted.dispatch(new RunAt<Tree>(failOnException) { 115 116 @Override 116 p ublic void run() {117 protected void runAt() { 117 118 assertThat(hostedObject.getName()).isEqualTo("new name"); 118 119 waiter.pass(); … … 128 129 final Waiter waiter = produceWaiter(2.0); 129 130 130 call(remotePath, remoteTestFramsClass.getParamEntry("resetHistory", ProcedureParam.class), new Object[] {}, new Future <Object>(failOnException()) {131 call(remotePath, remoteTestFramsClass.getParamEntry("resetHistory", ProcedureParam.class), new Object[] {}, new FutureHandler<Object>(failOnException) { 131 132 @Override 132 133 protected void result(Object result) { … … 135 136 }); 136 137 137 call(remotePath, remoteTestFramsClass.getParamEntry("appendHistory", ProcedureParam.class), new Object[] {"next word"}, new Future <Object>(failOnException()) {138 call(remotePath, remoteTestFramsClass.getParamEntry("appendHistory", ProcedureParam.class), new Object[] {"next word"}, new FutureHandler<Object>(failOnException) { 138 139 @Override 139 140 protected void result(Object result) { 140 hosted.dispatch(new RunAt< Instance>() {141 hosted.dispatch(new RunAt<Tree>(failOnException) { 141 142 @Override 142 p ublic void run() {143 protected void runAt() { 143 144 assertThat(hostedObject.getHistory()).isEqualTo("next word|"); 144 145 waiter.pass(); -
java/main/src/test/java/com/framsticks/model/f0/SchemaTest.java
r90 r97 20 20 assertThat(schema.getNeuroClasses().size()).isEqualTo(21); 21 21 22 assertThat(schema.getFramsClass("m").getName()).isEqualTo("Model"); 23 22 24 assertThat(schema.getNeuroClass("|").getName()).isEqualTo("Bend muscle"); 23 25 assertThat(schema.getNeuroClass("VEye").getParam("p")).isInstanceOf(FloatParam.class); -
java/main/src/test/java/com/framsticks/params/FramsClassBuilderTest.java
r96 r97 82 82 access.select(test); 83 83 84 assertThat(access.get("history", String.class)).isEqualTo(" first|");84 assertThat(access.get("history", String.class)).isEqualTo("initial|first|"); 85 85 Object result = access.call("appendHistory", new Object[] {"second"}); 86 86 87 87 assertThat(result).isInstanceOf(Integer.class); 88 assertThat(result).isEqualTo( 13);89 assertThat(access.get("history", String.class)).isEqualTo(" first|second|");88 assertThat(result).isEqualTo(21); 89 assertThat(access.get("history", String.class)).isEqualTo("initial|first|second|"); 90 90 91 91 result = access.call("resetHistory", null); -
java/main/src/test/java/com/framsticks/test/TestConfiguration.java
r96 r97 88 88 } 89 89 90 public static ExceptionResultHandler failOnException() { 91 return new ExceptionResultHandler() { 92 @Override 93 public void handle(FramsticksException e) { 94 assertThat(e).isNull(); 95 } 96 }; 97 98 } 90 public static final ExceptionResultHandler failOnException = new ExceptionResultHandler() { 91 @Override 92 public void handle(FramsticksException e) { 93 assertThat(e).isNull(); 94 } 95 }; 99 96 } -
java/main/src/test/resources/configs/FramsServerTest.xml
r90 r97 2 2 <Framsticks> 3 3 <import class="com.framsticks.running.FramsServer" /> 4 <import class="com.framsticks.remote.Remote Instance" />4 <import class="com.framsticks.remote.RemoteTree" /> 5 5 <import class="com.framsticks.running.LoggingOutputListener" /> 6 6 <FramsServer name="frams" port="9008"> 7 7 <LoggingOutputListener /> 8 8 </FramsServer> 9 <!-- <Remote Instance name="remote" address="localhost:9008" /> -->9 <!-- <RemoteTree name="remote" address="localhost:9008" /> --> 10 10 </Framsticks> -
java/main/src/test/resources/configs/ProcedureBrowserTest.xml
r90 r97 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <Browser> 3 <import class="com.framsticks.core.Object Instance" />3 <import class="com.framsticks.core.ObjectTree" /> 4 4 <import class="com.framsticks.test.TestClass" /> 5 <Object Instance name="test">5 <ObjectTree name="test"> 6 6 <TestClass /> 7 </Object Instance>7 </ObjectTree> 8 8 </Browser> -
java/main/src/test/resources/configs/ServerTest.xml
r96 r97 2 2 <Framsticks> 3 3 <import class="com.framsticks.hosting.Server" /> 4 <import class="com.framsticks.remote.Remote Instance" />5 <import class="com.framsticks.core.Object Instance" />4 <import class="com.framsticks.remote.RemoteTree" /> 5 <import class="com.framsticks.core.ObjectTree" /> 6 6 <import class="com.framsticks.test.TestClass" /> 7 7 <import class="com.framsticks.running.LoggingOutputListener" /> 8 8 <Server name="server" port="9007"> 9 <Object Instance name="test">9 <ObjectTree name="test"> 10 10 <TestClass name="a test name" /> 11 </Object Instance>11 </ObjectTree> 12 12 </Server> 13 <Remote Instance name="remote" address="localhost:9007" />13 <RemoteTree name="remote" address="localhost:9007" /> 14 14 </Framsticks> -
java/main/src/test/resources/configs/test.xml
r96 r97 2 2 <Framsticks> 3 3 <import class="com.framsticks.gui.Browser" /> 4 <import class="com.framsticks.remote.Simulator Instance" />4 <import class="com.framsticks.remote.SimulatorTree" /> 5 5 <Browser name="browser"> 6 <Simulator Instance name="localhost:9009" address="localhost:9009" />6 <SimulatorTree name="localhost:9009" address="localhost:9009" /> 7 7 </Browser> 8 8 </Framsticks> -
java/main/src/test/resources/log4j.properties
r96 r97 26 26 log4j.appender.STDOUT.layout.ConversionPattern=%d{ABSOLUTE} [%-5p] [%t] %c -- %m%n 27 27 28 log4j.logger.com.framsticks=INFO 29 # log4j.logger.com.framsticks.hosting.Server=DEBUG 28 log4j.logger.com.framsticks=WARN 29 log4j.logger.com.framsticks.test.TestConfiguration=INFO 30 # log4j.logger.com.framsticks.gui.console.TrackConsole=DEBUG 31 # log4j.logger.com.framsticks.gui.controls.ProcedureControl=DEBUG 32 # log4j.logger.com.framsticks.test.TestClass=DEBUG 30 33 # log4j.logger.com.framsticks.communication.ServerConnection=TRACE 31 # log4j.logger.com.framsticks.util.dispatching. AbstractJoinable=DEBUG34 # log4j.logger.com.framsticks.util.dispatching.Dispatching=DEBUG 32 35 # log4j.logger.com.framsticks.parsers.F0Writer=TRACE 33 # log4j.logger.com.framsticks.core.ObjectInstance=DEBUG34 # log4j.logger.com.framsticks.core.Instance=DEBUG35 36 # log4j.logger.com.framsticks.running=DEBUG 36 37 # log4j.logger.com.framsticks.parsers.XmlLoader=DEBUG
Note: See TracChangeset
for help on using the changeset viewer.