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

WindhoverLabs / phoebus / #96

21 Nov 2023 04:15PM UTC coverage: 16.596% (+0.05%) from 16.544%
#96

push

web-flow
Merge pull request #90 from WindhoverLabs/88_out_of_memory_issues

WIP - 88 out of memory issues

97 of 217 new or added lines in 9 files covered. (44.7%)

4 existing lines in 3 files now uncovered.

17830 of 107434 relevant lines covered (16.6%)

0.17 hits per line

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

79.63
/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.beans.property.SimpleStringProperty;
8
import javafx.collections.FXCollections;
9
import javafx.collections.ObservableList;
10

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

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

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

26
  private static SimpleStringProperty managerStatus =
1✔
27
      new SimpleStringProperty("Connection Status: Disconnected");
28

29
  public static SimpleStringProperty getManagerStatus() {
NEW
30
    return managerStatus;
×
31
  }
32

33
  private static ArrayList<YamcsAware> listeners = new ArrayList<YamcsAware>();
1✔
34

35
  //  TODO: Really don't like this static block pattern. The proper way to do it is to add listeners
36
  // to the "servers" observable list.
37
  //  This will do, for now.
38

39
  static {
40
  }
41

42
  // At the moment we do not support setting a default server directly by the outside
43
  private static YamcsServer defaultServer = null;
1✔
44
  // TODO:When doing integration testing(specifically Connections App), refactor this
45
  // such that third parameter is removed.
46
  public static void setConnectionObjForServer(
47
      YamcsServerConnection newConnection, String oldServerName, String newServerName) {
48
    getServerFromName(oldServerName).setConnection(newConnection);
1✔
49
    if (defaultServerName != null && defaultServerName.equals(oldServerName)) {
1✔
50
      defaultServerName = newServerName;
1✔
51
    }
52
  }
1✔
53

54
  private static CMDR_YamcsInstance defaultInstance = null;
1✔
55
  private static String defaultInstanceName = null;
1✔
56
  private static String defaultServerName = null;
1✔
57

58
  public static String getDefaultServerName() {
59
    return defaultServerName;
1✔
60
  }
61

62
  public static String getDefaultInstanceName() {
63
    return defaultInstanceName;
1✔
64
  }
65

66
  public static YamcsServer getDefaultServer() {
67
    return defaultServer;
1✔
68
  }
69

70
  public static CMDR_YamcsInstance getDefaultInstance() {
71
    return defaultInstance;
1✔
72
  }
73

74
  public static void setDefaultInstance(String server, String instance) {
75
    defaultServer = getServerFromName(server);
1✔
76
    if (defaultServer == null) {
1✔
77
      log.warning("Server " + "\"" + server + "\" not found");
1✔
78
      return;
1✔
79
    }
80

81
    for (YamcsServer s : root.getItems()) {
1✔
82
      s.setDefaultInstance(null);
1✔
83
    }
1✔
84
    defaultInstanceName = instance;
1✔
85
    defaultServerName = server;
1✔
86
    defaultInstance = getServerFromName(server).getInstance(instance);
1✔
87
    if (defaultInstance == null) {
1✔
88
      log.warning("Should not happen: Instance " + "\"" + instance + "\" not found");
1✔
89
      return;
1✔
90
    }
91
    defaultServer.setDefaultInstance(defaultInstanceName);
1✔
92

93
    if (defaultInstance != null) {
1✔
94
      for (YamcsAware listener : listeners) {
1✔
95
        listener.changeDefaultInstance();
1✔
96
      }
1✔
97
    }
98
  }
1✔
99

100
  private YamcsObjectManager() {
101

102
    //    addYamcsListener(listener);
103
  }
104

105
  public static YamcsObject<YamcsServer> getRoot() {
106
    return root;
1✔
107
  }
108

