corefx got throughput working using grpc, removed unused session nodes menu option

This commit is contained in:
Blake J. Harnden 2019-05-31 16:06:24 -07:00
parent 4c1d7bfb22
commit b075181796
5 changed files with 49 additions and 14 deletions

View file

@ -400,11 +400,6 @@ public class Controller implements Initializable {
} }
} }
@FXML
private void onSessionNodesMenu(ActionEvent event) {
}
@FXML @FXML
private void onSessionHooksMenu(ActionEvent event) { private void onSessionHooksMenu(ActionEvent event) {
hooksDialog.showDialog(); hooksDialog.showDialog();
@ -505,7 +500,7 @@ public class Controller implements Initializable {
@Override @Override
protected Boolean call() throws Exception { protected Boolean call() throws Exception {
if (throughputMenuItem.isSelected()) { if (throughputMenuItem.isSelected()) {
return coreClient.startThroughput(); return coreClient.startThroughput(Controller.this);
} else { } else {
return coreClient.stopThroughput(); return coreClient.stopThroughput();
} }

View file

@ -19,7 +19,7 @@ public interface ICoreClient {
Integer currentSession(); Integer currentSession();
boolean startThroughput() throws IOException; boolean startThroughput(Controller controller) throws IOException;
boolean stopThroughput() throws IOException; boolean stopThroughput() throws IOException;

View file

@ -7,6 +7,7 @@ import com.core.client.rest.WlanConfig;
import com.core.data.*; import com.core.data.*;
import com.core.ui.dialogs.MobilityPlayerDialog; import com.core.ui.dialogs.MobilityPlayerDialog;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import io.grpc.Context;
import io.grpc.ManagedChannel; import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder; import io.grpc.ManagedChannelBuilder;
import io.grpc.StatusRuntimeException; import io.grpc.StatusRuntimeException;
@ -31,6 +32,7 @@ public class CoreGrpcClient implements ICoreClient {
private ManagedChannel channel; private ManagedChannel channel;
private final ExecutorService executorService = Executors.newFixedThreadPool(6); private final ExecutorService executorService = Executors.newFixedThreadPool(6);
private boolean handlingEvents = false; private boolean handlingEvents = false;
private boolean handlingThroughputs = false;
private CoreProto.Node nodeToProto(CoreNode node) { private CoreProto.Node nodeToProto(CoreNode node) {
CoreProto.Position position = CoreProto.Position.newBuilder() CoreProto.Position position = CoreProto.Position.newBuilder()
@ -226,15 +228,54 @@ public class CoreGrpcClient implements ICoreClient {
} }
@Override @Override
public boolean startThroughput() throws IOException { public boolean startThroughput(Controller controller) throws IOException {
// TODO: convert throughput CoreProto.ThroughputsRequest request = CoreProto.ThroughputsRequest.newBuilder().build();
return false; try {
handlingThroughputs = true;
executorService.submit(() -> {
Context.CancellableContext context = Context.current().withCancellation();
context.run(() -> {
try {
Iterator<CoreProto.ThroughputsEvent> iterator = blockingStub.throughputs(request);
while (handlingThroughputs) {
CoreProto.ThroughputsEvent event = iterator.next();
logger.info("handling throughputs: {}", event);
Throughputs throughputs = new Throughputs();
for (CoreProto.BridgeThroughput protoBridge : event.getBridgeThroughputsList()) {
BridgeThroughput bridge = new BridgeThroughput();
bridge.setNode(protoBridge.getNodeId());
bridge.setThroughput(protoBridge.getThroughput());
throughputs.getBridges().add(bridge);
}
for (CoreProto.InterfaceThroughput protoInterface : event.getInterfaceThroughputsList()) {
InterfaceThroughput interfaceThroughput = new InterfaceThroughput();
interfaceThroughput.setNode(protoInterface.getNodeId());
interfaceThroughput.setNodeInterface(protoInterface.getInterfaceId());
interfaceThroughput.setThroughput(protoInterface.getThroughput());
throughputs.getInterfaces().add(interfaceThroughput);
}
controller.handleThroughputs(throughputs);
}
logger.info("exiting handling throughputs");
} catch (StatusRuntimeException ex) {
logger.error("error handling session events", ex);
} finally {
context.cancel(null);
context.close();
}
});
});
return true;
} catch (StatusRuntimeException ex) {
throw new IOException("setup event handlers error", ex);
}
} }
@Override @Override
public boolean stopThroughput() throws IOException { public boolean stopThroughput() throws IOException {
// TODO: convert throughput logger.info("cancelling throughputs");
return false; handlingThroughputs = false;
return true;
} }
@Override @Override

View file

@ -149,7 +149,7 @@ public class CoreRestClient implements ICoreClient {
} }
@Override @Override
public boolean startThroughput() throws IOException { public boolean startThroughput(Controller controller) throws IOException {
String url = getUrl("throughput/start"); String url = getUrl("throughput/start");
return WebUtils.putJson(url); return WebUtils.putJson(url);
} }

View file

@ -35,7 +35,6 @@
</Menu> </Menu>
<Menu mnemonicParsing="false" text="Session"> <Menu mnemonicParsing="false" text="Session">
<items> <items>
<MenuItem mnemonicParsing="false" onAction="#onSessionNodesMenu" text="Nodes" />
<MenuItem mnemonicParsing="false" onAction="#onSessionHooksMenu" text="Hooks" /> <MenuItem mnemonicParsing="false" onAction="#onSessionHooksMenu" text="Hooks" />
<MenuItem mnemonicParsing="false" onAction="#onOptionsMenuLocation" text="Location" /> <MenuItem mnemonicParsing="false" onAction="#onOptionsMenuLocation" text="Location" />
<MenuItem mnemonicParsing="false" onAction="#onOptionsMenuBackground" text="Background" /> <MenuItem mnemonicParsing="false" onAction="#onOptionsMenuBackground" text="Background" />