Changeset 102 for java/main/src
- Timestamp:
- 07/16/13 23:31:35 (11 years ago)
- Location:
- java/main/src
- Files:
-
- 20 added
- 1 deleted
- 65 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/communication/ClientSideManagedConnection.java
r101 r102 132 132 133 133 public void send(ProtocolRequest request, ClientSideResponseFuture callback) { 134 //TODO RunAt135 134 sendImplementation(request, AtOnceDispatcher.getInstance(), callback); 136 135 } … … 466 465 467 466 final String finalEventPath = eventPath; 468 467 //TODO add arguments to the exception 469 468 send(new CallRequest().procedure("remove").path(eventPath), dispatcher, new ClientSideResponseFuture(future) { 470 469 -
java/main/src/main/java/com/framsticks/communication/Connection.java
r101 r102 18 18 import java.io.PrintWriter; 19 19 import java.net.Socket; 20 import java.net.SocketTimeoutException;21 20 import java.util.Collection; 22 21 import java.util.HashSet; … … 87 86 public Connection setAddress(String address) { 88 87 return setAddress(new Address(address)); 89 }90 91 public synchronized boolean isConnected() {92 return socket != null && socket.isConnected();93 88 } 94 89 … … 131 126 132 127 readChars = 0; 133 while (readChars == 0) { 134 try { 135 readChars = input.read(readBuffer); 136 } catch (SocketTimeoutException ignored) { 137 //timeout - continue 138 } 128 readChars = input.read(readBuffer); 129 if (readChars < 0) { 130 throw new SocketClosedException().msg("socket is closed"); 139 131 } 140 132 iterator = 0; … … 143 135 throw new InterruptedException(); 144 136 } catch (Exception e) { 145 throw new FramsticksException().msg("failed to read line").cause(e); 137 log.debug("failed to read line (closing): {}", e.getMessage()); 138 throw new SocketClosedException().msg("failed to read line").cause(e); 146 139 } 147 140 } … … 162 155 protected abstract void processNextInputBatch(); 163 156 157 164 158 protected final void processInputBatchesUntilClosed() { 165 while (isRunning() && isConnected()) {159 while (isRunning() && !socket.isClosed()) { 166 160 try { 167 161 processNextInputBatch(); 162 } catch (SocketClosedException e) { 163 log.log(isRunning() ? Level.ERROR : Level.DEBUG, "socket is closing: {}", e.getShortMessage(new StringBuilder())); 164 // log.log(isRunning() ? Level.ERROR : Level.DEBUG, "caught exception: ", e); 165 break; 168 166 } catch (FramsticksException e) { 167 log.debug("{} caught exception in receiver thread {}", this, e.getMessage()); 169 168 handle(e); 170 169 } catch (Exception e) { … … 173 172 } 174 173 } 174 log.debug("{} finished processing input", this); 175 175 } 176 176 … … 227 227 Dispatching.use(threads, this); 228 228 229 senderThread.dispatch(new RunAt<Connection>( ThrowExceptionHandler.getInstance()) {229 senderThread.dispatch(new RunAt<Connection>(this) { 230 230 @Override 231 231 protected void runAt() { … … 238 238 }); 239 239 240 receiverThread.dispatch(new RunAt<Connection>( ThrowExceptionHandler.getInstance()) {240 receiverThread.dispatch(new RunAt<Connection>(this) { 241 241 @Override 242 242 protected void runAt() { 243 243 receiverThreadRoutine(); 244 244 interruptJoinable(); 245 finishJoinable();245 // finishJoinable(); 246 246 } 247 247 }); … … 260 260 261 261 protected static void startClientConnection(Connection connection) { 262 while (connection.isRunning() && !connection.isConnected()) {262 while (connection.isRunning() && connection.socket == null) { 263 263 log.debug("connecting to {}", connection.address); 264 264 try { 265 265 connection.socket = new Socket(connection.getAddressObject().getHostName(), connection.getAddressObject().getPort()); 266 266 } catch (IOException e) { 267 log. info("{} failed to connect (retrying): ", connection, e);267 log.warn("{} failed to connect (retrying): {}", connection, e.getMessage()); 268 268 Dispatching.sleep(0.5); 269 269 } … … 272 272 log.debug("{} connected", connection); 273 273 try { 274 connection.socket.setSoTimeout(500);274 // connection.socket.setSoTimeout(500); 275 275 connection.setupStreams(); 276 276 } catch (Exception e) { … … 319 319 @Override 320 320 public void handle(FramsticksException exception) { 321 log.debug("{} handling {}", this, exception.getMessage()); 321 322 exceptionHandler.handle(exception); 322 323 } … … 358 359 } 359 360 361 public synchronized boolean isConnected() { 362 return socket != null && socket.isConnected(); 363 } 364 360 365 } -
java/main/src/main/java/com/framsticks/communication/ServerSideManagedConnection.java
r101 r102 32 32 33 33 34 protected void processNextInputBatch() {35 processNextRequest();36 }37 34 38 35 @Override … … 92 89 93 90 94 protected void processNext Request() {91 protected void processNextInputBatch() { 95 92 final Holder<Integer> id = new Holder<>(); 96 93 final String line = getLine(); … … 106 103 } 107 104 108 //TODO what to do here?109 105 handleRequest(request, new ServerSideResponseFuture() { 110 106 @Override -
java/main/src/main/java/com/framsticks/core/AbstractTree.java
r101 r102 34 34 import com.framsticks.util.dispatching.JoinableState; 35 35 import com.framsticks.util.dispatching.RunAt; 36 import com.framsticks.util.dispatching.Thread;37 36 import com.framsticks.util.dispatching.ThrowExceptionHandler; 38 37 import com.framsticks.util.lang.Pair; … … 42 41 */ 43 42 @FramsClassAnnotation 44 public abstract class AbstractTree extends AbstractJoinable implements Dispatcher<Tree>,Tree, JoinableParent, NeedFileAcceptor {43 public abstract class AbstractTree extends AbstractJoinable implements Tree, JoinableParent, NeedFileAcceptor { 45 44 46 45 private static final Logger log = LogManager.getLogger(AbstractTree.class); … … 49 48 private ExceptionResultHandler handler = ThrowExceptionHandler.getInstance(); 50 49 51 protected final BufferedDispatcher<Tree> bufferedDispatcher = new BufferedDispatcher<>( );50 protected final BufferedDispatcher<Tree> bufferedDispatcher = new BufferedDispatcher<>(this); 52 51 53 52 protected final PriorityQueue<Pair<Integer, NeedFileAcceptor>> needFileAcceptors = new PriorityQueue<>(32, new Comparator<Pair<Integer, NeedFileAcceptor>>() { … … 77 76 public void assignRootObject(Object object) { 78 77 if (root == null) { 79 throw new FramsticksException().msg("root ishas no type specified");78 throw new FramsticksException().msg("root has no type specified"); 80 79 } 81 80 if (root.getObject() != null) { … … 89 88 public @Nonnull Node getAssignedRoot() { 90 89 if (root == null) { 91 throw new FramsticksException().msg("root has no type specified yet") ;90 throw new FramsticksException().msg("root has no type specified yet").arg("in", this); 92 91 } 93 92 return root; … … 173 172 @Override 174 173 public Dispatcher<Tree> getDispatcher() { 175 return bufferedDispatcher .getTargetDispatcher();174 return bufferedDispatcher; 176 175 } 177 176 … … 181 180 @Override 182 181 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 182 bufferedDispatcher.setTargetDispatcher(dispatcher); 187 183 } … … 213 209 @Override 214 210 protected void joinableStart() { 215 if (bufferedDispatcher.getTargetDispatcher() == null) { 216 bufferedDispatcher.setTargetDispatcher(new Thread<Tree>()); 217 } 218 Dispatching.use(bufferedDispatcher.getTargetDispatcher(), this); 211 bufferedDispatcher.createThreadIfNeeded(); 212 Dispatching.use(bufferedDispatcher, this); 219 213 } 220 214 221 215 @Override 222 216 protected void joinableInterrupt() { 223 Dispatching.drop(bufferedDispatcher .getTargetDispatcher(), this);217 Dispatching.drop(bufferedDispatcher, this); 224 218 } 225 219 … … 231 225 @Override 232 226 protected void joinableJoin() throws InterruptedException { 233 Dispatching.join(bufferedDispatcher .getTargetDispatcher());227 Dispatching.join(bufferedDispatcher); 234 228 } 235 229 236 230 @Override 237 231 public void childChangedState(Joinable joinable, JoinableState state) { 238 if (joinable == bufferedDispatcher .getTargetDispatcher()) {232 if (joinable == bufferedDispatcher) { 239 233 proceedToState(state); 240 234 } … … 333 327 } 334 328 } 335 throw new FramsticksException().msg("failed to find need file acceptor in tree").arg("tree", AbstractTree.this) ;329 throw new FramsticksException().msg("failed to find need file acceptor in tree").arg("tree", AbstractTree.this).arg("needfile", needFile); 336 330 } 337 331 }); -
java/main/src/main/java/com/framsticks/core/ListChange.java
r100 r102 1 1 package com.framsticks.core; 2 3 import java.util.Arrays; 4 import java.util.Set; 5 import java.util.TreeSet; 6 7 import org.apache.commons.lang.StringUtils; 2 8 3 9 import com.framsticks.params.annotations.FramsClassAnnotation; … … 9 15 * @author Piotr Sniegowski 10 16 */ 11 @FramsClassAnnotation(order = {"type", "pos", "id" })17 @FramsClassAnnotation(order = {"type", "pos", "id", "hint"}) 12 18 public class ListChange { 13 19 20 public static enum Action { 21 Add, 22 Remove, 23 Modify 24 } 14 25 15 /** 16 * @param action 17 */ 18 public ListChange(Action action, Integer position, String identifier) { 26 27 public ListChange(Action action, Integer position, String identifier, Object... hints) { 19 28 this.action = action; 20 29 this.position = position; 21 30 this.identifier = identifier; 31 if (hints.length != 0) { 32 this.hints = new TreeSet<>(); 33 for (Object h : hints) { 34 this.hints.add(h.toString()); 35 } 36 } 22 37 } 23 38 … … 40 55 } 41 56 42 public static enum Action {43 Add,44 Remove,45 Modify46 // Add(0),47 // Remove(1),48 // Modify(2);49 57 50 // public final int value; 58 public boolean hasHint(String hint) { 59 if (hints == null) { 60 return false; 61 } 62 return hints.contains(hint); 63 } 51 64 52 // /**53 // * @param value54 // */55 // Action(int value) {56 // this.value = value;57 // }58 59 }60 65 61 66 public Action action = Action.Add; … … 64 69 @ParamAnnotation(id = "id") 65 70 public String identifier; 71 72 protected Set<String> hints; 73 74 @ParamAnnotation 75 public String getHints() { 76 return StringUtils.join(hints, ","); 77 } 78 79 @ParamAnnotation 80 public void setHints(String hints) { 81 if (!Strings.notEmpty(hints)) { 82 this.hints = null; 83 return; 84 } 85 this.hints = new TreeSet<>(); 86 this.hints.addAll(Arrays.asList(StringUtils.split(hints, ","))); 87 } 66 88 67 89 @ParamAnnotation … … 79 101 @Override 80 102 public String toString() { 81 return action + " " + identifier + " " + position; 103 StringBuilder b = new StringBuilder(); 104 b.append(action).append(" ").append(identifier).append(" ").append(position); 105 if (hints != null && !hints.isEmpty()) { 106 b.append(" ").append(getHints()); 107 } 108 return b.toString(); 82 109 } 83 110 … … 86 113 if (object instanceof ListChange) { 87 114 ListChange r = (ListChange) object; 88 return Misc.equals(action, r.action) && Misc.equals(position, r.position) && Misc.equals(identifier, r.identifier) ;115 return Misc.equals(action, r.action) && Misc.equals(position, r.position) && Misc.equals(identifier, r.identifier) && Misc.equals(hints, r.hints); 89 116 } 90 117 return false; -
java/main/src/main/java/com/framsticks/core/LocalTree.java
r101 r102 15 15 import com.framsticks.params.types.ProcedureParam; 16 16 import com.framsticks.util.FramsticksException; 17 import com.framsticks.util.dispatching.Dispatcher; 18 import com.framsticks.util.dispatching.DispatcherSetable; 17 19 import com.framsticks.util.dispatching.Dispatching; 18 20 import com.framsticks.util.dispatching.Future; … … 33 35 public LocalTree() { 34 36 super(); 35 37 bufferedDispatcher.setBuffer(false); 36 38 } 37 39 40 @SuppressWarnings({ "rawtypes", "unchecked" }) 38 41 @AutoAppendAnnotation 39 42 public void setRootObject(Object object) { … … 49 52 joinableRootObject = (Joinable) object; 50 53 } 54 if (object instanceof DispatcherSetable) { 55 DispatcherSetable<?> setable = (DispatcherSetable<?>) object; 56 setable.setDispatcher((Dispatcher) this); 57 } 51 58 } 52 59 53 60 public Object getRootObject() { 54 return getAssignedRoot().getObject(); 61 Object result = getAssignedRoot().getObject(); 62 if (result == null) { 63 throw new FramsticksException().msg("object tree is empty").arg("tree", this); 64 } 65 return result; 55 66 } 56 67 57 68 public <T> T getRootObject(Class<T> type) { 58 69 Object result = getRootObject(); 59 if (result == null) {60 throw new FramsticksException().msg("object tree is empty").arg("tree", this);61 }62 70 if (!type.isInstance(result)) { 63 71 throw new FramsticksException().msg("object tree holds object of different kind").arg("object", result).arg("requested", type).arg("tree", this); … … 181 189 } 182 190 } 191 183 192 } -
java/main/src/main/java/com/framsticks/core/Tree.java
r101 r102 13 13 import com.framsticks.params.types.ProcedureParam; 14 14 import com.framsticks.util.dispatching.Dispatcher; 15 import com.framsticks.util.dispatching.DispatcherSetable; 15 16 import com.framsticks.util.dispatching.ExceptionResultHandler; 16 17 import com.framsticks.util.dispatching.Future; 17 18 import com.framsticks.util.dispatching.Joinable; 18 19 19 public interface Tree extends Dispatcher<Tree>, Joinable, ExceptionResultHandler {20 public interface Tree extends Dispatcher<Tree>, DispatcherSetable<Tree>, Joinable, ExceptionResultHandler { 20 21 21 22 public @Nonnull Node getAssignedRoot(); … … 54 55 public ExceptionResultHandler getExceptionHandler(); 55 56 56 public void setDispatcher(Dispatcher<Tree> dispatcher);57 // public void setDispatcher(Dispatcher<Tree> dispatcher); 57 58 58 public Dispatcher<Tree> getDispatcher();59 // public Dispatcher<Tree> getDispatcher(); 59 60 60 61 public <A> void addListener(Path path, EventParam param, EventListener<A> listener, Class<A> argumentType, Future<Void> future); -
java/main/src/main/java/com/framsticks/core/TreeOperations.java
r101 r102 44 44 public static final SideNoteKey<Boolean> FETCHED_MARK = SideNoteKey.make(Boolean.class); 45 45 46 public static @Nonnull 47 FramsClass processFetchedInfo(Tree tree, File file) { 46 public static @Nonnull FramsClass processFetchedInfo(Tree tree, File file) { 48 47 assert tree.isActive(); 49 48 FramsClass framsClass = Loaders.loadFramsClass(file.getContent()); -
java/main/src/main/java/com/framsticks/dumping/PrintWriterSink.java
r84 r102 1 1 package com.framsticks.dumping; 2 2 3 import com.framsticks.params.Sink Interface;3 import com.framsticks.params.Sink; 4 4 5 5 import java.io.PrintWriter; … … 8 8 * @author Piotr Sniegowski 9 9 */ 10 public class PrintWriterSink implements Sink Interface{10 public class PrintWriterSink implements Sink { 11 11 12 12 protected final PrintWriter stream; -
java/main/src/main/java/com/framsticks/dumping/SaveStream.java
r100 r102 2 2 3 3 import static com.framsticks.core.TreeOperations.*; 4 import static com.framsticks.params.AccessOperations.*; 4 5 import com.framsticks.core.Node; 5 6 import com.framsticks.core.Path; … … 8 9 import com.framsticks.params.FramsClass; 9 10 import com.framsticks.params.ListAccess; 10 import com.framsticks.params.Sink Interface;11 import com.framsticks.params.Sink; 11 12 import com.framsticks.parsers.Savers; 12 13 import com.framsticks.core.Tree; … … 30 31 private final static Logger log = LogManager.getLogger(SaveStream.class.getName()); 31 32 32 protected final Sink Interfacesink;33 protected final Sink sink; 33 34 protected final Tree tree; 34 35 protected final Future<Void> future; … … 38 39 private int dispatched = 0; 39 40 40 public SaveStream(Sink Interfacesink, Tree tree, Path root, Future<Void> future) {41 public SaveStream(Sink sink, Tree tree, Path root, Future<Void> future) { 41 42 assert Dispatching.isThreadSafe(); 42 43 this.sink = sink; … … 83 84 sink.print("file").breakLine(); 84 85 //stream.print("#" + access.getSelected().getClass().getCanonicalName() + "\n"); 85 access.save(sink);86 save(access, sink); 86 87 sink.print("eof").breakLine(); 87 88 sink.print("ok").breakLine(); -
java/main/src/main/java/com/framsticks/experiment/Experiment.java
r101 r102 2 2 3 3 import java.util.Map; 4 5 import org.apache.logging.log4j.Level; 6 import org.apache.logging.log4j.Logger; 7 import org.apache.logging.log4j.LogManager; 4 8 5 9 import com.framsticks.core.ListChange; 6 10 import com.framsticks.params.EventListener; 11 import com.framsticks.params.ParamFlags; 7 12 import com.framsticks.params.SimpleUniqueList; 8 13 import com.framsticks.params.annotations.AutoAppendAnnotation; 9 14 import com.framsticks.params.annotations.FramsClassAnnotation; 10 15 import com.framsticks.params.annotations.ParamAnnotation; 16 import com.framsticks.params.types.ProcedureParam; 17 import com.framsticks.remote.RemoteTree; 18 import com.framsticks.util.FramsticksException; 19 import com.framsticks.util.dispatching.AbstractJoinable; 20 import com.framsticks.util.dispatching.BufferedDispatcher; 21 import com.framsticks.util.dispatching.Dispatcher; 22 import com.framsticks.util.dispatching.DispatcherSetable; 23 import com.framsticks.util.dispatching.Dispatching; 24 import com.framsticks.util.dispatching.ExceptionResultHandler; 25 import com.framsticks.util.dispatching.Joinable; 11 26 import com.framsticks.util.dispatching.JoinableCollection; 27 import com.framsticks.util.dispatching.JoinableParent; 28 import com.framsticks.util.dispatching.JoinableState; 29 import com.framsticks.util.dispatching.RunAt; 12 30 13 31 @FramsClassAnnotation 14 public class Experiment extends JoinableCollection<Simulator> { 32 public class Experiment extends AbstractJoinable implements Dispatcher<Experiment>, DispatcherSetable<Experiment>, JoinableParent, ExceptionResultHandler { 33 private static final Logger log = LogManager.getLogger(Experiment.class); 34 35 protected final JoinableCollection<Simulator> simulatorAsJoinables = new JoinableCollection<Simulator>().setObservableName("simulators"); 36 37 protected final JoinableCollection<RemoteTree> simulatorCandidates = new JoinableCollection<RemoteTree>().setObservableName("candidates"); 15 38 16 39 protected final SimpleUniqueList<Simulator> simulators = new SimpleUniqueList<>(Simulator.class, 's'); 40 41 protected final SimpleUniqueList<Simulator> oldSimulators = new SimpleUniqueList<>(Simulator.class, 's'); 42 43 protected final BufferedDispatcher<Experiment> bufferedDispatcher = new BufferedDispatcher<>(this); 44 45 protected String expdef; 46 47 /** 48 * 49 */ 50 public Experiment() { 51 super(); 52 bufferedDispatcher.setBuffer(false); 53 54 Dispatching.dispatchLog(this, log, Level.DEBUG, "first task"); 55 56 57 simulators.addListener(new EventListener<ListChange>() { 58 @Override 59 public void action(ListChange argument) { 60 if (argument.getAction() == ListChange.Action.Add) { 61 simulators.fireChildrenChange(argument, ListChange.Action.Modify, "ready"); 62 } 63 } 64 }); 65 66 } 67 68 /** 69 * @return the simulatorCandidates 70 */ 71 public JoinableCollection<RemoteTree> getSimulatorCandidates() { 72 return simulatorCandidates; 73 } 17 74 18 75 @ParamAnnotation … … 21 78 } 22 79 80 @ParamAnnotation(id = "old_simulators") 81 public Map<String, Simulator> getOldSimulators() { 82 return oldSimulators.getView(); 83 } 84 85 /** 86 * @return the dispatcher 87 */ 88 @Override 89 public Dispatcher<Experiment> getDispatcher() { 90 return bufferedDispatcher; 91 } 92 93 /** 94 * @param dispatcher the dispatcher to set 95 */ 96 @Override 97 public void setDispatcher(Dispatcher<Experiment> dispatcher) { 98 bufferedDispatcher.setTargetDispatcher(dispatcher); 99 } 100 101 /** 102 * @return the expdef 103 */ 104 @ParamAnnotation(flags = ParamFlags.USERREADONLY) 105 public String getExpdef() { 106 return expdef; 107 } 108 109 /** 110 * @param expdef the expdef to set 111 */ 112 @ParamAnnotation 113 public void setExpdef(String expdef) { 114 this.expdef = expdef; 115 } 116 23 117 @ParamAnnotation(id = "simulators_changed") 24 118 public void addSimulatorsListener(EventListener<ListChange> listener) { … … 34 128 public void addSimulator(Simulator simulator) { 35 129 simulators.add(simulator); 36 } 130 simulatorAsJoinables.add(simulator); 131 132 133 134 135 136 } 137 138 protected void removeSimulator(Simulator simulator) { 139 simulatorAsJoinables.remove(simulator); 140 simulators.remove(simulator); 141 oldSimulators.add(simulator); 142 } 143 144 @ParamAnnotation(id = "old_simulators_changed") 145 public void addOldSimulatorsListener(EventListener<ListChange> listener) { 146 oldSimulators.addListener(listener); 147 } 148 149 @ParamAnnotation(id = "old_simulators_changed") 150 public void removeOldSimulatorsListener(EventListener<ListChange> listener) { 151 oldSimulators.removeListener(listener); 152 } 153 154 @Override 155 public String getName() { 156 return "experiment"; 157 } 158 159 @Override 160 public void childChangedState(Joinable joinable, JoinableState state) { 161 proceedToState(state); 162 } 163 164 @Override 165 protected void joinableStart() { 166 bufferedDispatcher.createThreadIfNeeded(); 167 Dispatching.use(bufferedDispatcher, this); 168 169 Dispatching.use(simulatorAsJoinables, this); 170 Dispatching.use(simulatorCandidates, this); 171 } 172 173 @Override 174 protected void joinableInterrupt() { 175 176 Dispatching.drop(simulatorAsJoinables, this); 177 Dispatching.drop(simulatorCandidates, this); 178 179 finishJoinable(); 180 } 181 182 @Override 183 protected void joinableFinish() { 184 log.debug("finishing experiment {}", this); 185 } 186 187 @Override 188 protected void joinableJoin() throws InterruptedException { 189 Dispatching.drop(bufferedDispatcher, this); 190 191 Dispatching.join(simulatorAsJoinables); 192 Dispatching.join(simulatorCandidates); 193 Dispatching.join(bufferedDispatcher.getTargetDispatcher()); 194 } 195 196 @Override 197 public void handle(FramsticksException exception) { 198 log.error("caught exception: ", exception); 199 } 200 201 @Override 202 public boolean isActive() { 203 return bufferedDispatcher.isActive(); 204 } 205 206 @Override 207 public void dispatch(RunAt<? extends Experiment> runnable) { 208 bufferedDispatcher.dispatch(runnable); 209 } 210 211 @ParamAnnotation(paramType = ProcedureParam.class) 212 public void connectToSimulator(String address) { 213 SimulatorConnector connector = new SimulatorConnector(); 214 connector.setAddress(address); 215 connector.attachTo(this); 216 } 217 37 218 } -
java/main/src/main/java/com/framsticks/experiment/Simulator.java
r101 r102 1 1 package com.framsticks.experiment; 2 2 3 import com.framsticks.params.ParamFlags; 3 import com.framsticks.communication.File; 4 import com.framsticks.communication.queries.NeedFile; 5 import com.framsticks.communication.queries.NeedFileAcceptor; 6 import com.framsticks.core.Path; 7 import com.framsticks.core.Tree; 8 import com.framsticks.core.ValueChange; 9 import com.framsticks.params.EventListener; 10 import com.framsticks.params.FramsClass; 4 11 import com.framsticks.params.UniqueObject; 5 12 import com.framsticks.params.annotations.FramsClassAnnotation; 6 13 import com.framsticks.params.annotations.ParamAnnotation; 14 import com.framsticks.params.types.EventParam; 7 15 import com.framsticks.params.types.ProcedureParam; 8 16 import com.framsticks.remote.RemoteTree; 17 import com.framsticks.util.FramsticksException; 9 18 import com.framsticks.util.dispatching.AbstractJoinable; 19 import com.framsticks.util.dispatching.Dispatcher; 10 20 import com.framsticks.util.dispatching.Dispatching; 21 import com.framsticks.util.dispatching.ExceptionResultHandler; 22 import com.framsticks.util.dispatching.Future; 23 import com.framsticks.util.dispatching.FutureHandler; 11 24 import com.framsticks.util.dispatching.Joinable; 12 25 import com.framsticks.util.dispatching.JoinableParent; 13 26 import com.framsticks.util.dispatching.JoinableState; 27 import com.framsticks.util.dispatching.RunAt; 28 import com.framsticks.util.dispatching.ThrowExceptionHandler; 29 import com.framsticks.util.lang.Holder; 30 import java.util.concurrent.atomic.AtomicInteger; 31 import org.apache.logging.log4j.LogManager; 32 import org.apache.logging.log4j.Logger; 33 import static com.framsticks.core.TreeOperations.*; 14 34 15 35 @FramsClassAnnotation 16 public class Simulator extends AbstractJoinable implements JoinableParent, UniqueObject { 36 public final class Simulator extends AbstractJoinable implements Dispatcher<Simulator>, JoinableParent, UniqueObject, ExceptionResultHandler { 37 38 private static final Logger log = LogManager.getLogger(Simulator.class); 39 17 40 protected String uid; 18 41 19 protected final RemoteTree remoteTree = new RemoteTree(); 42 protected final RemoteTree remoteTree; 43 protected final Path simulatorPath; 44 protected final FramsClass simulatorClass; 45 protected final Experiment experiment; 46 protected final EventListener<ValueChange> runningListener; 20 47 21 48 /** 22 49 * 23 50 */ 24 public Simulator( ) {51 public Simulator(Experiment experiment, RemoteTree remoteTree, Path simulatorPath) { 25 52 super(); 26 } 27 28 @ParamAnnotation 29 public void setAddress(String address) { 30 remoteTree.setAddress(address); 31 } 32 33 @ParamAnnotation(flags = ParamFlags.USERREADONLY) 53 this.remoteTree = remoteTree; 54 this.simulatorPath = simulatorPath.assureResolved(); 55 this.experiment = experiment; 56 this.simulatorClass = getFramsClass(simulatorPath); 57 58 assert remoteTree.isActive(); 59 assert experiment.isActive(); 60 61 log.debug("simulator ready {}", this); 62 63 runningListener = new EventListener<ValueChange>() { 64 @Override 65 public void action(ValueChange argument) { 66 log.debug("running state of {} changed: {}", this, argument); 67 } 68 }; 69 70 addListener(simulatorPath, simulatorClass.getParamEntry("running_changed", EventParam.class), runningListener, ValueChange.class, new FutureHandler<Void>(this) { 71 @Override 72 protected void result(Void result) { 73 log.debug("running listener for {} registered", this); 74 } 75 }); 76 } 77 78 @ParamAnnotation 34 79 public String getAddress() { 35 80 return remoteTree.getAddress(); … … 39 84 @ParamAnnotation 40 85 public String getName() { 41 42 return "simulator " + uid + " " + getAddress(); 86 return getAddress(); 43 87 } 44 88 … … 62 106 } 63 107 108 /** 109 * @return the simulatorPath 110 */ 111 public Path getSimulatorPath() { 112 return simulatorPath; 113 } 114 115 /** 116 * @return the simulatorClass 117 */ 118 public FramsClass getSimulatorClass() { 119 return simulatorClass; 120 } 121 64 122 @Override 65 123 protected void joinableStart() { 66 124 Dispatching.use(remoteTree, this); 67 68 125 } 69 126 … … 96 153 } 97 154 155 @ParamAnnotation(paramType = ProcedureParam.class) 156 public void abort() { 157 assert isActive(); 158 log.debug("explicitly aborting {}", this); 159 experiment.removeSimulator(this); 160 interruptJoinable(); 161 } 162 98 163 @Override 99 164 public void childChangedState(Joinable joinable, JoinableState state) { … … 101 166 } 102 167 168 @Override 169 public void handle(FramsticksException exception) { 170 experiment.handle(new FramsticksException().msg("exception caught in simulator").arg("simulator", this).cause(exception)); 171 } 172 173 @Override 174 public boolean isActive() { 175 return experiment.isActive(); 176 } 177 178 @SuppressWarnings({ "rawtypes", "unchecked" }) 179 @Override 180 public void dispatch(RunAt<? extends Simulator> runnable) { 181 experiment.dispatch((RunAt) runnable); 182 } 183 184 protected final AtomicInteger netloadIdCounter = new AtomicInteger(); 185 186 public void uploadNet(final File file, final Future<Object> future) { 187 final String netloadId = "NetLoadSaveLogic" + netloadIdCounter.getAndIncrement(); 188 189 log.debug("uploading file {} to {} identified by {}", file, simulatorPath, netloadId); 190 191 final Holder<NeedFileAcceptor> acceptor = new Holder<>(); 192 final Tree tree = simulatorPath.getTree(); 193 194 acceptor.set(new NeedFileAcceptor() { 195 196 @Override 197 public boolean acceptNeed(NeedFile needFile) { 198 if (!needFile.getDescription().equals(netloadId)) { 199 return false; 200 } 201 log.debug("accepting netload {}", netloadId); 202 needFile.getFuture().pass(file); 203 tree.dispatch(new RunAt<Tree>(ThrowExceptionHandler.getInstance()) { 204 205 @Override 206 protected void runAt() { 207 tree.removeNeedFileAcceptor(acceptor.get()); 208 } 209 }); 210 return true; 211 } 212 213 }); 214 215 simulatorPath.getTree().addNeedFileAcceptor(Integer.MIN_VALUE, acceptor.get()); 216 217 call(simulatorPath, getFramsClass(simulatorPath).getParamEntry("netload_id", ProcedureParam.class), new Object[] { netloadId }, new FutureHandler<Object>(future) { 218 219 @Override 220 protected void result(Object result) { 221 log.debug("upload of {} done", file); 222 future.pass(result); 223 } 224 }); 225 226 } 103 227 } -
java/main/src/main/java/com/framsticks/gui/Browser.java
r101 r102 6 6 import com.framsticks.core.*; 7 7 import com.framsticks.gui.console.Console; 8 import com.framsticks.gui.console.DirectConsole; 9 import com.framsticks.gui.console.ManagedConsole; 8 10 import com.framsticks.gui.console.TrackConsole; 9 11 import com.framsticks.gui.table.ColumnsConfig; … … 56 58 private static final Logger log = LogManager.getLogger(Browser.class); 57 59 58 protected final JoinableCollection<Frame> frames = new JoinableCollection<Frame>( ).setObservableName("frames");59 protected final JoinableCollection<Tree> trees = new JoinableCollection<Tree>( ).setObservableName("trees");60 protected final JoinableCollection<Console> consoles = new JoinableCollection<Console>( ).setObservableName("consoles");60 protected final JoinableCollection<Frame> frames = new JoinableCollection<Frame>(JoinableCollection.FinishPolicy.OnAll).setObservableName("frames"); 61 protected final JoinableCollection<Tree> trees = new JoinableCollection<Tree>(JoinableCollection.FinishPolicy.Never).setObservableName("trees"); 62 protected final JoinableCollection<Console> consoles = new JoinableCollection<Console>(JoinableCollection.FinishPolicy.Never).setObservableName("consoles"); 61 63 62 64 protected final List<PopupMenuEntryProvider> popupMenuEntryProviders = new LinkedList<>(); … … 123 125 } 124 126 }); 125 } 126 }); 127 // addNodeActionToTreePopupMenu("", new NodeAction() ) 127 menu.add(new AbstractAction("Open managed console") { 128 @Override 129 public void actionPerformed(ActionEvent e) { 130 consoles.add(new ManagedConsole().setTree(remoteTree)); 131 } 132 }); 133 menu.add(new AbstractAction("Open direct console") { 134 @Override 135 public void actionPerformed(ActionEvent e) { 136 consoles.add(new DirectConsole().setAddress(remoteTree.getAddress())); 137 } 138 }); 139 } 140 }); 128 141 129 142 } -
java/main/src/main/java/com/framsticks/gui/Frame.java
r101 r102 95 95 96 96 protected final Map<Tree, TreeAtFrame> treeAtFrames = new IdentityHashMap<>(); 97 protected JoinableCollection<Tree> trees = new JoinableCollection< >();97 protected JoinableCollection<Tree> trees = new JoinableCollection<Tree>().setObservableName("frame trees"); 98 98 99 99 public Frame(Browser browser) { -
java/main/src/main/java/com/framsticks/gui/MainFrame.java
r101 r102 51 51 @Override 52 52 public void actionPerformed(ActionEvent actionEvent) { 53 browser.autoResolvePath("/simulator/genepools/groups/0", null);53 // browser.autoResolvePath("/simulator/genepools/groups/0", null); 54 54 // browser.autoResolvePath("/simulator/populations/groups/0", null; 55 55 // browser.autoResolvePath("/simulator/genepools/groups/0/genotypes", null); -
java/main/src/main/java/com/framsticks/gui/console/DirectConsole.java
r97 r102 4 4 import java.util.List; 5 5 6 import com.framsticks.communication.Address; 6 7 import com.framsticks.communication.ClientSideRawConnection; 7 8 import com.framsticks.communication.ConnectionListener; 8 import com.framsticks.params.annotations.AutoAppendAnnotation;9 9 import com.framsticks.params.annotations.FramsClassAnnotation; 10 import com.framsticks.params.annotations.ParamAnnotation; 10 11 import com.framsticks.util.dispatching.ThrowExceptionHandler; 11 12 … … 19 20 } 20 21 21 @AutoAppendAnnotation 22 public DirectConsole setConnection(ClientSideRawConnection connection) { 23 this.connection = connection; 22 23 @ParamAnnotation 24 public DirectConsole setAddress(String address) { 25 return setAddress(new Address(address)); 26 } 27 28 public DirectConsole setAddress(Address address) { 29 this.connection = new ClientSideRawConnection(); 30 this.connection.setAddress(address); 24 31 return this; 25 32 } -
java/main/src/main/java/com/framsticks/gui/console/InteractiveConsole.java
r98 r102 54 54 @Override 55 55 protected void initializeGui() { 56 // TODO Auto-generated method stub57 56 super.initializeGui(); 58 57 -
java/main/src/main/java/com/framsticks/gui/console/ManagedConsole.java
r99 r102 46 46 return (ClientSideManagedConnection) connection; 47 47 } 48 48 49 49 50 protected void sendImplementation(String line) { … … 159 160 160 161 @AutoAppendAnnotation 161 public voidsetTree(RemoteTree tree) {162 public ManagedConsole setTree(RemoteTree tree) { 162 163 this.tree = tree; 163 164 connection = tree.getConnection(); 165 return this; 164 166 } 165 167 -
java/main/src/main/java/com/framsticks/gui/controls/ProcedureControl.java
r101 r102 6 6 import com.framsticks.params.Param; 7 7 import com.framsticks.params.types.ProcedureParam; 8 import com.framsticks.util.dispatching.ExceptionResultHandler;9 8 import com.framsticks.util.dispatching.FutureHandler; 10 import com.framsticks.util.dispatching.ThrowExceptionHandler;11 9 12 10 import javax.swing.*; … … 60 58 log.debug("argument {}: {}", arg, value); 61 59 } 62 //TODO FEH: make it show dialog 63 callProcedure(path, getParam(), arguments.toArray()); 60 callProcedure(path, getParam(), arguments.toArray(), getFrame()); 64 61 65 62 } … … 72 69 73 70 74 public static void callProcedure(final Path path, final ProcedureParam param, Object[] arguments) { 75 final ExceptionResultHandler handler = ThrowExceptionHandler.getInstance(); 71 public static void callProcedure(final Path path, final ProcedureParam param, Object[] arguments, Frame frame) { 76 72 77 73 assert path.getTree().isActive(); 78 74 79 path.getTree().call(path, param, arguments, new FutureHandler<Object>( handler) {75 path.getTree().call(path, param, arguments, new FutureHandler<Object>(frame) { 80 76 81 77 @Override … … 116 112 @Override 117 113 protected void refreshTable() { 118 // TODO Auto-generated method stub119 114 120 115 } … … 122 117 @Override 123 118 protected void clearTable() { 124 // TODO Auto-generated method stub125 119 126 120 } -
java/main/src/main/java/com/framsticks/gui/controls/SliderControl.java
r101 r102 39 39 private final int div = 10; 40 40 private JComponent changing = null; 41 public final static float LINE_HEIGHT_FACTOR = 1.2f; 41 42 42 43 private Class<? extends Number> valueType; … … 46 47 text = new JTextField(); 47 48 48 //TODO: that factor should be done as a constant 49 this.setMaximumSize(new Dimension(Integer.MAX_VALUE, (int)(LINE_HEIGHT * 1.2))); 49 this.setMaximumSize(new Dimension(Integer.MAX_VALUE, (int)(LINE_HEIGHT * LINE_HEIGHT_FACTOR))); 50 50 51 51 // ComponentUI ui = UIManager.getUI(slider); -
java/main/src/main/java/com/framsticks/gui/table/ProcedureColumn.java
r100 r102 38 38 return 0; 39 39 } 40 ProcedureControl.callProcedure(path, getParam(), new Object[] {} );40 ProcedureControl.callProcedure(path, getParam(), new Object[] {}, tableModel.getFrame()); 41 41 return 0; 42 42 } -
java/main/src/main/java/com/framsticks/gui/table/TableModel.java
r101 r102 13 13 import org.apache.logging.log4j.LogManager; 14 14 15 import com.framsticks.gui.Frame; 15 16 import com.framsticks.params.Access; 16 17 import com.framsticks.params.ListAccess; … … 166 167 } 167 168 169 public Frame getFrame() { 170 return listPanel.getFrame(); 171 } 172 168 173 } -
java/main/src/main/java/com/framsticks/gui/tree/EmptyNode.java
r100 r102 42 42 @Override 43 43 public void render(TreeCellRenderer renderer) { 44 // TODO Auto-generated method stub45 44 46 45 renderer.setToolTipText("?"); -
java/main/src/main/java/com/framsticks/gui/tree/TreeCellRenderer.java
r100 r102 89 89 90 90 } 91 92 93 return ImageProvider.SERVER; 91 return ImageProvider.FOLDER_OPEN; 94 92 } 95 93 -
java/main/src/main/java/com/framsticks/hosting/ClientAtServer.java
r100 r102 30 30 31 31 import static com.framsticks.core.TreeOperations.*; 32 import static com.framsticks.params.AccessOperations.*; 32 33 33 34 import java.net.Socket; … … 61 62 cliObject = new Cli(this); 62 63 rootTree = new LocalTree(); 64 rootTree.setName(server.getName() + " root tree"); 63 65 // rootTree.setDispatcher(new AtOnceDispatcher<Tree>()); 64 66 rootTree.setDispatcher(server.getHosted().getDispatcher()); … … 114 116 public static File printToFile(String path, Access access) { 115 117 ListSink sink = new ListSink(); 116 access.save(sink);118 save(access, sink); 117 119 return new File(path, new ListSource(sink.getOut())); 118 120 } … … 143 145 if (request instanceof SetRequest) { 144 146 SetRequest setRequest = (SetRequest) request; 145 //TODO Primitive Param?146 147 tree.set(path, access.getFramsClass().getParamEntry(setRequest.getField(), PrimitiveParam.class), setRequest.getValue(), new FutureHandler<Integer>(responseCallback) { 147 148 @Override … … 198 199 protected void joinableStart() { 199 200 Dispatching.use(connection, this); 201 Dispatching.use(rootTree, this); 200 202 } 201 203 202 204 @Override 203 205 protected void joinableInterrupt() { 206 Dispatching.drop(rootTree, this); 204 207 Dispatching.drop(connection, this); 205 208 } … … 207 210 @Override 208 211 protected void joinableFinish() { 212 209 213 } 210 214 … … 212 216 protected void joinableJoin() throws InterruptedException { 213 217 Dispatching.join(connection); 218 Dispatching.join(rootTree); 214 219 } 215 220 -
java/main/src/main/java/com/framsticks/hosting/Server.java
r101 r102 37 37 protected ServerSocket acceptSocket; 38 38 protected Tree hosted; 39 protected final JoinableCollection<ClientAtServer> clients = new JoinableCollection<ClientAtServer>( );39 protected final JoinableCollection<ClientAtServer> clients = new JoinableCollection<ClientAtServer>(JoinableCollection.FinishPolicy.Never); 40 40 41 41 public static class Accept { … … 68 68 } 69 69 70 @Override71 protected void joinableInterrupt() {72 Dispatching.drop(acceptThread, this);73 Dispatching.drop(hosted, this);74 Dispatching.drop(clients, this);75 try {76 acceptSocket.close();77 } catch (IOException e) {78 log.debug("exception caught during socket closing: ", e);79 }80 finishJoinable();81 }82 70 83 71 /** … … 101 89 public void childChangedState(Joinable joinable, JoinableState state) { 102 90 proceedToState(state); 103 }104 105 @Override106 protected void joinableStart() {107 Dispatching.use(acceptThread, this);108 Dispatching.use(hosted, this);109 Dispatching.use(clients, this);110 try {111 acceptSocket = new ServerSocket();112 } catch (IOException e) {113 throw new FramsticksException().msg("failed to create server socket").cause(e);114 }115 tryBind(0);116 91 } 117 92 … … 175 150 } 176 151 152 153 @Override 154 protected void joinableStart() { 155 Dispatching.use(acceptThread, this); 156 Dispatching.use(hosted, this); 157 Dispatching.use(clients, this); 158 try { 159 acceptSocket = new ServerSocket(); 160 acceptSocket.setReuseAddress(true); 161 } catch (IOException e) { 162 throw new FramsticksException().msg("failed to create server socket").cause(e); 163 } 164 tryBind(0); 165 } 166 167 @Override 168 protected void joinableInterrupt() { 169 Dispatching.drop(acceptThread, this); 170 Dispatching.drop(hosted, this); 171 Dispatching.drop(clients, this); 172 173 try { 174 acceptSocket.close(); 175 } catch (IOException e) { 176 log.debug("exception caught during socket closing: ", e); 177 } 178 179 finishJoinable(); 180 } 181 177 182 @Override 178 183 protected void joinableFinish() { -
java/main/src/main/java/com/framsticks/model/Model.java
r100 r102 37 37 public final List<NeuroConnection> neuroConnections = new ArrayList<NeuroConnection>(); 38 38 39 / /TODO: why those methods returns and accepts doubles?39 /** Those methods accept doubles to keep consistency with Framsticks server.*/ 40 40 @ParamAnnotation 41 41 public double getNumparts() { return (double)parts.size(); } -
java/main/src/main/java/com/framsticks/params/Access.java
r101 r102 44 44 void regRemove(EventParam param, EventListener<?> listener); 45 45 46 void save(SinkInterface sink);47 48 46 /** 49 47 * Removes all the properties values. … … 71 69 ParamBuilder buildParam(ParamBuilder builder); 72 70 73 74 71 } -
java/main/src/main/java/com/framsticks/params/AccessOperations.java
r101 r102 10 10 11 11 import static com.framsticks.params.SetStateFlags.*; 12 import static com.framsticks.util.lang.Containers.filterInstanceof; 12 13 13 14 public final class AccessOperations { … … 74 75 } 75 76 77 public static void save(Access access, Sink sink) { 78 if (access instanceof ObjectAccess) { 79 ObjectAccess objectAccess = (ObjectAccess) access; 80 FramsClass framsClass = access.getFramsClass(); 81 assert framsClass != null; 82 sink.print(framsClass.getId()).print(":").breakLine(); 83 for (PrimitiveParam<?> p : filterInstanceof(framsClass.getParamEntries(), PrimitiveParam.class)) { 84 Object value = objectAccess.get(p, Object.class); 85 if ((value == null) || value.equals(p.getDef(Object.class))) { 86 continue; 87 } 88 sink.print(p.getId()).print(":"); 89 p.save(sink, value); 90 sink.breakLine(); 91 } 92 sink.breakLine(); 93 return; 94 95 } 96 if (access instanceof ListAccess) { 97 ListAccess listAccess = (ListAccess) access; 98 for (CompositeParam p : filterInstanceof(listAccess.getParams(), CompositeParam.class)) { 99 Object child = listAccess.get(p, Object.class); 100 //this is probably an assertion 101 assert child != null; 102 save(listAccess.getElementAccess().select(child), sink); 103 } 104 return; 105 } 106 throw new FramsticksException().msg("unknown access category").arg("access", access); 107 } 108 76 109 public static void load(Access access, Source source) { 110 if (!(access instanceof ObjectAccess)) { 111 throw new FramsticksException().msg("access is not an object access").arg("access", access); 112 } 77 113 Entry entry; 78 114 while ((entry = readEntry(source)) != null) { -
java/main/src/main/java/com/framsticks/params/ListAccess.java
r101 r102 3 3 4 4 5 import static com.framsticks.util.lang.Containers.filterInstanceof;6 5 7 6 import com.framsticks.params.types.EventParam; … … 30 29 31 30 32 @Override33 public void save(SinkInterface sink) {34 for (CompositeParam p : filterInstanceof(getParams(), CompositeParam.class)) {35 Object child = get(p, Object.class);36 //this is probably an assertion37 assert child != null;38 elementAccess.select(child);39 elementAccess.save(sink);40 }41 }42 43 31 public Access getElementAccess() { 44 32 return elementAccess; … … 57 45 } 58 46 59 //TODO it could actually be used also60 47 @Override 61 48 public void tryAutoAppend(Object object) { 62 throw new InvalidOperationException() ;49 throw new InvalidOperationException().msg("It could actually be used also, the Access.select could be used to check whether type is correct"); 63 50 } 64 51 -
java/main/src/main/java/com/framsticks/params/ListSink.java
r84 r102 7 7 * @author Piotr Sniegowski 8 8 */ 9 public class ListSink implements Sink Interface{9 public class ListSink implements Sink { 10 10 protected final List<String> out; 11 11 protected StringBuilder lineBuilder = new StringBuilder(); … … 25 25 26 26 @Override 27 public Sink Interfaceprint(String str) {27 public Sink print(String str) { 28 28 lineBuilder.append(str); 29 29 return this; … … 31 31 32 32 @Override 33 public Sink Interfaceprint(Object obj) {33 public Sink print(Object obj) { 34 34 lineBuilder.append(obj); 35 35 return this; -
java/main/src/main/java/com/framsticks/params/Param.java
r101 r102 35 35 protected final int flags; 36 36 37 //TODO38 37 /** The variable determining whether the parameter is an extra parameter. */ 39 38 protected final int extra; -
java/main/src/main/java/com/framsticks/params/ParamCandidate.java
r101 r102 25 25 import com.framsticks.params.annotations.ParamAnnotation; 26 26 import com.framsticks.params.types.ProcedureParam; 27 // import com.framsticks.util.FramsticksException; 27 28 28 29 public class ParamCandidate { … … 477 478 Type rawType = p.getRawType(); 478 479 Type containedType = null; 479 //TODO make implementation here480 480 boolean map = false; 481 481 StringBuilder b = new StringBuilder(); … … 490 490 containedType = p.getActualTypeArguments()[0]; 491 491 b.append("e"); 492 } else { 493 return induceParamType(builder, rawType); 494 // throw new FramsticksException().msg("unknown raw type").arg("raw type", rawType); 492 495 } 493 496 if (!(containedType instanceof Class)) { … … 503 506 dependantClasses.add(containedClass); 504 507 b.append(FramsClassBuilder.getName(fca, containedClass)); 505 //TODO parameterize this506 508 if (map) { 507 509 b.append(" uid"); … … 516 518 Class<?> cl = (Class<?>) type; 517 519 518 // TODO:future support for enum520 // this is draft implementation of future support for enum 519 521 // if (cl.isEnum()) { 520 522 // Class<? extends Enum<?>> enumType = (Class<? extends Enum<?>>) cl; -
java/main/src/main/java/com/framsticks/params/PrimitiveParam.java
r90 r102 33 33 } 34 34 35 public void save(Sink Interfacesink, Object value) {35 public void save(Sink sink, Object value) { 36 36 sink.print(value); 37 37 } -
java/main/src/main/java/com/framsticks/params/SimpleAbstractAccess.java
r101 r102 2 2 3 3 4 import static com.framsticks.util.lang.Containers.filterInstanceof;5 4 6 5 … … 103 102 } 104 103 105 @Override106 public void save(SinkInterface sink) {107 assert framsClass != null;108 sink.print(framsClass.getId()).print(":").breakLine();109 for (PrimitiveParam<?> p : filterInstanceof(framsClass.getParamEntries(), PrimitiveParam.class)) {110 Object value = get(p, Object.class);111 if ((value == null) || value.equals(p.getDef(Object.class))) {112 continue;113 }114 sink.print(p.getId()).print(":");115 p.save(sink, value);116 sink.breakLine();117 }118 sink.breakLine();119 }120 104 121 105 protected abstract <T> void internalSet(ValueParam param, T value); -
java/main/src/main/java/com/framsticks/params/SimpleUniqueList.java
r101 r102 46 46 } 47 47 48 public void fireChildrenChange(T child, ListChange.Action action) { 49 ListChange change = new ListChange(action, UniqueListAccess.getNumberInMap(children, child), child.getUid()); 48 public void fireChildrenChange(ListChange original, ListChange.Action action, Object... hints) { 49 listeners.actionForAll(new ListChange(action, original.getPosition(), original.getIdentifier(), hints)); 50 51 } 52 53 public void fireChildrenChange(T child, ListChange.Action action, Object... hints) { 54 ListChange change = new ListChange(action, UniqueListAccess.getNumberInMap(children, child), child.getUid(), hints); 50 55 listeners.actionForAll(change); 51 56 } -
java/main/src/main/java/com/framsticks/params/types/BooleanParam.java
r88 r102 7 7 import com.framsticks.params.PrimitiveParam; 8 8 import com.framsticks.params.ReassignResult; 9 import com.framsticks.params.Sink Interface;9 import com.framsticks.params.Sink; 10 10 import com.framsticks.util.lang.Numbers; 11 11 … … 58 58 59 59 @Override 60 public void save(Sink Interfacesink, Object value) {60 public void save(Sink sink, Object value) { 61 61 assert value instanceof Boolean; 62 62 sink.print(((Boolean)value) ? "1" : "0"); -
java/main/src/main/java/com/framsticks/params/types/StringParam.java
r87 r102 5 5 import com.framsticks.params.PrimitiveParam; 6 6 import com.framsticks.params.ReassignResult; 7 import com.framsticks.params.Sink Interface;7 import com.framsticks.params.Sink; 8 8 9 9 import javax.annotation.concurrent.Immutable; … … 49 49 50 50 @Override 51 public void save(Sink Interfacesink, Object value) {51 public void save(Sink sink, Object value) { 52 52 assert value instanceof String; 53 53 String s = (String)value; -
java/main/src/main/java/com/framsticks/parsers/F0Writer.java
r100 r102 15 15 16 16 protected final Schema schema; 17 protected final Sink Interfacesink;17 protected final Sink sink; 18 18 protected final Model model; 19 19 protected boolean omitDefaults = true; 20 20 21 public F0Writer(Schema schema, Model model, Sink Interfacesink) {21 public F0Writer(Schema schema, Model model, Sink sink) { 22 22 this.schema = schema; 23 23 this.model = model; … … 32 32 protected void write(Access access) { 33 33 if (access instanceof ListAccess) { 34 // TODO35 34 for (ValueParam p : Containers.filterInstanceof(access.getParams(), ValueParam.class)) { 36 35 write(schema.getRegistry().prepareAccess((CompositeParam) p).select(access.get(p, Object.class))); -
java/main/src/main/java/com/framsticks/parsers/MultiParamLoader.java
r101 r102 23 23 } 24 24 25 /** TODO does it support multilines? */26 25 /** 27 26 * Specifies the condition to break execution. -
java/main/src/main/java/com/framsticks/parsers/Savers.java
r100 r102 1 1 package com.framsticks.parsers; 2 2 3 import com.framsticks.params.*; 4 import com.framsticks.params.SinkInterface; 3 import com.framsticks.params.Access; 4 import com.framsticks.params.FramsClass; 5 import com.framsticks.params.Param; 6 import com.framsticks.params.ReflectionAccess; 7 import com.framsticks.params.Sink; 8 import static com.framsticks.params.AccessOperations.*; 5 9 6 10 /** … … 8 12 */ 9 13 public class Savers { 10 public static <S extends Sink Interface> S saveFramsClass(S sink, FramsClass framsClass) {14 public static <S extends Sink> S saveFramsClass(S sink, FramsClass framsClass) { 11 15 12 16 Access framsClassAccess = new ReflectionAccess(FramsClass.class); 13 17 Access paramAccess = new ReflectionAccess(Param.class); 14 18 framsClassAccess.select(framsClass); 15 framsClassAccess.save(sink); 19 20 save(framsClassAccess, sink); 16 21 for (Param p : framsClass.getParamEntries()) { 17 paramAccess.select(p); 18 paramAccess.save(sink); 22 save(paramAccess.select(p), sink); 19 23 } 20 24 return sink; -
java/main/src/main/java/com/framsticks/parsers/XmlLoader.java
r101 r102 23 23 import com.framsticks.params.PrimitiveParam; 24 24 import com.framsticks.params.Registry; 25 import com.framsticks.util.AutoAttacher; 25 26 import com.framsticks.util.AutoBuilder; 26 27 import com.framsticks.util.FramsticksException; … … 137 138 138 139 for (Object child : childrenObjects) { 139 access.tryAutoAppend(child); 140 if (child instanceof AutoAttacher) { 141 ((AutoAttacher) child).attachTo(access.getSelected()); 142 } else { 143 access.tryAutoAppend(child); 144 } 140 145 } 141 146 } -
java/main/src/main/java/com/framsticks/remote/RemoteTree.java
r101 r102 56 56 } 57 57 58 public void setAddress(Address address) { 59 this.connection = Connection.to(new ClientSideManagedConnection(), address); 60 this.connection.setExceptionHandler(this); 61 this.connection.setNeedFileAcceptor(this); 62 } 63 58 64 @ParamAnnotation 59 65 public void setAddress(String address) { 60 this.connection = Connection.to(new ClientSideManagedConnection(), new Address(address)); 61 this.connection.setExceptionHandler(this); 62 this.connection.setNeedFileAcceptor(this); 66 setAddress(new Address(address)); 63 67 } 64 68 … … 72 76 } 73 77 78 74 79 @Override 75 80 public String toString() { 76 assert Dispatching.isThreadSafe(); 77 return "remote tree " + getName() + "(" + getAddress() + ")"; 81 return super.toString() + "[" + getAddress() + "]"; 78 82 } 79 83 … … 102 106 // assert param != null; 103 107 // // assert path.isResolved(); 104 // //TODO only do that if needed105 108 // connection.send(new GetRequest().field(param.getId()).path(path.getTextual()), this, new ClientSideResponseFuture(pathRemoveHandler(path, future)) { 106 109 // @Override … … 116 119 117 120 121 /** Fetch information. 122 * 123 * This method does not check whether the info is already in the cache, it will always issue a request or join 124 * with other already issued but returned info request. Too issue request only when needed, use TreeOperations.findInfo() 125 * 126 * */ 118 127 @Override 119 128 public void info(final Path path, final Future<FramsClass> future) { … … 153 162 }); 154 163 155 //TODO: if the info is in the cache, then don't communicate156 164 connection.send(new InfoRequest().path(path.getTextual()), AtOnceDispatcher.getInstance(), new ClientSideResponseFuture(compositeFuture) { 157 165 @Override … … 203 211 204 212 log.trace("storing value {} for {}", param, path); 205 //TODO break in passing exception handler is here 213 206 214 connection.send(new SetRequest().value(value.toString()).field(param.getId()).path(path.getTextual()), this, new ClientSideResponseFuture(future) { 207 215 @Override … … 224 232 @Override 225 233 protected void processOk(Response response) { 226 FramsClass framsClass = processFetchedInfo(RemoteTree.this, response.getFiles().get(0)); 234 assert bufferedDispatcher.getTargetDispatcher().isActive(); 235 FramsClass framsClass = Loaders.loadFramsClass(response.getFiles().get(0).getContent()); 236 putInfoIntoCache(framsClass); 237 227 238 assignRootParam(Param.build().name("Tree").id(RemoteTree.this.getName()).type("o " + framsClass.getId()).finish(CompositeParam.class)); 228 239 bufferedDispatcher.setBuffer(false); -
java/main/src/main/java/com/framsticks/running/ExternalProcess.java
r101 r102 22 22 import com.framsticks.params.annotations.ParamAnnotation; 23 23 import com.framsticks.util.FramsticksException; 24 import com.framsticks.util.Misc;25 24 import com.framsticks.util.dispatching.AbstractJoinable; 26 25 import com.framsticks.util.dispatching.Dispatching; … … 110 109 throw new FramsticksException().msg("failed to wait for process").cause(e); 111 110 } 112 log. debug("process ended {}", this);111 log.info("process ended {}", this); 113 112 // process = null; 114 113 } catch (FramsticksException e) { … … 131 130 @Override 132 131 protected void joinableStart() { 133 log.debug("running process with arguments: {}", arguments);132 log.debug("running process {}", this); 134 133 builder.command(arguments); 135 134 try { … … 160 159 @Override 161 160 public String toString() { 162 return getName() + "[" + Misc.returnNotNull(getCommand(), "?") + "]";161 return getName() + arguments; 163 162 } 164 163 -
java/main/src/main/java/com/framsticks/running/FramsServer.java
r90 r102 1 1 package com.framsticks.running; 2 2 3 4 5 import com.framsticks.params.ParamFlags; 3 6 import com.framsticks.params.annotations.FramsClassAnnotation; 4 7 import com.framsticks.params.annotations.ParamAnnotation; 8 import com.framsticks.util.lang.Strings; 5 9 6 10 @FramsClassAnnotation … … 9 13 protected Integer port; 10 14 protected String path; 15 protected String expdef; 11 16 12 17 /** … … 23 28 * @return the port 24 29 */ 25 @ParamAnnotation 30 @ParamAnnotation(flags = ParamFlags.USERREADONLY) 26 31 public Integer getPort() { 27 32 return port; … … 39 44 * @return the path 40 45 */ 41 @ParamAnnotation 46 @ParamAnnotation(flags = ParamFlags.USERREADONLY) 42 47 public String getPath() { 43 48 return path; … … 54 59 } 55 60 61 /** 62 * @return the expdef 63 */ 64 @ParamAnnotation(flags = ParamFlags.USERREADONLY) 65 public String getExpdef() { 66 return expdef; 67 } 68 69 /** 70 * @param expdef the expdef to set 71 */ 72 @ParamAnnotation 73 public void setExpdef(String expdef) { 74 this.expdef = expdef; 75 } 76 56 77 @Override 57 78 protected void joinableStart() { … … 60 81 arguments.add("-p" + port); 61 82 } 83 if (Strings.notEmpty(expdef)) { 84 arguments.add("Simulator.expdef=\"" + expdef + "\";"); 85 } 86 // log.debug("running {} with arguments {}", getCommand(), arguments); 62 87 super.joinableStart(); 63 88 } -
java/main/src/main/java/com/framsticks/test/PrimeExperiment.java
r101 r102 1 1 package com.framsticks.test; 2 2 3 import org.apache.logging.log4j.Logger; 4 import org.apache.logging.log4j.LogManager; 5 3 6 import com.framsticks.experiment.Experiment; 7 import com.framsticks.experiment.WorkPackageLogic; 4 8 import com.framsticks.params.annotations.FramsClassAnnotation; 9 import com.framsticks.params.annotations.ParamAnnotation; 10 import com.framsticks.test.prime.PrimePackage; 11 import com.framsticks.util.dispatching.Future; 5 12 6 13 @FramsClassAnnotation 7 14 public class PrimeExperiment extends Experiment { 15 private static final Logger log = LogManager.getLogger(PrimeExperiment.class); 16 17 @ParamAnnotation 18 public final WorkPackageLogic<PrimePackage> workPackageLogic; 19 20 protected int maxNumber = 3000; 21 protected int step = 100; 22 protected int numberCounter = 1; 23 24 /** 25 * 26 */ 27 public PrimeExperiment() { 28 setExpdef("prime"); 29 30 workPackageLogic = new WorkPackageLogic<PrimePackage>(this) { 31 32 @Override 33 protected void generateNextPackage(Future<PrimePackage> future) { 34 assert isActive(); 35 PrimePackage wp = new PrimePackage(); 36 37 log.debug("generated package: {}", wp); 38 wp.params.from_number = numberCounter; 39 numberCounter += step; 40 wp.params.to_number = numberCounter - 1; 41 wp.state.current_number = wp.params.from_number; 42 wp.state.getResultList().clear(); 43 44 future.pass(wp); 45 } 46 }; 47 } 48 49 protected void processFile() { 50 } 8 51 9 52 } -
java/main/src/main/java/com/framsticks/util/Misc.java
r100 r102 54 54 return value; 55 55 } 56 57 public static void checkEquals(Object expected, Object found, String message, Object context) { 58 if (equals(expected, found)) { 59 return; 60 } 61 throw new FramsticksException().msg(message).arg("expected", expected).arg("found", found).arg("in", context); 62 } 56 63 } -
java/main/src/main/java/com/framsticks/util/dispatching/AbstractJoinable.java
r101 r102 18 18 19 19 private static final Logger log = LogManager.getLogger(AbstractJoinable.class); 20 private static final Logger reportLog = LogManager.getLogger(AbstractJoinable.class.getName() + ".Report"); 20 21 21 22 protected final Set<JoinableParent> owners = new HashSet<JoinableParent>(); … … 35 36 } 36 37 38 39 37 40 public static void report() { 41 if (!reportLog.isDebugEnabled()) { 42 return; 43 } 38 44 StringBuilder b = new StringBuilder(); 39 45 synchronized (joinablesRegistry) { … … 42 48 } 43 49 } 44 log.debug("state: {}", b);50 reportLog.debug("state: {}", b); 45 51 } 46 52 … … 53 59 } 54 60 this.state = state; 55 56 log.debug("{} is notifying {} parents", this, joinableListeners.size()); 61 log.debug("{} changed state to {}", this, state); 62 57 63 58 64 List<JoinableParent> parents = new LinkedList<>(); … … 61 67 for (JoinableParent p : parents) { 62 68 if (p != null) { 69 log.debug("{} is notifying parent {} about change to {}", this, p, state); 63 70 Dispatching.childChangedState(p, this, state); 64 71 } … … 110 117 } 111 118 joinableJoin(); 112 synchronized (this) { 113 this.state = JoinableState.JOINED; 114 } 119 changeState(JoinableState.JOINED); 120 // synchronized (this) { 121 // this.state = JoinableState.JOINED; 122 // } 115 123 } 116 124 … … 158 166 synchronized (this) { 159 167 if (!owners.contains(owner)) { 160 return false; 161 // throw new FramsticksException().msg("object is not owning that joinable").arg("joinable", this).arg("object", owner); 168 // log.error("owner {} is not owning that joinable {}", owner, this); 169 // return false; 170 throw new FramsticksException().msg("object is not owning that joinable").arg("joinable", this).arg("object", owner); 162 171 } 163 172 // assert owners.containsKey(owner); 164 log.debug("{} is droping {}", owner, this);165 173 owners.remove(owner); 166 174 stop = owners.isEmpty(); 175 log.debug("{} is droping {} (users remaining: {})", owner, this, owners); 167 176 } 168 177 if (stop) { … … 195 204 @Override 196 205 public String toString() { 197 return get Name();206 return getClass().getSimpleName() + "(" + getName() + ")"; 198 207 } 199 208 … … 203 212 } 204 213 205 206 214 } -
java/main/src/main/java/com/framsticks/util/dispatching/BufferedDispatcher.java
r101 r102 2 2 3 3 4 public class BufferedDispatcher<C> { 4 import org.apache.logging.log4j.Logger; 5 import org.apache.logging.log4j.LogManager; 6 7 import com.framsticks.util.FramsticksException; 8 import com.framsticks.util.lang.Strings; 9 // import static com.framsticks.util.dispatching.AbstractJoinable.wrap; 10 11 public class BufferedDispatcher<C> extends AbstractJoinable implements Dispatcher<C>, JoinableParent { 12 private static final Logger log = LogManager.getLogger(BufferedDispatcher.class); 5 13 6 14 protected final RunnableQueue<C> queue = new RunnableQueue<>(); … … 8 16 protected Dispatcher<C> targetDispatcher; 9 17 10 protected boolean buffer = false; 18 protected boolean buffer = true; 19 protected Dispatcher<C> parent; 20 21 /** 22 * @param parent 23 */ 24 public BufferedDispatcher(Dispatcher<C> parent) { 25 this.parent = parent; 26 } 11 27 12 28 /** … … 21 37 */ 22 38 public synchronized void setTargetDispatcher(Dispatcher<C> targetDispatcher) { 39 if (this.targetDispatcher != null) { 40 throw new FramsticksException().msg("dispatcher is already set").arg("dispatcher", this.targetDispatcher).arg("in", this); 41 } 42 if (targetDispatcher == null) { 43 throw new FramsticksException().msg("trying to set empty target dispatcher").arg("in", this); 44 } 45 log.debug("setting {} to {}", this, targetDispatcher); 23 46 this.targetDispatcher = targetDispatcher; 47 flushQueue(); 24 48 } 25 49 26 50 public synchronized boolean isActive() { 27 if (targetDispatcher == null ) {51 if (targetDispatcher == null || buffer) { 28 52 return false; 29 53 // throw new FramsticksException().msg("no dispatcher is set for tree yet").arg("tree", this); … … 40 64 } 41 65 66 protected void flushQueue() { 67 if (this.buffer || targetDispatcher == null) { 68 return; 69 } 70 log.debug("flushing {} tasks in {}", queue.size(), this); 71 while (!queue.isEmpty()) { 72 targetDispatcher.dispatch(queue.pollFirst()); 73 } 74 } 75 42 76 public synchronized void setBuffer(final boolean buffer) { 43 77 if (this.buffer == buffer) { … … 49 83 } 50 84 this.buffer = false; 51 while (!queue.isEmpty()) { 52 targetDispatcher.dispatch(queue.pollFirst()); 85 flushQueue(); 86 } 87 88 @Override 89 public String toString() { 90 return parent + " -> " + Strings.toStringNullProof(targetDispatcher, "<null>"); 91 } 92 93 public void createThreadIfNeeded() { 94 if (targetDispatcher != null) { 95 return; 53 96 } 97 this.setTargetDispatcher(new Thread<C>().setName(parent.getName())); 98 } 99 100 @Override 101 public String getName() { 102 return parent + " buffered dispatcher"; 103 } 104 105 @Override 106 protected void joinableStart() { 107 Dispatching.use(targetDispatcher, this); 108 } 109 110 @Override 111 protected void joinableInterrupt() { 112 Dispatching.drop(targetDispatcher, this); 113 114 finishJoinable(); 115 } 116 117 @Override 118 protected void joinableFinish() { 54 119 55 120 } 56 121 122 @Override 123 protected void joinableJoin() throws InterruptedException { 124 Dispatching.join(targetDispatcher); 125 } 57 126 127 @Override 128 public void childChangedState(Joinable joinable, JoinableState state) { 129 proceedToState(state); 130 } 58 131 } -
java/main/src/main/java/com/framsticks/util/dispatching/Dispatching.java
r101 r102 3 3 import java.util.Timer; 4 4 5 import org.apache.logging.log4j.Level; 5 6 import org.apache.logging.log4j.Logger; 6 7 import org.apache.logging.log4j.LogManager; 7 8 8 9 import com.framsticks.util.FramsticksException; 10 import com.framsticks.util.Misc; 9 11 10 12 /** … … 32 34 } 33 35 36 public static <C> void dispatch(Dispatcher<C> dispatcher, RunAt<? extends C> runnable) { 37 dispatcher.dispatch(runnable); 38 } 39 34 40 // public static boolean assertInvokeLater(Dispatcher dispatcher, RunAt runnable) { 35 41 // dispatcher.invokeLater(runnable); … … 66 72 67 73 public static void use(final Joinable joinable, final JoinableParent owner) { 74 Misc.throwIfNull(joinable); 68 75 log.debug("using {} by {}", joinable, owner); 69 76 if (joinable.use(owner)) { … … 75 82 76 83 public static void drop(final Joinable joinable, final JoinableParent owner) { 84 Misc.throwIfNull(joinable); 77 85 log.debug("droping {} by {}", joinable, owner); 78 86 if (joinable.drop(owner)) { … … 84 92 85 93 public static void join(Joinable joinable) throws InterruptedException { 94 Misc.throwIfNull(joinable); 86 95 log.debug("joining {}", joinable); 87 96 try { … … 95 104 96 105 public static void childChangedState(final JoinableParent parent, final Joinable joinable, final JoinableState state) { 97 if (state.ordinal() < =JoinableState.RUNNING.ordinal()) {106 if (state.ordinal() < JoinableState.RUNNING.ordinal()) { 98 107 return; 99 108 } … … 113 122 } 114 123 } catch (InterruptedException e) { 124 log.debug("failed to wait on {} because of: {}", object, e.getMessage()); 115 125 } 116 126 } … … 123 133 return; 124 134 } catch (InterruptedException e) { 135 log.debug("failed to join {} because of: {}", joinable, e.getMessage()); 125 136 // throw new FramsticksException().msg("failed to join").arg("dispatcher", dispatcher).cause(e); 126 137 } … … 192 203 193 204 // public static class DispatcherWaiter<C, T extends Dispatcher<C> & Joinable> implements Dispatcher<C> { 194 // 195 // 196 // 197 198 // 199 // 200 // 201 // 202 // 203 // 204 205 // 206 // 207 // 208 // 209 // 210 // 211 // 212 // 213 // 214 // 215 216 // 217 218 // 219 // 220 // 221 // 222 223 // 224 // 225 // 226 // 227 // 205 // // protected boolean done = false; 206 // protected final T dispatcher; 207 // protected RunAt<? extends C> runnable; 208 209 // /** 210 // * @param joinable 211 // */ 212 // public DispatcherWaiter(T dispatcher) { 213 // this.dispatcher = dispatcher; 214 // } 215 216 // public synchronized void waitFor() { 217 // while ((runnable == null) && (dispatcher.getState().ordinal() <= JoinableState.RUNNING.ordinal())) { 218 // try { 219 // this.wait(); 220 // } catch (InterruptedException e) { 221 // } 222 // } 223 // if (runnable != null) { 224 // runnable.run(); 225 // } 226 227 // } 228 229 // @Override 230 // public boolean isActive() { 231 // return dispatcher.isActive(); 232 // } 233 234 // @Override 235 // public synchronized void dispatch(RunAt<? extends C> runnable) { 236 // this.runnable = runnable; 237 // this.notifyAll(); 238 // } 228 239 229 240 // } … … 284 295 } 285 296 297 public static <C> void dispatchLog(final Dispatcher<C> dispatcher, final Logger logger, final Level level, final Object text) { 298 dispatcher.dispatch(new RunAt<C>(ThrowExceptionHandler.getInstance()) { 299 300 @Override 301 protected void runAt() { 302 logger.log(level, "message dispatched into {}: {}", dispatcher, text); 303 } 304 }); 305 306 } 307 286 308 } -
java/main/src/main/java/com/framsticks/util/dispatching/JoinableCollection.java
r101 r102 21 21 protected final Set<T> joinables = new HashSet<T>(); 22 22 23 protected boolean finishIfOne; 23 public static enum FinishPolicy { 24 Never, 25 OnFirst, 26 OnAll 27 }; 28 29 protected final FinishPolicy finishPolicy; 24 30 25 31 protected String observableName; 26 32 27 33 public JoinableCollection() { 28 this(false); 29 } 30 31 public JoinableCollection(boolean finishIfOne) { 32 this.finishIfOne = finishIfOne; 34 this(FinishPolicy.OnAll); 35 } 36 37 38 /** 39 * @param finishPolicy 40 */ 41 public JoinableCollection(FinishPolicy finishPolicy) { 42 this.finishPolicy = finishPolicy; 33 43 } 34 44 … … 95 105 96 106 protected JoinableState getNextState() { 97 if ( joinables.isEmpty()) {107 if ((finishPolicy == FinishPolicy.Never && state == JoinableState.RUNNING) || joinables.isEmpty()) { 98 108 return state; 99 109 } 100 JoinableState result = finishIfOne ? JoinableState.INITILIAZED : JoinableState.JOINED; 110 boolean oneIsEnough = (finishPolicy == FinishPolicy.OnFirst); 111 JoinableState result = oneIsEnough ? JoinableState.INITILIAZED : JoinableState.JOINED; 101 112 for (Joinable j : joinables) { 102 113 JoinableState s = j.getState(); 103 if ( finishIfOne) {114 if (oneIsEnough) { 104 115 if (s.ordinal() > result.ordinal()) { 105 116 result = s; -
java/main/src/main/java/com/framsticks/util/dispatching/Monitor.java
r100 r102 5 5 import com.framsticks.util.dispatching.Dispatching; 6 6 import java.lang.Thread; 7 import java.util.concurrent.atomic.AtomicBoolean; 7 8 8 9 public class Monitor implements JoinableParent { … … 12 13 protected final Joinable joinable; 13 14 protected final Thread shutdownHook; 15 protected final AtomicBoolean dropped = new AtomicBoolean(false); 16 protected final AtomicBoolean joining = new AtomicBoolean(false); 14 17 15 18 /** … … 22 25 @Override 23 26 public void run() { 24 log.debug(" running shutdown hook");27 log.debug("droping and joining"); 25 28 Monitor.this.drop().join(); 29 log.debug("droped and joined"); 30 AbstractJoinable.report(); 26 31 } 27 32 }); … … 54 59 55 60 public Monitor drop() { 61 if (!dropped.compareAndSet(false, true)) { 62 return this; 63 } 56 64 log.debug("{} is droping", this); 57 65 Dispatching.drop(joinable, this); … … 60 68 61 69 public Monitor join() { 70 if (!joining.compareAndSet(false, true)) { 71 log.debug("not joining"); 72 return this; 73 } 74 62 75 log.debug("{} is joining", this); 63 76 Dispatching.joinAbsolutely(joinable); … … 69 82 /** In case IllegalStateException is caught, it means that JVM is in finalization stage */ 70 83 } 71 72 84 return this; 73 85 } -
java/main/src/main/java/com/framsticks/util/dispatching/RunnableQueue.java
r101 r102 19 19 } 20 20 21 public int size() { 22 return queue.size(); 23 } 24 21 25 } -
java/main/src/main/java/com/framsticks/util/dispatching/Thread.java
r101 r102 106 106 107 107 @ParamAnnotation 108 public voidsetName(String name) {108 public Thread<C> setName(String name) { 109 109 thread.setName(name); 110 return this; 110 111 } 111 112 … … 119 120 } 120 121 121 @Override122 public String toString() {123 return getName();124 }122 // @Override 123 // public String toString() { 124 // return getName(); 125 // } 125 126 126 127 @Override -
java/main/src/main/resources/common-columns.xml
r101 r102 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <AutoInjector> 3 <import class="com.framsticks.gui.table.ColumnsConfig" /> 3 4 <ColumnsConfig className="Genotype" columnsNames="uid name mutate" /> 4 5 <ColumnsConfig className="Part" columnsNames="x y z" /> 6 <ColumnsConfig className="Simulator" columnsNames="name init stop start abort" /> 5 7 </AutoInjector> -
java/main/src/main/resources/log4j2.xml
r101 r102 5 5 <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> 6 6 </Console> 7 < File name="File" fileName="framsticks.log">8 <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>9 < /File>7 <!-- <File name="File" fileName="framsticks.log"> --> 8 <!-- <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> --> 9 <!-- </File> --> 10 10 </appenders> 11 11 <loggers> … … 15 15 <!-- <logger name="com.framsticks.running.ExternalProcess" level="trace" /> --> 16 16 <!-- <logger name="com.framsticks.util.dispatching.AbstractJoinable" level="debug" /> --> 17 <!-- <logger name="com.framsticks.util.dispatching.AbstractJoinable.Report" level="info" /> --> 18 <!-- <logger name="com.framsticks.util.dispatching.Monitor" level="debug" /> --> 19 <logger name="com.framsticks.util.dispatching.BufferedDispatcher" level="debug" /> 20 <!-- <logger name="com.framsticks.util.dispatching.Dispatching" level="debug" /> --> 21 <logger name="com.framsticks.running" level="debug" /> 22 <!-- <logger name="com.framsticks.communication" level="debug" /> --> 23 <logger name="com.framsticks.experiment" level="debug" /> 24 <logger name="com.framsticks.experiment.Simulator" level="debug" /> 17 25 <root level="info"> 18 26 <appender-ref ref="Console"/> 19 < appender-ref ref="File"/>27 <!-- <appender-ref ref="File"/> --> 20 28 </root> 21 29 </loggers> -
java/main/src/main/resources/prime-gui.xml
r101 r102 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <Framsticks> 3 <include resource="/prime.xml" />4 3 5 4 <import class="com.framsticks.gui.Browser" /> … … 8 7 <RemoteTree name="prime-experiment" address="localhost:9007" /> 9 8 <RemoteTree name="worker" address="localhost:9100" /> 9 <include resource="/common-columns.xml" /> 10 10 </Browser> 11 11 </Framsticks> -
java/main/src/main/resources/prime.xml
r101 r102 3 3 <import class="com.framsticks.hosting.Server" /> 4 4 <import class="com.framsticks.test.PrimeExperiment" /> 5 <import class="com.framsticks.experiment.Simulator" /> 5 <!-- <import class="com.framsticks.experiment.Simulator" /> --> 6 <import class="com.framsticks.experiment.SimulatorConnector" /> 6 7 <import class="com.framsticks.core.LocalTree" /> 7 <import class="com.framsticks.running.LoggingOutputListener" />8 <import class="com.framsticks.running.FramsServer" />9 8 <Server port="9007"> 10 <LocalTree name=" test">11 <PrimeExperiment name="prime">12 <Simulator address="localhost:9100"/>13 <Simulator address="localhost:9101"/>14 <Simulator address="localhost:9102"/>9 <LocalTree name="prime-local-tree"> 10 <PrimeExperiment> 11 <SimulatorConnector address="localhost:9100" /> 12 <SimulatorConnector address="localhost:9101" /> 13 <SimulatorConnector address="localhost:9102" /> 15 14 </PrimeExperiment> 16 15 </LocalTree> 17 16 </Server> 18 <FramsServer name="frams" port="9100">19 <LoggingOutputListener />20 </FramsServer>21 <FramsServer name="frams" port="9101">22 <LoggingOutputListener />23 </FramsServer>24 <FramsServer name="frams" port="9102">25 <LoggingOutputListener />26 </FramsServer>27 17 </Framsticks> 28 18 -
java/main/src/test/java/com/framsticks/core/ListChangeTest.java
r101 r102 7 7 8 8 import com.framsticks.core.ListChange.Action; 9 import com.framsticks.params.AccessOperations;9 import static com.framsticks.params.AccessOperations.*; 10 10 import com.framsticks.params.FramsClass; 11 11 import com.framsticks.params.ListSink; … … 40 40 public void testFramsClass() { 41 41 framsClass = FramsClass.build().forClass(ListChange.class); 42 assertThat(framsClass.getParamCount()).isEqualTo( 3);42 assertThat(framsClass.getParamCount()).isEqualTo(4); 43 43 } 44 44 … … 60 60 61 61 @Test(dependsOnMethods = "createReflectionAccess") 62 public void load () throws Exception {63 AccessOperations.load(access.select(listChange), ListSource.createFrom("type:2", "pos:0", "id:test"));62 public void loading() throws Exception { 63 load(access.select(listChange), ListSource.createFrom("type:2", "pos:0", "id:test")); 64 64 65 65 assertThat(listChange.action).isEqualTo(Action.Modify); … … 68 68 69 69 ListSink sink = new ListSink(); 70 access.select(listChange).save(sink);70 save(access.select(listChange), sink); 71 71 assertThat(sink.getOut()).isEqualTo(Arrays.asList("ListChange:", "type:2", "pos:0", "id:test", "")); 72 72 } -
java/main/src/test/java/com/framsticks/gui/console/DirectConsoleTest.java
r97 r102 20 20 protected Joinable createSubject() { 21 21 22 connection = new ClientSideRawConnection(); 23 connection.setAddress(new Address("localhost:9009")); 24 25 console = new DirectConsole().setConnection(connection); 22 console = new DirectConsole().setAddress(new Address("localhost:9009")); 26 23 joinables = new JoinableCollection<>(); 27 24 joinables.setObservableName("connection and console"); 28 25 joinables.add(console); 29 joinables.add(con nection);26 joinables.add(console.getConnection()); 30 27 31 28 return joinables; -
java/main/src/test/java/com/framsticks/test/MonitorBasedTest.java
r96 r102 30 30 } 31 31 32 @AfterClass(timeOut = 3000 )32 @AfterClass(timeOut = 30000) 33 33 public void tearDown() { 34 34 monitor.drop().join(); -
java/main/src/test/java/com/framsticks/test/PrimeExperimentTest.java
r101 r102 6 6 7 7 import com.framsticks.core.XmlBasedTest; 8 import com.framsticks.util.dispatching.Dispatching; 9 import com.framsticks.util.dispatching.StackedJoinable; 10 11 import org.apache.logging.log4j.Logger; 12 import org.apache.logging.log4j.LogManager; 8 13 9 14 @Test 10 15 public class PrimeExperimentTest extends XmlBasedTest { 11 16 17 private static final Logger log = LogManager.getLogger(PrimeExperimentTest.class); 18 12 19 protected PrimeExperiment experiment; 20 13 21 14 22 @Test 15 23 public void start() { 24 log.debug("starting"); 16 25 assertThat(framsticks).isNotNull(); 17 assertThat(framsticks.get("prime")).isInstanceOf(PrimeExperiment.class); 18 experiment = (PrimeExperiment) framsticks.get("prime"); 26 assertThat(framsticks.size()).isEqualTo(1); 27 assertThat(framsticks.get("stacked")).isInstanceOf(StackedJoinable.class); 28 StackedJoinable stacked = (StackedJoinable) framsticks.get("stacked"); 29 30 assertThat(stacked.size()).isEqualTo(2); 31 assertThat(stacked.get(1)).isInstanceOf(PrimeExperiment.class); 32 // assertThat(framsticks.get("prime")).isInstanceOf(PrimeExperiment.class); 33 // experiment = (PrimeExperiment) framsticks.get("prime"); 34 // 35 Dispatching.sleep(3); 19 36 } 37 20 38 } -
java/main/src/test/resources/configs/PrimeExperimentTest.xml
r101 r102 3 3 <import class="com.framsticks.test.PrimeExperiment" /> 4 4 <import class="com.framsticks.experiment.Simulator" /> 5 <PrimeExperiment name="prime"> 6 </PrimeExperiment> 5 <import class="com.framsticks.util.dispatching.StackedJoinable" /> 6 <import class="com.framsticks.util.dispatching.JoinableCollection" /> 7 <import class="com.framsticks.running.LoggingOutputListener" /> 8 <import class="com.framsticks.running.FramsServer" /> 9 <import class="com.framsticks.experiment.SimulatorConnector" /> 10 <StackedJoinable interval="1"> 11 <JoinableCollection name="servers"> 12 <FramsServer name="frams" port="9100" expdef="prime"> 13 <LoggingOutputListener /> 14 </FramsServer> 15 <FramsServer name="frams" port="9101" expdef="prime"> 16 <LoggingOutputListener /> 17 </FramsServer> 18 </JoinableCollection> 19 <PrimeExperiment> 20 <SimulatorConnector address="localhost:9100" /> 21 <SimulatorConnector address="localhost:9101" /> 22 </PrimeExperiment> 23 </StackedJoinable> 7 24 </Framsticks> -
java/main/src/test/resources/configs/ServerTest.xml
r101 r102 6 6 <import class="com.framsticks.test.TestClass" /> 7 7 <import class="com.framsticks.running.LoggingOutputListener" /> 8 <Server port="900 7">8 <Server port="9006"> 9 9 <LocalTree name="test"> 10 10 <TestClass name="a test name" /> 11 11 </LocalTree> 12 12 </Server> 13 <RemoteTree name="remote" address="localhost:900 7" />13 <RemoteTree name="remote" address="localhost:9006" /> 14 14 </Framsticks> -
java/main/src/test/resources/log4j2.xml
r100 r102 7 7 </appenders> 8 8 <loggers> 9 <logger name="com.framsticks" level="warn" /> 9 <logger name="com.framsticks" level="info" /> 10 <logger name="com.framsticks.running.ExternalProcess" level="debug" /> 10 11 <logger name="com.framsticks.test.TestConfiguration" level="info" /> 12 <logger name="com.framsticks.experiment" level="debug" /> 13 <logger name="com.framsticks.test.PrimeExperiment" level="debug" /> 14 <!-- <logger name="com.framsticks.util.dispatching.AbstractJoinable" level="debug" /> --> 15 <!-- <logger name="com.framsticks.util.dispatching.AbstractJoinable.Report" level="info" /> --> 16 <!-- <logger name="com.framsticks.util.dispatching.Monitor" level="debug" /> --> 17 <!-- <logger name="com.framsticks.util.dispatching.StackedJoinable" level="debug" /> --> 11 18 <root level="info"> 12 19 <appender-ref ref="Console"/>
Note: See TracChangeset
for help on using the changeset viewer.