source: java/main/src/main/java/com/framsticks/experiment/SimulatorConnector.java @ 105

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

HIGHLIGHTS:

  • import refactorization: move Tree, Path, etc.

from core to structure package

  • initial serialization implementation
  • improve PrimeExperiment? test
  • many organizational changes and convenience improvements

CHANGELOG:
Make registry in AbstractTree? final.

Move most classes from core to structure package.

Minor changes.

Switch names of Future and FutureHandler?.

Rename ExceptionResultHandler? to ExceptionHandler?.

Rename ExceptionHandler? to ExceptionDispatcherHandler?.

Fix bug in ParamCandidate? cache.

Add missing synchronization to the BufferedDispatcher?.

Develop @Serialized support.

Rework serialization further.

Add serialization/deserialization interface to ValueParam?.

Move getStorageType and isNumeric from Param down to params hierarchy.

Minor changes.

Improve param type induction.

Add TestSerializedClass? for testing new serialization.

Add info files gor GenePool? and Population.

Add standard.expt exemplary netfile.

Add type name field to PropertiesObject?.

Use PropertiesObject? for PropertiesAccess? instead of ordinary map.

Hide getFramsClass is several more places.

More unification accross FramsClass?, Access and Path.

Add ParamCollection?.

Simplify interface for getting params from FramsClass?, Access
or Path.

Make Access.call() interface variadic.

Add arguments(args) convenience wrapper around new Object[] {args}.

Upgrade to apache.commons.lang version 3.1

Minor improvement with Response constructors.

Develop proper result printing in ClientAtServer?.

Add experimentNetsave to PrimeExperiment?.

File size: 2.4 KB
Line 
1package com.framsticks.experiment;
2
3import org.apache.logging.log4j.Level;
4import org.apache.logging.log4j.Logger;
5import org.apache.logging.log4j.LogManager;
6
7import com.framsticks.communication.Address;
8import com.framsticks.params.annotations.FramsClassAnnotation;
9import com.framsticks.params.annotations.ParamAnnotation;
10import com.framsticks.remote.RemoteTree;
11import com.framsticks.structure.Path;
12import com.framsticks.util.AutoAttacher;
13import com.framsticks.util.Misc;
14import com.framsticks.util.dispatching.Dispatcher;
15import com.framsticks.util.dispatching.Dispatching;
16import com.framsticks.util.dispatching.Future;
17import com.framsticks.util.lang.Casting;
18import com.framsticks.util.lang.Strings;
19
20import static com.framsticks.structure.TreeOperations.*;
21
22@FramsClassAnnotation
23public class SimulatorConnector implements AutoAttacher {
24        private static final Logger log = LogManager.getLogger(SimulatorConnector.class);
25
26
27        protected Experiment experiment;
28        protected Address address;
29        protected RemoteTree remoteTree;
30
31        @SuppressWarnings({ "rawtypes", "unchecked" })
32        @Override
33        public void attachTo(Object parent) {
34                experiment = Casting.throwCast(Experiment.class, parent);
35
36                Misc.throwIfNull(address);
37                log.debug("connecting to simulator at {}", address);
38                // experiment
39                remoteTree = new RemoteTree();
40                remoteTree.setAddress(address);
41                remoteTree.setDispatcher((Dispatcher) experiment.getDispatcher());
42
43
44                experiment.getSimulatorCandidates().add(remoteTree);
45
46                Dispatching.dispatchLog(remoteTree, log, Level.DEBUG, "first task in remote tree");
47
48                tryGet(remoteTree, "/simulator", new Future<Path>(experiment) {
49
50                        @Override
51                        protected void result(Path result) {
52                                log.debug("resolved simulator path: {}", result);
53                                Misc.checkEquals(experiment.getExpdef(), bindAccess(result).get("expdef", String.class), "expdef mismatch in connected simulator", this);
54
55                                Simulator simulator = new Simulator(experiment, remoteTree, result);
56                                experiment.addSimulator(simulator);
57                                experiment.getSimulatorCandidates().remove(remoteTree);
58                        }
59                });
60        }
61
62        @ParamAnnotation
63        public void setAddress(String address) {
64                this.address = new Address(address);
65        }
66
67        @ParamAnnotation
68        public String getAddress() {
69                return Strings.toStringNullProof(address, "");
70        }
71
72        @Override
73        public String toString() {
74                return "simulator connector to: " + Strings.toStringNullProof(address, "<null>");
75        }
76
77}
Note: See TracBrowser for help on using the repository browser.