source: java/main/src/main/java/com/framsticks/experiment/Experiment.java @ 103

Last change on this file since 103 was 103, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • add auto loading and saving algorithms between

frams files format and Java classes

  • respect ValueChange? events in GUI (do not reload object)
  • support results of procedures in Java server
  • make Experiment automatically convert between frams file and NetFile? object
  • add MessageLogger? (compatible with original frams server messages)
  • WorkPackageLogic? now validates results, is able to discard them, reschedule

whole package, or only uncomputed remainder

CHANGELOG:
Show just a short description in PrimeExperiment?.

Add primes_changed event to the PrimeExperiment?.

Make WorkPackageLogic? robust to frams server returning invalid results.

Add MessageLogger? to logics.

Add NetFile? interface. Support Messages from server.

Minor changes to connections.

Merge results in the PrimeExperiment?.

More netload class->file conversion to Simulator.

Move netsave parsing to Simulator.

Fix bug with inverted ordering of events firing in Experiment.

Minor changes.

Minor logging changes.

Use AccessOperations?.convert in NetLoadSaveLogic?

NetLoadSaveLogic? now encloses the conversion.

Use more generic AccessOperations? saveAll and loadAll in PrimePackage?.

Add Result class for enclosing of call invocations' results.

Improve feature request handling in Connections.

Use AccessOperations?.convert in RemoteTree? events parsing.

Minor change.

Add some information params to Java server root and CLI objects.

A draft implementation of loadAll algorithm.

That algorithm tries to load objects into a tree structure.

Add AccessOperationsTest? test.

Develop WorkPackageLogic?.

  • add state tracking fields
  • add work package generation

Add utility class SimplePrimitive?.

Meant for Java backend classes, enclose a single primitive value
and set of listeners.

Improve primitive value refresh in GUI.

When ValueChange? found in called event, do not reload whole
object, but only update GUI (no communication is performed).

Use ValueChange? in the TestClass? test.

Minor changes.

Sending all packages in PrimeExperiment? to the frams servers.

Develop AccessOperations?.loadComposites().

Remove addAccess from MultiParamLoader? interface.

There is now no default AccessProvider? in MultiParamLoader?.
User must explicitely set AccessStash? or Registry.

Improve saving algorithms in AccessOperations?.

