- Timestamp:
- 07/14/13 23:20:04 (11 years ago)
- Location:
- java/main
- Files:
-
- 35 added
- 20 deleted
- 87 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/pom.xml
r100 r101 17 17 <properties> 18 18 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 19 <framsticks.config>/ configs/framsticks.xml</framsticks.config>19 <framsticks.config>/framsticks.xml</framsticks.config> 20 20 </properties> 21 21 -
java/main/src/main/java/com/framsticks/communication/ClientSideManagedConnection.java
r100 r101 3 3 import com.framsticks.communication.queries.ApplicationRequest; 4 4 import com.framsticks.communication.queries.CallRequest; 5 import com.framsticks.communication.queries.NeedFile; 6 import com.framsticks.communication.queries.NeedFileAcceptor; 5 7 import com.framsticks.communication.queries.ProtocolRequest; 6 8 import com.framsticks.communication.queries.RegisterRequest; … … 43 45 private boolean isHandshakeDone = false; 44 46 47 protected NeedFileAcceptor needFileAcceptor; 48 49 /** 50 * @return the needFileAcceptor 51 */ 52 public NeedFileAcceptor getNeedFileAcceptor() { 53 return needFileAcceptor; 54 } 55 56 /** 57 * @param needFileAcceptor the needFileAcceptor to set 58 */ 59 public void setNeedFileAcceptor(NeedFileAcceptor needFileAcceptor) { 60 this.needFileAcceptor = needFileAcceptor; 61 } 45 62 46 63 /** … … 64 81 protocolVersion = -1; 65 82 } 66 67 68 83 69 84 protected List<String> readFileContent() { … … 116 131 } 117 132 118 private Map<Integer, SentQuery<?>> queryMap = new HashMap<>();119 120 private SentQuery<?> currentlySentQuery;121 122 133 public void send(ProtocolRequest request, ClientSideResponseFuture callback) { 123 134 //TODO RunAt … … 154 165 sentQuery.dispatcher = dispatcher; 155 166 167 156 168 senderThread.dispatch(new RunAt<Connection>(callback) { 157 169 @Override 158 170 protected void runAt() { 159 Integer id; 160 synchronized (ClientSideManagedConnection.this) { 161 162 while (!(requestIdEnabled || currentlySentQuery == null)) { 163 try { 164 ClientSideManagedConnection.this.wait(); 165 } catch (InterruptedException ignored) { 166 break; 167 } 168 } 169 if (requestIdEnabled) { 170 queryMap.put(nextQueryId, sentQuery); 171 id = nextQueryId++; 172 } else { 173 currentlySentQuery = sentQuery; 174 id = null; 175 } 176 } 171 Integer id = sentQueries.put(null, sentQuery); 172 177 173 String command = sentQuery.request.getCommand(); 178 174 StringBuilder message = new StringBuilder(); … … 188 184 flushOut(); 189 185 log.debug("sending query: {}", out); 190 191 186 } 192 187 }); 193 /*194 synchronized (this) {195 log.debug("queueing query: {}", query);196 queryQueue.offer(sentQuery);197 notifyAll();198 }199 */200 188 } 201 189 … … 204 192 return "client connection " + address; 205 193 } 206 207 194 208 195 private void sendQueryVersion(final int version, final Future<Void> future) { … … 229 216 } 230 217 231 private synchronized @Nonnull SentQuery<?> fetchQuery(@Nullable Integer id, boolean remove) { 232 try { 233 if (id == null) { 234 if (requestIdEnabled) { 235 throw new FramsticksException().msg("request_id is enabled and id is missing"); 236 } 237 SentQuery<?> result = currentlySentQuery; 238 if (remove) { 239 currentlySentQuery = null; 240 notifyAll(); 241 } 242 return result; 243 } 244 245 if (!queryMap.containsKey(id)) { 246 throw new FramsticksException().msg("id is unknown").arg("id", id); 247 } 248 249 SentQuery<?> result = queryMap.get(id); 250 if (remove) { 251 queryMap.remove(id); 252 } 253 return result; 254 255 } catch (FramsticksException e) { 256 throw new FramsticksException().msg("failed to match response to sent query").cause(e); 257 } 258 } 218 protected class IdCollection<T> { 219 220 221 protected final Map<Integer, T> map = new HashMap<>(); 222 protected T current; 223 224 public Integer put(Integer idProposition, T value) { 225 synchronized (ClientSideManagedConnection.this) { 226 while (!(requestIdEnabled || current == null)) { 227 try { 228 ClientSideManagedConnection.this.wait(); 229 } catch (InterruptedException ignored) { 230 break; 231 } 232 } 233 if (!requestIdEnabled) { 234 current = value; 235 return null; 236 } 237 if (idProposition == null) { 238 idProposition = nextQueryId++; 239 } 240 map.put(idProposition, value); 241 return idProposition; 242 } 243 } 244 245 public void clear(Integer id) { 246 if (requestIdEnabled) { 247 current = null; 248 } else { 249 map.remove(id); 250 } 251 } 252 253 public @Nonnull T fetch(@Nullable Integer id, boolean remove) { 254 synchronized (ClientSideManagedConnection.this) { 255 try { 256 if (id == null) { 257 if (requestIdEnabled) { 258 throw new FramsticksException().msg("request_id is enabled and id is missing"); 259 } 260 T result = current; 261 current = null; 262 ClientSideManagedConnection.this.notifyAll(); 263 return result; 264 } 265 if (!map.containsKey(id)) { 266 throw new FramsticksException().msg("id is unknown").arg("id", id); 267 } 268 269 T result = map.get(id); 270 if (remove) { 271 map.remove(id); 272 } 273 return result; 274 275 } catch (FramsticksException e) { 276 throw new FramsticksException().msg("failed to match response to sent query").cause(e); 277 } 278 } 279 } 280 } 281 282 protected IdCollection<SentQuery<?>> sentQueries = new IdCollection<>(); 283 protected IdCollection<NeedFile> needFiles = new IdCollection<>(); 259 284 260 285 private int nextQueryId = 0; … … 269 294 throw new FramsticksException().msg("expected file line").arg("got", fileLine); 270 295 } 271 String eventObjectPath = Request.takeGroup(rest, matcher, 1).toString();272 String eventCalleePath = Request.takeGroup(rest, matcher, 2).toString();296 String eventObjectPath = Strings.takeGroup(rest, matcher, 1).toString(); 297 String eventCalleePath = Strings.takeGroup(rest, matcher, 2).toString(); 273 298 final File file = new File("", new ListSource(readFileContent())); 274 299 log.debug("firing event {}", eventObjectPath); … … 277 302 listener = registeredListeners.get(eventObjectPath); 278 303 } 279 if (listener 304 if (listener == null) { 280 305 throw new FramsticksException().msg("failed to find registered event").arg("event path", eventObjectPath).arg("object", eventCalleePath); 281 306 } … … 283 308 } 284 309 310 protected void processNeedFile(Pair<Integer, CharSequence> rest) { 311 final Integer id = rest.first; 312 String suggestedName = null; 313 String description = null; 314 Pair<CharSequence, CharSequence> s = Request.takeString(rest.second); 315 if (s != null) { 316 suggestedName = s.first.toString(); 317 Pair<CharSequence, CharSequence> d = Request.takeString(s.second); 318 if (d != null) { 319 description = d.first.toString(); 320 } 321 } 322 323 final Future<File> future = new Future<File>() { 324 325 protected void send(final File result) { 326 log.info("sending file: " + result); 327 needFiles.clear(id); 328 sendFile(null, result, id, ClientSideManagedConnection.this); 329 330 } 331 332 @Override 333 protected void result(File result) { 334 send(result); 335 } 336 337 @Override 338 public void handle(FramsticksException exception) { 339 send(new File("", ListSource.createFrom("# invalid", "# " + exception.getMessage()))); 340 } 341 }; 342 343 NeedFile needFile = new NeedFile(suggestedName, description, future); 344 345 if (needFileAcceptor.acceptNeed(needFile)) { 346 return; 347 } 348 349 future.handle(new FramsticksException().msg("acceptor did not accepted need")); 350 } 351 285 352 protected void processFile(Pair<Integer, CharSequence> rest) { 286 final SentQuery<?> sentQuery = fetchQuery(rest.first, false);353 final SentQuery<?> sentQuery = sentQueries.fetch(rest.first, false); 287 354 288 355 String currentFilePath = rest.second.toString(); … … 292 359 293 360 sentQuery.files.add(new File(currentFilePath, new ListSource(readFileContent()))); 294 295 361 } 296 362 … … 318 384 if (keyword.equals("ok") || keyword.equals("error")) { 319 385 320 final SentQuery<?> sentQuery = fetchQuery(rest.first, true);386 final SentQuery<?> sentQuery = sentQueries.fetch(rest.first, true); 321 387 322 388 log.debug("parsing response for request {}", sentQuery); 323 389 324 390 sentQuery.dispatchResponseProcess(new Response(command.first.equals("ok"), rest.second.toString(), sentQuery.getFiles())); 391 return; 392 } 393 if (keyword.equals("needfile")) { 394 processNeedFile(rest); 325 395 return; 326 396 } … … 336 406 @Override 337 407 public void handle(FramsticksException exception) { 338 interrupt ();408 interruptJoinable(); 339 409 // finish(); 340 410 } -
java/main/src/main/java/com/framsticks/communication/Connection.java
r100 r101 1 1 package com.framsticks.communication; 2 2 3 import com.framsticks.params.Source; 3 4 import com.framsticks.params.annotations.AutoAppendAnnotation; 4 5 import com.framsticks.params.annotations.FramsClassAnnotation; … … 60 61 threads.add(senderThread); 61 62 threads.add(receiverThread); 62 63 63 } 64 64 … … 242 242 protected void runAt() { 243 243 receiverThreadRoutine(); 244 interrupt ();245 finish ();244 interruptJoinable(); 245 finishJoinable(); 246 246 } 247 247 }); … … 251 251 protected void joinableInterrupt() { 252 252 Dispatching.drop(threads, this); 253 finish ();253 finishJoinable(); 254 254 } 255 255 … … 331 331 332 332 333 protected static String idToString(Integer id) { 334 return id != null ? " " + id.toString() : ""; 335 } 336 337 protected final void putFile(File file, Integer outId) { 338 putLine("file" + idToString(outId)/* + " " + f.getPath()*/); 339 Source content = file.getContent(); 340 String line; 341 while ((line = content.readLine()) != null) { 342 putLine(line); 343 } 344 putLine("eof"); 345 } 346 347 public final void sendFile(final String header, final File file, final Integer id, ExceptionResultHandler handler) { 348 senderThread.dispatch(new RunAt<Connection>(handler) { 349 @Override 350 protected void runAt() { 351 if (header != null) { 352 putLine(header); 353 } 354 putFile(file, id); 355 flushOut(); 356 } 357 }); 358 } 359 333 360 } -
java/main/src/main/java/com/framsticks/communication/File.java
r96 r101 6 6 import javax.annotation.Nonnull; 7 7 8 import com.framsticks.params.Source Interface;8 import com.framsticks.params.Source; 9 9 // import com.framsticks.util.lang.Strings; 10 import com.framsticks.util.lang.Strings; 10 11 11 12 /** … … 14 15 public final class File { 15 16 protected final String path; 16 protected final Source Interfacecontent;17 protected final Source content; 17 18 18 public File(@Nonnull String path, @Nonnull Source Interfacecontent) {19 public File(@Nonnull String path, @Nonnull Source content) { 19 20 // assert Strings.notEmpty(path); 20 21 this.path = path; … … 26 27 } 27 28 28 public Source InterfacegetContent() {29 public Source getContent() { 29 30 return content; 30 31 } … … 35 36 return result; 36 37 } 38 39 @Override 40 public String toString() { 41 StringBuilder b = new StringBuilder(); 42 if (Strings.notEmpty(path)) { 43 b.append(path).append(": "); 44 } 45 b.append(content.toString()); 46 return b.toString(); 47 } 48 37 49 } -
java/main/src/main/java/com/framsticks/communication/Request.java
r99 r101 7 7 import com.framsticks.util.FramsticksException; 8 8 import com.framsticks.util.lang.Pair; 9 import com.framsticks.util.lang.Strings; 9 10 10 11 /** … … 78 79 } 79 80 80 public static CharSequence takeGroup(CharSequence input, Matcher matcher, int group) {81 // return (matcher.start(group) == matcher.end(group)) ? null : input.subSequence(matcher.start(group), matcher.end(group));82 return input.subSequence(matcher.start(group), matcher.end(group));83 }84 81 85 82 public static Pair<CharSequence, CharSequence> takeString(CharSequence line) { … … 89 86 } 90 87 assert ((matcher.start(1) == -1) != (matcher.start(2) == -1)); 91 return new Pair<CharSequence, CharSequence>( takeGroup(line, matcher, (matcher.start(1) != -1 ? 1 : 2)),takeGroup(line, matcher, 3));88 return new Pair<CharSequence, CharSequence>(Strings.takeGroup(line, matcher, (matcher.start(1) != -1 ? 1 : 2)), Strings.takeGroup(line, matcher, 3)); 92 89 } 93 90 94 protected static final Pattern REQUEST_ID_BREAKER_PATTERN = Pattern.compile("^\\s*( [0-9]+)\\s*(.*)$");91 protected static final Pattern REQUEST_ID_BREAKER_PATTERN = Pattern.compile("^\\s*(-?[0-9]+)\\s*(.*)$"); 95 92 96 93 protected final static Pair<Integer, CharSequence> takeRequestId(boolean withId, CharSequence line) { … … 100 97 return null; 101 98 } 102 return new Pair<Integer, CharSequence>(Integer.valueOf( takeGroup(line, matcher, 1).toString()),takeGroup(line, matcher, 2));99 return new Pair<Integer, CharSequence>(Integer.valueOf(Strings.takeGroup(line, matcher, 1).toString()), Strings.takeGroup(line, matcher, 2)); 103 100 } 104 101 return new Pair<Integer, CharSequence>(null, line); -
java/main/src/main/java/com/framsticks/communication/ServerSideManagedConnection.java
r100 r101 2 2 3 3 import com.framsticks.communication.queries.*; 4 import com.framsticks.params.SourceInterface;5 4 import com.framsticks.util.FramsticksException; 6 5 import com.framsticks.util.lang.Holder; … … 69 68 } 70 69 71 protected final void putFile(File file, String outId) {72 putLine("file" + outId/* + " " + f.getPath()*/);73 SourceInterface content = file.getContent();74 String line;75 while ((line = content.readLine()) != null) {76 putLine(line);77 }78 putLine("eof");79 }80 70 81 public final void sendFile(final String header, final File file) {82 senderThread.dispatch(new RunAt<Connection>(requestHandler) {83 @Override84 protected void runAt() {85 putLine(header);86 putFile(file, "");87 flushOut();88 }89 });90 }91 71 92 72 protected final void respond(final Response response, final Integer id) { … … 94 74 @Override 95 75 protected void runAt() { 96 String outId = id != null ? " " + id : "";97 76 if (response.getFiles() != null) { 98 77 for (File f : response.getFiles()) { 99 putFile(f, outId);78 putFile(f, id); 100 79 } 101 80 } 102 81 StringBuilder statusLine = new StringBuilder(); 103 statusLine.append(response.getOk() ? "ok" : "error").append( outId);82 statusLine.append(response.getOk() ? "ok" : "error").append(idToString(id)); 104 83 if (Strings.notEmpty(response.getComment())) { 105 84 Request.quoteValue(statusLine.append(" "), response.getComment()); -
java/main/src/main/java/com/framsticks/communication/queries/CallRequest.java
r96 r101 17 17 18 18 public CallRequest addArguments(String arguments) { 19 // this.arguments = arguments;20 19 return this; 21 20 } -
java/main/src/main/java/com/framsticks/core/AbstractTree.java
r100 r101 1 1 package com.framsticks.core; 2 2 3 import java.util.Comparator; 4 import java.util.Iterator; 3 5 import java.util.Map; 6 import java.util.PriorityQueue; 4 7 5 8 import javax.annotation.Nonnull; … … 9 12 import org.apache.logging.log4j.LogManager; 10 13 14 import com.framsticks.communication.queries.NeedFile; 15 import com.framsticks.communication.queries.NeedFileAcceptor; 11 16 import com.framsticks.params.Access; 12 17 import com.framsticks.params.CompositeParam; 13 18 import com.framsticks.params.FramsClass; 19 import com.framsticks.params.ParamFlags; 14 20 import com.framsticks.params.ParamsPackage; 15 21 import com.framsticks.params.Registry; … … 20 26 import com.framsticks.util.Misc; 21 27 import com.framsticks.util.dispatching.AbstractJoinable; 28 import com.framsticks.util.dispatching.BufferedDispatcher; 22 29 import com.framsticks.util.dispatching.Dispatcher; 23 30 import com.framsticks.util.dispatching.Dispatching; 24 31 import com.framsticks.util.dispatching.ExceptionResultHandler; 25 32 import com.framsticks.util.dispatching.Joinable; 26 import com.framsticks.util.dispatching.JoinableDispatcher;27 33 import com.framsticks.util.dispatching.JoinableParent; 28 34 import com.framsticks.util.dispatching.JoinableState; … … 30 36 import com.framsticks.util.dispatching.Thread; 31 37 import com.framsticks.util.dispatching.ThrowExceptionHandler; 32 import com.framsticks.util.lang. Casting;38 import com.framsticks.util.lang.Pair; 33 39 34 40 /** … … 36 42 */ 37 43 @FramsClassAnnotation 38 public abstract class AbstractTree extends AbstractJoinable implements Dispatcher<Tree>, Tree, JoinableParent {44 public abstract class AbstractTree extends AbstractJoinable implements Dispatcher<Tree>, Tree, JoinableParent, NeedFileAcceptor { 39 45 40 46 private static final Logger log = LogManager.getLogger(AbstractTree.class); … … 43 49 private ExceptionResultHandler handler = ThrowExceptionHandler.getInstance(); 44 50 45 private JoinableDispatcher<Tree> dispatcher; 51 protected final BufferedDispatcher<Tree> bufferedDispatcher = new BufferedDispatcher<>(); 52 53 protected final PriorityQueue<Pair<Integer, NeedFileAcceptor>> needFileAcceptors = new PriorityQueue<>(32, new Comparator<Pair<Integer, NeedFileAcceptor>>() { 54 55 @Override 56 public int compare(Pair<Integer, NeedFileAcceptor> arg0, Pair<Integer, NeedFileAcceptor> arg1) { 57 if (arg0.first < arg1.first) { 58 return -1; 59 } 60 if (arg0.first > arg1.first) { 61 return 1; 62 } 63 return 0; 64 } 65 }); 46 66 47 67 @Override … … 152 172 */ 153 173 @Override 154 public JoinableDispatcher<Tree> getDispatcher() {155 return dispatcher;174 public Dispatcher<Tree> getDispatcher() { 175 return bufferedDispatcher.getTargetDispatcher(); 156 176 } 157 177 … … 160 180 */ 161 181 @Override 162 public void setDispatcher( JoinableDispatcher<Tree> dispatcher) {163 if ( this.dispatcher!= null) {164 throw new FramsticksException().msg("dispatcher is already set").arg("tree", this).arg("dispatcher", dispatcher);165 } 166 this.dispatcher = dispatcher;182 public void setDispatcher(Dispatcher<Tree> dispatcher) { 183 if (bufferedDispatcher.getTargetDispatcher() != null) { 184 throw new FramsticksException().msg("dispatcher is already set").arg("tree", this).arg("dispatcher", bufferedDispatcher.getTargetDispatcher()); 185 } 186 bufferedDispatcher.setTargetDispatcher(dispatcher); 167 187 } 168 188 … … 170 190 * @return the name 171 191 */ 172 @ParamAnnotation 192 @ParamAnnotation(flags = ParamFlags.USERREADONLY) 173 193 public String getName() { 174 194 return name; … … 193 213 @Override 194 214 protected void joinableStart() { 195 if ( dispatcher== null) {196 dispatcher = new Thread<Tree>();197 } 198 Dispatching.use( dispatcher, this);215 if (bufferedDispatcher.getTargetDispatcher() == null) { 216 bufferedDispatcher.setTargetDispatcher(new Thread<Tree>()); 217 } 218 Dispatching.use(bufferedDispatcher.getTargetDispatcher(), this); 199 219 } 200 220 201 221 @Override 202 222 protected void joinableInterrupt() { 203 Dispatching.drop( dispatcher, this);223 Dispatching.drop(bufferedDispatcher.getTargetDispatcher(), this); 204 224 } 205 225 … … 211 231 @Override 212 232 protected void joinableJoin() throws InterruptedException { 213 Dispatching.join( dispatcher);233 Dispatching.join(bufferedDispatcher.getTargetDispatcher()); 214 234 } 215 235 216 236 @Override 217 237 public void childChangedState(Joinable joinable, JoinableState state) { 218 if (joinable == dispatcher) {238 if (joinable == bufferedDispatcher.getTargetDispatcher()) { 219 239 proceedToState(state); 220 240 } … … 223 243 @Override 224 244 public boolean isActive() { 225 if (dispatcher == null) { 226 throw new FramsticksException().msg("no dispatcher is set for tree yet").arg("tree", this); 227 } 228 return dispatcher.isActive(); 245 return bufferedDispatcher.isActive(); 229 246 } 230 247 231 248 @Override 232 249 public void dispatch(RunAt<? extends Tree> runnable) { 233 if (dispatcher == null) { 234 throw new FramsticksException().msg("no dispatcher is set for tree yet").arg("tree", this); 235 } 236 dispatcher.dispatch(runnable); 250 bufferedDispatcher.dispatch(runnable); 237 251 } 238 252 … … 242 256 243 257 @Override 244 public void putSideNote(Object object, Object key, Objectvalue) {258 public <T> void putSideNote(Object object, SideNoteKey<T> key, T value) { 245 259 assert isActive(); 246 260 Misc.throwIfNull(object); … … 253 267 } 254 268 @SuppressWarnings("unchecked") 255 Map< Object, Object> sideNotesMap = (Map<Object, Object>) sideNote;269 Map<SideNoteKey<?>, Object> sideNotesMap = (Map<SideNoteKey<?>, Object>) sideNote; 256 270 sideNotesMap.put(key, value); 257 271 } 258 272 259 @Override 260 public <T> T getSideNote(Object object, Object key, Class<T> valueType) { 273 @SuppressWarnings("unchecked") 274 @Override 275 public <T> T getSideNote(Object object, SideNoteKey<T> key) { 261 276 assert isActive(); 262 277 Misc.throwIfNull(object); … … 266 281 return null; 267 282 } 268 return Casting.nullOrThrowCast(valueType, ((Map<?, ?>) sideNote).get(key)); 269 } 270 271 @Override 272 public boolean removeSideNote(Object object, Object key) { 283 Object value = ((Map<SideNoteKey<?>, Object>) sideNote).get(key); 284 if (value == null) { 285 return null; 286 } 287 return (T) value; 288 } 289 290 @Override 291 public boolean removeSideNote(Object object, SideNoteKey<?> key) { 292 assert isActive(); 273 293 Object sideNote = sideNotes.get(object); 274 294 if (sideNote == null) { … … 276 296 } 277 297 @SuppressWarnings("unchecked") 278 Map< Object, Object> sideNotesMap = (Map<Object, Object>) sideNote;298 Map<SideNoteKey<?>, Object> sideNotesMap = (Map<SideNoteKey<?>, Object>) sideNote; 279 299 boolean result = (sideNotesMap.remove(key) != null); 280 300 if (sideNotesMap.isEmpty()) { … … 284 304 } 285 305 306 @Override 307 public void addNeedFileAcceptor(int priority, NeedFileAcceptor acceptor) { 308 assert isActive(); 309 needFileAcceptors.add(Pair.make(priority, acceptor)); 310 } 311 312 @Override 313 public void removeNeedFileAcceptor(NeedFileAcceptor acceptor) { 314 assert isActive(); 315 Iterator<Pair<Integer, NeedFileAcceptor>> i = needFileAcceptors.iterator(); 316 while (i.hasNext()) { 317 if (i.next().second == acceptor) { 318 i.remove(); 319 break; 320 } 321 } 322 } 323 324 @Override 325 public boolean acceptNeed(final NeedFile needFile) { 326 Dispatching.dispatchIfNotActive(this, new RunAt<AbstractTree>(needFile.getFuture()) { 327 328 @Override 329 protected void runAt() { 330 for (Pair<Integer, NeedFileAcceptor> acceptor : needFileAcceptors) { 331 if (acceptor.second.acceptNeed(needFile)) { 332 return; 333 } 334 } 335 throw new FramsticksException().msg("failed to find need file acceptor in tree").arg("tree", AbstractTree.this); 336 } 337 }); 338 return true; 339 } 340 286 341 } 287 342 -
java/main/src/main/java/com/framsticks/core/Framsticks.java
r100 r101 29 29 public static void main(final String[] args) { 30 30 31 String config = "/ configs/framsticks.xml";31 String config = "/framsticks.xml"; 32 32 if (args.length != 0) { 33 33 config = args[0]; -
java/main/src/main/java/com/framsticks/core/LocalTree.java
r100 r101 15 15 import com.framsticks.params.types.ProcedureParam; 16 16 import com.framsticks.util.FramsticksException; 17 import com.framsticks.util.dispatching.Dispatching; 17 18 import com.framsticks.util.dispatching.Future; 19 import com.framsticks.util.dispatching.Joinable; 20 import com.framsticks.util.dispatching.JoinableState; 18 21 19 22 import static com.framsticks.core.TreeOperations.*; … … 23 26 private static final Logger log = LogManager.getLogger(LocalTree.class); 24 27 25 protected Object rootObject;28 protected Joinable joinableRootObject; 26 29 27 30 /** … … 42 45 assignRootParam(access.buildParam(new ParamBuilder()).id(getName()).finish(CompositeParam.class)); 43 46 assignRootObject(object); 47 48 if (object instanceof Joinable) { 49 joinableRootObject = (Joinable) object; 50 } 44 51 } 45 52 … … 69 76 // @Override 70 77 // public void get(Path path, ValueParam param, Future<Object> future) { 71 // 72 // 73 // 78 // assert isActive(); 79 // path = resolveTopSync(path); 80 // future.pass(bindAccess(path).get(param, Object.class)); 74 81 // } 75 82 … … 137 144 } 138 145 } 146 147 @Override 148 protected void joinableStart() { 149 super.joinableStart(); 150 if (joinableRootObject != null) { 151 Dispatching.use(joinableRootObject, this); 152 } 153 } 154 155 @Override 156 protected void joinableInterrupt() { 157 if (joinableRootObject != null) { 158 Dispatching.drop(joinableRootObject, this); 159 } 160 super.joinableInterrupt(); 161 } 162 163 @Override 164 protected void joinableFinish() { 165 super.joinableFinish(); 166 } 167 168 @Override 169 protected void joinableJoin() throws InterruptedException { 170 if (joinableRootObject != null) { 171 Dispatching.join(joinableRootObject); 172 } 173 super.joinableJoin(); 174 } 175 176 @Override 177 public void childChangedState(Joinable joinable, JoinableState state) { 178 super.childChangedState(joinable, state); 179 if (joinable == joinableRootObject) { 180 proceedToState(state); 181 } 182 } 139 183 } -
java/main/src/main/java/com/framsticks/core/Path.java
r100 r101 31 31 final LinkedList<Node> nodes; 32 32 33 public static final SideNoteKey<CompositeParam> OBJECT_PARAM_KEY = SideNoteKey.make(CompositeParam.class); 34 33 35 protected static Object getKnownChild(Tree tree, Access access, CompositeParam param, ExceptionResultHandler handler) { 34 36 Object child = access.get(param, Object.class); … … 38 40 try { 39 41 tree.prepareAccess(param); 40 tree.putSideNote(child, CompositeParam.class, param);42 tree.putSideNote(child, OBJECT_PARAM_KEY, param); 41 43 return child; 42 44 } catch (FramsticksException e) { … … 164 166 b.append("/").append(e); 165 167 access.select(current.getObject()); 166 tree.putSideNote(current.getObject(), CompositeParam.class, current.getParam());168 tree.putSideNote(current.getObject(), OBJECT_PARAM_KEY, current.getParam()); 167 169 current = new Node(current.getTree(), c, getKnownChild(tree, access, c, handler)); 168 170 nodes.add(current); -
java/main/src/main/java/com/framsticks/core/Tree.java
r100 r101 3 3 import javax.annotation.Nonnull; 4 4 5 import com.framsticks.communication.queries.NeedFileAcceptor; 5 6 import com.framsticks.params.Access; 6 7 import com.framsticks.params.CompositeParam; … … 15 16 import com.framsticks.util.dispatching.Future; 16 17 import com.framsticks.util.dispatching.Joinable; 17 import com.framsticks.util.dispatching.JoinableDispatcher;18 18 19 19 public interface Tree extends Dispatcher<Tree>, Joinable, ExceptionResultHandler { … … 54 54 public ExceptionResultHandler getExceptionHandler(); 55 55 56 public void setDispatcher( JoinableDispatcher<Tree> dispatcher);56 public void setDispatcher(Dispatcher<Tree> dispatcher); 57 57 58 public JoinableDispatcher<Tree> getDispatcher();58 public Dispatcher<Tree> getDispatcher(); 59 59 60 60 public <A> void addListener(Path path, EventParam param, EventListener<A> listener, Class<A> argumentType, Future<Void> future); … … 64 64 public Registry getRegistry(); 65 65 66 public void putSideNote(Object object, Object key, Objectvalue);66 public <T> void putSideNote(Object object, SideNoteKey<T> key, T value); 67 67 68 public boolean removeSideNote(Object object, Objectkey);68 public boolean removeSideNote(Object object, SideNoteKey<?> key); 69 69 70 public <T> T getSideNote(Object object, Object key, Class<T> valueType); 70 public <T> T getSideNote(Object object, SideNoteKey<T> key); 71 72 public void addNeedFileAcceptor(int priority, NeedFileAcceptor acceptor); 73 74 public void removeNeedFileAcceptor(NeedFileAcceptor acceptor); 71 75 72 76 } -
java/main/src/main/java/com/framsticks/core/TreeOperations.java
r100 r101 1 1 package com.framsticks.core; 2 3 2 4 3 import java.util.HashSet; … … 22 21 import com.framsticks.params.PropertiesAccess; 23 22 import com.framsticks.params.UniqueListAccess; 24 import com.framsticks.params. Util;23 import com.framsticks.params.ParamsUtil; 25 24 import com.framsticks.params.types.EventParam; 26 25 import com.framsticks.params.types.ObjectParam; … … 43 42 } 44 43 45 public static final Object FETCHED_MARK = new Object(); 46 47 public static @Nonnull FramsClass processFetchedInfo(Tree tree, File file) { 44 public static final SideNoteKey<Boolean> FETCHED_MARK = SideNoteKey.make(Boolean.class); 45 46 public static @Nonnull 47 FramsClass processFetchedInfo(Tree tree, File file) { 48 48 assert tree.isActive(); 49 49 FramsClass framsClass = Loaders.loadFramsClass(file.getContent()); … … 80 80 assert path.isTheSame(files.get(0).getPath()); 81 81 82 83 82 try { 84 83 log.debug("process fetched values: {}", path); … … 98 97 if (path.getTop().getParam() instanceof ObjectParam) { 99 98 assert results.size() == 1; 100 Util.takeAllNonNullValues(bindAccess(result), parsingAccess.select(results.get(0)));99 ParamsUtil.takeAllNonNullValues(bindAccess(result), parsingAccess.select(results.get(0))); 101 100 mark(result.getTree(), result.getTopObject(), FETCHED_MARK, true); 102 101 future.pass(result); 103 102 return; 104 103 } 105 106 104 107 105 final ListAccess listAccess = (ListAccess) access; … … 139 137 140 138 targetAccess.select(childTo); 141 Util.takeAllNonNullValues(targetAccess, parsingAccess);139 ParamsUtil.takeAllNonNullValues(targetAccess, parsingAccess); 142 140 if (newOne) { 143 141 listAccess.set(id, childTo); … … 188 186 } 189 187 190 191 public static @NonnullAccess bindAccessFromSideNote(Tree tree, Object object) {192 CompositeParam param = tree.getSideNote(object, CompositeParam.class, CompositeParam.class);188 public static @Nonnull 189 Access bindAccessFromSideNote(Tree tree, Object object) { 190 CompositeParam param = tree.getSideNote(object, Path.OBJECT_PARAM_KEY); 193 191 if (param == null) { 194 192 throw new FramsticksException().msg("failed to bind access from side node").arg("tree", tree).arg("object", object).arg("type", object.getClass()); … … 197 195 } 198 196 199 public static @Nonnull Access bindAccess(Tree tree, String path) { 197 public static @Nonnull 198 Access bindAccess(Tree tree, String path) { 200 199 log.debug("bind access for textual: {} in {}", path, tree); 201 200 return bindAccess(Path.to(tree, path)); 202 201 } 203 202 204 public static @Nonnull Access bindAccess(Node node) { 203 public static @Nonnull 204 Access bindAccess(Node node) { 205 205 Tree tree = node.getTree(); 206 206 assert tree.isActive(); … … 209 209 try { 210 210 Access access = tree.prepareAccess(node.getParam()); 211 tree.putSideNote(node.getObject(), CompositeParam.class, node.getParam());211 tree.putSideNote(node.getObject(), Path.OBJECT_PARAM_KEY, node.getParam()); 212 212 213 213 return access.select(node.getObject()); … … 218 218 } 219 219 220 public static @Nonnull Access bindAccess(Path path) { 220 public static @Nonnull 221 Access bindAccess(Path path) { 221 222 assert path.getTree().isActive(); 222 223 path.assureResolved(); … … 280 281 }); 281 282 } 282 283 283 284 284 /** … … 323 323 public static Object createAccessee(Tree tree, CompositeParam param) { 324 324 Object object = tree.prepareAccess(param).createAccessee(); 325 tree.putSideNote(object, CompositeParam.class, param);325 tree.putSideNote(object, Path.OBJECT_PARAM_KEY, param); 326 326 return object; 327 327 } … … 329 329 public static Object createAccessee(Tree tree, Access access) { 330 330 Object object = access.createAccessee(); 331 tree.putSideNote(object, CompositeParam.class, access.buildParam(new ParamBuilder()).finish(CompositeParam.class));331 tree.putSideNote(object, Path.OBJECT_PARAM_KEY, access.buildParam(new ParamBuilder()).finish(CompositeParam.class)); 332 332 return object; 333 333 } 334 334 335 public static boolean isMarked(Tree tree, Object object, Objectmark, boolean defValue) {336 assert tree.isActive(); 337 Boolean v = tree.getSideNote(object, mark , Boolean.class);335 public static boolean isMarked(Tree tree, Object object, SideNoteKey<Boolean> mark, boolean defValue) { 336 assert tree.isActive(); 337 Boolean v = tree.getSideNote(object, mark); 338 338 return (v != null ? v : defValue); 339 339 } 340 340 341 public static void mark(Tree tree, Object object, Objectmark, boolean value) {341 public static void mark(Tree tree, Object object, SideNoteKey<Boolean> mark, boolean value) { 342 342 assert tree.isActive(); 343 343 tree.putSideNote(object, mark, value); … … 348 348 } 349 349 350 public static <T extends Param> T getParam(Path path, String id, Class<T> type) { 351 return getFramsClass(path).getParamEntry(id, type); 352 } 353 354 public static <T> T getOrCreateSideNote(Tree tree, Object object, SideNoteKey<T> key) { 355 T result = tree.getSideNote(object, key); 356 if (result == null) { 357 result = key.newValue(); 358 tree.putSideNote(object, key, result); 359 } 360 return result; 361 } 362 363 public static <T> boolean hasSideNotes(Tree tree, Object object, SideNoteKey<T> key) { 364 return tree.getSideNote(object, key) != null; 365 } 366 367 public static <T> boolean hasSideNote(Path path, SideNoteKey<T> key) { 368 return path.getTree().getSideNote(path.getTopObject(), key) != null; 369 } 370 371 public static <T> T getSideNote(Path path, SideNoteKey<T> key) { 372 assert path.isResolved(); 373 return path.getTree().getSideNote(path.getTopObject(), key); 374 } 375 376 public static <T> void putSideNote(Path path, SideNoteKey<T> key, T value) { 377 path.getTree().putSideNote(path.getTopObject(), key, value); 378 } 379 380 public static boolean removeSideNote(Path path, SideNoteKey<?> key) { 381 assert path.isResolved(); 382 return path.getTree().removeSideNote(path.getTopObject(), key); 383 } 384 350 385 } -
java/main/src/main/java/com/framsticks/gui/Browser.java
r100 r101 1 1 package com.framsticks.gui; 2 2 3 import com.framsticks.communication.File; 4 import com.framsticks.communication.queries.NeedFile; 5 import com.framsticks.communication.queries.NeedFileAcceptor; 3 6 import com.framsticks.core.*; 4 7 import com.framsticks.gui.console.Console; … … 9 12 import com.framsticks.params.annotations.FramsClassAnnotation; 10 13 import com.framsticks.params.annotations.ParamAnnotation; 14 import com.framsticks.parsers.FileSource; 11 15 import com.framsticks.remote.RemoteTree; 12 16 import com.framsticks.util.FramsticksException; … … 22 26 23 27 import javax.swing.*; 28 import javax.swing.filechooser.FileNameExtensionFilter; 24 29 25 30 import org.apache.logging.log4j.Logger; … … 30 35 import java.awt.datatransfer.StringSelection; 31 36 import java.awt.event.ActionEvent; 37 import java.awt.event.ActionListener; 38 import java.awt.event.WindowAdapter; 39 import java.awt.event.WindowEvent; 40 import java.io.IOException; 32 41 import java.util.ArrayList; 33 42 import java.util.LinkedList; 34 43 import java.util.List; 44 import java.util.regex.Matcher; 45 import java.util.regex.Pattern; 46 35 47 import com.framsticks.util.dispatching.RunAt; 48 import com.framsticks.util.lang.Strings; 36 49 37 50 /** … … 132 145 } 133 146 147 protected static final Pattern extensionFilterPattern = Pattern.compile("\\*\\.(\\S+)"); 148 134 149 @AutoAppendAnnotation 135 public void addTree( Tree tree) {150 public void addTree(final Tree tree) { 136 151 log.debug("adding tree: {}", tree); 137 152 tree.setDispatcher(new SwingDispatcher<Tree>()); 138 153 tree.setExceptionHandler(this); 139 154 trees.add(tree); 155 156 final NeedFileAcceptor acceptor = new NeedFileAcceptor() { 157 158 protected boolean done = false; 159 160 @Override 161 public boolean acceptNeed(final NeedFile needFile) { 162 final JFileChooser chooser = new JFileChooser(); 163 final JFrame frame = new JFrame(); 164 165 frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); 166 167 frame.addWindowListener(new WindowAdapter() { 168 @Override 169 public void windowClosing(WindowEvent e) { 170 if (!done) { 171 needFile.getFuture().handle(new FramsticksException().msg("user closed the window")); 172 } 173 frame.setVisible(false); 174 frame.dispose(); 175 } 176 }); 177 178 frame.setTitle(Strings.toStringEmptyProof(needFile.getDescription(), "Choose file")); 179 chooser.setMultiSelectionEnabled(false); 180 Matcher matcher = extensionFilterPattern.matcher(needFile.getSuggestedName()); 181 if (matcher.matches()) { 182 chooser.setFileFilter(new FileNameExtensionFilter(Strings.toStringEmptyProof(needFile.getDescription(), "file"), Strings.takeGroup(needFile.getSuggestedName(), matcher, 1).toString())); 183 } 184 185 frame.getContentPane().add(chooser); 186 187 chooser.addActionListener(new ActionListener() { 188 189 @Override 190 public void actionPerformed(ActionEvent event) { 191 if (event.getActionCommand().equals("CancelSelection")) { 192 needFile.getFuture().handle(new FramsticksException().msg("user cancelled choose")); 193 frame.setVisible(false); 194 frame.dispose(); 195 } 196 if (event.getActionCommand().equals("ApproveSelection")) { 197 File file = null; 198 String filename = chooser.getSelectedFile().getAbsolutePath(); 199 try { 200 file = new File("", new FileSource(filename)); 201 } catch (IOException e) { 202 needFile.getFuture().handle(new FramsticksException().msg("failed to open choosed file").arg("filename", filename).cause(e)); 203 } 204 if (file != null) { 205 done = true; 206 needFile.getFuture().pass(file); 207 } 208 frame.setVisible(false); 209 frame.dispose(); 210 } 211 } 212 }); 213 frame.setVisible(true); 214 return true; 215 } 216 }; 217 218 tree.dispatch(new RunAt<Tree>(this) { 219 @Override 220 protected void runAt() { 221 log.debug("adding need file acceptor: {}", acceptor); 222 tree.addNeedFileAcceptor(Integer.MAX_VALUE, acceptor); 223 } 224 }); 225 140 226 } 141 227 … … 143 229 // final Tree i = trees.get("localhost"); 144 230 // i.dispatch(new RunAt<Tree>(future) { 145 // 146 // 147 // 148 // 149 // 150 // 151 // 152 // 153 // 154 // 155 // 156 // 157 // 158 // 159 // 231 // @Override 232 // protected void runAt() { 233 // TreeOperations.tryGet(i, path, new FutureHandler<Path>(future) { 234 // @Override 235 // protected void result(final Path p) { 236 // future.pass(p); 237 // mainFrame.dispatch(new RunAt<Frame>(future) { 238 // @Override 239 // protected void runAt() { 240 // mainFrame.goTo(p); 241 // } 242 // }); 243 // } 244 // }); 245 // } 160 246 // }); 161 247 } … … 183 269 protected void runAt() { 184 270 final Path p = Path.to(i, "/"); 271 log.debug("adding path: {}", p); 185 272 dispatch(new RunAt<Browser>(this) { 186 273 @Override -
java/main/src/main/java/com/framsticks/gui/Frame.java
r100 r101 243 243 @Override 244 244 public void actionPerformed(ActionEvent actionEvent) { 245 interrupt ();245 interruptJoinable(); 246 246 } 247 247 }); … … 268 268 log.debug("trying mount: {}", path); 269 269 if (!tree.getAssignedRoot().isResolved()) { 270 log.debug("root not yet assigned, geting root"); 270 271 tree.get(path, new FutureHandler<Path>(this) { 271 272 -
java/main/src/main/java/com/framsticks/gui/FrameJoinable.java
r100 r101 31 31 */ 32 32 public FrameJoinable() { 33 statusBar = new StatusBar( );33 statusBar = new StatusBar(this); 34 34 } 35 35 … … 101 101 @Override 102 102 protected void runAt() { 103 finish ();103 finishJoinable(); 104 104 } 105 105 }); … … 135 135 public void windowClosing(WindowEvent e) { 136 136 log.info("received closing"); 137 interrupt ();137 interruptJoinable(); 138 138 } 139 139 }); -
java/main/src/main/java/com/framsticks/gui/Gui.java
r100 r101 7 7 import javax.swing.Box; 8 8 import javax.swing.BoxLayout; 9 import javax.swing.JComponent; 9 10 import javax.swing.JLabel; 10 11 import javax.swing.JPanel; 12 import javax.swing.border.TitledBorder; 11 13 12 14 import org.apache.logging.log4j.Logger; … … 24 26 import com.framsticks.params.CompositeParam; 25 27 import com.framsticks.params.Param; 28 import com.framsticks.params.ParamFlags; 26 29 import com.framsticks.params.PrimitiveParam; 27 30 import com.framsticks.params.types.BinaryParam; … … 101 104 } 102 105 103 public static <P extends Param, C extends Control> void fillWithControls(ControlOwner owner, Collection<P> params, Map<P, C> components, Class<C> controlType) {104 JPanel panel = owner.getPanelForControls();106 public static <P extends Param, C extends Control> void fillWithControls(ControlOwner owner, JPanel panel, Collection<P> params, Map<String, C> components, Class<C> controlType) { 107 panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); 105 108 for (P param : params) { 106 if (param. isUserHidden()) {109 if (param.hasFlag(ParamFlags.USERHIDDEN)) { 107 110 continue; 108 111 } … … 122 125 line.setLayout(new BoxLayout(line, BoxLayout.LINE_AXIS)); 123 126 line.setAlignmentX(JPanel.LEFT_ALIGNMENT); 124 JLabel label = new JLabel(Strings.notEmpty(param.getName()) ? param.getName() : (Strings.notEmpty(param.getId()) ? param.getId() : "?")); 125 label.setToolTipText(control.getToolTipText()); 126 label.setHorizontalAlignment(JLabel.RIGHT); 127 Dimension labelSize = new Dimension(150, 30); 128 label.setMaximumSize(labelSize); 129 label.setMinimumSize(labelSize); 130 label.setPreferredSize(labelSize); 131 line.add(label); 132 line.add(Box.createRigidArea(new Dimension(8, 0))); 127 133 128 line.add(control); 134 129 line.revalidate(); 135 130 panel.add(line); 136 131 panel.add(Box.createRigidArea(new Dimension(0, 8))); 132 components.put(param.getId(), control); 137 133 //component.setAlignmentX(LEFT_ALIGNMENT); 138 components.put(param, control);134 // components.put(param.getId(), control); 139 135 } 140 136 141 137 } 138 139 public static String getBestName(Param param) { 140 if (Strings.notEmpty(param.getName())) { 141 return param.getName(); 142 } 143 if (Strings.notEmpty(param.getId())) { 144 return param.getId(); 145 } 146 return "?"; 147 } 148 149 public static void setupTitledControl(Control control, JComponent... components) { 150 151 control.setLayout(new BoxLayout(control, BoxLayout.PAGE_AXIS)); 152 control.setBorder(new TitledBorder(Gui.getBestName(control.getParam()))); 153 for (JComponent c : components) { 154 // control.add(Box.createRigidArea(new Dimension(0, 4))); 155 control.add(c); 156 } 157 } 158 159 public static void layoutInRow(JPanel panel, JComponent first, JComponent... components) { 160 panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS)); 161 panel.setAlignmentX(JPanel.LEFT_ALIGNMENT); 162 163 panel.add(first); 164 for (JComponent c : components) { 165 panel.add(Box.createRigidArea(new Dimension(8, 0))); 166 panel.add(c); 167 } 168 } 169 170 public static void addLeftToLabel(Control control, JComponent... components) { 171 172 JLabel label = new JLabel(getBestName(control.getParam())); 173 label.setToolTipText(control.getToolTipText()); 174 label.setHorizontalAlignment(JLabel.LEFT); 175 Dimension labelSize = new Dimension(150, 30); 176 label.setMaximumSize(labelSize); 177 label.setMinimumSize(labelSize); 178 label.setPreferredSize(labelSize); 179 180 layoutInRow(control, label, components); 181 182 } 142 183 } -
java/main/src/main/java/com/framsticks/gui/MainFrame.java
r100 r101 73 73 } 74 74 75 // private void onConnectionEstablished() {76 // assert isActive();77 78 // addNodeActionToTreePopupMenu("Open in console", new NodeAction() {79 // @Override80 // public void actionPerformed(TreeNode treeNode) {81 // assert isActive();82 // }83 // });84 85 86 87 88 // // browser.addNodeActionToTreePopupMenu("Resolve recursively", new NodeAction() {89 // // @Override90 // // public void actionPerformed(TreeNode treeNode) {91 // // final Child child = treeNode.getChild();92 // // //server.invokeLater(new Runnable() {93 // // @Override94 // // public void run() {95 // // resolveRecursively(child);96 // // }97 // // });98 // // }99 // // });100 101 102 // // addNodeActionToTreePopupMenu("Store in file", new NodeAction() {103 // // @Override104 // // public void actionPerformed(final TreeNode treeNode) {105 // // // final Node node = treeNode.getNode();106 // // // server.invokeLater(new Runnable() {107 // // // @Override108 // // // public void run() {109 // // // try {110 // // // log.info("storing");111 // // // //File file = new File();112 // // // StoreStream stream = new StoreStream(file, server.getManager());113 // // // stream.store(node);114 // // // } catch (FileNotFoundException e) {115 // // // e.printStackTrace();116 // // // }117 // // // }118 // // // });119 // // }120 // // });121 122 123 // // arguments.forEach("resolve", new UnaryFunctor<Boolean, String>() {124 // // @Override125 // // public Boolean call(final String s) {126 // // server.getManager().resolvePath(s, new StateFunctor() {127 // // @Override128 // // public void call(Exception e) {129 // // if (e != null) {130 // // log.error("failed to resolve: {}", s);131 // // return;132 // // }133 // // log.info("succeeded to resolve: {}", s);134 // // }135 // // });136 // // return true;137 // // }138 // // });139 140 141 // // arguments.forEach("console", new UnaryFunctor<Boolean, String>() {142 // // @Override143 // // public Boolean call(String s) {144 // // showConsoleFrame().setCommandLine(s);145 // // return true;146 // // }147 // // });148 // }149 150 151 // /**152 // * Creates panel with start, step, stop buttons.153 // */154 // @Override155 // protected JPanel createLeftTopPanel() {156 // assert isActive();157 // Dimension buttonDimension = new Dimension(45, 45);158 159 // JPanel panel = new JPanel();160 161 // stop = new JButton(ImageProvider.loadImage(ImageProvider.SIM_STOP));162 // stop.addActionListener(new ActionListener() {163 164 // public void actionPerformed(ActionEvent e) {165 // setSimulationRunning(false);166 // }167 168 // });169 170 // stop.setPreferredSize(buttonDimension);171 // stop.setToolTipText("Simulation Stop");172 // stop.setEnabled(false);173 174 // step = new JButton(ImageProvider.loadImage(ImageProvider.SIM_STEP));175 // /*176 // step.addActionListener(new ActionListener() {177 178 // public void actionPerformed(ActionEvent e) {179 // connection.send(new CallQuery().setMethod("step").setPath("/simulator"));180 // }181 182 // });183 // */184 185 // step.setPreferredSize(buttonDimension);186 // step.setToolTipText("Simulation Step");187 188 // start = new JButton(ImageProvider.loadImage(ImageProvider.SIM_START));189 // start.addActionListener(new ActionListener() {190 191 // public void actionPerformed(ActionEvent e) {192 // setSimulationRunning(true);193 // }194 195 // });196 197 // start.setPreferredSize(buttonDimension);198 // start.setToolTipText("Start Simulation");199 200 // JPanel buttonPanel = new JPanel();201 // buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));202 // buttonPanel.add(Box.createHorizontalStrut(5));203 // buttonPanel.add(stop);204 // buttonPanel.add(Box.createHorizontalStrut(10));205 // buttonPanel.add(step);206 // buttonPanel.add(Box.createHorizontalStrut(10));207 // buttonPanel.add(start);208 // buttonPanel.add(Box.createHorizontalStrut(5));209 210 // buttonPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory211 // .createRaisedBevelBorder(), "Simulation Control",212 // TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION213 // ));214 215 // panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));216 // panel.add(Box.createHorizontalGlue());217 // panel.add(buttonPanel);218 // panel.add(Box.createHorizontalGlue());219 // return panel;220 // }221 75 222 76 /** … … 248 102 } 249 103 250 // public ConsoleFrame showConsoleFrame() {251 // assert isActive();252 // /*253 // ConsoleFrame consoleFrame = new ConsoleFrame(connection);254 // consoleFrame.show(MainFrame.this);255 // return consoleFrame;256 // */257 // return null;258 // }259 260 104 /** 261 105 * Closes connection with manager. -
java/main/src/main/java/com/framsticks/gui/ModifiablePanel.java
r100 r101 9 9 import java.awt.event.ActionEvent; 10 10 import java.awt.event.ActionListener; 11 import static com.framsticks.core.TreeOperations.*; 11 12 12 13 /** … … 24 25 protected final JLabel label; 25 26 protected final JButton applyButton; 27 protected final JButton revertButton; 26 28 protected final JPanel centerPanel; 27 29 … … 32 34 log.debug("create panel for type: {}", className); 33 35 34 35 36 36 JPanel pageEndPanel = new JPanel(); 37 37 pageEndPanel.setLayout(new BoxLayout(pageEndPanel, BoxLayout.X_AXIS)); … … 41 41 applyButton.setName("apply"); 42 42 43 revertButton = new JButton("Revert"); 44 revertButton.setName("revert"); 45 46 pageEndPanel.add(applyButton); 47 pageEndPanel.add(Box.createHorizontalStrut(10)); 48 49 pageEndPanel.add(revertButton); 50 pageEndPanel.add(Box.createHorizontalStrut(10)); 51 52 pageEndPanel.setPreferredSize(new Dimension(0, 30)); 53 43 54 applyButton.addActionListener(new ActionListener() { 44 55 public void actionPerformed(ActionEvent e) { … … 46 57 } 47 58 }); 48 pageEndPanel.add(applyButton);49 59 50 pageEndPanel.add(Box.createHorizontalStrut(10)); 51 pageEndPanel.setPreferredSize(new Dimension(0, 30)); 60 revertButton.addActionListener(new ActionListener() { 61 public void actionPerformed(ActionEvent e) { 62 revertChanges(); 63 } 64 }); 52 65 53 66 label = new JLabel(); … … 67 80 68 81 protected abstract void applyChanges(); 82 protected abstract void revertChanges(); 69 83 70 84 protected void setupContentComponent(Component contentComponent) { … … 73 87 } 74 88 89 protected void refreshControlButtons() { 90 assert frame.isActive(); 91 boolean hasChanges = hasSideNotes(getTree(), getCurrentObject(), treeAtFrame.getUserChangesKey()); 92 applyButton.setEnabled(hasChanges); 93 revertButton.setEnabled(hasChanges); 94 } 95 75 96 } -
java/main/src/main/java/com/framsticks/gui/ObjectPanel.java
r100 r101 5 5 import com.framsticks.gui.controls.ControlOwner; 6 6 import com.framsticks.gui.controls.ValueControl; 7 import com.framsticks.gui.controls.ValueControlListener;8 7 import com.framsticks.params.Access; 9 8 import com.framsticks.params.Param; 10 import com.framsticks.params.ValueParam;11 9 12 10 import org.apache.logging.log4j.Logger; … … 16 14 17 15 import java.util.Collection; 18 import java.util. IdentityHashMap;16 import java.util.HashMap; 19 17 import java.util.Map; 20 18 import static com.framsticks.util.lang.Containers.filterInstanceof; 21 19 22 20 import com.framsticks.util.FramsticksException; 21 22 import static com.framsticks.core.TreeOperations.*; 23 23 24 24 @SuppressWarnings("serial") … … 27 27 private static final Logger log = LogManager.getLogger(ObjectPanel.class); 28 28 29 final protected Map< Param, Control> components = new IdentityHashMap<Param, Control>();30 final protected Map< ValueParam, ValueControl> valueControls = new IdentityHashMap<ValueParam, ValueControl>();29 final protected Map<String, Control> controls = new HashMap<String, Control>(); 30 final protected Map<String, ValueControl> valueControls = new HashMap<String, ValueControl>(); 31 31 32 32 protected final JPanel contentPanel; … … 38 38 contentPanel = new JPanel(); 39 39 scrollPane = new JScrollPane(contentPanel); 40 contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.PAGE_AXIS)); 40 41 41 setupContentComponent(scrollPane); 42 42 43 Gui.fillWithControls(this, params, components, Control.class);43 Gui.fillWithControls(this, contentPanel, params, controls, Control.class); 44 44 setName(framsClass.getId()); 45 45 46 for (final ValueControl c : filterInstanceof(co mponents.values(), ValueControl.class)) {47 valueControls.put(c.getParam() , c);46 for (final ValueControl c : filterInstanceof(controls.values(), ValueControl.class)) { 47 valueControls.put(c.getParam().getId(), c); 48 48 c.setUserEnabled(true); 49 c.setListener(new ValueControlListener() {50 @Override51 public boolean onChange(Object newValue) {52 if (currentPath == null) {53 return true;54 }55 boolean result = treeAtFrame.changeValue(currentPath.assureResolved().getTopObject(), c, newValue);56 refreshControlButtons();57 return result;58 }59 });60 49 } 61 50 … … 68 57 assert frame.isActive(); 69 58 assert currentPath != null; 70 treeAtFrame.pushLocalChanges(currentPath); 59 treeAtFrame.pushUserChangesToTree(currentPath); 60 refreshControlButtons(); 71 61 } 72 62 73 protected void refreshControlButtons() { 74 assert frame.isActive(); 75 applyButton.setEnabled(treeAtFrame.hasLocalChanges(currentPath.getTopObject())); 63 64 @Override 65 protected void revertChanges() { 66 assert currentPath != null; 67 removeSideNote(currentPath, treeAtFrame.getUserChangesKey()); 68 pullValuesFromLocalToUser(bindAccess(currentPath)); 76 69 } 77 70 … … 81 74 log.debug("refreshing components"); 82 75 83 final Map<ValueControl, Object> values = new IdentityHashMap<ValueControl, Object>(); 84 for (Map.Entry<ValueParam, ValueControl> e : valueControls.entrySet()) { 85 values.put(e.getValue(), access.get(e.getKey().getId(), Object.class)); 76 UserChanges userChanges = getSideNote(currentPath, treeAtFrame.getUserChangesKey()); 77 78 79 for (Map.Entry<String, ValueControl> e : valueControls.entrySet()) { 80 String id = e.getKey(); 81 Object value; 82 if (userChanges != null && userChanges.changes.containsKey(id)) { 83 value = userChanges.changes.get(id); 84 } else { 85 value = access.get(id, Object.class); 86 } 87 88 e.getValue().pushValueToUserInterface(value); 86 89 } 87 90 88 89 NodeAtFrame nodeAtFrame = treeAtFrame.getLocalInfo(currentPath.getTopObject()); 90 if (nodeAtFrame != null) { 91 for (Map.Entry<ValueControl, Object> e : nodeAtFrame.localChanges.entrySet()) { 92 values.put(e.getKey(), e.getValue()); 93 } 91 for (Map.Entry<String, Control> e : controls.entrySet()) { 92 e.getValue().refreshState(); 94 93 } 95 94 96 for (Map.Entry<ValueControl, Object> e : values.entrySet()) {97 e.getKey().pushValueToUserInterface(e.getValue());98 }99 95 refreshControlButtons(); 100 ObjectPanel.this.revalidate(); 101 96 // ObjectPanel.this.revalidate(); 102 97 } 103 98 … … 105 100 public String getTitle() { 106 101 return "Properties"; 107 }108 109 @Override110 public JPanel getPanelForControls() {111 return contentPanel;112 102 } 113 103 … … 122 112 } 123 113 114 @Override 115 public boolean onValueChange(ValueControl control, Object newValue) { 116 if (currentPath == null) { 117 return true; 118 } 119 boolean result = treeAtFrame.changeValue(currentPath.assureResolved().getTopObject(), control, newValue); 120 refreshControlButtons(); 121 return result; 122 } 123 124 124 } -
java/main/src/main/java/com/framsticks/gui/StatusBar.java
r100 r101 15 15 import com.framsticks.util.FramsticksException; 16 16 import com.framsticks.util.dispatching.Dispatcher; 17 import com.framsticks.util.dispatching.Dispatching; 17 18 import com.framsticks.util.dispatching.ExceptionResultHandler; 18 19 import com.framsticks.util.dispatching.RunAt; 19 20 20 public class StatusBar implements ExceptionResultHandler , Dispatcher<StatusBar>{21 public class StatusBar implements ExceptionResultHandler { 21 22 private static final Logger log = LogManager.getLogger(StatusBar.class); 22 23 … … 24 25 protected JPanel swing; 25 26 protected ExceptionResultHandler exceptionHandler; 27 protected final Dispatcher<?> dispatcher; 26 28 27 29 /** 28 30 * 29 31 */ 30 public StatusBar() { 32 public StatusBar(Dispatcher<?> dispatcher) { 33 this.dispatcher = dispatcher; 34 } 35 36 @SuppressWarnings({"rawtypes", "unchecked"}) 37 public void showInfo(final Object value) { 38 Dispatching.dispatchIfNotActive(dispatcher, new RunAt(this) { 39 40 @Override 41 protected void runAt() { 42 String text = value.toString(); 43 log.info("info: {}", text); 44 statusBar.setText(text); 45 46 } 47 }); 31 48 } 32 49 33 50 @Override 51 @SuppressWarnings({"rawtypes", "unchecked"}) 34 52 public void handle(final FramsticksException exception) { 35 dispatch (new RunAt<StatusBar>(this) {53 dispatcher.dispatch(new RunAt(this) { 36 54 37 55 @Override … … 58 76 } 59 77 60 @Override61 public boolean isActive() {62 return SwingDispatcher.getInstance().isActive();63 }64 65 @Override66 public void dispatch(RunAt<? extends StatusBar> runnable) {67 SwingDispatcher.getInstance().dispatch(runnable);68 }69 70 78 /** 71 79 * @return the swing -
java/main/src/main/java/com/framsticks/gui/SwingDispatcher.java
r98 r101 1 1 package com.framsticks.gui; 2 2 3 import java.awt.event.ActionEvent;4 import java.awt.event.ActionListener;5 3 6 4 import com.framsticks.util.dispatching.AbstractJoinable; 7 5 import com.framsticks.util.dispatching.Dispatcher; 8 import com.framsticks.util.dispatching.JoinableDispatcher;9 import com.framsticks.util.dispatching.Task;10 6 import com.framsticks.util.dispatching.ThrowExceptionHandler; 11 7 … … 16 12 * @author Piotr Sniegowski 17 13 */ 18 public class SwingDispatcher<C> extends AbstractJoinable implements JoinableDispatcher<C> {14 public class SwingDispatcher<C> extends AbstractJoinable implements Dispatcher<C> { 19 15 20 16 @SuppressWarnings("rawtypes") … … 42 38 @Override 43 39 public final void dispatch(RunAt<? extends C> runnable) { 44 if (runnable instanceof Task) {45 final Task<?> task = (Task<?>) runnable;46 Timer timer = new Timer(0, null);47 timer.addActionListener(new ActionListener() {48 49 @Override50 public void actionPerformed(ActionEvent event) {51 task.run();52 }53 54 });55 timer.setInitialDelay((int) (task.getMoment() - System.currentTimeMillis()));56 timer.setRepeats(false);57 timer.start();58 return;59 }60 40 SwingUtilities.invokeLater(runnable); 61 41 } … … 73 53 @Override 74 54 protected void joinableInterrupt() { 75 finish ();55 finishJoinable(); 76 56 } 77 57 -
java/main/src/main/java/com/framsticks/gui/TreeAtFrame.java
r100 r101 4 4 import org.apache.logging.log4j.LogManager; 5 5 6 import com.framsticks.core.SideNoteKey; 6 7 import com.framsticks.core.Tree; 7 8 import com.framsticks.core.Node; 8 9 import com.framsticks.core.Path; 9 import com.framsticks.core.TreeOperations;10 import static com.framsticks.core.TreeOperations.*; 10 11 import com.framsticks.gui.controls.ValueControl; 11 12 import com.framsticks.params.CompositeParam; 12 13 import com.framsticks.params.FramsClass; 14 import com.framsticks.params.PrimitiveParam; 13 15 14 16 import java.util.*; … … 30 32 protected Node rootNode; 31 33 34 protected final SideNoteKey<UserChanges> userChangesKey = SideNoteKey.make(UserChanges.class); 35 32 36 public TreeAtFrame(Tree tree, Frame frame) { 33 37 this.frame = frame; … … 44 48 public Tree getTree() { 45 49 return tree; 50 } 51 52 /** 53 * @return the userChangesKey 54 */ 55 public SideNoteKey<UserChanges> getUserChangesKey() { 56 return userChangesKey; 46 57 } 47 58 … … 71 82 if (panels.isEmpty()) { 72 83 panel = new EmptyTreePanel(parameters); 73 } else 84 } else if (panels.size() == 1) { 74 85 panel = panels.get(0); 75 86 } else { … … 83 94 } 84 95 85 86 public boolean hasLocalChanges(Object object) {87 NodeAtFrame nodeAtFrame = tree.getSideNote(object, this, NodeAtFrame.class);88 if (nodeAtFrame == null) {89 return false;90 }91 return !nodeAtFrame.localChanges.isEmpty();92 }93 94 public NodeAtFrame assureLocalInfo(Object object) {95 assert frame.isActive();96 NodeAtFrame nodeAtFrame = tree.getSideNote(object, this, NodeAtFrame.class);97 98 if (nodeAtFrame == null) {99 nodeAtFrame = new NodeAtFrame();100 // log.debug();101 tree.putSideNote(object, this, nodeAtFrame);102 }103 return nodeAtFrame;104 }105 106 public NodeAtFrame getLocalInfo(Object object) {107 return tree.getSideNote(object, this, NodeAtFrame.class);108 }109 110 96 public boolean changeValue(Object object, ValueControl component, Object newValue) { 111 97 log.debug("changing value of {} to '{}'", component, newValue); 112 98 113 assureLocalInfo(object).localChanges.put(component, newValue);99 getOrCreateSideNote(tree, object, userChangesKey).changes.put(component.getParam().getId(), newValue); 114 100 115 101 return true; 116 102 } 117 103 118 public void pushLocalChanges(Path path) { 104 105 public void pushUserChangesToTree(final Path path) { 119 106 assert frame.isActive(); 120 107 path.assureResolved(); 121 108 122 NodeAtFrame nodeAtFrame = getLocalInfo(path.getTopObject());123 if ( nodeAtFrame== null) {109 final UserChanges userChanges = getSideNote(path, userChangesKey); 110 if (userChanges == null) { 124 111 return; 125 112 } 126 for (Map.Entry<ValueControl, Object> e : nodeAtFrame.localChanges.entrySet()) { 127 TreeOperations.set(path, e.getKey().getParam(), e.getValue(), new FutureHandler<Integer>(frame) { 113 removeSideNote(path, userChangesKey); 114 115 for (final Map.Entry<String, Object> e : userChanges.changes.entrySet()) { 116 set(path, getParam(path, e.getKey(), PrimitiveParam.class), e.getValue(), new FutureHandler<Integer>(frame) { 128 117 @Override 129 118 protected void result(Integer flag) { 119 assert frame.isActive(); 120 userChanges.changes.remove(e.getKey()); 130 121 } 131 122 }); -
java/main/src/main/java/com/framsticks/gui/TreePanel.java
r100 r101 2 2 3 3 import com.framsticks.core.Path; 4 import com.framsticks.core.TreeOperations; 4 import com.framsticks.core.Tree; 5 import static com.framsticks.core.TreeOperations.*; 5 6 import com.framsticks.gui.tree.AbstractNode; 6 7 import com.framsticks.gui.tree.TreeNode; … … 28 29 } 29 30 setCurrentPath(path); 30 pullValuesFromLocalToUser( TreeOperations.bindAccess(path));31 pullValuesFromLocalToUser(bindAccess(path)); 31 32 } 32 33 … … 79 80 return treeAtFrame; 80 81 } 81 82 public final Object getCurrentObject() { 83 assert currentPath != null; 84 return currentPath.getTopObject(); 85 } 86 public final Tree getTree() { 87 assert currentPath != null; 88 return currentPath.getTree(); 89 } 82 90 83 91 public final String getClassName() { -
java/main/src/main/java/com/framsticks/gui/controls/CheckBoxControl.java
r100 r101 10 10 import org.apache.logging.log4j.LogManager; 11 11 12 import com.framsticks.gui.Gui; 12 13 import com.framsticks.params.types.BooleanParam; 13 14 … … 31 32 }); 32 33 this.setMaximumSize(new Dimension(Integer.MAX_VALUE, Control.LINE_HEIGHT)); 33 addAsOnlyChild(checkBox);34 Gui.addLeftToLabel(this, checkBox); 34 35 } 35 36 -
java/main/src/main/java/com/framsticks/gui/controls/Control.java
r100 r101 1 1 package com.framsticks.gui.controls; 2 2 3 import java.awt.BorderLayout;3 // import java.awt.BorderLayout; 4 4 5 import javax.swing.JComponent; 5 6 6 import javax.swing.JPanel; 7 7 8 import com.framsticks.core.Path; 8 9 import com.framsticks.params.ParamFlags; 9 10 import com.framsticks.params.Param; 10 11 import com.framsticks.util.FramsticksException; 12 import com.framsticks.util.Misc; 11 13 import com.framsticks.util.dispatching.ExceptionResultHandler; 12 14 … … 57 59 58 60 public final boolean isReadonly() { 59 return !userEnabled || param.hasFlag(ParamFlags.READONLY) ;61 return !userEnabled || param.hasFlag(ParamFlags.READONLY) || param.hasFlag(ParamFlags.USERREADONLY); 60 62 } 61 63 62 protected void addAsOnlyChild(JComponent component) {63 this.setLayout(new BorderLayout());64 this.add(component, BorderLayout.CENTER);65 }66 64 67 65 @Override … … 74 72 owner.handle(exception); 75 73 } 74 75 public Path getCurrentPath() { 76 return owner.getCurrentPath(); 77 } 78 79 public Path assureCurrentPath() { 80 return Misc.throwIfNull(owner.getCurrentPath()); 81 } 82 83 public void refreshState() { 84 } 76 85 } -
java/main/src/main/java/com/framsticks/gui/controls/ControlOwner.java
r100 r101 1 1 package com.framsticks.gui.controls; 2 2 3 import javax.swing.JPanel;4 3 5 4 import com.framsticks.core.Path; … … 9 8 public interface ControlOwner extends ExceptionResultHandler { 10 9 11 public JPanel getPanelForControls();12 10 public Path getCurrentPath(); 13 11 public Frame getFrame(); 12 public boolean onValueChange(ValueControl control, Object newValue); 14 13 15 14 } -
java/main/src/main/java/com/framsticks/gui/controls/EnumControl.java
r100 r101 1 1 package com.framsticks.gui.controls; 2 2 3 import com.framsticks.gui.Gui; 3 4 import com.framsticks.params.types.EnumParam; 4 5 import com.framsticks.util.lang.Numbers; … … 35 36 } 36 37 }); 37 addAsOnlyChild(list);38 Gui.addLeftToLabel(this, list); 38 39 } 39 40 -
java/main/src/main/java/com/framsticks/gui/controls/EventControl.java
r100 r101 1 1 package com.framsticks.gui.controls; 2 2 3 import java.awt.Dimension;4 3 import java.awt.event.ActionEvent; 5 4 import java.awt.event.ActionListener; 6 7 import javax.swing.JButton; 8 5 import java.text.SimpleDateFormat; 6 import java.util.ArrayList; 7 import java.util.Date; 8 import java.util.List; 9 10 11 12 import com.framsticks.core.Path; 13 import com.framsticks.core.SideNoteKey; 14 import com.framsticks.gui.Frame; 15 import com.framsticks.gui.Gui; 16 import com.framsticks.gui.table.AbstractTableModel; 17 import com.framsticks.params.EventListener; 9 18 import com.framsticks.params.types.EventParam; 19 import com.framsticks.util.FramsticksUnsupportedOperationException; 20 import com.framsticks.util.dispatching.Dispatching; 21 import com.framsticks.util.dispatching.FutureHandler; 22 import com.framsticks.util.dispatching.RunAt; 23 import com.framsticks.util.lang.Pair; 24 25 import static com.framsticks.core.TreeOperations.*; 10 26 11 27 /** … … 13 29 */ 14 30 @SuppressWarnings("serial") 15 public class EventControl extends Control {31 public class EventControl extends HistoryControl { 16 32 // private static final Logger log = LogManager.getLogger(EventControl.class.getName()); 17 33 18 protected final JButton button; 19 boolean subscribed = true; 34 @SuppressWarnings("rawtypes") 35 protected final SideNoteKey<EventListener> listenerKey = SideNoteKey.make(EventListener.class); 36 37 public static class History { 38 protected final List<Pair<Date, Object>> entries = new ArrayList<>(); 39 }; 40 41 protected final SideNoteKey<History> historyKey = SideNoteKey.make(History.class); 42 protected TableModel tableModel; 20 43 21 44 public EventControl(final EventParam eventParam) { 22 45 super(eventParam); 23 46 24 button = new JButton("subscribe"); 25 this.add(button); 26 this.setMaximumSize(new Dimension(Integer.MAX_VALUE, Control.LINE_HEIGHT)); 27 28 button.addActionListener(new ActionListener() { 47 mainButton.setText("Subscribe"); 48 mainButton.setName("subscription"); 49 50 tableModel = new TableModel(); 51 resultsTable.setModel(tableModel); 52 53 mainButton.addActionListener(new ActionListener() { 29 54 @Override 30 55 public void actionPerformed(ActionEvent e) { 31 if (subscribed) { 32 //panel.getCurrentTreeNode().unsubscribe(eventParam); 33 } else { 34 //panel.getCurrentTreeNode().subscribe(eventParam); 56 final Path path = assureCurrentPath(); 57 EventListener<?> listener = getSideNote(path, listenerKey); 58 if (listener != null) { 59 removeSideNote(path, listenerKey); 60 refreshState(); 61 path.getTree().removeListener(path, getParam(), listener, FutureHandler.doNothing(Void.class, owner.getFrame())); 62 return; 35 63 } 64 65 final EventListener<Object> newListener = new EventListener<Object>() { 66 @Override 67 public void action(final Object argument) { 68 /** actions can be invoked from anywhere */ 69 Dispatching.dispatchIfNotActive(owner.getFrame(), new RunAt<Frame>(owner.getFrame()) { 70 71 @Override 72 protected void runAt() { 73 getOrCreateSideNote(path.getTree(), path.getTopObject(), historyKey).entries.add(Pair.make(new Date(), argument)); 74 refreshTable(); 75 } 76 }); 77 // owner.getFrame().getStatusBar().showInfo("event " + param + " happened: " + argument); 78 } 79 }; 80 81 path.getTree().addListener(path, getParam(), newListener, Object.class, new FutureHandler<Void>(owner.getFrame()) { 82 83 @Override 84 protected void result(Void result) { 85 putSideNote(path, listenerKey, newListener); 86 refreshState(); 87 } 88 }); 89 36 90 } 37 91 }); 38 92 93 updateFoldState(); 94 Gui.setupTitledControl(this, controlRow, resultsScrollPane); 39 95 } 40 96 41 97 @Override 42 98 protected void updateEnabled(boolean enabled) { 43 button.setEnabled(enabled); 44 } 45 46 /* 47 @Override 48 public void refresh() { 49 subscribed = panel.getCurrentTreeNode().hasSubscribed((EventParam)param); 50 button.setText(subscribed ? "unsubscribe" : "subscribe"); 51 this.revalidate(); 52 } 53 */ 99 mainButton.setEnabled(enabled); 100 } 101 102 public boolean isListening() { 103 return hasSideNote(getCurrentPath(), listenerKey); 104 } 105 106 protected void refreshButtonState() { 107 mainButton.setText(isListening() ? "Don't listen" : "Listen"); 108 } 109 110 @Override 111 protected void refreshTable() { 112 History history = getSideNote(assureCurrentPath(), historyKey); 113 tableModel.entries = history != null ? history.entries : null; 114 tableModel.refreshAll(); 115 } 116 117 @Override 118 protected void clearTable() { 119 History history = getSideNote(assureCurrentPath(), historyKey); 120 if (history != null) { 121 history.entries.clear(); 122 } 123 refreshTable(); 124 } 125 126 public void refreshState() { 127 refreshButtonState(); 128 refreshTable(); 129 } 130 131 @Override 132 public EventParam getParam() { 133 return (EventParam) param; 134 } 135 136 137 public class TableModel extends AbstractTableModel { 138 139 List<Pair<Date, Object>> entries; 140 SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss:SSS"); 141 142 @Override 143 public Class<?> getColumnClass(int columnIndex) { 144 return String.class; 145 } 146 147 @Override 148 public int getColumnCount() { 149 return 2; 150 } 151 152 @Override 153 public String getColumnName(int columnIndex) { 154 return columnIndex == 0 ? "Occured at" : "Argument"; 155 } 156 157 @Override 158 public int getRowCount() { 159 if (entries == null) { 160 return 0; 161 } 162 if (isFolded()) { 163 return entries.isEmpty() ? 0 : 1; 164 } 165 return entries.size(); 166 } 167 168 @Override 169 public Object getValueAt(int rowIndex, int columnIndex) { 170 if (entries == null) { 171 return null; 172 } 173 Pair<Date, Object> entry; 174 if (isFolded()) { 175 if (rowIndex > 0) { 176 return null; 177 } 178 if (entries.isEmpty()) { 179 return null; 180 } 181 entry = entries.get(entries.size() - 1); 182 } else { 183 entry = entries.get(rowIndex); 184 } 185 return columnIndex == 0 ? format.format(entry.first) : entry.second; 186 } 187 188 @Override 189 public boolean isCellEditable(int rowIndex, int columnIndex) { 190 return false; 191 } 192 193 @Override 194 public void setValueAt(Object value, int rowIndex, int columnIndex) { 195 throw new FramsticksUnsupportedOperationException().msg("setting value in event history"); 196 } 197 198 199 } 54 200 } -
java/main/src/main/java/com/framsticks/gui/controls/ProcedureControl.java
r100 r101 5 5 import com.framsticks.gui.Gui; 6 6 import com.framsticks.params.Param; 7 import com.framsticks.params.ValueParam;8 7 import com.framsticks.params.types.ProcedureParam; 9 8 import com.framsticks.util.dispatching.ExceptionResultHandler; 10 9 import com.framsticks.util.dispatching.FutureHandler; 11 10 import com.framsticks.util.dispatching.ThrowExceptionHandler; 12 import com.framsticks.util.swing.TooltipConstructor;13 11 14 12 import javax.swing.*; 15 import javax.swing.border.BevelBorder;16 13 17 14 import org.apache.logging.log4j.Logger; … … 20 17 import java.awt.event.ActionEvent; 21 18 import java.awt.event.ActionListener; 22 import java.util. IdentityHashMap;19 import java.util.HashMap; 23 20 import java.util.LinkedList; 24 21 import java.util.List; … … 26 23 27 24 @SuppressWarnings("serial") 28 public class ProcedureControl extends Control implements ControlOwner {25 public class ProcedureControl extends HistoryControl implements ControlOwner { 29 26 30 27 private static final Logger log = LogManager.getLogger(ProcedureControl.class); 31 28 32 protected final J Button procedureButton;29 protected final JPanel argumentsPanel; 33 30 34 final protected Map< ValueParam, ValueControl> components = new IdentityHashMap<>();31 final protected Map<String, ValueControl> components = new HashMap<>(); 35 32 36 33 public ProcedureControl(ProcedureParam procedureParam) { 37 34 super(procedureParam); 38 35 39 this.setToolTipText(new TooltipConstructor()40 .append("name", procedureParam.getName())41 .append("id", procedureParam.getId())42 .append("help", procedureParam.getHelp())43 .build());44 36 45 procedureButton = new JButton("Call");46 procedureButton.setName("call");37 mainButton.setText("Call"); 38 mainButton.setName("call"); 47 39 48 this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));49 40 50 Gui.fillWithControls(this, procedureParam.getArgumentsType(), components, ValueControl.class); 41 argumentsPanel = new JPanel(); 42 argumentsPanel.setName("arguments"); 43 44 Gui.fillWithControls(this, argumentsPanel, procedureParam.getArgumentsType(), components, ValueControl.class); 51 45 52 46 if (components.size() != procedureParam.getArgumentsType().size()) { 53 procedureButton.setEnabled(false); 54 } 55 if (!components.isEmpty()) { 56 this.setBorder(new BevelBorder(BevelBorder.RAISED)); 47 mainButton.setEnabled(false); 57 48 } 58 49 59 procedureButton.addActionListener(new ActionListener() {50 mainButton.addActionListener(new ActionListener() { 60 51 @Override 61 52 public void actionPerformed(ActionEvent e) { … … 65 56 final List<Object> arguments = new LinkedList<Object>(); 66 57 for (Param arg : getParam().getArgumentsType()) { 67 Object value = components.get(arg ).getCurrentValue();58 Object value = components.get(arg.getId()).getCurrentValue(); 68 59 arguments.add(value); 69 60 log.debug("argument {}: {}", arg, value); … … 74 65 } 75 66 }); 76 this.add(procedureButton); 67 68 updateFoldState(); 69 Gui.setupTitledControl(this, argumentsPanel, controlRow, resultsScrollPane); 77 70 78 71 } 72 79 73 80 74 public static void callProcedure(final Path path, final ProcedureParam param, Object[] arguments) { … … 93 87 94 88 @Override 95 public JPanel getPanelForControls() {96 return this;97 }98 99 @Override100 89 public ProcedureParam getParam() { 101 90 return (ProcedureParam) param; … … 104 93 @Override 105 94 protected void updateEnabled(boolean enabled) { 106 procedureButton.setEnabled(enabled);95 mainButton.setEnabled(enabled); 107 96 for (ValueControl vc : components.values()) { 108 97 vc.setUserEnabled(enabled); … … 120 109 } 121 110 111 @Override 112 public boolean onValueChange(ValueControl control, Object newValue) { 113 return true; 114 } 115 116 @Override 117 protected void refreshTable() { 118 // TODO Auto-generated method stub 119 120 } 121 122 @Override 123 protected void clearTable() { 124 // TODO Auto-generated method stub 125 126 } 127 122 128 } -
java/main/src/main/java/com/framsticks/gui/controls/SliderControl.java
r100 r101 18 18 import org.apache.logging.log4j.LogManager; 19 19 20 import com.framsticks.gui.Gui; 20 21 import com.framsticks.params.types.DecimalParam; 21 22 import com.framsticks.params.types.FloatParam; … … 98 99 slider.setPaintTicks(true); 99 100 100 this.setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); 101 this.setAlignmentX(Box.CENTER_ALIGNMENT); 102 this.setAlignmentY(Box.CENTER_ALIGNMENT); 103 104 JPanel sliderPanel = new JPanel(); 105 // sliderPanel.setLayout(new BoxLayout(sliderPanel, BoxLayout.LINE_AXIS)); 101 106 102 107 103 … … 140 136 })); 141 137 142 JPanel sVPanel = new JPanel(); 143 sVPanel.setLayout(new BoxLayout(sVPanel, BoxLayout.LINE_AXIS)); 144 sVPanel.add(text); 145 Layout.copyComponentDimensions(sVPanel, text); 146 147 JPanel sPanel = new JPanel(); 148 sPanel.setLayout(new BoxLayout(sPanel, BoxLayout.LINE_AXIS)); 149 138 JPanel valuePanel = new JPanel(); 139 valuePanel.setLayout(new BoxLayout(valuePanel, BoxLayout.LINE_AXIS)); 140 valuePanel.add(text); 141 Layout.copyComponentDimensions(valuePanel, text); 142 143 144 JPanel sliderPanel = new JPanel(); 150 145 sliderPanel.setLayout(new BorderLayout()); 151 146 sliderPanel.add(slider, BorderLayout.CENTER); … … 153 148 sliderPanel.setMinimumSize(new Dimension(0, 60)); 154 149 155 sPanel.add(sVPanel); 156 sPanel.add(sliderPanel); 157 158 this.add(sPanel); 150 151 this.setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); 152 this.setAlignmentX(Box.CENTER_ALIGNMENT); 153 this.setAlignmentY(Box.CENTER_ALIGNMENT); 154 155 Gui.addLeftToLabel(this, valuePanel, sliderPanel); 159 156 } 160 157 -
java/main/src/main/java/com/framsticks/gui/controls/TextAreaControl.java
r100 r101 1 1 package com.framsticks.gui.controls; 2 2 3 import com.framsticks.gui.Gui; 3 4 import com.framsticks.params.PrimitiveParam; 4 5 … … 27 28 textArea.setMaximumSize(new Dimension(Integer.MAX_VALUE, maxSize)); 28 29 29 this.revalidate(); 30 Gui.setupTitledControl(this, textScrollPane); 31 // this.revalidate(); 30 32 } 31 33 -
java/main/src/main/java/com/framsticks/gui/controls/TextFieldControl.java
r98 r101 1 1 package com.framsticks.gui.controls; 2 2 3 import com.framsticks.gui.Gui; 3 4 import com.framsticks.params.PrimitiveParam; 4 5 import com.framsticks.util.lang.Strings; … … 33 34 addDefaultDocumentListener(textField); 34 35 35 addAsOnlyChild(textField);36 Gui.addLeftToLabel(this, textField); 36 37 } 37 38 -
java/main/src/main/java/com/framsticks/gui/controls/ValueControl.java
r100 r101 12 12 import com.framsticks.util.lang.FlagsUtil; 13 13 import com.framsticks.util.swing.TooltipConstructor; 14 // import static com.framsticks.core.TreeOperations.*; 14 15 15 16 /** … … 20 21 private static final Logger log = 21 22 LogManager.getLogger(ValueControl.class); 22 23 /**24 *25 */26 protected ValueControlListener listener;27 23 28 24 public ValueControl(PrimitiveParam<?> primitiveParam) { … … 64 60 public abstract Object pullValueFromUserInterface(); 65 61 66 public void setListener(ValueControlListener listener) {67 this.listener = listener;68 }69 70 62 protected Object filterValueThroughConstraints(Object candidate) { 71 Object oldValue = pullValueFromUserInterface(); 63 Object oldValue = pullValueFromUserInterface();//bindAccess(owner.getCurrentPath()).get(getParam(), Object.class); 72 64 try { 73 65 ReassignResult<?> res = getParam().reassign(candidate, oldValue); … … 92 84 protected boolean notifyOfChange() { 93 85 if (!programmaticChange) { 94 if (listener == null) { 95 return true; 96 } 97 return listener.onChange(getCurrentValue()); 86 return owner.onValueChange(this, getCurrentValue()); 98 87 } 99 88 return true; -
java/main/src/main/java/com/framsticks/gui/table/ListPanel.java
r100 r101 54 54 table = new JTable(tableModel); 55 55 tableModel.setupTable(); 56 table.setShowGrid(false); 56 57 57 58 scrollPane = new JScrollPane(table); … … 72 73 73 74 @Override 75 protected void revertChanges() { 76 } 77 78 @Override 74 79 public void pullValuesFromLocalToUser(Access access) { 75 80 tableModel.attachSource(Casting.throwCast(ListAccess.class, access)); 81 refreshControlButtons(); 76 82 } 77 83 … … 87 93 return table; 88 94 } 95 89 96 } -
java/main/src/main/java/com/framsticks/gui/table/PrimitiveColumn.java
r100 r101 2 2 3 3 import com.framsticks.params.PrimitiveParam; 4 import com.framsticks.util. UnsupportedOperationException;4 import com.framsticks.util.FramsticksUnsupportedOperationException; 5 5 6 6 public class PrimitiveColumn extends Column { … … 31 31 @Override 32 32 public int setValueAt(int rowIndex, Object value) { 33 throw new UnsupportedOperationException().msg("setting value in table");33 throw new FramsticksUnsupportedOperationException().msg("setting value in table"); 34 34 } 35 35 -
java/main/src/main/java/com/framsticks/gui/table/TableModel.java
r100 r101 3 3 import java.util.ArrayList; 4 4 import java.util.Collections; 5 import java.util.LinkedList;6 5 import java.util.List; 7 6 … … 10 9 import javax.swing.JTable; 11 10 import javax.swing.UIManager; 12 import javax.swing.event.TableModelEvent;13 import javax.swing.event.TableModelListener;14 11 15 12 import org.apache.logging.log4j.Logger; … … 23 20 import com.framsticks.util.lang.Casting; 24 21 25 public class TableModel implements javax.swing.table.TableModel {22 public class TableModel extends AbstractTableModel { 26 23 27 24 private static final Logger log = LogManager.getLogger(TableModel.class); 28 25 29 protected List<TableModelListener> listeners = new LinkedList<>();30 26 protected ListAccess access; 31 27 protected Access elementAccess; … … 52 48 } 53 49 54 protected void refreshAll() {55 for (TableModelListener l : listeners) {56 l.tableChanged(new TableModelEvent(this));57 }58 }59 50 60 51 /** … … 74 65 } 75 66 76 @Override77 public void addTableModelListener(TableModelListener listener) {78 listeners.add(listener);79 }80 67 81 68 @Override … … 114 101 } 115 102 116 @Override117 public void removeTableModelListener(TableModelListener listener) {118 listeners.remove(listener);119 }120 103 121 104 -
java/main/src/main/java/com/framsticks/gui/tree/TreeModel.java
r100 r101 17 17 import com.framsticks.core.Node; 18 18 import com.framsticks.core.Path; 19 import com.framsticks.core.SideNoteKey; 19 20 import com.framsticks.core.TreeOperations; 20 21 import com.framsticks.gui.Frame; … … 24 25 import com.framsticks.params.ListAccess; 25 26 import com.framsticks.params.PrimitiveParam; 26 import com.framsticks.params. Util;27 import com.framsticks.params.ParamsUtil; 27 28 import com.framsticks.params.ValueParam; 28 29 import com.framsticks.params.types.EventParam; 29 30 import com.framsticks.util.FramsticksException; 30 31 import com.framsticks.util.Misc; 31 import com.framsticks.util. UnsupportedOperationException;32 import com.framsticks.util.FramsticksUnsupportedOperationException; 32 33 import com.framsticks.util.dispatching.FutureHandler; 33 34 import com.framsticks.util.lang.Casting; … … 91 92 @Override 92 93 public void valueForPathChanged(TreePath path, Object value) { 93 throw new UnsupportedOperationException().msg("changing value of tree node");94 throw new FramsticksUnsupportedOperationException().msg("changing value of tree node"); 94 95 } 95 96 … … 133 134 public TreeModelEvent prepareModelEventRegarding(Access access, String id, TreePath treeListPath) { 134 135 135 int number = Util.getNumberOfCompositeParamChild(access, access.get(id, Object.class));136 int number = ParamsUtil.getNumberOfCompositeParamChild(access, access.get(id, Object.class)); 136 137 if (number == -1) { 137 138 log.debug("encountered minor tree inconsistency in {}", treeListPath); … … 438 439 439 440 440 protected final Object createdTag = new Object();441 protected final SideNoteKey<Boolean> createdTag = SideNoteKey.make(Boolean.class); 441 442 442 443 -
java/main/src/main/java/com/framsticks/gui/tree/TreeNode.java
r100 r101 4 4 import java.util.Iterator; 5 5 import java.util.LinkedList; 6 import java.util.List;7 6 8 7 import org.apache.logging.log4j.LogManager; … … 11 10 import com.framsticks.core.Node; 12 11 import com.framsticks.core.Path; 12 import com.framsticks.core.SideNoteKey; 13 13 import com.framsticks.core.Tree; 14 14 import com.framsticks.gui.Frame; … … 59 59 hashCode = System.identityHashCode(path.getTopObject()); 60 60 61 if ( getTree().getSideNote(path.getTopObject(), getTreeModel().createdTag, Object.class) == getTreeModel().createdTag) {61 if (isMarked(path.getTree(), path.getTopObject(), getTreeModel().createdTag, false)) { 62 62 return; 63 63 } 64 64 65 65 // path.getTree().putSideNote(path.getTopObject(), Textual.class, path.getTextual()); 66 path.getTree().putSideNote(path.getTopObject(), getTreeModel().createdTag, getTreeModel().createdTag);66 mark(path.getTree(), path.getTopObject(), getTreeModel().createdTag, true); 67 67 68 68 /** Iterate over all EventParams and for matching ValueParams register listeners. */ … … 239 239 } 240 240 Access access = bindAccessForTreeObject(child); 241 CompositeParam param = getTree().getSideNote(child, CompositeParam.class, CompositeParam.class);241 CompositeParam param = getTree().getSideNote(child, Path.OBJECT_PARAM_KEY); 242 242 String name = param.getId(); 243 243 … … 262 262 } 263 263 264 // public static class Textual {265 // }266 264 267 265 public String getTextual() { 268 266 return textual; 269 // return getTree().getSideNote(lock(), Textual.class, String.class); 270 } 271 272 protected final Object listenersTag = new Object(); 273 274 public List<EventListener<?>> getListeners() { 275 @SuppressWarnings("unchecked") 276 List<EventListener<?>> result = getTree().getSideNote(lock(), listenersTag, List.class); 277 if (result == null) { 278 result = new LinkedList<>(); 279 getTree().putSideNote(lock(), listenersTag, result); 280 } 281 282 return result; 283 } 267 } 268 269 @SuppressWarnings("rawtypes") 270 protected final SideNoteKey<LinkedList> listenersTag = SideNoteKey.make(LinkedList.class); 284 271 285 272 protected <A> void tryAddListener(final Path path, final EventParam eventParam, Class<A> argumentType, final EventListener<A> listener) { 286 273 getTree().addListener(path, eventParam, listener, argumentType, new FutureHandler<Void>(getFrame()) { 274 @SuppressWarnings("unchecked") 287 275 @Override 288 276 protected void result(Void result) { 289 277 assert getFrame().isActive(); 290 278 log.debug("registered gui listener for {} at {}", eventParam, path); 291 get Listeners().add(listener);279 getOrCreateSideNote(getTree(), lock(), listenersTag).add(listener); 292 280 } 293 281 }); -
java/main/src/main/java/com/framsticks/hosting/Cli.java
r100 r101 58 58 client.connection.sendFile( 59 59 "event " + event.pathToEvent + " " + event.name, 60 ClientAtServer.printToFile("", tree.getRegistry().createAccess(argument.getClass()).select(argument)) 60 ClientAtServer.printToFile("", tree.getRegistry().createAccess(argument.getClass()).select(argument)), 61 null, 62 client 61 63 ); 62 64 } -
java/main/src/main/java/com/framsticks/hosting/Server.java
r100 r101 6 6 7 7 import com.framsticks.core.Tree; 8 import com.framsticks.params.ParamFlags; 8 9 import com.framsticks.params.annotations.AutoAppendAnnotation; 9 10 import com.framsticks.params.annotations.FramsClassAnnotation; … … 17 18 import com.framsticks.util.dispatching.JoinableState; 18 19 import com.framsticks.util.dispatching.RunAt; 19 import com.framsticks.util.dispatching.Task;20 20 import com.framsticks.util.dispatching.ThrowExceptionHandler; 21 21 … … 24 24 import java.net.ServerSocket; 25 25 import java.net.Socket; 26 import java.util.TimerTask; 27 26 28 import com.framsticks.util.dispatching.Thread; 27 29 … … 61 63 * @param port the port to set 62 64 */ 63 @ParamAnnotation 65 @ParamAnnotation(flags = ParamFlags.USERREADONLY) 64 66 public void setPort(int port) { 65 67 this.port = port; … … 76 78 log.debug("exception caught during socket closing: ", e); 77 79 } 78 finish ();80 finishJoinable(); 79 81 } 80 82 … … 150 152 151 153 protected void tryBind(int when) { 152 acceptThread.dispatch(new Task<Accept>(ThrowExceptionHandler.getInstance(), when) { 154 Dispatching.getTimer().schedule(new TimerTask() { 155 153 156 @Override 154 protected void runAt() { 155 try { 156 acceptSocket.bind(new InetSocketAddress(port)); 157 log.debug("started accepting on port {}", port); 158 acceptNext(); 159 return; 160 } catch (IOException e) { 161 log.warn("failed to accept on port {} (repeating): ", port, e); 162 } 163 tryBind(1000); 157 public void run() { 158 acceptThread.dispatch(new RunAt<Accept>(ThrowExceptionHandler.getInstance()) { 159 @Override 160 protected void runAt() { 161 try { 162 acceptSocket.bind(new InetSocketAddress(port)); 163 log.debug("started accepting on port {}", port); 164 acceptNext(); 165 return; 166 } catch (IOException e) { 167 log.warn("failed to accept on port {} (repeating): ", port, e); 168 } 169 tryBind(1000); 170 } 171 }); 164 172 } 165 }); 173 174 }, when); 166 175 } 167 176 … … 178 187 } 179 188 180 // @Override181 // public FramsClass getInfoFromCache(String id) {182 // assert isActive();183 // if (id == null) {184 // return null;185 // }186 // FramsClass cached = registry.getFramsClass(id);187 // if (cached != null) {188 // return cached;189 // }190 // try {191 // Class<?> nativeClass = Class.forName(id);192 // FramsClass framsClass = FramsClass.build().forClass(nativeClass);193 194 // if (!framsClass.getId().equals(id)) {195 // log.error("no matching id");196 // return null;197 // }198 199 // registry.registerReflectedClass(null, id, nativeClass);200 // registry.putFramsClass(framsClass);201 // return framsClass;202 // } catch (ClassNotFoundException ignored) {203 // } catch (ConstructionException e) {204 // log.error("failed to use info from cache: {}", e);205 // }206 207 // return null;208 // }209 210 // @Override211 // protected void fetchInfo(Path path, Future<FramsClass> future) {212 // assert isActive();213 214 // FramsClass framsClass = getInfoFromCache(path.getTop().getObject().getClass().getCanonicalName());215 // if (framsClass == null) {216 // log.error("failed to create frams class for: {}", path.getTop().getObject().getClass());217 // future.result(null, new Exception());218 // return;219 // }220 // future.result(framsClass, null);221 // }222 189 } -
java/main/src/main/java/com/framsticks/model/ModelBuilder.java
r100 r101 7 7 8 8 import com.framsticks.model.f0.Schema; 9 import com.framsticks.params. Util;9 import com.framsticks.params.ParamsUtil; 10 10 import com.framsticks.params.annotations.AutoAppendAnnotation; 11 11 import com.framsticks.params.annotations.FramsClassAnnotation; … … 35 35 } 36 36 F0Parser parser = new F0Parser(schema, stream); 37 components.addAll( Util.stripAccess(parser.parse(), ModelComponent.class));37 components.addAll(ParamsUtil.stripAccess(parser.parse(), ModelComponent.class)); 38 38 } 39 39 return build(); -
java/main/src/main/java/com/framsticks/params/Access.java
r100 r101 44 44 void regRemove(EventParam param, EventListener<?> listener); 45 45 46 void setDefault(boolean numericOnly);47 48 void setDefault(int i, boolean numericOnly);49 50 void setMin();51 52 void setMin(int i);53 54 void setMax();55 56 void setMax(int i);57 58 46 void save(SinkInterface sink); 59 60 void load(SourceInterface stream);61 47 62 48 /** … … 69 55 Object getSelected(); 70 56 71 Access cloneAccess() throws ConstructionException;57 Access cloneAccess(); 72 58 73 59 Object createAccessee(); -
java/main/src/main/java/com/framsticks/params/ArrayListAccess.java
r100 r101 24 24 25 25 @Override 26 public ArrayListAccess cloneAccess() throws ConstructionException{26 public ArrayListAccess cloneAccess() { 27 27 return new ArrayListAccess(elementAccess.cloneAccess()); 28 28 } … … 124 124 @Override 125 125 public ArrayListAccess select(Object object) { 126 list = Util.selectObjectForAccess(this, object, List.class);126 list = ParamsUtil.selectObjectForAccess(this, object, List.class); 127 127 return this; 128 128 } -
java/main/src/main/java/com/framsticks/params/FramsClassBuilder.java
r100 r101 5 5 import java.lang.reflect.Member; 6 6 import java.lang.reflect.Method; 7 import java.lang.reflect.ParameterizedType;8 import java.lang.reflect.Type;9 7 import java.util.ArrayList; 10 8 import java.util.Collections; … … 40 38 } 41 39 42 public static ParamBuilder induceParamType(ParamBuilder builder, Type type) {43 // if (type.equals(Void.TYPE)) {44 // throw new ConstructionException().msg("void is not a valid type");45 // }46 47 if (type instanceof ParameterizedType) {48 ParameterizedType p = (ParameterizedType) type;49 Type rawType = p.getRawType();50 Type containedType = null;51 //TODO make implementation here52 boolean map = false;53 StringBuilder b = new StringBuilder();54 if (rawType.equals(Map.class)) {55 containedType = p.getActualTypeArguments()[1];56 map = true;57 b.append("l");58 } else if (rawType.equals(List.class)) {59 containedType = p.getActualTypeArguments()[0];60 b.append("l");61 } else if (rawType.equals(EventListener.class)) {62 containedType = p.getActualTypeArguments()[0];63 b.append("e");64 }65 if (!(containedType instanceof Class)) {66 return builder;67 }68 b.append(" ");69 70 Class<?> containedClass = (Class<?>) containedType;71 FramsClassAnnotation fca = containedClass.getAnnotation(FramsClassAnnotation.class);72 if (fca == null) {73 throw new ConstructionException().msg("the contained class is not annotated").arg("class", containedClass);74 }75 b.append(getName(fca, containedClass));76 //TODO parametrize this77 if (map) {78 b.append(" uid");79 }80 81 builder.type(b.toString());82 return builder;83 }84 85 if (type instanceof Class) {86 87 Class<?> cl = (Class<?>) type;88 89 // TODO: future support for enum90 // if (cl.isEnum()) {91 // Class<? extends Enum<?>> enumType = (Class<? extends Enum<?>>) cl;92 // Enum<?>[] enums = enumType.getEnumConstants();93 // StringBuilder b = new StringBuilder();94 95 // b.append("d 0 ").append(enums.length - 1).append(" 0 ");96 // for (Enum<?> e : enums) {97 // b.append("~").append(e.name());98 // }99 // return b.toString();100 // }101 if (cl.equals(Integer.class) || cl.equals(int.class)) {102 builder.type("d");103 return builder;104 }105 if (cl.equals(String.class)) {106 builder.type("s");107 return builder;108 }109 if (cl.equals(Double.class) || cl.equals(double.class)) {110 builder.type("f");111 return builder;112 }113 if (cl.equals(Boolean.class) || cl.equals(boolean.class)) {114 builder.type( "d 0 1");115 return builder;116 }117 if (cl.equals(Object.class)) {118 builder.type("x");119 return builder;120 }121 122 123 // builder.type("o " + (cl).getCanonicalName());124 builder.type("o " + cl.getSimpleName());125 builder.fillStorageType(cl);126 return builder;127 }128 129 throw new ConstructionException().msg("failed to find framsticks for native type").arg("type", type);130 }131 132 133 public static ParamBuilder induceParamType(ParamBuilder builder, ParamCandidate candidate) {134 Method method = candidate.getCaller();135 if (method == null) {136 return induceParamType(builder, candidate.getType());137 }138 139 if (!method.getReturnType().equals(Void.TYPE)) {140 builder.resultType(induceParamType(Param.build(), method.getGenericReturnType()).finish(ValueParam.class));141 }142 143 List<ValueParam> arguments = new ArrayList<>();144 int number = 0;145 for (Type arg : method.getGenericParameterTypes()) {146 arguments.add(induceParamType(Param.build(), arg).idAndName("arg" + (number++)).finish(ValueParam.class));147 }148 builder.argumentsType(arguments);149 150 return builder;151 }152 40 153 41 public static final String GENERATE_HELP_PREFIX = "automatically generated from: "; … … 238 126 ParamBuilder builder = Param.build().id(pc.getId()).name(pc.getName()).flags(pc.getFlags()); 239 127 240 induceParamType(builder, pc);128 pc.induceParamType(builder); 241 129 242 130 for (ParamAnnotation pa : pc.getAnnotations()) { … … 365 253 } 366 254 255 256 367 257 } -
java/main/src/main/java/com/framsticks/params/InvalidOperationException.java
r99 r101 1 1 package com.framsticks.params; 2 2 3 import com.framsticks.util. UnsupportedOperationException;3 import com.framsticks.util.FramsticksUnsupportedOperationException; 4 4 5 5 @SuppressWarnings("serial") 6 public class InvalidOperationException extends UnsupportedOperationException {6 public class InvalidOperationException extends FramsticksUnsupportedOperationException { 7 7 8 8 } -
java/main/src/main/java/com/framsticks/params/ListAccess.java
r100 r101 7 7 import com.framsticks.params.types.EventParam; 8 8 import com.framsticks.params.types.ProcedureParam; 9 import com.framsticks.util.UnimplementedException;10 9 11 10 /** … … 30 29 // } 31 30 32 @Override33 public void setDefault(boolean numericOnly) {34 }35 36 @Override37 public void setDefault(int i, boolean numericOnly) {38 }39 40 @Override41 public void setMin() {42 }43 44 @Override45 public void setMin(int i) {46 }47 48 @Override49 public void setMax() {50 }51 52 @Override53 public void setMax(int i) {54 }55 31 56 32 @Override … … 63 39 elementAccess.save(sink); 64 40 } 65 }66 67 @Override68 public void load(SourceInterface stream) {69 throw new UnimplementedException().msg("load in list access");70 41 } 71 42 -
java/main/src/main/java/com/framsticks/params/ListSource.java
r86 r101 5 5 import java.util.List; 6 6 7 public class ListSource implements Source Interface{7 public class ListSource implements Source { 8 8 9 9 private Iterator<String> iterator = null; 10 //private final List<String> source;10 private final List<String> list; 11 11 12 public ListSource(List<String> source) {13 //this.source = source;14 iterator = source.iterator();12 public ListSource(List<String> list) { 13 this.list = list; 14 iterator = list.iterator(); 15 15 } 16 16 … … 38 38 39 39 @Override 40 public Source InterfaceopenInclude(String include) {40 public Source openInclude(String include) { 41 41 return null; 42 42 } … … 59 59 return iterator == null; 60 60 } 61 62 @Override 63 public String toString() { 64 if (list.isEmpty()) { 65 return "?"; 66 } 67 StringBuilder b = new StringBuilder(); 68 int print = Math.min(list.size(), 3); 69 for (int i = 0; i < print; ++i) { 70 if (i != 0) { 71 b.append(" "); 72 } 73 b.append(list.get(i)); 74 } 75 return b.toString(); 76 } 77 61 78 } -
java/main/src/main/java/com/framsticks/params/Param.java
r99 r101 96 96 } 97 97 98 public boolean isUserHidden() {99 return (flags & ParamFlags.USERHIDDEN) != 0;100 }101 102 98 public static ParamBuilder build() { 103 99 return new ParamBuilder(); -
java/main/src/main/java/com/framsticks/params/ParamCandidate.java
r100 r101 10 10 import java.lang.reflect.ParameterizedType; 11 11 import java.lang.reflect.Type; 12 import java.util.ArrayList; 12 13 import java.util.Arrays; 13 14 import java.util.Collection; … … 15 16 import java.util.Comparator; 16 17 import java.util.HashMap; 18 import java.util.HashSet; 19 import java.util.IdentityHashMap; 17 20 import java.util.LinkedList; 18 21 import java.util.List; … … 75 78 protected final OneTime<Method> adder = new OneTime<>("adder"); 76 79 protected final OneTime<Method> remover = new OneTime<>("remover"); 80 protected int flags = 0; 77 81 78 82 protected final List<ParamAnnotation> annotations = new LinkedList<>(); … … 162 166 public List<ParamAnnotation> getAnnotations() { 163 167 return Collections.unmodifiableList(annotations); 168 } 169 170 protected final java.util.Set<Class<?>> dependantClasses = new HashSet<>(); 171 172 // public void addDependantClass(Class<?> javaClass) { 173 // dependantClasses.add(javaClass); 174 // } 175 176 /** 177 * @return the dependantClasses 178 */ 179 public java.util.Set<Class<?>> getDependantClasses() { 180 return Collections.unmodifiableSet(dependantClasses); 164 181 } 165 182 … … 247 264 this.name.set(name); 248 265 annotations.add(paramAnnotation); 266 flags |= paramAnnotation.flags(); 249 267 if (member instanceof Field) { 250 268 field.set((Field) member); … … 299 317 300 318 public int getFlags() { 301 int f = 0;319 int f = flags; 302 320 if (isReadOnly()) { 303 321 f |= ParamFlags.READONLY; … … 341 359 protected final Map<String, ParamCandidate> candidates; 342 360 protected final List<ParamCandidate> order; 361 protected final java.util.Set<Class<?>> dependantClasses = new HashSet<>(); 343 362 344 363 /** … … 364 383 return order; 365 384 } 366 } 385 386 public java.util.Set<Class<?>> getDependentClasses() { 387 return dependantClasses; 388 } 389 } 390 391 protected static final Map<Class<?>, Set> setsCache = Collections.synchronizedMap(new IdentityHashMap<Class<?>, Set>()); 367 392 368 393 public static Set getAllCandidates(Class<?> javaClass) throws ConstructionException { 394 Set result = setsCache.get(javaClass); 395 if (result != null) { 396 return result; 397 } 369 398 370 399 List<Class<?>> javaClasses = new LinkedList<>(); … … 374 403 } 375 404 376 Set resultSet = new Set(new HashMap<String, ParamCandidate>(), new LinkedList<ParamCandidate>());405 result = new Set(new HashMap<String, ParamCandidate>(), new LinkedList<ParamCandidate>()); 377 406 378 407 for (Class<?> j : javaClasses) { 379 Set set = new Set(resultSet.getCandidates(), new LinkedList<ParamCandidate>()); 408 Set set = new Set(result.getCandidates(), new LinkedList<ParamCandidate>()); 409 380 410 filterParamsCandidates(set, j.getDeclaredFields()); 381 411 filterParamsCandidates(set, j.getDeclaredMethods()); … … 383 413 FramsClassAnnotation fa = j.getAnnotation(FramsClassAnnotation.class); 384 414 if (fa != null) { 415 416 if (j != javaClass) { 417 result.dependantClasses.add(j); 418 } 419 for (Class<?> r : fa.register()) { 420 result.dependantClasses.add(r); 421 } 422 423 385 424 final List<String> order = Arrays.asList(fa.order()); 386 425 Collections.sort(set.getOrder(), new Comparator<ParamCandidate>() { … … 396 435 }); 397 436 } 398 result Set.getOrder().addAll(0, set.getOrder());399 } 400 401 for (ParamCandidate pc : result Set.getOrder()) {437 result.getOrder().addAll(0, set.getOrder()); 438 } 439 440 for (ParamCandidate pc : result.getOrder()) { 402 441 pc.validate(); 403 } 404 405 return resultSet; 442 pc.induceParamType(Param.build()); 443 result.dependantClasses.addAll(pc.getDependantClasses()); 444 } 445 446 setsCache.put(javaClass, result); 447 448 return result; 406 449 } 407 450 … … 425 468 } 426 469 470 protected ParamBuilder induceParamType(ParamBuilder builder, Type type) { 471 // if (type.equals(Void.TYPE)) { 472 // throw new ConstructionException().msg("void is not a valid type"); 473 // } 474 475 if (type instanceof ParameterizedType) { 476 ParameterizedType p = (ParameterizedType) type; 477 Type rawType = p.getRawType(); 478 Type containedType = null; 479 //TODO make implementation here 480 boolean map = false; 481 StringBuilder b = new StringBuilder(); 482 if (rawType.equals(Map.class)) { 483 containedType = p.getActualTypeArguments()[1]; 484 map = true; 485 b.append("l"); 486 } else if (rawType.equals(List.class)) { 487 containedType = p.getActualTypeArguments()[0]; 488 b.append("l"); 489 } else if (rawType.equals(EventListener.class)) { 490 containedType = p.getActualTypeArguments()[0]; 491 b.append("e"); 492 } 493 if (!(containedType instanceof Class)) { 494 return builder; 495 } 496 b.append(" "); 497 498 Class<?> containedClass = (Class<?>) containedType; 499 FramsClassAnnotation fca = containedClass.getAnnotation(FramsClassAnnotation.class); 500 if (fca == null) { 501 throw new ConstructionException().msg("the contained class is not annotated").arg("class", containedClass); 502 } 503 dependantClasses.add(containedClass); 504 b.append(FramsClassBuilder.getName(fca, containedClass)); 505 //TODO parameterize this 506 if (map) { 507 b.append(" uid"); 508 } 509 510 builder.type(b.toString()); 511 return builder; 512 } 513 514 if (type instanceof Class) { 515 516 Class<?> cl = (Class<?>) type; 517 518 // TODO: future support for enum 519 // if (cl.isEnum()) { 520 // Class<? extends Enum<?>> enumType = (Class<? extends Enum<?>>) cl; 521 // Enum<?>[] enums = enumType.getEnumConstants(); 522 // StringBuilder b = new StringBuilder(); 523 524 // b.append("d 0 ").append(enums.length - 1).append(" 0 "); 525 // for (Enum<?> e : enums) { 526 // b.append("~").append(e.name()); 527 // } 528 // return b.toString(); 529 // } 530 if (cl.equals(Integer.class) || cl.equals(int.class)) { 531 builder.type("d"); 532 return builder; 533 } 534 if (cl.equals(String.class)) { 535 builder.type("s"); 536 return builder; 537 } 538 if (cl.equals(Double.class) || cl.equals(double.class)) { 539 builder.type("f"); 540 return builder; 541 } 542 if (cl.equals(Boolean.class) || cl.equals(boolean.class)) { 543 builder.type( "d 0 1"); 544 return builder; 545 } 546 if (cl.equals(Object.class)) { 547 builder.type("x"); 548 return builder; 549 } 550 551 552 // builder.type("o " + (cl).getCanonicalName()); 553 builder.type("o " + cl.getSimpleName()); 554 dependantClasses.add(cl); 555 builder.fillStorageType(cl); 556 return builder; 557 } 558 559 throw new ConstructionException().msg("failed to find framsticks for native type").arg("type", type); 560 } 561 562 563 public ParamBuilder induceParamType(ParamBuilder builder) { 564 Method method = getCaller(); 565 if (method == null) { 566 return induceParamType(builder, getType()); 567 } 568 569 if (!method.getReturnType().equals(Void.TYPE)) { 570 builder.resultType(induceParamType(Param.build(), method.getGenericReturnType()).finish(ValueParam.class)); 571 } 572 573 List<ValueParam> arguments = new ArrayList<>(); 574 int number = 0; 575 for (Type arg : method.getGenericParameterTypes()) { 576 arguments.add(induceParamType(Param.build(), arg).idAndName("arg" + (number++)).finish(ValueParam.class)); 577 } 578 builder.argumentsType(arguments); 579 580 return builder; 581 } 582 427 583 }; -
java/main/src/main/java/com/framsticks/params/PropertiesAccess.java
r100 r101 76 76 @Override 77 77 public PropertiesAccess select(Object object) { 78 properties = Util.selectObjectForAccess(this, object, Map.class);78 properties = ParamsUtil.selectObjectForAccess(this, object, Map.class); 79 79 return this; 80 80 } -
java/main/src/main/java/com/framsticks/params/ReflectionAccess.java
r100 r101 1 1 package com.framsticks.params; 2 2 3 import java.lang.reflect.Field;4 3 import java.lang.reflect.InvocationTargetException; 5 4 import java.lang.reflect.Method; 6 import java.util.ArrayList; 7 import java.util.Collections; 8 import java.util.Comparator; 9 import java.util.HashMap; 10 import java.util.IdentityHashMap; 11 import java.util.List; 12 import java.util.Map; 13 14 import javax.annotation.concurrent.Immutable; 5 15 6 16 7 import org.apache.logging.log4j.Logger; 17 8 import org.apache.logging.log4j.LogManager; 18 9 19 import com.framsticks.params.annotations.AutoAppendAnnotation;20 10 import com.framsticks.params.types.EventParam; 21 11 import com.framsticks.params.types.ProcedureParam; 22 12 import com.framsticks.util.FramsticksException; 23 import com.framsticks.util.lang.Pair;24 13 25 14 import static com.framsticks.util.lang.Containers.*; … … 37 26 38 27 protected final Class<?> javaClass; 39 protected final Backend backend;28 protected final ReflectionAccessBackend backend; 40 29 41 30 private Object object; 42 43 @Immutable44 public static class Backend {45 46 protected static final Map<Pair<Class<?>, FramsClass>, Backend> synchronizedCache = Collections.synchronizedMap(new HashMap<Pair<Class<?>, FramsClass>, Backend>());47 48 49 public interface ReflectedGetter {50 public <T> T get(Object object, Class<T> type) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException;51 }52 53 public interface ReflectedSetter {54 public <T> void set(Object object, T value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException;55 }56 57 public interface ReflectedCaller {58 public Object call(Object object, Object[] arguments) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException;59 }60 61 public interface ReflectedAdder{62 public void reg(Object object, EventListener<?> listener) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException;63 }64 65 public interface ReflectedRemover{66 public void regRemove(Object object, EventListener<?> listener) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException;67 }68 69 protected final Map<ValueParam, ReflectedSetter> setters = new IdentityHashMap<>();70 protected final Map<ValueParam, ReflectedGetter> getters = new IdentityHashMap<>();71 protected final Map<ProcedureParam, ReflectedCaller> callers = new IdentityHashMap<>();72 protected final Map<EventParam, ReflectedAdder> adders = new IdentityHashMap<>();73 protected final Map<EventParam, ReflectedRemover> removers = new IdentityHashMap<>();74 75 protected final List<Method> autoAppendMethods = new ArrayList<>();76 77 /**78 * @param params79 */80 public Backend() {81 }82 83 public static Backend getOrCreateFor(Class<?> reflectedClass, FramsClass framsClass) {84 85 Pair<Class<?>, FramsClass> id = new Pair<Class<?>, FramsClass>(reflectedClass, framsClass);86 Backend backend = synchronizedCache.get(id);87 if (backend != null) {88 return backend;89 }90 91 log.debug("constructing backend for {}", id);92 backend = new Backend();93 94 Map<String, ParamCandidate> candidates = ParamCandidate.getAllCandidates(reflectedClass).getCandidates();95 96 try {97 for (final ProcedureParam pp : filterInstanceof(framsClass.getParamEntries(), ProcedureParam.class)) {98 if (!candidates.containsKey(pp.getId())) {99 log.trace("java class does implement method {}", pp);100 continue;101 }102 ParamCandidate pc = candidates.get(pp.getId());103 final Method method = pc.getCaller();104 105 backend.callers.put(pp, new ReflectedCaller() {106 107 @Override108 public Object call(Object object, Object[] arguments) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {109 return method.invoke(object, arguments);110 }111 });112 113 }114 115 for (final EventParam ep : filterInstanceof(framsClass.getParamEntries(), EventParam.class)) {116 if (!candidates.containsKey(ep.getId())) {117 log.trace("java class does not implement the event param {}", ep);118 continue;119 }120 ParamCandidate ec = candidates.get(ep.getId());121 final Method adder = ec.getAdder();122 final Method remover = ec.getRemover();123 124 backend.adders.put(ep, new ReflectedAdder() {125 126 @Override127 public void reg(Object object, EventListener<?> listener) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {128 adder.invoke(object, listener);129 }130 });131 132 backend.removers.put(ep, new ReflectedRemover() {133 134 @Override135 public void regRemove(Object object, EventListener<?> listener) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {136 remover.invoke(object, listener);137 }138 });139 }140 141 for (final ValueParam vp : filterInstanceof(framsClass.getParamEntries(), ValueParam.class)) {142 if (!candidates.containsKey(vp.getId())) {143 throw new ConstructionException().msg("missing candidate for param").arg("param", vp);144 }145 ParamCandidate pc = candidates.get(vp.getId());146 if (pc.isReadOnly() && !vp.hasFlag(ParamFlags.READONLY)) {147 throw new ConstructionException().msg("readonly state conflict").arg("param", vp);148 }149 if (!typeMatch(pc.getRawType(), vp.getStorageType())) {150 throw new ConstructionException().msg("types mismatch for param").arg("param", vp).arg("candidate", pc.getType()).arg("storage", vp.getStorageType());151 }152 153 final boolean primitive = pc.isPrimitive();154 if (pc.getField() != null) {155 final Field f = pc.getField();156 backend.getters.put(vp, new ReflectedGetter() {157 @Override158 public <T> T get(Object object, Class<T> type) throws IllegalArgumentException, IllegalAccessException {159 return type.cast(f.get(object));160 }161 });162 if (!pc.isFinal()) {163 backend.setters.put(vp, new ReflectedSetter() {164 @Override165 public <T> void set(Object object, T value) throws IllegalArgumentException, IllegalAccessException {166 if (value == null && primitive) {167 throw new FramsticksException().msg("setting null to primitive value");168 }169 f.set(object, value);170 }171 });172 }173 } else {174 final Method g = pc.getGetter();175 176 backend.getters.put(vp, new ReflectedGetter() {177 @Override178 public <T> T get(Object object, Class<T> type) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {179 return type.cast(g.invoke(object));180 }181 });182 183 if (!pc.isFinal()) {184 final Method s = pc.getSetter();185 backend.setters.put(vp, new ReflectedSetter() {186 @Override187 public <T> void set(Object object, T value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {188 if (value == null && primitive) {189 throw new FramsticksException().msg("setting null to primitive value");190 }191 s.invoke(object, value);192 }193 });194 }195 }196 }197 } catch (ConstructionException e) {198 throw e.arg("java class", reflectedClass).arg("framsClass", framsClass);199 }200 201 Class<?> javaClass = reflectedClass;202 while (javaClass != null) {203 204 for (Method m : javaClass.getDeclaredMethods()) {205 AutoAppendAnnotation a = m.getAnnotation(AutoAppendAnnotation.class);206 if (a == null) {207 continue;208 }209 Class<?>[] args = m.getParameterTypes();210 if (args.length != 1) {211 throw new ConstructionException().msg("invalid number of arguments in AutoAppend marked method").arg("method", m).arg("arguments", args.length);212 }213 backend.autoAppendMethods.add(m);214 }215 216 javaClass = javaClass.getSuperclass();217 }218 219 Collections.sort(backend.autoAppendMethods, new Comparator<Method>() {220 221 @Override222 public int compare(Method m0, Method m1) {223 Class<?> arg0 = m0.getParameterTypes()[0];224 Class<?> arg1 = m1.getParameterTypes()[0];225 if (arg0.isAssignableFrom(arg1)) {226 return 1;227 }228 if (arg1.isAssignableFrom(arg0)) {229 return -1;230 }231 return 0;232 }233 });234 235 synchronizedCache.put(id, backend);236 return backend;237 }238 239 }240 241 public static boolean typeMatch(Class<?> a, Class<?> b) {242 if (b.isPrimitive()) {243 throw new FramsticksException().msg("failed to match type, right argument is primitive").arg("left", a).arg("right", b);244 }245 if (!a.isPrimitive()) {246 return a.equals(b);247 }248 249 if (a.equals(int.class)) {250 return b.equals(Integer.class);251 }252 if (a.equals(double.class)) {253 return b.equals(Double.class);254 }255 if (a.equals(boolean.class)) {256 return b.equals(Boolean.class);257 }258 throw new FramsticksException().msg("failed to match types").arg("left", a).arg("right", b);259 }260 261 262 263 31 264 32 public ReflectionAccess(Class<?> javaClass) throws ConstructionException { … … 268 36 269 37 public ReflectionAccess(Class<?> javaClass, FramsClass framsClass) throws ConstructionException { 270 this(javaClass, framsClass, Backend.getOrCreateFor(javaClass, framsClass));271 } 272 273 protected ReflectionAccess(Class<?> javaClass, FramsClass framsClass, Backend backend) throws ConstructionException {38 this(javaClass, framsClass, ReflectionAccessBackend.getOrCreateFor(javaClass, framsClass)); 39 } 40 41 protected ReflectionAccess(Class<?> javaClass, FramsClass framsClass, ReflectionAccessBackend backend) throws ConstructionException { 274 42 super(framsClass); 275 43 this.javaClass = javaClass; … … 278 46 279 47 @Override 280 public ReflectionAccess cloneAccess() throws ConstructionException{48 public ReflectionAccess cloneAccess() { 281 49 return new ReflectionAccess(javaClass, framsClass, backend); 282 50 } … … 290 58 } 291 59 292 return backend.getters.get(param ).get(object, type);60 return backend.getters.get(param.getId()).get(object, type); 293 61 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { 294 62 throw new FramsticksException().msg("failed to get").cause(e); … … 310 78 throw new FramsticksException().msg("no object set"); 311 79 } 312 Backend.ReflectedSetter s = backend.setters.get(param);80 ReflectionAccessBackend.ReflectedSetter s = backend.setters.get(param.getId()); 313 81 if (s == null) { 314 82 throw new FramsticksException().msg("trying to set unsettable"); … … 334 102 } 335 103 336 backend.adders.get(param ).reg(object, listener);104 backend.adders.get(param.getId()).reg(object, listener); 337 105 return; 338 106 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { … … 352 120 } 353 121 354 backend.removers.get(param ).regRemove(object, listener);122 backend.removers.get(param.getId()).regRemove(object, listener); 355 123 return; 356 124 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { … … 364 132 @Override 365 133 public Object call(String id, Object[] arguments) { 366 return call(framsClass.getParamEntry(id, ProcedureParam.class), arguments); 367 } 368 369 @Override 370 public Object call(ProcedureParam param, Object[] arguments) { 371 try { 372 try { 373 if (object == null) { 374 throw new FramsticksException().msg("no object set"); 375 } 376 Backend.ReflectedCaller c = backend.callers.get(param); 134 try { 135 try { 136 if (object == null) { 137 throw new FramsticksException().msg("no object set"); 138 } 139 ReflectionAccessBackend.ReflectedCaller c = backend.callers.get(id); 377 140 if (c == null) { 378 141 throw new FramsticksException().msg("method is not bound"); … … 383 146 } 384 147 } catch (FramsticksException e) { 385 throw e.arg("param", param).arg("access", this); 386 } 387 } 388 389 void resetErrors() { 390 //TODO this replaces returnedObject.resetErrors(); 148 throw e.arg("param", framsClass.getParam(id)).arg("access", this); 149 } 150 } 151 152 @Override 153 public Object call(ProcedureParam param, Object[] arguments) { 154 return call(param.getId(), arguments); 391 155 } 392 156 … … 396 160 return; 397 161 } 398 399 resetErrors();400 162 401 163 try { … … 416 178 @Override 417 179 public ReflectionAccess select(Object object) { 418 this.object = Util.selectObjectForAccess(this, object, javaClass);180 this.object = ParamsUtil.selectObjectForAccess(this, object, javaClass); 419 181 return this; 420 182 } … … 425 187 } 426 188 427 // TODO: find a better place for it428 public static String objectToString(Object object) {429 StringBuilder b = new StringBuilder();430 for (Field f : object.getClass().getFields()) {431 b.append(f.getName());432 b.append(":");433 try {434 Object value = f.get(object);435 b.append((value != null) ? value.toString() : "<null>");436 } catch (IllegalAccessException e) {437 e.printStackTrace();438 }439 b.append("\n");440 }441 return b.toString();442 }443 444 445 189 @Override 446 190 public Object createAccessee() { … … 448 192 return javaClass.newInstance(); 449 193 } catch (InstantiationException | IllegalAccessException e) { 450 e.printStackTrace(); 451 } 452 log.fatal("failed to create reflected object of class {} for frams type {}", javaClass.getCanonicalName(), framsClass.getId()); 453 return null; 454 } 455 194 throw new FramsticksException().msg("failed to create reflected object").arg("java class", javaClass).arg("frams class", framsClass).cause(e); 195 } 196 } 456 197 457 198 @Override -
java/main/src/main/java/com/framsticks/params/Registry.java
r100 r101 8 8 import com.framsticks.util.DoubleMap; 9 9 import com.framsticks.util.FramsticksException; 10 import com.framsticks.util.FramsticksUnsupportedOperationException; 10 11 import com.framsticks.util.lang.Strings; 11 12 … … 20 21 */ 21 22 @FramsClassAnnotation 22 public class Registry {23 public class Registry implements AccessProvider { 23 24 private static final Logger log = LogManager.getLogger(Registry.class.getName()); 24 25 … … 45 46 46 47 public Registry registerAndBuild(Class<?> javaClass) { 48 if (javaToFramsAssociation.containsKey(javaClass)) { 49 return this; 50 } 47 51 register(javaClass); 48 52 associate(javaClass, putFramsClass(FramsClass.build().forClass(javaClass))); 49 for (Class<?> r : javaClass.getAnnotation(FramsClassAnnotation.class).register()) {53 for (Class<?> r : ParamCandidate.getAllCandidates(javaClass).getDependentClasses()) { 50 54 registerAndBuild(r); 51 55 } … … 157 161 } 158 162 163 @Override 164 public Access getAccess(String name) { 165 return createAccess(name); 166 } 167 168 @Override 169 public void addAccess(Access access) { 170 throw new FramsticksUnsupportedOperationException().msg("adding accesses to Registry"); 171 } 172 159 173 } -
java/main/src/main/java/com/framsticks/params/SimpleAbstractAccess.java
r100 r101 4 4 import static com.framsticks.util.lang.Containers.filterInstanceof; 5 5 6 import org.apache.logging.log4j.Logger;7 import org.apache.logging.log4j.LogManager;8 6 9 7 import com.framsticks.params.types.ObjectParam; 10 8 import com.framsticks.util.FramsticksException; 11 import static com.framsticks.params.SetStateFlags.*;12 9 13 10 /** … … 23 20 * @author Piotr Sniegowski 24 21 */ 25 public abstract class SimpleAbstractAccess implements Access { 26 27 private final static Logger log = LogManager.getLogger(SimpleAbstractAccess.class.getName()); 22 public abstract class SimpleAbstractAccess implements ObjectAccess { 28 23 29 24 protected final FramsClass framsClass; … … 40 35 return framsClass; 41 36 } 42 43 /**44 * Simple String key, value class.45 */46 public static class Entry {47 48 public final String key;49 public final String value;50 51 public Entry(String key, String value) {52 this.key = key;53 this.value = value;54 }55 56 @Override57 public String toString() {58 return key + " = " + value;59 }60 }61 62 37 63 38 @Override … … 129 104 130 105 @Override 131 public void setDefault(boolean numericOnly) {132 for (int i = 0; i < framsClass.getParamCount(); i++) {133 setDefault(i, numericOnly);134 }135 }136 137 @Override138 public void setDefault(int i, boolean numericOnly) {139 ValueParam entry = framsClass.getParamEntry(i, ValueParam.class);140 if ((entry != null) && (!numericOnly || entry.isNumeric())) {141 set(i, entry.getDef(entry.getStorageType()));142 }143 }144 145 @Override146 public void setMin() {147 for (int i = 0; i < framsClass.getParamCount(); i++) {148 setMin(i);149 }150 }151 152 @Override153 public void setMin(int i) {154 PrimitiveParam<?> entry = framsClass.getParamEntry(i, PrimitiveParam.class);155 Object min = entry.getMin(entry.getStorageType());156 if (min != null) {157 set(i, min);158 }159 }160 161 @Override162 public void setMax() {163 for (int i = 0; i < framsClass.getParamCount(); i++) {164 setMax(i);165 }166 }167 168 @Override169 public void setMax(int i) {170 PrimitiveParam<?> entry = framsClass.getParamEntry(i, PrimitiveParam.class);171 Object max = entry.getMax(entry.getStorageType());172 if (max != null) {173 set(i, max);174 }175 }176 177 @Override178 106 public void save(SinkInterface sink) { 179 107 assert framsClass != null; … … 189 117 } 190 118 sink.breakLine(); 191 }192 193 private static Entry readEntry(SourceInterface source) {194 195 String line;196 String key = null;197 StringBuilder value = null;198 while ((line = source.readLine()) != null) {199 if (key == null) {200 int colonIndex = line.indexOf(':');201 if (colonIndex == -1) {202 return null;203 }204 key = line.substring(0, colonIndex);205 String inlineValue = line.substring(colonIndex + 1);206 207 208 if (!inlineValue.startsWith("~")) {209 return new Entry(key, inlineValue);210 }211 value = new StringBuilder();212 value.append(inlineValue.substring(1));213 continue;214 }215 if (value.length() != 0) {216 value.append(System.getProperty("line.separator"));217 }218 if (line.endsWith("~") && !line.endsWith("\\~")) {219 value.append(line.substring(0, line.length() - 1));220 return new Entry(key, value.toString().replaceAll("\\\\~", "~"));221 }222 value.append(line);223 }224 return null;225 }226 227 @Override228 public void load(SourceInterface source) {229 //TODO not clearing values, because get from manager gives only fields, not children230 //this.clearValues();231 232 Entry entry;233 while ((entry = readEntry(source)) != null) {234 Param param = getParam(entry.key);235 if (param == null) {236 throw new FramsticksException().msg("param not found in access").arg("name", entry.key).arg("access", this);237 }238 if (!(param instanceof ValueParam)) {239 throw new FramsticksException().msg("param is not a value param").arg("param", param).arg("access", this);240 }241 if ((param.getFlags() & ParamFlags.DONTLOAD) == 0) {242 int retFlags = this.set((ValueParam) param, entry.value);243 if ((retFlags & (PSET_HITMIN | PSET_HITMAX)) != 0) {244 String which = ((retFlags & PSET_HITMIN) != 0) ? "small" : "big";245 log.warn("value of key '{}' was too {}, adjusted", entry.key, which);246 }247 }248 }249 119 } 250 120 … … 266 136 } 267 137 268 /*269 protected <T extends Comparable<T>> int setAndCut(Param param, Object value, Class<T> type) {270 int flags = 0;271 T val = type.cast(value);272 T min = param.getMin(type);273 T max = param.getMax(type);274 if (min != null && val.compareTo(min) < 0) {275 val = min;276 flags |= Flags.PSET_HITMIN;277 }278 if (max != null && val.compareTo(max) > 0) {279 val = max;280 flags |= Flags.PSET_HITMAX;281 }282 internalSet(param, val);283 return flags;284 }*/285 286 287 138 @Override 288 139 public ParamBuilder buildParam(ParamBuilder builder) { -
java/main/src/main/java/com/framsticks/params/UniqueListAccess.java
r100 r101 4 4 import com.framsticks.util.FramsticksException; 5 5 import com.framsticks.util.UnimplementedException; 6 import com.framsticks.util. UnsupportedOperationException;6 import com.framsticks.util.FramsticksUnsupportedOperationException; 7 7 import com.framsticks.util.lang.Casting; 8 8 import com.framsticks.util.lang.Numbers; … … 205 205 @Override 206 206 public <T> int set(int i, T value) { 207 throw new UnsupportedOperationException().msg("accesing unique list through index");207 throw new FramsticksUnsupportedOperationException().msg("accesing unique list through index"); 208 208 } 209 209 … … 251 251 @Override 252 252 public UniqueListAccess select(Object object) { 253 map = Util.selectObjectForAccess(this, object, Map.class);253 map = ParamsUtil.selectObjectForAccess(this, object, Map.class); 254 254 return this; 255 255 } -
java/main/src/main/java/com/framsticks/params/annotations/ParamAnnotation.java
r90 r101 22 22 23 23 String help() default ""; 24 //int flags() default 0;24 int flags() default 0; 25 25 int extra() default 0; 26 26 // String group() default ""; -
java/main/src/main/java/com/framsticks/parsers/F0Parser.java
r100 r101 12 12 import com.framsticks.model.f0.Schema; 13 13 14 import static com.framsticks.params.SimpleAbstractAccess.*;15 14 16 15 import com.framsticks.params.Param; … … 26 25 import com.framsticks.params.FramsClass; 27 26 import com.framsticks.params.Access; 27 import com.framsticks.params.AccessOperations.Entry; 28 28 import static com.framsticks.params.ParamFlags.*; 29 29 import static com.framsticks.params.SetStateFlags.*; -
java/main/src/main/java/com/framsticks/parsers/FileSource.java
r86 r101 1 1 package com.framsticks.parsers; 2 2 3 import com.framsticks.params.Source Interface;3 import com.framsticks.params.Source; 4 4 import com.framsticks.util.io.Encoding; 5 5 … … 7 7 8 8 9 public class FileSource implements Source Interface{9 public class FileSource implements Source { 10 10 11 11 private BufferedReader reader; … … 60 60 61 61 @Override 62 public Source InterfaceopenInclude(String include)62 public Source openInclude(String include) 63 63 { 64 64 try … … 89 89 } 90 90 91 @Override 92 public String toString() { 93 return filename; 94 } 95 91 96 } -
java/main/src/main/java/com/framsticks/parsers/Loaders.java
r100 r101 13 13 // private static final Logger log = LogManager.getLogger(Loaders.class.getName()); 14 14 15 public static @Nonnull FramsClass loadFramsClass(Source Interfacesource) throws ConstructionException {15 public static @Nonnull FramsClass loadFramsClass(Source source) throws ConstructionException { 16 16 final MultiParamLoader loader = new MultiParamLoader(); 17 17 loader.setNewSource(source); -
java/main/src/main/java/com/framsticks/parsers/MultiParamLoader.java
r100 r101 68 68 * File from which data should be read. 69 69 */ 70 private Source InterfacecurrentSource;70 private Source currentSource; 71 71 72 72 protected String currentLine; … … 83 83 * actual reader. 84 84 */ 85 private Map<String, Source Interface> fileMap = new HashMap<String, SourceInterface>();85 private Map<String, Source> fileMap = new HashMap<String, Source>(); 86 86 87 87 /** 88 88 * List of known classes. 89 89 */ 90 pr ivate Map<String, Access> knownParamInterfaces = new HashMap<String, Access>();90 protected AccessProvider accessProvider = new AccessStash(); 91 91 92 92 /** … … 100 100 public String getCurrentLine() { 101 101 return currentLine; 102 } 103 104 /** 105 * @return the accessProvider 106 */ 107 public AccessProvider getAccessProvider() { 108 return accessProvider; 109 } 110 111 /** 112 * @param accessProvider the accessProvider to set 113 */ 114 public void setAccessProvider(AccessProvider accessProvider) { 115 this.accessProvider = accessProvider; 102 116 } 103 117 … … 184 198 } 185 199 log.trace("loading into {}", lastAccess); 186 lastAccess.load(currentSource);200 AccessOperations.load(lastAccess, currentSource); 187 201 188 202 if (changeStatus(Status.AfterObject)) { … … 194 208 195 209 // found unknown object 196 emptyParam.load(currentSource);210 AccessOperations.load(emptyParam, currentSource); 197 211 if (changeStatus(Status.AfterObject)) { 198 212 return LoopAction.Break; … … 262 276 if (line.charAt(line.length() - 1) == ':') { 263 277 String typeName = line.substring(0, line.length() - 1); 264 lastAccess = knownParamInterfaces.get(typeName);278 lastAccess = accessProvider.getAccess(typeName); 265 279 266 280 if (lastAccess != null) { … … 300 314 */ 301 315 public void addAccess(Access access) { 302 /**TODO: by id or by name? rather by id, because from file is always lowercase*/ 303 knownParamInterfaces.put(access.getId(), access); 316 accessProvider.addAccess(access); 304 317 } 305 318 … … 324 337 */ 325 338 326 public boolean setNewSource(Source Interfacesource) {339 public boolean setNewSource(Source source) { 327 340 log.debug("switching current source to {}...", source.getFilename()); 328 341 … … 351 364 log.info("including file {}...", includeFilename); 352 365 353 Source InterfacenewSource = currentSource.openInclude(includeFilename);366 Source newSource = currentSource.openInclude(includeFilename); 354 367 if (newSource == null) { 355 368 return; … … 426 439 } 427 440 428 public static List<Object> loadAll(Source Interfacesource, Access access) {441 public static List<Object> loadAll(Source source, Access access) { 429 442 final List<Object> result = new LinkedList<>(); 430 443 -
java/main/src/main/java/com/framsticks/parsers/XmlLoader.java
r100 r101 20 20 21 21 import com.framsticks.params.Access; 22 import com.framsticks.params.ParamFlags; 23 import com.framsticks.params.PrimitiveParam; 22 24 import com.framsticks.params.Registry; 23 25 import com.framsticks.util.AutoBuilder; … … 107 109 for (int i = 0; i < attributes.getLength(); ++i) { 108 110 Node attributeNode = attributes.item(i); 109 access.set(mangleAttribute(attributeNode.getNodeName()), attributeNode.getNodeValue()); 111 PrimitiveParam<?> param = access.getFramsClass().getParamEntry(mangleAttribute(attributeNode.getNodeName()), PrimitiveParam.class); 112 if (param.hasFlag(ParamFlags.READONLY)) { 113 throw new FramsticksException().msg("cannot configure readonly param").arg("param", param).arg("in", access); 114 } 115 access.set(param, attributeNode.getNodeValue()); 110 116 } 111 117 -
java/main/src/main/java/com/framsticks/remote/RemoteTree.java
r100 r101 7 7 import com.framsticks.communication.queries.SetRequest; 8 8 import com.framsticks.core.AbstractTree; 9 import com.framsticks.core.ListChange; 9 10 import com.framsticks.core.Path; 11 import com.framsticks.core.ValueChange; 10 12 import com.framsticks.params.*; 11 13 import com.framsticks.params.EventListener; 12 import com.framsticks.params.annotations.AutoAppendAnnotation;13 14 import com.framsticks.params.annotations.FramsClassAnnotation; 14 15 import com.framsticks.params.annotations.ParamAnnotation; … … 17 18 import com.framsticks.parsers.Loaders; 18 19 import com.framsticks.parsers.MultiParamLoader; 19 import com.framsticks.core.Tree;20 20 import com.framsticks.util.*; 21 21 import com.framsticks.util.dispatching.AtOnceDispatcher; 22 22 import com.framsticks.util.dispatching.Dispatching; 23 import com.framsticks.util.dispatching.Dispatching.DispatcherWaiter;24 23 import com.framsticks.util.dispatching.DispatchingFuture; 25 24 import com.framsticks.util.dispatching.ExceptionResultHandler; … … 52 51 53 52 public RemoteTree() { 53 bufferedDispatcher.setBuffer(true); 54 registry.registerAndBuild(ListChange.class); 55 registry.registerAndBuild(ValueChange.class); 54 56 } 55 57 56 58 @ParamAnnotation 57 59 public void setAddress(String address) { 58 setConnection(Connection.to(new ClientSideManagedConnection(), new Address(address))); 59 } 60 61 @ParamAnnotation 60 this.connection = Connection.to(new ClientSideManagedConnection(), new Address(address)); 61 this.connection.setExceptionHandler(this); 62 this.connection.setNeedFileAcceptor(this); 63 } 64 65 @ParamAnnotation(flags = ParamFlags.USERREADONLY) 62 66 public String getAddress() { 63 67 return connection == null ? "<disconnected>" : connection.getAddress().toString(); 64 }65 66 @AutoAppendAnnotation67 public void setConnection(final ClientSideManagedConnection connection) {68 this.connection = connection;69 this.connection.setExceptionHandler(this);70 68 } 71 69 … … 219 217 super.joinableStart(); 220 218 221 dispatch(new RunAt<RemoteTree>(ThrowExceptionHandler.getInstance()) {219 bufferedDispatcher.getTargetDispatcher().dispatch(new RunAt<RemoteTree>(ThrowExceptionHandler.getInstance()) { 222 220 @Override 223 221 protected void runAt() { 224 final DispatcherWaiter<Tree, Tree> waiter = new DispatcherWaiter<Tree, Tree>(RemoteTree.this); 225 226 connection.send(new InfoRequest().path("/"), waiter, new ClientSideResponseFuture(this) { 222 223 connection.send(new InfoRequest().path("/"), bufferedDispatcher.getTargetDispatcher(), new ClientSideResponseFuture(this) { 227 224 @Override 228 225 protected void processOk(Response response) { 229 226 FramsClass framsClass = processFetchedInfo(RemoteTree.this, response.getFiles().get(0)); 230 227 assignRootParam(Param.build().name("Tree").id(RemoteTree.this.getName()).type("o " + framsClass.getId()).finish(CompositeParam.class)); 228 bufferedDispatcher.setBuffer(false); 231 229 } 232 230 }); 233 231 234 waiter.waitFor();235 232 } 236 233 }); … … 295 292 protected void runAt() { 296 293 assert isActive(); 297 if (argumentType.equals( Object.class)) {294 if (argumentType.equals(File.class)) { 298 295 listener.action(Casting.tryCast(argumentType, file)); 299 296 return; 300 297 } 301 Access access = registry.createAccess(argumentType); 302 Object argument = access.createAccessee(); 303 access.select(argument); 304 if (!argumentType.isInstance(argument)) { 305 throw new FramsticksException().msg("created argument is of wrond type").arg("expected", argumentType).arg("created", argument.getClass()); 306 } 307 A typedArgument = argumentType.cast(argument); 298 // Access access = registry.createAccess(argumentType); 308 299 309 300 // log.info("executing event with argument {}", argumentType); … … 311 302 loader.setNewSource(file.getContent()); 312 303 loader.addBreakCondition(MultiParamLoader.Status.AfterObject); 313 loader.addAccess(access); 304 loader.setAccessProvider(registry); 305 // loader.addAccess(access); 314 306 loader.go(); 315 316 listener.action(typedArgument); 307 Object argument = loader.getLastAccess().getSelected(); 308 // Object argument = access.getSelected(); 309 if (argument == null) { 310 listener.action(null); 311 } 312 if (!argumentType.isInstance(argument)) { 313 throw new FramsticksException().msg("created argument is of wrong type").arg("expected", argumentType).arg("created", argument.getClass()); 314 } 315 listener.action(argumentType.cast(argument)); 317 316 } 318 317 }); -
java/main/src/main/java/com/framsticks/running/ExternalProcess.java
r100 r101 8 8 import java.io.PrintWriter; 9 9 import java.util.ArrayList; 10 import java.util.LinkedList;11 10 import java.util.List; 12 11 … … 15 14 import org.apache.logging.log4j.LogManager; 16 15 16 import com.framsticks.core.ValueChange; 17 import com.framsticks.params.EventListener; 18 import com.framsticks.params.EventListeners; 19 import com.framsticks.params.ParamFlags; 17 20 import com.framsticks.params.annotations.AutoAppendAnnotation; 18 21 import com.framsticks.params.annotations.FramsClassAnnotation; … … 42 45 protected BufferedReader output; 43 46 protected Integer exitCode; 44 45 protected final List<OutputListener> listeners = new LinkedList<>(); 47 protected String echoInput; 48 49 protected final EventListeners<ValueChange> listeners = new EventListeners<>(); 46 50 47 51 @AutoAppendAnnotation 48 public void addListener(OutputListener listener) { 52 @ParamAnnotation(id = "line_output") 53 public void addOutputListener(EventListener<ValueChange> listener) { 49 54 synchronized (listeners) { 50 55 listeners.add(listener); 56 } 57 } 58 59 @ParamAnnotation(id = "line_output") 60 public void removeOutputListener(EventListener<ValueChange> listener) { 61 synchronized (listeners) { 62 listeners.remove(listener); 51 63 } 52 64 } … … 65 77 * @return the command 66 78 */ 67 @ParamAnnotation 79 @ParamAnnotation(flags = ParamFlags.USERREADONLY) 68 80 public String getCommand() { 69 81 return arguments.get(0); … … 80 92 protected void readerTask() { 81 93 94 log.debug("reading output from " + this); 82 95 String line; 83 96 try { … … 86 99 log.trace("read line: {}", line); 87 100 synchronized (listeners) { 88 for (OutputListener l : listeners) { 89 l.onLineRead(line); 90 } 101 listeners.actionForAll(new ValueChange(line)); 91 102 } 92 103 } … … 104 115 log.error("exception caught in process {}", this, e); 105 116 } 106 interrupt ();117 interruptJoinable(); 107 118 // finish(); 108 119 } 109 120 110 @ParamAnnotation 121 @ParamAnnotation(flags = ParamFlags.USERREADONLY) 111 122 public void setDirectory(String directory) { 112 123 builder.directory(new File(directory)); … … 115 126 @ParamAnnotation 116 127 public String getDirectory() { 117 return builder.directory() .getName();128 return builder.directory() != null ? builder.directory().getName() : "."; 118 129 } 119 130 … … 140 151 }); 141 152 Dispatching.use(readerThread, this); 153 154 if (echoInput != null) { 155 input.println(echoInput); 156 input.flush(); 157 } 142 158 } 143 159 … … 152 168 public PrintWriter getInput() { 153 169 return input; 170 } 171 172 /** 173 * @return the echoInput 174 */ 175 @ParamAnnotation(flags = ParamFlags.USERREADONLY) 176 public String getEchoInput() { 177 return echoInput; 178 } 179 180 /** 181 * @param echoInput the echoInput to set 182 */ 183 @ParamAnnotation 184 public void setEchoInput(String echoInput) { 185 this.echoInput = echoInput; 154 186 } 155 187 … … 162 194 163 195 @Override 164 @ParamAnnotation 196 @ParamAnnotation(flags = ParamFlags.USERREADONLY) 165 197 public String getName() { 166 198 return readerThread.getName(); -
java/main/src/main/java/com/framsticks/running/LoggingOutputListener.java
r100 r101 4 4 import org.apache.logging.log4j.LogManager; 5 5 6 import com.framsticks.core.ValueChange; 7 import com.framsticks.params.EventListener; 6 8 import com.framsticks.params.annotations.FramsClassAnnotation; 7 9 8 10 @FramsClassAnnotation 9 public class LoggingOutputListener implements OutputListener{11 public class LoggingOutputListener implements EventListener<ValueChange> { 10 12 private static final Logger log = 11 13 LogManager.getLogger(LoggingOutputListener.class); … … 13 15 14 16 @Override 15 public void onLineRead(String line) {16 log.info( line);17 public void action(ValueChange change) { 18 log.info(change.toString()); 17 19 } 18 20 -
java/main/src/main/java/com/framsticks/test/TestChild.java
r100 r101 1 1 package com.framsticks.test; 2 2 3 import com.framsticks. core.ListChange;3 import com.framsticks.params.AbstractUniqueObject; 4 4 import com.framsticks.params.annotations.FramsClassAnnotation; 5 5 import com.framsticks.params.annotations.ParamAnnotation; 6 6 7 7 @FramsClassAnnotation 8 public class TestChild {8 public class TestChild extends AbstractUniqueObject { 9 9 10 10 protected String name = "child"; 11 11 12 protected String uid;13 12 protected final TestClass parent; 14 13 /** … … 17 16 public TestChild(TestClass parent) { 18 17 this.parent = parent; 19 this.uid = "c" + (parent.counter++);20 18 } 21 19 … … 34 32 public void setName(String name) { 35 33 this.name = name; 36 parent.fireChildrenChange(this, ListChange.Action.Modify); 37 } 38 39 /** 40 * @return the uid 41 */ 42 @ParamAnnotation 43 public String getUid() { 44 return uid; 34 parent.children.modify(this); 45 35 } 46 36 -
java/main/src/main/java/com/framsticks/test/TestClass.java
r100 r101 1 1 package com.framsticks.test; 2 2 3 import java.util.Collections;4 import java.util.LinkedList;5 import java.util.List;6 3 import java.util.Map; 7 4 … … 11 8 import com.framsticks.core.ListChange; 12 9 import com.framsticks.params.EventListener; 13 import com.framsticks.params.UniqueListAccess; 10 import com.framsticks.params.EventListeners; 11 import com.framsticks.params.SimpleUniqueList; 14 12 import com.framsticks.params.annotations.FramsClassAnnotation; 15 13 import com.framsticks.params.annotations.ParamAnnotation; … … 26 24 "createChild", 27 25 "children_changed" 28 },29 register = {30 ChangeEvent.class,31 TestChild.class,32 ListChange.class33 26 } 34 27 ) … … 40 33 protected String name = "test"; 41 34 protected String history = "initial|"; 42 protected final List<EventListener<ChangeEvent>> historyListeners = new LinkedList<>(); 43 protected final List<EventListener<ListChange>> childrenListeners = new LinkedList<>(); 35 protected final EventListeners<TestChangeEvent> historyListeners = new EventListeners<>(); 44 36 45 protected final Map<String, TestChild> children = UniqueListAccess.createMap(TestChild.class, this); 46 protected int counter = 0; 37 protected final SimpleUniqueList<TestChild> children = new SimpleUniqueList<>(TestChild.class, 'c'); 47 38 48 39 /** … … 89 80 @ParamAnnotation 90 81 public Map<String, TestChild> getChildren() { 91 return Collections.unmodifiableMap(children);82 return children.getView(); 92 83 } 93 84 … … 111 102 TestChild child = new TestChild(this); 112 103 child.name = name; 113 children.put(child.getUid(), child); 114 fireChildrenChange(child, ListChange.Action.Add); 104 children.add(child); 115 105 } 116 106 117 107 protected void fireHistoryChange() { 118 for (EventListener<ChangeEvent> l : historyListeners) { 119 ChangeEvent event = new ChangeEvent(); 120 event.history = history; 121 l.action(event); 122 } 108 TestChangeEvent event = new TestChangeEvent(); 109 event.history = history; 110 historyListeners.actionForAll(event); 123 111 } 124 112 125 protected void fireChildrenChange(TestChild child, ListChange.Action action) {126 ListChange change = new ListChange(action, UniqueListAccess.getNumberInMap(children, child), child.getUid());127 for (EventListener<ListChange> l : childrenListeners) {128 l.action(change);129 }130 }131 113 132 114 @ParamAnnotation(id = "history_changed") 133 public void addHistoryListener(EventListener< ChangeEvent> listener) {115 public void addHistoryListener(EventListener<TestChangeEvent> listener) { 134 116 historyListeners.add(listener); 135 117 } 136 118 137 119 @ParamAnnotation(id = "history_changed") 138 public void removeHistoryListener(EventListener< ChangeEvent> listener) {120 public void removeHistoryListener(EventListener<TestChangeEvent> listener) { 139 121 historyListeners.remove(listener); 140 122 } … … 142 124 @ParamAnnotation(id = "children_changed") 143 125 public void addChildrenListener(EventListener<ListChange> listener) { 144 children Listeners.add(listener);126 children.addListener(listener); 145 127 } 146 128 147 129 @ParamAnnotation(id = "children_changed") 148 130 public void removeChildrenListener(EventListener<ListChange> listener) { 149 children Listeners.remove(listener);131 children.removeListener(listener); 150 132 } 151 133 -
java/main/src/main/java/com/framsticks/util/dispatching/AbstractJoinable.java
r100 r101 39 39 synchronized (joinablesRegistry) { 40 40 for (AbstractJoinable j : joinablesRegistry) { 41 b.append("\n").append(j.getState()).append(" : ").append(j) ;41 b.append("\n").append(j.getState()).append(" : ").append(j).append(" - ").append(j.getClass()); 42 42 } 43 43 } … … 73 73 74 74 75 p ublic final boolean start() {75 protected final boolean startJoinable() { 76 76 if (changeState(JoinableState.RUNNING)) { 77 77 joinableStart(); … … 81 81 } 82 82 83 p ublic final boolean interrupt() {83 protected final boolean interruptJoinable() { 84 84 if (changeState(JoinableState.FINISHING)) { 85 85 joinableInterrupt(); … … 89 89 } 90 90 91 protected final boolean finish () {91 protected final boolean finishJoinable() { 92 92 if (changeState(JoinableState.JOINABLE)) { 93 93 joinableFinish(); … … 118 118 switch (state) { 119 119 case RUNNING: 120 return start ();120 return startJoinable(); 121 121 case FINISHING: 122 return interrupt ();122 return interruptJoinable(); 123 123 case JOINABLE: 124 return finish ();124 return finishJoinable(); 125 125 default: return false; 126 126 } … … 149 149 assert monitor == null; 150 150 monitor = owner.getMonitor(); 151 return this.start ();151 return this.startJoinable(); 152 152 } 153 153 return false; … … 170 170 @Override 171 171 protected void runAt() { 172 interrupt ();172 interruptJoinable(); 173 173 } 174 174 }); -
java/main/src/main/java/com/framsticks/util/dispatching/AtOnceDispatcher.java
r99 r101 5 5 * @author Piotr Sniegowski 6 6 */ 7 public class AtOnceDispatcher<C> extends AbstractJoinable implements JoinableDispatcher<C> {7 public class AtOnceDispatcher<C> extends AbstractJoinable implements Dispatcher<C> { 8 8 9 9 @SuppressWarnings("rawtypes") … … 37 37 @Override 38 38 protected void joinableInterrupt() { 39 finish ();39 finishJoinable(); 40 40 } 41 41 -
java/main/src/main/java/com/framsticks/util/dispatching/Dispatcher.java
r90 r101 4 4 * @author Piotr Sniegowski 5 5 */ 6 public interface Dispatcher<C> {6 public interface Dispatcher<C> extends Joinable { 7 7 public boolean isActive(); 8 8 public void dispatch(RunAt<? extends C> runnable); -
java/main/src/main/java/com/framsticks/util/dispatching/Dispatching.java
r100 r101 1 1 package com.framsticks.util.dispatching; 2 3 import java.util.Timer; 2 4 3 5 import org.apache.logging.log4j.Logger; … … 11 13 public abstract class Dispatching { 12 14 private static final Logger log = LogManager.getLogger(Dispatching.class); 15 16 protected static final Timer timer = new Timer(); 17 18 public static Timer getTimer() { 19 return timer; 20 } 13 21 14 22 public static boolean isThreadSafe() { … … 183 191 } 184 192 185 public static class DispatcherWaiter<C, T extends Dispatcher<C> & Joinable> implements Dispatcher<C> {186 // protected boolean done = false;187 protected final T dispatcher;188 protected RunAt<? extends C> runnable;189 190 /**191 * @param joinable192 */193 public DispatcherWaiter(T dispatcher) {194 this.dispatcher = dispatcher;195 }196 197 public synchronized void waitFor() {198 while ((runnable == null) && (dispatcher.getState().ordinal() <= JoinableState.RUNNING.ordinal())) {199 try {200 this.wait();201 } catch (InterruptedException e) {202 }203 }204 if (runnable != null) {205 runnable.run();206 }207 208 }209 210 @Override211 public boolean isActive() {212 return dispatcher.isActive();213 }214 215 @Override216 public synchronized void dispatch(RunAt<? extends C> runnable) {217 this.runnable = runnable;218 this.notifyAll();219 }220 221 }193 // public static class DispatcherWaiter<C, T extends Dispatcher<C> & Joinable> implements Dispatcher<C> { 194 // // protected boolean done = false; 195 // protected final T dispatcher; 196 // protected RunAt<? extends C> runnable; 197 198 // /** 199 // * @param joinable 200 // */ 201 // public DispatcherWaiter(T dispatcher) { 202 // this.dispatcher = dispatcher; 203 // } 204 205 // public synchronized void waitFor() { 206 // while ((runnable == null) && (dispatcher.getState().ordinal() <= JoinableState.RUNNING.ordinal())) { 207 // try { 208 // this.wait(); 209 // } catch (InterruptedException e) { 210 // } 211 // } 212 // if (runnable != null) { 213 // runnable.run(); 214 // } 215 216 // } 217 218 // @Override 219 // public boolean isActive() { 220 // return dispatcher.isActive(); 221 // } 222 223 // @Override 224 // public synchronized void dispatch(RunAt<? extends C> runnable) { 225 // this.runnable = runnable; 226 // this.notifyAll(); 227 // } 228 229 // } 222 230 223 231 public static class Waiter { -
java/main/src/main/java/com/framsticks/util/dispatching/JoinableCollection.java
r97 r101 8 8 import java.util.Set; 9 9 10 import com.framsticks.params.ParamFlags; 10 11 import com.framsticks.params.annotations.AutoAppendAnnotation; 11 12 import com.framsticks.params.annotations.FramsClassAnnotation; 13 import com.framsticks.params.annotations.ParamAnnotation; 12 14 import com.framsticks.util.FramsticksException; 13 15 import com.framsticks.util.Misc; … … 72 74 protected void joinableInterrupt() { 73 75 if (joinables.isEmpty()) { 74 finish ();76 finishJoinable(); 75 77 return; 76 78 } … … 137 139 public T get(String name) { 138 140 for (T j : joinables) { 139 if ( j.getName().equals(name)) {141 if (name.equals(j.getName())) { 140 142 return j; 141 143 } … … 153 155 154 156 @Override 157 @ParamAnnotation 155 158 public String getName() { 156 159 return observableName; 160 } 161 162 @ParamAnnotation(flags = ParamFlags.USERREADONLY) 163 public final void setName(String name) { 164 observableName = name; 157 165 } 158 166 … … 185 193 } 186 194 195 196 187 197 } -
java/main/src/main/java/com/framsticks/util/dispatching/Thread.java
r100 r101 3 3 import org.apache.logging.log4j.Logger; 4 4 import org.apache.logging.log4j.LogManager; 5 6 import java.util.LinkedList;7 import java.util.ListIterator;8 5 9 6 … … 14 11 * @author Piotr Sniegowski 15 12 */ 16 public class Thread<C> extends AbstractJoinable implements JoinableDispatcher<C> {13 public class Thread<C> extends AbstractJoinable implements Dispatcher<C> { 17 14 18 15 private static final Logger log = LogManager.getLogger(Thread.class); … … 20 17 protected final java.lang.Thread thread; 21 18 22 private final LinkedList<Task<? extends C>> queue = new LinkedList<>(); 19 protected final Object condition = new Object(); 20 private RunnableQueue<C> queue = new RunnableQueue<>(); 23 21 24 22 public Thread() { 25 thread = new java.lang.Thread(new java.lang.Runnable() {23 thread = new java.lang.Thread(new Runnable() { 26 24 @Override 27 25 public void run() { … … 30 28 }); 31 29 } 32 33 30 34 31 public Thread(java.lang.Thread thread) { … … 51 48 ExceptionHandler exceptionHandler = getMonitor().getTaskExceptionHandler(); 52 49 while (!java.lang.Thread.interrupted()) { 53 Task<? extends C> task;54 synchronized ( queue) {50 RunAt<? extends C> runnable; 51 synchronized (condition) { 55 52 if (queue.isEmpty()) { 56 53 try { 57 queue.wait();54 condition.wait(); 58 55 } catch (InterruptedException ignored) { 59 56 break; … … 61 58 continue; 62 59 } 63 task = queue.peekFirst(); 64 assert task != null; 65 if (task.moment > System.currentTimeMillis()) { 66 try { 67 queue.wait(task.moment - System.currentTimeMillis()); 68 } catch (InterruptedException ignored) { 69 continue; 60 runnable = queue.pollFirst(); 61 } 62 if (runnable != null) { 63 try { 64 runnable.run(); 65 } catch (Exception e) { 66 if (exceptionHandler != null) { 67 if (exceptionHandler.handle(this, e)) { 68 continue; 69 } 70 70 } 71 continue;71 log.error("error in thread: ", e); 72 72 } 73 queue.pollFirst();74 }75 try {76 task.run();77 } catch (Exception e) {78 if (exceptionHandler != null) {79 if (exceptionHandler.handle(this, e)) {80 continue;81 }82 }83 log.error("error in thread: ", e);84 73 } 85 74 } 86 75 log.debug("finishing thread {}", this); 87 finish ();76 finishJoinable(); 88 77 } 89 78 90 protected void enqueueTask(Task<? extends C> task) {91 synchronized (queue) {92 ListIterator<Task<? extends C>> i = queue.listIterator();93 while (i.hasNext()) {94 Task<? extends C> t = i.next();95 if (t.getMoment() > task.getMoment()) {96 i.previous();97 i.add(task);98 task = null;99 break;100 }101 }102 if (task != null) {103 queue.add(task);104 }105 79 106 /* 107 Iterator<Task> j = queue.iterator(); 108 Task prev = null; 109 while (j.hasNext()) { 110 Task next = j.next(); 111 assert (prev == null) || prev.getMoment() <= next.getMoment(); 112 prev = next; 113 } 114 */ 115 queue.notify(); 80 @Override 81 public void dispatch(RunAt<? extends C> runnable) { 82 synchronized (condition) { 83 queue.push(runnable); 84 condition.notifyAll(); 116 85 } 117 86 } 118 87 119 @Override 120 public void dispatch(final RunAt<? extends C> runnable) { 121 if (!(runnable instanceof Task)) { 122 enqueueTask(new Task<C>(runnable) { 123 @Override 124 protected void runAt() { 125 runnable.run(); 126 } 127 }); 128 return; 88 public RunnableQueue<C> switchQueue(RunnableQueue<C> queue) { 89 synchronized (condition) { 90 RunnableQueue<C> result = this.queue; 91 this.queue = queue; 92 return result; 129 93 } 130 enqueueTask((Task<? extends C>) runnable);131 94 } 132 95 -
java/main/src/main/java/com/framsticks/util/lang/Holder.java
r96 r101 33 33 } 34 34 35 public static <T2> Holder<T2> make(T2 value) { 36 return new Holder<T2>(value); 37 } 38 35 39 } -
java/main/src/main/java/com/framsticks/util/lang/Strings.java
r99 r101 1 1 package com.framsticks.util.lang; 2 3 import java.util.regex.Matcher; 2 4 3 5 import com.framsticks.util.FramsticksException; … … 78 80 } 79 81 82 public static CharSequence takeGroup(CharSequence input, Matcher matcher, int group) { 83 // return (matcher.start(group) == matcher.end(group)) ? null : input.subSequence(matcher.start(group), matcher.end(group)); 84 return input.subSequence(matcher.start(group), matcher.end(group)); 85 } 86 80 87 } -
java/main/src/main/resources/log4j2.xml
r100 r101 11 11 <loggers> 12 12 <!-- <logger name="com.framsticks.hosting.Cli" level="debug" /> --> 13 <!-- <logger name="com.framsticks.gui. tree.TreeModel" level="debug" /> -->13 <!-- <logger name="com.framsticks.gui.Frame" level="debug" /> --> 14 14 <!-- <logger name="com.framsticks.params.SimpleAbstractAccess" level="debug" /> --> 15 <!-- <logger name="com.framsticks.gui.Frame" level="debug" /> --> 15 <!-- <logger name="com.framsticks.running.ExternalProcess" level="trace" /> --> 16 <!-- <logger name="com.framsticks.util.dispatching.AbstractJoinable" level="debug" /> --> 16 17 <root level="info"> 17 18 <appender-ref ref="Console"/> -
java/main/src/test/java/com/framsticks/communication/RequestTest.java
r99 r101 28 28 29 29 assertThat(Request.takeRequestId(true, " 2 simple second")).isEqualTo(Pair.make(2, "simple second")); 30 assertThat(Request.takeRequestId(true, " -3 simple")).isEqualTo(Pair.make(-3, "simple")); 30 31 } 31 32 -
java/main/src/test/java/com/framsticks/core/ListChangeTest.java
r100 r101 7 7 8 8 import com.framsticks.core.ListChange.Action; 9 import com.framsticks.params.AccessOperations; 9 10 import com.framsticks.params.FramsClass; 10 11 import com.framsticks.params.ListSink; … … 60 61 @Test(dependsOnMethods = "createReflectionAccess") 61 62 public void load() throws Exception { 62 access.select(listChange).load(ListSource.createFrom("type:2", "pos:0", "id:test"));63 AccessOperations.load(access.select(listChange), ListSource.createFrom("type:2", "pos:0", "id:test")); 63 64 64 65 assertThat(listChange.action).isEqualTo(Action.Modify); -
java/main/src/test/java/com/framsticks/core/XmlBasedTest.java
r96 r101 26 26 } 27 27 28 protected abstract String getConfigurationName(); 28 protected String getConfigurationName() { 29 return this.getClass().getSimpleName() + ".xml"; 30 } 29 31 30 32 -
java/main/src/test/java/com/framsticks/gui/ProcedureBrowserTest.java
r100 r101 17 17 import com.framsticks.params.types.StringParam; 18 18 import com.framsticks.parsers.XmlLoader; 19 import com.framsticks.test. ChangeEvent;19 import com.framsticks.test.TestChangeEvent; 20 20 import com.framsticks.test.TestClass; 21 21 import com.framsticks.util.dispatching.FutureHandler; … … 82 82 waitForIdle(); 83 83 84 final EventListener< ChangeEvent> listener = new EventListener<ChangeEvent>() {84 final EventListener<TestChangeEvent> listener = new EventListener<TestChangeEvent>() { 85 85 86 86 @Override 87 public void action( ChangeEvent argument) {87 public void action(TestChangeEvent argument) { 88 88 assertThat(argument.history).isEqualTo(""); 89 89 } … … 96 96 assertThat(access.get("history", String.class)).isEqualTo("initial|Żółw|"); 97 97 98 tree.addListener(Path.to(tree, "/"), access.getFramsClass().getParamEntry("history_changed", EventParam.class), listener, ChangeEvent.class, FutureHandler.doNothing(Void.class, failOnException));98 tree.addListener(Path.to(tree, "/"), access.getFramsClass().getParamEntry("history_changed", EventParam.class), listener, TestChangeEvent.class, FutureHandler.doNothing(Void.class, failOnException)); 99 99 } 100 100 }); -
java/main/src/test/java/com/framsticks/gui/console/TrackConsoleTest.java
r98 r101 3 3 import org.testng.annotations.Test; 4 4 5 import com.framsticks.communication.Address;6 import com.framsticks.communication.ClientSideManagedConnection;7 import com.framsticks.communication.Connection;8 5 import com.framsticks.core.Path; 9 6 import com.framsticks.gui.GuiTest; … … 28 25 tree = new RemoteTree(); 29 26 30 tree.set Connection(Connection.to(new ClientSideManagedConnection(), new Address("localhost:9009")));27 tree.setAddress("localhost:9009"); 31 28 32 29 console = new TrackConsole().setConnection(tree.getConnection()); -
java/main/src/test/java/com/framsticks/hosting/ServerTest.java
r100 r101 15 15 import com.framsticks.remote.RemoteTree; 16 16 17 import com.framsticks.test. ChangeEvent;17 import com.framsticks.test.TestChangeEvent; 18 18 import com.framsticks.test.TestClass; 19 19 import com.framsticks.core.Tree; … … 45 45 protected LocalTree hosted; 46 46 protected TestClass hostedObject; 47 protected EventListener< ChangeEvent> listener;47 protected EventListener<TestChangeEvent> listener; 48 48 protected EventListener<ListChange> childListener; 49 49 … … 52 52 53 53 54 @Override55 protected String getConfigurationName() {56 return "ServerTest.xml";57 }58 54 59 55 @Test … … 127 123 public void registerListener() { 128 124 final Waiter waiter = produceWaiter(1.0); 129 listener = new EventListener< ChangeEvent>() {130 131 @Override 132 public void action( ChangeEvent argument) {125 listener = new EventListener<TestChangeEvent>() { 126 127 @Override 128 public void action(TestChangeEvent argument) { 133 129 listenerArguments.add(argument.history); 134 130 } … … 142 138 }); 143 139 144 addListener(remotePath, remoteTestFramsClass.getParamEntry("history_changed", EventParam.class), listener, ChangeEvent.class, produceWaiter(1.0).passInFuture(Void.class));140 addListener(remotePath, remoteTestFramsClass.getParamEntry("history_changed", EventParam.class), listener, TestChangeEvent.class, produceWaiter(1.0).passInFuture(Void.class)); 145 141 } 146 142 -
java/main/src/test/java/com/framsticks/model/ModelPackageTest.java
r100 r101 8 8 import com.framsticks.params.FramsClass; 9 9 import com.framsticks.params.ReflectionAccess; 10 import com.framsticks.params.Source Interface;10 import com.framsticks.params.Source; 11 11 import com.framsticks.params.ValueParam; 12 12 import com.framsticks.parsers.FileSource; … … 25 25 assertThat(stream).describedAs("stream " + filename).isNotNull(); 26 26 27 Source Interfacesource = new FileSource(stream, filename);27 Source source = new FileSource(stream, filename); 28 28 29 29 assertThat(source.isClosed()).isFalse(); -
java/main/src/test/java/com/framsticks/params/FramsClassBuilderTest.java
r100 r101 10 10 import com.framsticks.params.types.StringParam; 11 11 import com.framsticks.parsers.Savers; 12 import com.framsticks.test. ChangeEvent;12 import com.framsticks.test.TestChangeEvent; 13 13 import com.framsticks.test.TestClass; 14 14 import com.framsticks.test.TestConfiguration; … … 69 69 "id:history_changed", 70 70 "name:HistoryListener", 71 "type:e ChangeEvent",71 "type:e TestChangeEvent", 72 72 "", 73 73 "prop:", … … 128 128 final Holder<String> called = new Holder<>(); 129 129 130 final EventListener< ChangeEvent> listener = new EventListener<ChangeEvent>() {130 final EventListener<TestChangeEvent> listener = new EventListener<TestChangeEvent>() { 131 131 132 132 @Override 133 public void action( ChangeEvent argument) {133 public void action(TestChangeEvent argument) { 134 134 called.set(argument.history); 135 135 } -
java/main/src/test/java/com/framsticks/params/ParamBuilderTest.java
r100 r101 30 30 public void loadParam() throws Exception { 31 31 access = new ReflectionAccess(ParamBuilder.class, builderFramsClass); 32 Source Interfacesource = ListSource.createFrom("prop:", "id:v", "name:variable", "type:f", "help:just a testing variable", "");32 Source source = ListSource.createFrom("prop:", "id:v", "name:variable", "type:f", "help:just a testing variable", ""); 33 33 34 34 MultiParamLoader loader = new MultiParamLoader(); -
java/main/src/test/java/com/framsticks/parsers/F0ParserTest.java
r100 r101 73 73 @Test(dependsOnMethods = {"readF0"}) 74 74 public void stripAccess() { 75 components = Util.stripAccess(accesses, ModelComponent.class);75 components = ParamsUtil.stripAccess(accesses, ModelComponent.class); 76 76 77 77 assertThat(components.get(1)).isInstanceOf(Part.class); -
java/main/src/test/java/com/framsticks/running/ExternalProcessTest.java
r90 r101 9 9 import org.testng.annotations.Test; 10 10 11 import com.framsticks.core.ValueChange; 12 import com.framsticks.params.EventListener; 11 13 import com.framsticks.test.TestConfiguration; 12 14 import com.framsticks.util.dispatching.Monitor; … … 25 27 final List<String> output = new LinkedList<>(); 26 28 27 process.add Listener(new OutputListener() {29 process.addOutputListener(new EventListener<ValueChange>() { 28 30 @Override 29 public void onLineRead(String line) {30 output.add( line);31 public void action(ValueChange change) { 32 output.add(change.value.toString()); 31 33 } 32 34 }); -
java/main/src/test/resources/configs/ServerTest.xml
r99 r101 6 6 <import class="com.framsticks.test.TestClass" /> 7 7 <import class="com.framsticks.running.LoggingOutputListener" /> 8 <Server name="server"port="9007">8 <Server port="9007"> 9 9 <LocalTree name="test"> 10 10 <TestClass name="a test name" />
Note: See TracChangeset
for help on using the changeset viewer.