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

WindhoverLabs / phoebus / #94

18 Oct 2023 08:23PM UTC coverage: 16.596% (+0.05%) from 16.544%
#94

Pull #90

lorenzo-gomez-windhover
-Remove app-commander-parameter-export from build.
Pull Request #90: WIP - 88 out of memory issues

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

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

83.72
/core/commander-core/src/main/java/com/windhoverlabs/yamcs/core/YamcsWebSocketClient.java
1
/*
2
 * Copyright 2014 The Netty Project
3
 *
4
 * The Netty Project licenses this file to you under the Apache License,
5
 * version 2.0 (the "License"); you may not use this file except in compliance
6
 * with the License. You may obtain a copy of the License at:
7
 *
8
 *   https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
 * License for the specific language governing permissions and limitations
14
 * under the License.
15
 */
16
package com.windhoverlabs.yamcs.core;
17

18
import com.google.gson.Gson;
19
import java.net.URI;
20
import java.net.URISyntaxException;
21
import java.util.ArrayList;
22
import java.util.function.Consumer;
23
import org.java_websocket.client.WebSocketClient;
24
import org.java_websocket.handshake.ServerHandshake;
25

26
/**
27
 * This is an example of a WebSocket client.
28
 *
29
 * <p>In order to run this example you need a compatible WebSocket server. Therefore you can either
30
 * start the WebSocket server from the examples by running {@link
31
 * io.netty.example.http.websocketx.server.WebSocketServer} or connect to an existing WebSocket
32
 * server such as <a href="https://www.websocket.org/echo.html">ws://echo.websocket.org</a>.
33
 *
34
 * <p>The client will attempt to connect to the URI passed to it as the first argument. You don't
35
 * have to specify any arguments if you want to connect to the example WebSocket server, as this is
36
 * the default.
37
 */
38
public class YamcsWebSocketClient {
39

40
  class YamcsMessage {
41
    public String type;
42
    public SubscribeTMStatisticsRequest options;
43

44
    public YamcsMessage(String type, SubscribeTMStatisticsRequest options) {
1✔
45
      this.type = type;
1✔
46
      this.options = options;
1✔
47
    }
1✔
48
  }
49

50
  class SubscribeTMStatisticsRequest {
51
    String instance;
52
    String processor;
53

54
    public SubscribeTMStatisticsRequest(String instance, String processor) {
1✔
55
      this.instance = instance;
1✔
56
      this.processor = processor;
1✔
57
    }
1✔
58
  }
59

60
  public class TmStatistics {
×
61

62
    // Packet name.
63
    public String packetName;
64
    public String qualifiedName;
65
    public String receivedPackets; // String decimal
66
    public String subscribedParameterCount;
67
    public String lastReceived; // RFC 3339 timestamp
68
    public String lastPacketTime; // RFC 3339 timestamp
69
    public String packetRate; // String decimal
70
    public String dataRate; // String decimal
71
  }
72

73
  class Statistics {
×
74
    // Yamcs instance name.
75
    String instance;
76

77
    // Processor name.
78
    String processor;
79
    ArrayList<TmStatistics> tmstats;
80
    String lastUpdated; // RFC 3339 timestamp
81
  }
82

83
  class StatisticsMessage {
×
84
    String type;
85
    int call;
86
    int seq;
87
    Statistics data;
88
  }
89

90
  private WebSocketClient mWs;
91
  private Consumer<ArrayList<TmStatistics>> statsConsumer;
92
  private String instance;
93
  private String processor;
94

95
  public YamcsWebSocketClient(
96
      Consumer<ArrayList<TmStatistics>> consumer,
97
      String address,
98
      int port,
99
      String instance,
100
      String processor) {
1✔
101
    this.statsConsumer = consumer;
1✔
102
    this.instance = instance;
1✔
103
    this.processor = processor;
1✔
104
    try {
105
      mWs =
1✔
106
          new WebSocketClient(
107
              new URI("ws://" + address + ":" + Integer.toString(port) + "/api/websocket")) {
1✔
108
            @Override
109
            public void onMessage(String message) {
110
              Gson obj = new Gson();
1✔
111
              StatisticsMessage stats = obj.fromJson(message, StatisticsMessage.class);
1✔
112
              statsConsumer.accept(stats.data.tmstats);
1✔
113
            }
1✔
114

115
            @Override
116
            public void onOpen(ServerHandshake handshake) {
117
              System.out.println("opened connection");
1✔
118
              Gson obj = new Gson();
1✔
119
              subscribeTMStatistics(instance, processor, obj);
1✔
120
            }
1✔
121

122
            @Override
123
            public void onClose(int code, String reason, boolean remote) {
124
              System.out.println("closed connection:" + reason);
1✔
125
              System.out.println("closed connection:" + code);
1✔
126
              System.out.println("closed connection:" + remote);
1✔
127
              //              mWs.reconnect();
128

129
            }
1✔
130

131
            @Override
132
            public void onError(Exception ex) {
133
              ex.printStackTrace();
×
134
            }
×
135
          };
136

137
      //     Disable timeout:
138
      // https://github.com/TooTallNate/Java-WebSocket/wiki/Lost-connection-detection
139
      mWs.setConnectionLostTimeout(0);
1✔
140

141
      mWs.connect();
1✔
142
    } catch (URISyntaxException e) {
×
143
      // TODO Auto-generated catch block
144
      e.printStackTrace();
×
145
    }
1✔
146
    // open websocket
147
  }
1✔
148

149
  private void subscribeTMStatistics(String instance, String processor, Gson obj) {
150
    //                  TODO:Create a map that maps the instance to the specific call id. This way we don't open a
151
    // connection for each instance...
152
    //                  This would be irrelevant if there was a stats subscription in the YamcsClient Java API.
153
    String message =
1✔
154
        obj.toJson(
1✔
155
            new YamcsMessage("tmstats", new SubscribeTMStatisticsRequest(instance, processor)));
156
    // send message
157
    mWs.send(message);
1✔
158
  }
1✔
159

160
  public void close() {
161
    mWs.close();
1✔
162
  }
1✔
163
}
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