109
  static {
110
    YamcsAware managerListener =
1✔
111
        new YamcsAware() {
1✔
112
          /**
113
           * TODO:At the moment onYamcsConnected is not being called changeDefaultInstance is
114
           * driving the listeners for now.
115
           */
116
          public void onYamcsConnected() {
117
            if (!anyServerConnected()) {
1✔
118
              managerStatus.set("Connection Status: Connected");
1✔
119
            }
120
          }
1✔
121

122
          public void onYamcsDisconnected() {
NEW
123
            if (!anyServerConnected()) {
×
NEW
124
              managerStatus.set("Connection Status: Disconnected");
×
125
            }
NEW
126
          }
×
127

128
          public void changeDefaultInstance() {
129
            if (anyServerConnected()) {
1✔
NEW
130
              managerStatus.set("Connection Status: Connected");
×
131
              //                    TODO:Keep this simple for now, need to think about this logic a bit
132
              // more.
133
              //              managerStatus.set(
134
              //                  "Connection Status: Connected. Default Server: \""
135
              //                      + getDefaultServerName()
136
              //                      + "\""
137
              //                      + ". Default set to "
138
              //                      + "\""
139
              //                      + getDefaultInstanceName()
140
              //                      + "\"");
141
            }
142
          }
1✔
143

144
          public void onInstancesReady(YamcsServer s) {
NEW
145
            managerStatus.set("Connection Status: Connected to \"" + s.getName() + "\"");
×
NEW
146
          }
×
147
        };
148
    listeners.add(managerListener);
1✔
149
    root =
1✔
150
        new YamcsObject<YamcsServer>("") {
1✔
151

152
          @Override
153
          public String getObjectType() {
154
            return "root";
1✔
155
          }
156

157
          @Override
158
          public ObservableList<YamcsServer> getItems() {
159
            return servers;
1✔
160
          }
161

162
          @Override
163
          public void createAndAddChild(String name) {
164
            YamcsServer newServer = new YamcsServer(name);
1✔
165
            try {
166
              for (YamcsAware l : listeners) {
1✔
167
                newServer.addListener(l);
1✔
168
              }
1✔
169
            } catch (Exception e) {
×
170
              // TODO Auto-generated catch block
171
              e.printStackTrace();
×
172
            }
1✔
173
            getItems().add(newServer);
1✔
174
          }
1✔
175
        };
176
  }
1✔
177

178
  public static void addYamcsListener(YamcsAware newListener) {
179
    log.info("addYamcsListener on YamcsServer");
1✔
180
    listeners.add(newListener);
1✔
181
    if (defaultInstance != null) {
1✔
182
      newListener.changeDefaultInstance();
1✔
183
    }
184
    //  for (YamcsServer s : YamcsObjectManager.getRoot().getItems()) {
185
    //  s.addListener(yamcsListener);
186
    // }
187
  }
1✔
188

189
  /**
190
   * Traverse through allServers and find the server object that matches name
191
   *
192
   * @param name Name of the user-defined server.
193
   * @return The object with the server name.
194
   */
195
  public static YamcsServer getServerFromName(String name) {
196
    YamcsServer outServer = null;
1✔
197
    for (YamcsObject<?> server : root.getItems()) {
1✔
198
      if (server.getName().equals(name)) {
1✔
199
        outServer = (YamcsServer) server;
1✔
200
      }
201
    }
1✔
202
    return outServer;
1✔
203
  }
204

205
  /**
206
   * Traverse through allServers and find the instance object that matches pathToInstance
207
   *
208
   * @param serverName Name of the user-defined server. "Server_A:yamcs-cfs"
209
   * @return The object with the server name.
210
   */
211
  public static CMDR_YamcsInstance getInstanceFromName(String serverName, String instanceName) {
212
    CMDR_YamcsInstance outServer = null;
1✔
213
    for (YamcsObject<?> server : root.getItems()) {
1✔
214
      if (server.getName().equals(serverName)) {
1✔
215
        outServer = ((YamcsServer) server).getInstance(instanceName);
1✔
216
      }
217
    }
1✔
218
    return outServer;
1✔
219
  }
220
  //  TODO:Right now there are several ways to "trigger" these events. I think this function should
221
  // become the only and default way
222
  //  to avoid redundant code paths that maintenance more difficult and makes code harder to follow.
223
  static void triggerYamcsListeners(YamcsAwareMethod m) {
224
    for (YamcsAware l : listeners) {
1✔
225
      switch (m) {
1✔
226
        case onYamcsDisconnected:
227
          {
228
            l.onYamcsDisconnected();
×
229
          }
NEW
230
          break;
×
231
        case changeDefaultInstance:
232
          l.changeDefaultInstance();
1✔
233
          ;
234
          break;
1✔
235
        case onYamcsConnected:
236
          {
237
            l.onYamcsConnected();
1✔
238
          }
239
          break;
1✔
240
        default:
241
          break;
242
      }
243
    }
1✔
244
  }
1✔
245

246
  public static void removeListener(YamcsAware l) {
247
    listeners.remove(l);
×
248
  }
×
249

250
  public static void switchProcessor(String processorName) {
251
    if (defaultInstance != null) {
×
252
      for (YamcsAware listener : listeners) {
×
253
        getDefaultInstance()
×
254
            .switchProcessor(
×
255
                getDefaultServer().getYamcsClient(), getDefaultServer().getName(), processorName);
×
256
        listener.changeProcessor(getDefaultInstance().getName(), processorName);
×
257
      }
×
258
    }
259
  }
×
260

261
  private static boolean anyServerConnected() {
262
    boolean isConnected = false;
1✔
263
    for (var s : servers) {
1✔
264
      if (s.getServerState() == ConnectionState.CONNECTED) {
1✔
NEW
265
        isConnected = true;
×
266
      }
267
    }
1✔
268

269
    return isConnected;
1✔
270
  }
271
}
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