FDAQ is now configurable
This commit is contained in:
2014-01-22 13:29:07 +01:00
parent 10072d2c85
commit 7ba589feba
4 changed files with 89 additions and 16 deletions
+11
View File
@@ -25,6 +25,17 @@ This will take the default connections settings:
* Kill Port: 2234
* Number Of Elements: Integer.MAX_VALUE/2
If you need to specify different settings create a property files with following content:
```
ch.psi.fda.fdaq.hostname=myhost
ch.psi.fda.fdaq.port=1234
ch.psi.fda.fdaq.killPort=4321
```
Use `-Dch.psi.fda.fdaq.config=<file>` to use this property file as base configuration.
# Development
A standalone jar can be build via `mvn clean compile assembly:single`.
@@ -0,0 +1,62 @@
/**
*
* Copyright 2014 Paul Scherrer Institute. All rights reserved.
*
* This code is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This code is distributed in the hope that it will be useful, but without any
* warranty; without even the implied warranty of merchantability or fitness for
* a particular purpose. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <http://www.gnu.org/licenses/>.
*
*/
package ch.psi.fda.fdaq;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
public class FdaqConfiguration {
private String hostname = "mchip015.psi.ch";
private int port = 2233;
private int killPort = 2234;
public void loadFile(File file) {
Properties properties = new Properties();
try {
properties.load(new FileReader(file));
} catch (IOException e) {
throw new RuntimeException("Cannot read file "+file, e);
}
hostname = properties.getProperty(FdaqConfiguration.class.getPackage().getName()+".hostname", hostname);
port = Integer.parseInt(properties.getProperty(FdaqConfiguration.class.getPackage().getName()+".port", port+""));
killPort = Integer.parseInt(properties.getProperty(FdaqConfiguration.class.getPackage().getName()+".killPort", killPort+""));
}
public String getHostname() {
return hostname;
}
public void setHostname(String hostname) {
this.hostname = hostname;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public int getKillPort() {
return killPort;
}
public void setKillPort(int killPort) {
this.killPort = killPort;
}
}
@@ -31,6 +31,8 @@ import com.google.common.eventbus.EventBus;
@SuppressWarnings("restriction")
public class FdaqMain {
public final static String FDAQ_CONFIG = "ch.psi.fda.fdaq.config";
public static void main(String[] args) {
if(args.length != 1){
@@ -40,9 +42,16 @@ public class FdaqMain {
File file = new File(args[1]);
FdaqConfiguration configuration = new FdaqConfiguration();
String config = System.getProperty(FDAQ_CONFIG);
if(config != null){
configuration.loadFile(new File(config));
}
EventBus bus = new AsyncEventBus(Executors.newSingleThreadExecutor());
final FdaqService fdaq = new FdaqService(bus);
final FdaqService fdaq = new FdaqService(bus, configuration);
Signal.handle(new Signal("INT"), new SignalHandler() {
int count = 0;
@@ -48,21 +48,12 @@ public class FdaqService {
private final EventBus bus;
private String hostname = "mchip015.psi.ch";
private int port = 2233;
private int killPort = 2234;
private int numberOfElements = Integer.MAX_VALUE;
private FdaqConfiguration configuration;
private final int numberOfElements = Integer.MAX_VALUE/2;
public FdaqService(EventBus bus){
public FdaqService(EventBus bus, FdaqConfiguration configuration){
this.bus = bus;
}
public FdaqService(EventBus bus, String hostname, int port, int killPort, int numberOfElements){
this.bus = bus;
this.hostname = hostname;
this.port = port;
this.killPort = killPort;
this.numberOfElements = numberOfElements;
this.configuration = configuration;
}
/**
@@ -84,7 +75,7 @@ public class FdaqService {
stopAcquisition = false;
echoSocket = new Socket(hostname, port);
echoSocket = new Socket(configuration.getHostname(), configuration.getPort());
out = new DataOutputStream(echoSocket.getOutputStream());
in = new DataInputStream(echoSocket.getInputStream());
@@ -178,7 +169,7 @@ public class FdaqService {
try {
running=false;
stopAcquisition = true;
Socket echoSocket = new Socket(hostname, killPort);
Socket echoSocket = new Socket(configuration.getHostname(), configuration.getKillPort());
DataOutputStream out = new DataOutputStream(echoSocket.getOutputStream());
ByteBuffer bytebuffer = ByteBuffer.allocate(1 * 4); // 2