- Timestamp:
- 07/08/13 23:04:56 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/remote/RemoteTree.java
r97 r98 8 8 import com.framsticks.core.AbstractTree; 9 9 import com.framsticks.core.Mode; 10 import com.framsticks.core.TreeOperations;11 10 import com.framsticks.core.ListChange; 12 import com.framsticks.core.Node;13 11 import com.framsticks.core.Path; 14 12 import com.framsticks.params.*; … … 22 20 import com.framsticks.util.*; 23 21 import com.framsticks.util.dispatching.Dispatching; 22 import com.framsticks.util.dispatching.Dispatching.DispatcherWaiter; 24 23 import com.framsticks.util.dispatching.Future; 25 24 import com.framsticks.util.dispatching.FutureHandler; … … 27 26 import com.framsticks.util.dispatching.JoinableParent; 28 27 import com.framsticks.util.dispatching.JoinableState; 28 import com.framsticks.util.dispatching.ThrowExceptionHandler; 29 29 import com.framsticks.util.lang.Casting; 30 30 import com.framsticks.util.lang.Pair; … … 52 52 public Pair<Path, Subscription<?>> getSubscription(Path path) { 53 53 for (Pair<Path, Subscription<?>> s : subscriptions) { 54 if (s.first. matches(path)) {54 if (s.first.isTheSameObjects(path)) { 55 55 return s; 56 56 } … … 75 75 public void setConnection(final ClientSideManagedConnection connection) { 76 76 this.connection = connection; 77 // final ExceptionResultHandler failure = new ExceptionResultHandler() { 78 // @Override 79 // public void handle(FramsticksException exception) { 80 // log.fatal("failed to establish connection: ", exception); 81 // // log.fatal("unsupported protocol version!\n minimal version is: " + "\nmanager protocol is: " + connection.getProtocolVersion()); 82 // Dispatching.drop(connection, RemoteTree.this); 83 // fireRun(exception); 84 // } 85 // }; 86 77 } 78 79 public final ClientSideManagedConnection getConnection() { 80 return connection; 87 81 } 88 82 … … 93 87 } 94 88 95 public final ClientSideManagedConnection getConnection() { 96 return connection; 97 } 98 99 @Override 100 public void get(final Path path, final PrimitiveParam<?> param, Mode mode, final Future<Object> future) { 89 @Override 90 public void get(final Path path, final ValueParam param, Mode mode, final Future<Object> future) { 101 91 assert isActive(); 102 92 assert param != null; 103 assert path.isResolved();93 // assert path.isResolved(); 104 94 //TODO only do that if needed 105 95 connection.send(new GetRequest().field(param.getId()).path(path.getTextual()), this, new ClientSideResponseFuture(future) { … … 107 97 protected void processOk(Response response) { 108 98 assert isActive(); 109 TreeOperations.processFetchedValues(path, response.getFiles());110 future.pass(bindAccess(path ).get(param, Object.class));99 processFetchedValues(path, response.getFiles()); 100 future.pass(bindAccess(path.tryResolveIfNeeded()).get(param, Object.class)); 111 101 } 112 102 }); … … 164 154 throw new FramsticksException().msg("path mismatch").arg("returned path", response.getFiles().get(0).getPath()); 165 155 } 166 FramsClass framsClass = TreeOperations.processFetchedInfo(RemoteTree.this, response.getFiles().get(0));156 FramsClass framsClass = processFetchedInfo(RemoteTree.this, response.getFiles().get(0)); 167 157 168 158 CompositeParam thisParam = path.getTop().getParam(); … … 176 166 177 167 @Override 178 public void get(final Path path, Mode mode, final Future<Object> future) { 179 assert isActive(); 180 assert path.getTop().getObject() != null; 168 public void get(final Path path, final Mode mode, final Future<Path> future) { 169 assert isActive(); 181 170 182 171 log.trace("fetching values for " + path); 183 connection.send(new GetRequest().path(path.getTextual()), this, new ClientSideResponseFuture(future) { 184 @Override 185 protected void processOk(Response response) { 186 assert isActive(); 187 TreeOperations.processFetchedValues(path, response.getFiles()); 188 future.pass(path.getTopObject()); 189 } 190 }); 191 } 192 193 @Override 194 public void resolve(final Path path, final Future<Path> future) { 195 TreeOperations.resolve(path, future); 196 } 172 findInfo(path, new FutureHandler<FramsClass>(future) { 173 @Override 174 protected void result(FramsClass result) { 175 176 connection.send(new GetRequest().path(path.getTextual()), RemoteTree.this, new ClientSideResponseFuture(future) { 177 @Override 178 protected void processOk(Response response) { 179 assert isActive(); 180 Path p = path.tryResolveIfNeeded(); 181 processFetchedValues(p, response.getFiles()); 182 future.pass(p.tryResolveIfNeeded().assureResolved()); 183 } 184 }); 185 } 186 }); 187 } 188 197 189 198 190 @Override 199 191 protected void tryRegisterOnChangeEvents(final Path path) { 200 192 assert isActive(); 201 AccessInterface access = TreeOperations.bindAccess(path);193 AccessInterface access = bindAccess(path); 202 194 if (!(access instanceof ListAccess)) { 203 195 return; … … 274 266 protected void result(Path result) { 275 267 log.debug(listChange + ": " + result); 276 fireListChange(result, listChange);277 268 } 278 269 }; … … 282 273 assert isActive(); 283 274 log.debug("reacting to change " + listChange + " in " + path); 284 AccessInterface access = TreeOperations.bindAccess(path);275 AccessInterface access = bindAccess(path); 285 276 assert access != null; 286 277 287 278 if ((listChange.getAction() == ListChange.Action.Modify) && (listChange.getPosition() == -1)) { 288 279 final String p = path.getTextual(); 289 TreeOperations.resolveAndGet(this, p, futureListChanger(listChange, p));280 tryGet(this, p, futureListChanger(listChange, p)); 290 281 return; 291 282 } … … 296 287 case Add: { 297 288 final String p = path.getTextual() + "/" + childParam.getId(); 298 TreeOperations.resolveAndGet(this, p, futureListChanger(listChange, p));289 tryGet(this, p, futureListChanger(listChange, p)); 299 290 break; 300 291 } 301 292 case Remove: { 302 293 access.set(childParam, null); 303 fireListChange(path, listChange);304 294 break; 305 295 } 306 296 case Modify: { 307 297 final String p = path.getTextual() + "/" + childParam.getId(); 308 TreeOperations.resolveAndGet(this, p, futureListChanger(listChange, p));298 tryGet(this, p, futureListChanger(listChange, p)); 309 299 break; 310 300 } … … 315 305 public void set(final Path path, final PrimitiveParam<?> param, final Object value, final Future<Integer> future) { 316 306 assert isActive(); 317 final Integer flag = TreeOperations.bindAccess(path).set(param, value);307 final Integer flag = bindAccess(path).set(param, value); 318 308 319 309 log.trace("storing value " + param + " for " + path); … … 331 321 Dispatching.use(connection, this); 332 322 super.joinableStart(); 323 324 dispatch(new RunAt<RemoteTree>(ThrowExceptionHandler.getInstance()) { 325 @Override 326 protected void runAt() { 327 final DispatcherWaiter<Tree, Tree> waiter = new DispatcherWaiter<Tree, Tree>(RemoteTree.this); 328 329 connection.send(new InfoRequest().path("/"), waiter, new ClientSideResponseFuture(this) { 330 @Override 331 protected void processOk(Response response) { 332 FramsClass framsClass = processFetchedInfo(RemoteTree.this, response.getFiles().get(0)); 333 assignRootParam(Param.build().name("Tree").id(RemoteTree.this.getName()).type("o " + framsClass.getId()).finish(CompositeParam.class)); 334 } 335 }); 336 337 waiter.waitFor(); 338 } 339 }); 333 340 } 334 341 … … 373 380 } 374 381 375 @Override 376 public Path create(Path path) { 377 assert isActive(); 378 assert !path.isResolved(); 379 Path resolved = path.tryFindResolution(); 380 if (!resolved.isResolved()) { 381 log.debug("creating: " + path); 382 AccessInterface access = registry.prepareAccess(path.getTop().getParam()); 383 assert access != null; 384 Object child = access.createAccessee(); 385 assert child != null; 386 if (path.size() == 1) { 387 setRoot(new Node(getRoot().getParam(), child)); 388 } else { 389 bindAccess(this, path.getUnder()).set(path.getTop().getParam(), child); 390 } 391 resolved = path.appendResolution(child); 392 } 393 tryRegisterOnChangeEvents(resolved); 394 return resolved; 395 } 382 // @Override 383 // public Path create(Path path) { 384 // assert isActive(); 385 // assert !path.isResolved(); 386 // Path resolved = path.tryFindResolution(); 387 // if (!resolved.isResolved()) { 388 // log.debug("creating: " + path); 389 // //TODO: access parent here, check if it is valid, only then create 390 // AccessInterface access = registry.prepareAccess(path.getTop().getParam()); 391 // assert access != null; 392 // Object child = access.createAccessee(); 393 // assert child != null; 394 // if (path.size() == 1) { 395 // setRoot(new Node(getRoot().getParam(), child)); 396 // } else { 397 // bindAccess(this, path.getUnder()).set(path.getTop().getParam(), child); 398 // } 399 // resolved = path.appendResolution(child); 400 // } 401 // tryRegisterOnChangeEvents(resolved); 402 // return resolved; 403 // } 396 404 397 405 }
Note: See TracChangeset
for help on using the changeset viewer.