
org.yamcs.sle.udpslebridge.FrameSources Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsle Show documentation
Show all versions of jsle Show documentation
Java implementation for the SLE (Space Link Extension) protocol.
package org.yamcs.sle.udpslebridge;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.yamcs.sle.provider.FrameSource;
/**
* Initializes and keeps a reference to all frame sources (e.g. UDP receiver or file reader).
*/
public class FrameSources {
Map sources = new HashMap<>();
static FrameSources instance;
public FrameSources(Properties properties) {
// load all sources
Collection ids = getIds(properties, "fsource");
for (String id : ids) {
String key = "fsource." + id + ".type";
String type = Util.getProperty(properties, key);
FrameSource fsource;
if ("udp".equals(type)) {
fsource = new UdpFrameSource(properties, id);
} else if ("file".equals(type)) {
fsource = new FileFrameSource(properties, id);
} else {
throw new ConfigurationException("Unknown frame source type '" + type + "'");
}
fsource.startup();
sources.put(id, fsource);
}
}
static public FrameSource getSource(String id) {
return instance.sources.get(id);
}
public static void init(Properties properties) {
instance = new FrameSources(properties);
}
public FrameSources getInstance() {
return instance;
}
/**
* return a set of ids from all the properties of type prefix.id.xyz
*/
static Collection getIds(Properties props, String prefix) {
Set r = new HashSet<>();
for (Object k : props.keySet()) {
String[] a = ((String) k).split("\\.");
if (a.length > 2 && prefix.equals(a[0])) {
r.add(a[1]);
}
}
return r;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy