Changeset 90 for java/main/src/main/java/com/framsticks/core/Instance.java
- Timestamp:
- 07/02/13 16:20:07 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/core/Instance.java
r88 r90 8 8 9 9 import javax.annotation.Nonnull; 10 import javax.annotation.OverridingMethodsMustInvokeSuper;11 10 12 11 import org.apache.log4j.Logger; … … 14 13 import com.framsticks.communication.File; 15 14 import com.framsticks.params.AccessInterface; 15 import com.framsticks.params.CompositeParam; 16 16 import com.framsticks.params.ConstructionException; 17 17 import com.framsticks.params.FramsClass; 18 18 import com.framsticks.params.ListAccess; 19 19 import com.framsticks.params.Param; 20 import com.framsticks.params.ParamsPackage; 20 21 import com.framsticks.params.Registry; 21 22 import com.framsticks.params.ValueParam; 23 import com.framsticks.params.annotations.AutoAppendAnnotation; 22 24 import com.framsticks.params.annotations.FramsClassAnnotation; 23 25 import com.framsticks.params.types.ObjectParam; 26 import com.framsticks.params.types.ProcedureParam; 24 27 import com.framsticks.parsers.Loaders; 25 28 import com.framsticks.parsers.MultiParamLoader; 29 import com.framsticks.util.FramsticksException; 26 30 import com.framsticks.util.StateFunctor; 27 31 import com.framsticks.util.UnsupportedOperationException; … … 40 44 private static final Logger log = Logger.getLogger(Instance.class.getName()); 41 45 42 protected Node root; 46 private Node root; 47 48 protected @Nonnull Node setRoot(CompositeParam param, Object object) { 49 // if (isRootAssigned()) { 50 // throw new FramsticksException().msg("root is already assigned"); 51 // } 52 // assert isActive(); 53 root = new Node(param, object); 54 return root; 55 } 56 57 protected @Nonnull Node getRoot() { 58 // assert isActive(); 59 assert root != null; 60 return root; 61 } 62 63 public boolean isRootAssigned() { 64 // assert isActive(); 65 return root != null; 66 } 43 67 44 68 protected Set<InstanceListener> listeners = new HashSet<InstanceListener>(); … … 68 92 } 69 93 70 public void fetchValue(Path path, Param param, StateFunctor stateFunctor) { 71 stateFunctor.call(null); 72 } 73 74 public void fetchValues(Path path, StateFunctor stateFunctor) { 75 stateFunctor.call(null); 76 } 94 /** This is part of the Instance interface. 95 * 96 */ 97 public abstract void fetchValue(Path path, Param param, StateFunctor stateFunctor); 98 99 /** This is part of the Instance interface. 100 * 101 */ 102 public abstract void fetchValues(Path path, StateFunctor stateFunctor); 103 104 /** This is part of the Instance interface. 105 * 106 */ 107 public abstract void call(Path path, ProcedureParam param, Object[] arguments, StateFunctor stateFunctor); 77 108 78 109 protected void tryRegisterOnChangeEvents(Path path) { … … 82 113 public void storeValue(Path path, Param param, Object value, final StateFunctor stateFunctor) { 83 114 assert isActive(); 84 invokeLater(new RunAt<Instance>() {115 dispatch(new RunAt<Instance>() { 85 116 @Override 86 117 public void run() { … … 104 135 public void addListener(final InstanceListener listener) { 105 136 assert Dispatching.isThreadSafe(); 106 Dispatching. invokeLaterOrNow(this, new RunAt<Instance>() {137 Dispatching.dispatchIfNotActive(this, new RunAt<Instance>() { 107 138 @Override 108 139 public void run() { … … 114 145 public void removeListener(final InstanceListener listener) { 115 146 assert Dispatching.isThreadSafe(); 116 Dispatching. invokeLaterOrNow(this, new RunAt<Instance>() {147 Dispatching.dispatchIfNotActive(this, new RunAt<Instance>() { 117 148 @Override 118 149 public void run() { … … 142 173 public FramsClass getInfoFromCache(String id) { 143 174 assert isActive(); 144 return registry.get InfoFromCache(id);175 return registry.getFramsClass(id); 145 176 } 146 177 … … 169 200 } 170 201 202 public final AccessInterface bindAccess(String path) { 203 return bindAccess(getPath(path)); 204 } 205 171 206 public final AccessInterface bindAccess(Node node) { 207 assert isActive(); 172 208 assert node.getObject() != null; 173 209 174 210 try { 175 return registry.prepareAccess(node.getParam()).select(node.getObject()); 211 AccessInterface access = registry.prepareAccess(node.getParam()); 212 if (access == null) { 213 throw new FramsticksException().msg("failed to prepare access for param").arg("param", node.getParam()); 214 } 215 return access.select(node.getObject()); 176 216 } catch (ConstructionException e) { 177 217 log.error("failed to bind access for " + node.getParam() + ": " + e); … … 185 225 186 226 public final AccessInterface bindAccess(Path path) { 187 assert path.isResolved();227 path.assureResolved(); 188 228 return bindAccess(path.getTop()); 189 229 } … … 260 300 assert child != null; 261 301 if (path.size() == 1) { 262 root = new Node(root.getParam(), child);302 setRoot(getRoot().getParam(), child); 263 303 } else { 264 304 bindAccess(path.getUnder()).set(path.getTop().getParam(), child); … … 277 317 FramsClass framsClass = Loaders.loadFramsClass(file.getContent()); 278 318 if ("/".equals(file.getPath())) { 279 if ( root.getParam().getContainedTypeName() == null) {280 root = new Node(Param.build().name("Instance").id(getName()).type("o " + framsClass.getId()), root.getObject());281 } 282 } 283 registry.put InfoIntoCache(framsClass);319 if (getRoot().getParam().getContainedTypeName() == null) { 320 setRoot(Param.build().name("Instance").id(getName()).type("o " + framsClass.getId()).finish(CompositeParam.class), getRoot().getObject()); 321 } 322 } 323 registry.putFramsClass(framsClass); 284 324 return framsClass; 285 325 } … … 299 339 loader.go(); 300 340 fireFetch(path); 301 // for (NodeListener l : listeners) {302 // l.onChange(this);303 // }304 341 return; 305 342 } … … 318 355 String id = listAccess.computeIdentifierFor(accessInterface.getSelected()); 319 356 //TODO listAccessParam 320 Param param = Param.build(). type("o " + accessInterface.getId()).id(id).finish();357 Param param = Param.build().forAccess(accessInterface).id(id).finish(); 321 358 Object child = accessInterface.getSelected(); 322 359 accessInterface.select(null); … … 327 364 328 365 fireFetch(path); 329 // for (NodeListener l : listeners) {330 // l.onChange(this);331 // }332 366 } catch (Exception e) { 333 367 log.error("exception occurred while loading: " + e); … … 358 392 } 359 393 394 @AutoAppendAnnotation 395 public void usePackage(ParamsPackage paramsPackage) { 396 log.debug("using package " + paramsPackage + " in instance " + this); 397 paramsPackage.register(registry); 398 } 399 400 @AutoAppendAnnotation 401 public void takeFromRegistry(Registry registry) { 402 log.debug("taking from registry " + registry + " in instance " + this); 403 this.registry.takeAllFrom(registry); 404 } 405 360 406 @Override 361 @OverridingMethodsMustInvokeSuper 362 protected void firstTask() { 363 root = new Node(Param.build().name("Instance").id(getName()).type("o"), null); 364 com.framsticks.model.Package.register(registry); 407 protected void joinableStart() { 408 dispatch(new RunAt<Instance>() { 409 @Override 410 public void run() { 411 if (!isRootAssigned()) { 412 setRoot(Param.build().name("Instance").id(getName()).type("o").finish(CompositeParam.class), null); 413 } 414 } 415 }); 416 super.joinableStart(); 365 417 } 366 418
Note: See TracChangeset
for help on using the changeset viewer.