Skip to content

Commit

Permalink
Merge pull request #81 from WindhoverLabs/select_processor
Browse files Browse the repository at this point in the history
Select processor
  • Loading branch information
lorenzo-gomez-windhover authored Jul 21, 2023
2 parents bac8306 + 930f551 commit ea6fac6
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,7 @@ The following table has all the yamcs versions that have been _tested_, along wi
| `0.1.1` | `5.6.0` `5.6.2`|
| `0.2.2` | `yamcs-5.7.9-whl-rc2`|

## Processors


![Switch Processor](images/current_processor_phoebus.png "Switch Processor")
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Messages {
public static String MenuPath;
public static String RemoveConnection;
public static String SetDefault;
public static String SwitchProcessor;
// ---
// --- Keep alphabetically sorted and 'in sync' with messages.properties!
// ---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.windhoverlabs.pv.yamcs.YamcsAware;
import com.windhoverlabs.yamcs.core.CMDR_YamcsInstance;
import com.windhoverlabs.yamcs.core.CMDR_YamcsInstanceState;
import com.windhoverlabs.yamcs.core.ConnectionState;
import com.windhoverlabs.yamcs.core.YamcsObject;
import com.windhoverlabs.yamcs.core.YamcsObjectManager;
Expand All @@ -18,6 +19,7 @@
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.Tooltip;
Expand All @@ -38,6 +40,8 @@ public class Tree {
// TODO: Move this root handling to another model class. This would make it easier to decouple
private YamcsObject<?> root;

private Menu switchProcessor;

@FXML
public void initialize() {
treeView.setId("ConnectionsTreeView");
Expand Down Expand Up @@ -270,6 +274,8 @@ public Boolean call(YamcsServerConnection connection) {
}
});

switchProcessor = new Menu(Messages.SwitchProcessor);

// add menu items to menu
contextMenu.getItems().add(addServer);
contextMenu.getItems().add(removeServer);
Expand All @@ -280,6 +286,7 @@ public Boolean call(YamcsServerConnection connection) {
contextMenu.getItems().add(disconnectServer);
contextMenu.getItems().add(setAsDefault);
contextMenu.getItems().add(editServer);
contextMenu.getItems().add(switchProcessor);

// setContextMenu to label
treeView.setContextMenu(contextMenu);
Expand All @@ -300,6 +307,7 @@ public Boolean call(YamcsServerConnection connection) {
editServer.setDisable(true);
connectAllServers.setDisable(true);
disconnectAllServers.setDisable(true);
switchProcessor.setDisable(false);

} else {
YamcsObject<?> selectedObject = selectedItem.getValue();
Expand Down Expand Up @@ -332,6 +340,7 @@ public Boolean call(YamcsServerConnection connection) {
editServer.setDisable(true);
}
setAsDefault.setDisable(true);
switchProcessor.setDisable(true);
} else if (selectedObject.getObjectType() == CMDR_YamcsInstance.OBJECT_TYPE) {
/* This is a instance node. */
addServer.setDisable(true);
Expand All @@ -344,8 +353,10 @@ public Boolean call(YamcsServerConnection connection) {
if (YamcsObjectManager.getDefaultInstance() != null
&& YamcsObjectManager.getDefaultInstance().equals(selectedObject)) {
setAsDefault.setDisable(true);
switchProcessor.setDisable(false);
} else {
setAsDefault.setDisable(false);
switchProcessor.setDisable(true);
}

editServer.setDisable(true);
Expand All @@ -359,8 +370,25 @@ public Boolean call(YamcsServerConnection connection) {
disconnectServer.setDisable(false);
setAsDefault.setDisable(false);
editServer.setDisable(false);
switchProcessor.setDisable(true);
}
}
if (YamcsObjectManager.getDefaultInstance() != null
&& YamcsObjectManager.getDefaultInstance().getInstanceState()
== CMDR_YamcsInstanceState.ACTIVATED) {
switchProcessor.getItems().clear();
YamcsObjectManager.getDefaultInstance()
.getProcessors(YamcsObjectManager.getDefaultServer().getYamcsClient())
.forEach(
pName -> {
MenuItem processor = new MenuItem(pName);
processor.setOnAction(
event -> {
YamcsObjectManager.switchProcessor(pName);
});
switchProcessor.getItems().add(processor);
});
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ EditConnection=Edit
MenuPath=Yamcs
RemoveConnection=Remove Connection
SetDefault=Set As Default
SwitchProcessor=Switch Processor
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ public void onYamcsDisconnected() {
e.printStackTrace();
}
}

public void changeProcessor(String instance, String processor) {
try {
notifyListenersOfDisconnect();
// this.not
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};

YamcsObjectManager.addYamcsListener(yamcsListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class YamcsSubscriptionService implements YamcsAware, ParameterSubscripti
private static final Logger log = Logger.getLogger(YamcsSubscriptionService.class.getName());

private String instanceName;
private String currentProcessor;

private Map<NamedObjectId, Set<YamcsPV>> pvsById = new LinkedHashMap<>();

Expand All @@ -74,10 +75,14 @@ public ParameterSubscription getSubscription() {
static final Alarm UDF = Alarm.of(AlarmSeverity.UNDEFINED, AlarmStatus.UNDEFINED, "UDF");

public YamcsSubscriptionService(
ParameterSubscription newSubscriprion, String newServerName, String newInstanceName) {
ParameterSubscription newSubscriprion,
String newServerName,
String newInstanceName,
String processor) {
serverName = newServerName;
subscription = newSubscriprion;
instanceName = newInstanceName;
currentProcessor = processor;
subscription.addListener(this);

// Periodically check if the subscription needs a refresh
Expand All @@ -95,6 +100,7 @@ public YamcsSubscriptionService(
.setAbortOnInvalid(false)
.setUpdateOnExpiration(true)
.addAllId(ids)
.setProcessor(currentProcessor)
.build());
}
},
Expand Down Expand Up @@ -128,11 +134,13 @@ private String getYamcsPvName(String pvName, String serverName) {

@Override
public void changeProcessor(String instance, String processor) {
currentProcessor = processor;
executor.execute(
() -> {
// Ready to receive some data
Set<NamedObjectId> ids = getRequestedIdentifiers();
log.fine(String.format("Subscribing to %s [%s/%s]", ids, instance, processor));
// log.fine(String.format("Subscribing to %s [%s/%s]", ids, instance,
// processor));
subscription.sendMessage(
SubscribeParametersRequest.newBuilder()
.setInstance(instance)
Expand Down Expand Up @@ -162,7 +170,7 @@ public void register(YamcsPV pv) {
subscription.sendMessage(
SubscribeParametersRequest.newBuilder()
.setInstance(instanceName)
.setProcessor("realtime")
.setProcessor(currentProcessor)
.setSendFromCache(true)
.setAbortOnInvalid(false)
.setUpdateOnExpiration(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.windhoverlabs.pv.yamcs.YamcsPV;
import com.windhoverlabs.pv.yamcs.YamcsSubscriptionService;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.ExecutionException;
import java.util.logging.Logger;
Expand All @@ -27,6 +28,10 @@ public class CMDR_YamcsInstance extends YamcsObject<YamcsObject<?>> {
private ArchiveClient yamcsArchiveClient;
private CMDR_YamcsInstanceState instanceState;

public CMDR_YamcsInstanceState getInstanceState() {
return instanceState;
}

// Make this class generic?
public class CommandOption {
private String id;
Expand Down Expand Up @@ -100,12 +105,14 @@ public String getObjectType() {

protected void initProcessorClient(YamcsClient yamcsClient) {
yamcsProcessor = yamcsClient.createProcessorClient(getName(), "realtime");
// yamcsClient.listProcessors(OBJECT_TYPE)
}

protected void initYamcsSubscriptionService(YamcsClient yamcsClient, String serverName) {
protected void initYamcsSubscriptionService(
YamcsClient yamcsClient, String serverName, String procesor) {
paramSubscriptionService =
new YamcsSubscriptionService(
yamcsClient.createParameterSubscription(), serverName, this.getName());
yamcsClient.createParameterSubscription(), serverName, this.getName(), procesor);
}

protected void initEventSubscription(YamcsClient yamcsClient, String serverName) {
Expand Down Expand Up @@ -144,7 +151,7 @@ protected void initEventSubscription(YamcsClient yamcsClient, String serverName)
// TODO:This shoud return whether or not the instance activated successfully.
public void activate(YamcsClient yamcsClient, String serverName) {
initProcessorClient(yamcsClient);
initYamcsSubscriptionService(yamcsClient, serverName);
initYamcsSubscriptionService(yamcsClient, serverName, "realtime");
initEventSubscription(yamcsClient, serverName);

try {
Expand Down Expand Up @@ -203,4 +210,29 @@ public void publishEvent(String message, YamcsClient yamcsClient) {
.setSource("Commander")
.build());
}

public ArrayList<String> getProcessors(YamcsClient yamcsClient) {

ArrayList<String> processors = new ArrayList<String>();
try {
yamcsClient
.listProcessors(getName())
.get()
.forEach(
p -> {
processors.add(p.getName());
});
} catch (InterruptedException | ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return processors;
}

public void switchProcessor(YamcsClient yamcsClient, String serverName, String processorName) {
// This seems redundant....
paramSubscriptionService.destroy();
initYamcsSubscriptionService(yamcsClient, serverName, processorName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,15 @@ static void triggreYamcsListeners(YamcsAwareMethod m) {
public static void removeListener(YamcsAware l) {
listeners.remove(l);
}

public static void switchProcessor(String processorName) {
if (defaultInstance != null) {
for (YamcsAware listener : listeners) {
getDefaultInstance()
.switchProcessor(
getDefaultServer().getYamcsClient(), getDefaultServer().getName(), processorName);
listener.changeProcessor(getDefaultInstance().getName(), processorName);
}
}
}
}
Binary file added images/current_processor_phoebus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ea6fac6

Please sign in to comment.