• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

WindhoverLabs / phoebus / #77

03 Sep 2023 05:01PM UTC coverage: 16.544% (-0.02%) from 16.566%
#77

push

web-flow
Merge pull request #87 from WindhoverLabs/param_export

Param export

50 of 50 new or added lines in 3 files covered. (100.0%)

17740 of 107229 relevant lines covered (16.54%)

0.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.48
/core/commander-core/src/main/java/com/windhoverlabs/yamcs/core/YamcsObjectManager.java
1
package com.windhoverlabs.yamcs.core;
2

3
import com.windhoverlabs.pv.yamcs.YamcsAware;
4
import com.windhoverlabs.pv.yamcs.YamcsAware.YamcsAwareMethod;
5
import java.util.ArrayList;
6
import java.util.logging.Logger;
7
import javafx.collections.FXCollections;
8
import javafx.collections.ObservableList;
9

10
/**
11
 * Very simple class which manages YamcsObjects. Users of commander-core should always use this
12
 * class to access YamcsObject objects via the getRoot() method.
13
 *
14
 * @author lgomez
15
 */
16
public final class YamcsObjectManager {
17

18
  /** Logger for all file browser code */
19
  public static final Logger log = Logger.getLogger(YamcsObjectManager.class.getPackageName());
1✔
20

21
  private static YamcsObject<YamcsServer> root;
22
  private static ObservableList<YamcsServer> servers = FXCollections.observableArrayList();
1✔
23

24
  // At the moment we do not support setting a default server directly by the outside
25
  private static YamcsServer defaultServer = null;
1✔
26

27
  private static ArrayList<YamcsAware> listeners = new ArrayList<YamcsAware>();
1✔
28

29
  // TODO:When doing integration testing(specifically Connections App), refactor this
30
  // such that third parameter is removed.
31
  public static void setConnectionObjForServer(
32
      YamcsServerConnection newConnection, String oldServerName, String newServerName) {
33
    getServerFromName(oldServerName).setConnection(newConnection);
1✔
34
    if (defaultServerName != null && defaultServerName.equals(oldServerName)) {
1✔
35
      defaultServerName = newServerName;
1✔
36
    }
37
  }
1✔
38

39
  private static CMDR_YamcsInstance defaultInstance = null;
1✔
40
  private static String defaultInstanceName = null;
1✔
41
  private static String defaultServerName = null;
1✔
42

43
  public static String getDefaultServerName() {
44
    return defaultServerName;
1✔
45
  }
46

47
  public static String getDefaultInstanceName() {
48
    return defaultInstanceName;
1✔
49
  }
50

51
  public static YamcsServer getDefaultServer() {
52
    return defaultServer;
1✔
53
  }
54

55
  public static CMDR_YamcsInstance getDefaultInstance() {
56
    return defaultInstance;
1✔
57
  }
58

59
  public static void setDefaultInstance(String server, String instance) {
60
    defaultServer = getServerFromName(server);
1✔
61
    if (defaultServer == null) {
1✔
62
      log.warning("Server " + "\"" + server + "\" not found");
1✔
63
      return;
1✔
64
    }
65

66
    for (YamcsServer s : root.getItems()) {
1✔
67
      s.setDefaultInstance(null);
1✔
68
    }
1✔
69
    defaultInstanceName = instance;
1✔
70
    defaultServerName = server;
1✔
71
    defaultInstance = getServerFromName(server).getInstance(instance);
1✔
72
    if (defaultInstance == null) {
1✔
73
      log.warning("Should not happen: Instance " + "\"" + instance + "\" not found");
1✔
74
      return;
1✔
75
    }
76
    defaultServer.setDefaultInstance(defaultInstanceName);
1✔
77

78
    if (defaultInstance != null) {
1✔
79
      for (YamcsAware listener : listeners) {
1✔
80
        listener.changeDefaultInstance();
1✔
81
      }
1✔
82
    }
83
  }
1✔
84

85
  private YamcsObjectManager() {}
86

87
  public static YamcsObject<YamcsServer> getRoot() {
88
    return root;
1✔
89
  }
90

91
  static {
92
    root =
1✔
93
        new YamcsObject<YamcsServer>("") {
1✔
94

95
          @Override
96
          public String getObjectType() {
97
            return "root";
1✔
98
          }
99

100
          @Override
101
          public ObservableList<YamcsServer> getItems() {
102
            return servers;
1✔
103
          }
104

105
          @Override
106
          public void createAndAddChild(String name) {
107
            YamcsServer newServer = new YamcsServer(name);
1✔
108
            try {
109
              for (YamcsAware l : listeners) {
1✔
110
                newServer.addListener(l);
1✔
111
              }
1✔
112
            } catch (Exception e) {
×
113
              // TODO Auto-generated catch block
114
              e.printStackTrace();
×
115
            }
1✔
116
            getItems().add(newServer);
1✔
117
          }
1✔
118
        };
119
  }
1✔
120

121
  public static void addYamcsListener(YamcsAware newListener) {
122
    log.info("addYamcsListener on YamcsServer");
1✔
123
    listeners.add(newListener);
1✔
124
    if (defaultInstance != null) {
1✔
125
      newListener.changeDefaultInstance();
1✔
126
    }
127
    //  for (YamcsServer s : YamcsObjectManager.getRoot().getItems()) {
128
    //  s.addListener(yamcsListener);
129
    // }
130
  }
1✔
131

132
  /**
133
   * Traverse through allServers and find the server object that matches name
134
   *
135
   * @param name Name of the user-defined server.
136
   * @return The object with the server name.
137
   */
138
  public static YamcsServer getServerFromName(String name) {
139
    YamcsServer outServer = null;
1✔
140
    for (YamcsObject<?> server : root.getItems()) {
1✔
141
      if (server.getName().equals(name)) {
1✔
142
        outServer = (YamcsServer) server;
1✔
143
      }
144
    }
1✔
145
    return outServer;
1✔
146
  }
147

148
  /**
149
   * Traverse through allServers and find the instance object that matches pathToInstance
150
   *
151
   * @param serverName Name of the user-defined server. "Server_A:yamcs-cfs"
152
   * @return The object with the server name.
153
   */
154
  public static CMDR_YamcsInstance getInstanceFromName(String serverName, String instanceName) {
155
    CMDR_YamcsInstance outServer = null;
1✔
156
    for (YamcsObject<?> server : root.getItems()) {
1✔
157
      if (server.getName().equals(serverName)) {
1✔
158
        outServer = ((YamcsServer) server).getInstance(instanceName);
1✔
159
      }
160
    }
1✔
161
    return outServer;
1✔
162
  }
163

164
  static void triggreYamcsListeners(YamcsAwareMethod m) {
165
    for (YamcsAware l : listeners) {
1✔
166
      switch (m) {
×
167
        case onYamcsDisconnected:
168
          {
169
            l.onYamcsDisconnected();
×
170
          }
171
      }
172
    }
×
173
  }
1✔
174

175
  public static void removeListener(YamcsAware l) {
176
    listeners.remove(l);
×
177
  }
×
178

179
  public static void switchProcessor(String processorName) {
180
    if (defaultInstance != null) {
×
181
      for (YamcsAware listener : listeners) {
×
182
        getDefaultInstance()
×
183
            .switchProcessor(
×
184
                getDefaultServer().getYamcsClient(), getDefaultServer().getName(), processorName);
×
185
        listener.changeProcessor(getDefaultInstance().getName(), processorName);
×
186
      }
×
187
    }
188
  }
×
189
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc