Skip to content

Commit

Permalink
gapic: Restructure Paths.java.
Browse files Browse the repository at this point in the history
Use the visitor pattern to implement:
 • toNode() - Takes a path.Any, returns an unboxed Node type.
 • toAny() - Inverse of toNode.
 • parentOf() - Returns the parent node of the given node.
 • setParent() - Returns a copy of the node with the parent changed.
 • toString()

Long and verbose, but is explicit and does the job. Happy to try and replace portions with reflection magic - I just want something that works for now.
  • Loading branch information
ben-clayton committed Sep 14, 2017
1 parent f816a40 commit ef11f7f
Show file tree
Hide file tree
Showing 8 changed files with 1,335 additions and 583 deletions.
4 changes: 2 additions & 2 deletions gapic/src/main/com/google/gapid/models/ApiState.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void onStateFollowed(Path.Any path) {
@Override
protected ListenableFuture<Node> doLoad(Path.Any path) {
return Futures.transformAsync(client.get(path),
tree -> Futures.transform(client.get(Paths.any(tree.getStateTree().getRoot())),
tree -> Futures.transform(client.get(Paths.toAny(tree.getStateTree().getRoot())),
val -> new RootNode(
tree.getStateTree().getRoot().getTree(), val.getStateTreeNode())));
}
Expand Down Expand Up @@ -115,7 +115,7 @@ protected void fireLoadedEvent() {

public ListenableFuture<Node> load(Node node) {
return node.load(shell, () -> Futures.transformAsync(
client.get(Paths.any(node.getPath(Path.StateTreeNode.newBuilder()))),
client.get(Paths.toAny(node.getPath(Path.StateTreeNode.newBuilder()))),
value -> Futures.transform(constants.loadConstants(value.getStateTreeNode()),
ignore -> new NodeData(value.getStateTreeNode()))));
}
Expand Down
7 changes: 3 additions & 4 deletions gapic/src/main/com/google/gapid/models/AtomStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.google.gapid.models;

import static com.google.gapid.proto.service.memory.Memory.PoolNames.Application_VALUE;
import static com.google.gapid.util.Paths.any;
import static com.google.gapid.util.Paths.commandTree;
import static com.google.gapid.util.Paths.lastCommand;
import static com.google.gapid.util.Paths.observationsAfter;
Expand Down Expand Up @@ -104,14 +103,14 @@ public void onContextSelected(FilteringContext ctx) {
@Override
protected ListenableFuture<Node> doLoad(Path.Any path) {
return Futures.transformAsync(client.get(path),
tree -> Futures.transform(client.get(Paths.any(tree.getCommandTree().getRoot())),
tree -> Futures.transform(client.get(Paths.toAny(tree.getCommandTree().getRoot())),
val -> new RootNode(
tree.getCommandTree().getRoot().getTree(), val.getCommandTreeNode())));
}

public ListenableFuture<Node> load(Node node) {
return node.load(shell, () -> Futures.transformAsync(
client.get(any(node.getPath(Path.CommandTreeNode.newBuilder()))), v1 -> {
client.get(Paths.toAny(node.getPath(Path.CommandTreeNode.newBuilder()))), v1 -> {
Service.CommandTreeNode data = v1.getCommandTreeNode();
if (data.getGroup().isEmpty() && data.hasCommands()) {
return Futures.transform(
Expand All @@ -122,7 +121,7 @@ public ListenableFuture<Node> load(Node node) {
}

public ListenableFuture<API.Command> loadCommand(Path.Command path) {
return Futures.transformAsync(client.get(any(path)), value ->
return Futures.transformAsync(client.get(Paths.toAny(path)), value ->
Futures.transform(constants.loadConstants(value.getCommand()), ignore ->
value.getCommand()));
}
Expand Down
2 changes: 1 addition & 1 deletion gapic/src/main/com/google/gapid/models/ConstantSets.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ConstantSets {

public ConstantSets(Client client) {
this.cache = FutureCache.hardCache(
path -> Futures.transform(client.get(Paths.any(path)), Service.Value::getConstantSet),
path -> Futures.transform(client.get(Paths.toAny(path)), Service.Value::getConstantSet),
result -> result.getConstantsCount() != 0);
}

Expand Down
2 changes: 1 addition & 1 deletion gapic/src/main/com/google/gapid/models/Devices.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void loadDevices() {
rpcController.start().listen(Futures.transformAsync(client.getDevices(), paths -> {
List<ListenableFuture<Service.Value>> results = Lists.newArrayList();
for (Path.Device path : paths) {
results.add(client.get(Paths.any(path)));
results.add(client.get(Paths.toAny(path)));
}
return Futures.allAsList(results);
}), new UiErrorCallback<List<Service.Value>, List<Device.Instance>, Void>(shell, LOG) {
Expand Down
8 changes: 2 additions & 6 deletions gapic/src/main/com/google/gapid/models/Follower.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.google.common.util.concurrent.ListenableFuture;
import com.google.gapid.proto.service.api.API;
import com.google.gapid.proto.service.path.Path;
import com.google.gapid.proto.service.path.Path.Any.PathCase;
import com.google.gapid.rpc.Rpc;
import com.google.gapid.rpc.RpcException;
import com.google.gapid.rpc.UiCallback;
Expand All @@ -37,15 +36,13 @@
import com.google.gapid.util.Flags.Flag;
import com.google.gapid.util.ObjectStore;
import com.google.gapid.util.Paths;

import org.eclipse.swt.widgets.Shell;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.eclipse.swt.widgets.Shell;

/**
* Model handling link following throughout the UI.
Expand Down Expand Up @@ -209,8 +206,7 @@ public void onFollow(Path.Any path) {
case FIELD:
case ARRAY_INDEX:
case MAP_INDEX:
if (Paths.contains(path, n ->
n.getPathCase() == PathCase.STATE || n.getPathCase() == PathCase.GLOBAL_STATE)) {
if (Paths.contains(path, n -> n instanceof Path.State || n instanceof Path.GlobalState)) {
listeners.fire().onStateFollowed(path);
} else {
LOG.log(WARNING, "Unknown follow path result: " + path);
Expand Down
Loading

0 comments on commit ef11f7f

Please sign in to comment.