File size: 5.7 KB
Line 
1package com.framsticks.experiment;
2
3import java.util.Map;
4
5import org.apache.logging.log4j.Level;
6import org.apache.logging.log4j.Logger;
7import org.apache.logging.log4j.LogManager;
8
9import com.framsticks.core.ListChange;
10import com.framsticks.params.EventListener;
11import com.framsticks.params.ParamFlags;
12import com.framsticks.params.SimpleUniqueList;
13import com.framsticks.params.annotations.AutoAppendAnnotation;
14import com.framsticks.params.annotations.FramsClassAnnotation;
15import com.framsticks.params.annotations.ParamAnnotation;
16import com.framsticks.params.types.ProcedureParam;
17import com.framsticks.remote.RemoteTree;
18import com.framsticks.util.FramsticksException;
19import com.framsticks.util.dispatching.AbstractJoinable;
20import com.framsticks.util.dispatching.BufferedDispatcher;
21import com.framsticks.util.dispatching.Dispatcher;
22import com.framsticks.util.dispatching.DispatcherSetable;
23import com.framsticks.util.dispatching.Dispatching;
24import com.framsticks.util.dispatching.ExceptionResultHandler;
25import com.framsticks.util.dispatching.Joinable;
26import com.framsticks.util.dispatching.JoinableCollection;
27import com.framsticks.util.dispatching.JoinableParent;
28import com.framsticks.util.dispatching.JoinableState;
29import com.framsticks.util.dispatching.RunAt;
30
31@FramsClassAnnotation
32public 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");
38
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         */
51        public Experiment() {
52                super();
53                bufferedDispatcher.setBuffer(false);
54
55                Dispatching.dispatchLog(this, log, Level.DEBUG, "first task");
56        }
57
58        /**
59         * @return the simulatorCandidates
60         */
61        public JoinableCollection<RemoteTree> getSimulatorCandidates() {
62                return simulatorCandidates;
63        }
64
65        @ParamAnnotation
66        public Map<String, Simulator> getSimulators() {
67                return simulators.getView();
68        }
69
70        @ParamAnnotation(id = "old_simulators")
71        public Map<String, Simulator> getOldSimulators() {
72                return oldSimulators.getView();
73        }
74
75        /**
76         * @return the dispatcher
77         */
78        @Override
79        public Dispatcher<Experiment> getDispatcher() {
80                return bufferedDispatcher;
81        }
82
83        /**
84         * @param dispatcher the dispatcher to set
85         */
86        @Override
87        public void setDispatcher(Dispatcher<Experiment> dispatcher) {
88                bufferedDispatcher.setTargetDispatcher(dispatcher);
89        }
90
91        /**
92         * @return the expdef
93         */
94        @ParamAnnotation(flags = ParamFlags.USERREADONLY)
95        public String getExpdef() {
96                return expdef;
97        }
98
99        /**
100         * @param expdef the expdef to set
101         */
102        @ParamAnnotation
103        public void setExpdef(String expdef) {
104                this.expdef = expdef;
105        }
106
107
108        @ParamAnnotation(id = "simulators_changed")
109        public void addSimulatorsListener(EventListener<ListChange> listener) {
110                simulators.addListener(listener);
111        }
112
113        @ParamAnnotation(id = "simulators_changed")
114        public void removeSimulatorsListener(EventListener<ListChange> listener) {
115                simulators.removeListener(listener);
116        }
117
118        @AutoAppendAnnotation
119        public void addSimulator(Simulator simulator) {
120                simulators.add(simulator);
121                simulatorAsJoinables.add(simulator);
122                simulators.fireChildrenChange(simulator, ListChange.Action.Modify, "ready");
123
124        }
125
126        protected void removeSimulator(Simulator simulator) {
127                simulatorAsJoinables.remove(simulator);
128                simulators.remove(simulator);
129                oldSimulators.add(simulator);
130        }
131
132        @ParamAnnotation(id = "old_simulators_changed")
133        public void addOldSimulatorsListener(EventListener<ListChange> listener) {
134                oldSimulators.addListener(listener);
135        }
136
137        @ParamAnnotation(id = "old_simulators_changed")
138        public void removeOldSimulatorsListener(EventListener<ListChange> listener) {
139                oldSimulators.removeListener(listener);
140        }
141
142        @Override
143        public String getName() {
144                return "experiment";
145        }
146
147        @Override
148        public void childChangedState(Joinable joinable, JoinableState state) {
149                proceedToState(state);
150        }
151
152        @Override
153        protected void joinableStart() {
154                bufferedDispatcher.createThreadIfNeeded();
155                Dispatching.use(bufferedDispatcher, this);
156
157                Dispatching.use(simulatorAsJoinables, this);
158                Dispatching.use(simulatorCandidates, this);
159        }
160
161        @Override
162        protected void joinableInterrupt() {
163
164                Dispatching.drop(simulatorAsJoinables, this);
165                Dispatching.drop(simulatorCandidates, this);
166
167                finishJoinable();
168        }
169
170        @Override
171        protected void joinableFinish() {
172                log.debug("finishing experiment {}", this);
173        }
174
175        @Override
176        protected void joinableJoin() throws InterruptedException {
177                Dispatching.drop(bufferedDispatcher, this);
178
179                Dispatching.join(simulatorAsJoinables);
180                Dispatching.join(simulatorCandidates);
181                Dispatching.join(bufferedDispatcher.getTargetDispatcher());
182        }
183
184        @Override
185        public void handle(FramsticksException exception) {
186                log.error("caught exception: ", exception);
187        }
188
189        @Override
190        public boolean isActive() {
191                return bufferedDispatcher.isActive();
192        }
193
194        @Override
195        public void dispatch(RunAt<? extends Experiment> runnable) {
196                bufferedDispatcher.dispatch(runnable);
197        }
198
199        @ParamAnnotation(paramType = ProcedureParam.class)
200        public void connectToSimulator(String address) {
201                SimulatorConnector connector = new SimulatorConnector();
202                connector.setAddress(address);
203                connector.attachTo(this);
204        }
205
206}
Note: See TracBrowser for help on using the repository browser.