source: java/main/src/main/java/com/framsticks/experiment/NetLoadSaveLogic.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: 3.5 KB
Line 
1package com.framsticks.experiment;
2
3
4import org.apache.logging.log4j.Logger;
5import org.apache.logging.log4j.LogManager;
6
7import com.framsticks.core.ListChange;
8import com.framsticks.core.Message;
9import com.framsticks.params.EventListener;
10import com.framsticks.params.MessageLogger;
11import com.framsticks.params.annotations.FramsClassAnnotation;
12import com.framsticks.params.annotations.ParamAnnotation;
13import com.framsticks.util.dispatching.Future;
14import com.framsticks.util.dispatching.FutureHandler;
15
16@FramsClassAnnotation
17public abstract class NetLoadSaveLogic<NF extends NetFile> extends AbstractExperimentLogic {
18        private static final Logger log = LogManager.getLogger(NetLoadSaveLogic.class);
19
20        protected String option = "an option";
21
22        protected final Class<NF> netJavaClass;
23
24        protected final MessageLogger messages = new MessageLogger(NetLoadSaveLogic.class);
25
26        /**
27         * @param experiment
28         */
29        public NetLoadSaveLogic(Experiment parentExperiment, Class<NF> netJavaClassArg) {
30                super(parentExperiment);
31                this.netJavaClass = netJavaClassArg;
32
33                experiment.addSimulatorsListener(new EventListener<ListChange>() {
34
35                        @Override
36                        public void action(final ListChange change) {
37                                assert experiment.isActive();
38                                final Simulator simulator = experiment.getSimulators().get(change.getIdentifier());
39                                log.debug("processing list change: {}", change);
40
41                                if (change.getAction() == ListChange.Action.Add) {
42                                        log.debug("registering in {}", simulator);
43                                        simulator.getRemoteTree().getRegistry().registerAndBuild(netJavaClass);
44                                }
45
46                                if (!change.hasHint("stoped")) {
47                                        issueNetloadIfReady(change, simulator);
48                                        return;
49                                }
50
51                                log.debug("issuing netsave to: {}", simulator);
52                                simulator.netsave(netJavaClass, new FutureHandler<NF>(simulator) {
53
54                                        @Override
55                                        protected void result(NF net) {
56                                                log.debug("netsave of {} done: {}", simulator, net.getShortDescription());
57                                                netsave(simulator, net);
58                                                issueNetloadIfReady(change, simulator);
59                                        }
60                                });
61                        }
62                });
63        }
64
65        protected void issueNetloadIfReady(ListChange change, final Simulator simulator) {
66                if (!change.hasHint("ready")) {
67                        return;
68                }
69                log.debug("issuing netload to: {}", simulator);
70                netload(simulator, new FutureHandler<NF>(simulator) {
71
72                        @Override
73                        protected void result(final NF net) {
74                                if (net == null) {
75                                        log.debug("no file for upload provided - leaving simulator idle");
76                                        return;
77                                }
78
79                                simulator.netload(net, new FutureHandler<Object>(this) {
80
81                                        @Override
82                                        protected void result(Object result) {
83                                                NetLoadSaveLogic.this.messages.info("netload", "done " + net.getShortDescription());
84                                                log.debug("netload of {} done", net.getShortDescription());
85                                                simulator.start();
86                                        }
87                                });
88                        }
89                });
90        }
91
92        public abstract void netload(Simulator simulator, Future<NF> net);
93
94        public abstract void netsave(Simulator simulator, NF net);
95
96        /**
97         * @return the option
98         */
99        @ParamAnnotation
100        public String getOption() {
101                return option;
102        }
103
104        /**
105         * @param option the option to set
106         */
107        @ParamAnnotation
108        public void setOption(String option) {
109                this.option = option;
110        }
111
112        /**
113         * @return the netJavaClass
114         */
115        @ParamAnnotation(name = "Java class representing netfile")
116        public String getNetJavaClassName() {
117                return netJavaClass.getCanonicalName();
118        }
119
120        @ParamAnnotation(id = "messages")
121        public void addMessageListener(EventListener<Message> listener) {
122                messages.add(listener);
123        }
124
125        @ParamAnnotation(id = "messages")
126        public void removeMessageListener(EventListener<Message> listener) {
127                messages.remove(listener);
128        }
129
130}
Note: See TracBrowser for help on using the repository browser.