FDA-1
Improved rest server
This commit is contained in:
@@ -42,8 +42,8 @@ public class AcquisitionEngine {
|
||||
private static final Logger logger = Logger.getLogger(AcquisitionEngine.class.getName());
|
||||
|
||||
private AcquisitionConfiguration config;
|
||||
private ChannelService cservice;
|
||||
private final ZMQDataService dservice;
|
||||
private ChannelService cService;
|
||||
private final ZMQDataService zmqService;
|
||||
|
||||
/**
|
||||
* Variable holding the current acquisition
|
||||
@@ -57,9 +57,9 @@ public class AcquisitionEngine {
|
||||
private BlockingQueue<ExecutionRequest> requests = new LinkedBlockingQueue<>();
|
||||
|
||||
@Inject
|
||||
public AcquisitionEngine(ChannelService cservice, ZMQDataService dservice, AcquisitionConfiguration config) {
|
||||
this.dservice = dservice;
|
||||
this.cservice = cservice;
|
||||
public AcquisitionEngine(ChannelService cService, ZMQDataService zmqService, AcquisitionConfiguration config) {
|
||||
this.zmqService = zmqService;
|
||||
this.cService = cService;
|
||||
this.config = config;
|
||||
|
||||
// Start main execution loop
|
||||
@@ -76,11 +76,11 @@ public class AcquisitionEngine {
|
||||
|
||||
EventBus ebus = new EventBus();
|
||||
// Provide tracking id to data service and register the service to the event bus
|
||||
AcquisitionEngine.this.dservice.setTrackingId(r.getTrackingId());
|
||||
ebus.register(AcquisitionEngine.this.dservice);
|
||||
AcquisitionEngine.this.zmqService.setTrackingId(r.getTrackingId());
|
||||
ebus.register(AcquisitionEngine.this.zmqService);
|
||||
|
||||
synchronized (AcquisitionEngine.this) { // synchronize access to acquisition object via the AcquisitionEngine object
|
||||
acquisition = new Acquisition(AcquisitionEngine.this.cservice, AcquisitionEngine.this.config);
|
||||
acquisition = new Acquisition(AcquisitionEngine.this.cService, AcquisitionEngine.this.config);
|
||||
currentRequest = r;
|
||||
}
|
||||
acquisition.initalize(ebus, r.getConfiguration());
|
||||
@@ -88,7 +88,7 @@ public class AcquisitionEngine {
|
||||
logger.info("" + r.getTrackingId() + " done");
|
||||
|
||||
// Cleanup
|
||||
ebus.unregister(AcquisitionEngine.this.dservice);
|
||||
ebus.unregister(AcquisitionEngine.this.zmqService);
|
||||
} finally {
|
||||
acquisition.destroy();
|
||||
|
||||
|
||||
@@ -28,12 +28,13 @@ public class RestServer {
|
||||
|
||||
public static void main(String[] args) throws IOException, ParseException {
|
||||
|
||||
// Option handling
|
||||
int port = 8080;
|
||||
String hostname = InetAddress.getLocalHost().getHostName();
|
||||
|
||||
Options options = new Options();
|
||||
options.addOption("h", false, "Help");
|
||||
options.addOption("p", true, "Server port (default: "+port+")");
|
||||
options.addOption("s", true, "Server address (default: "+hostname+")");
|
||||
|
||||
GnuParser parser = new GnuParser();
|
||||
CommandLine line = parser.parse(options, args);
|
||||
@@ -41,18 +42,17 @@ public class RestServer {
|
||||
if (line.hasOption("p")) {
|
||||
port = Integer.parseInt(line.getOptionValue("p"));
|
||||
}
|
||||
if (line.hasOption("s")) {
|
||||
hostname = line.getOptionValue("s");
|
||||
}
|
||||
if (line.hasOption("h")) {
|
||||
HelpFormatter f = new HelpFormatter();
|
||||
f.printHelp("broker", options);
|
||||
return;
|
||||
}
|
||||
|
||||
URI baseUri = UriBuilder.fromUri("http://" + InetAddress.getLocalHost().getHostName() + "/").port(port).build();
|
||||
URI baseUri = UriBuilder.fromUri("http://" + hostname + "/").port(port).build();
|
||||
|
||||
|
||||
// Broker broker = createBroker(config);
|
||||
|
||||
|
||||
ResourceBinder binder = new ResourceBinder();
|
||||
|
||||
ResourceConfig resourceConfig = new ResourceConfig(JacksonFeature.class);
|
||||
@@ -61,15 +61,15 @@ public class RestServer {
|
||||
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
|
||||
|
||||
// Static content
|
||||
// String home = System.getenv("BROKER_BASE");
|
||||
// String home = System.getenv("FDA_BASE");
|
||||
// if (home == null) {
|
||||
// home = "src/main/assembly";
|
||||
// }
|
||||
// home = home + "/www";
|
||||
// server.getServerConfiguration().addHttpHandler(new StaticHttpHandler(home), "/static");
|
||||
|
||||
logger.info("Broker started");
|
||||
// logger.info(String.format("Management interface available at %sstatic/", baseUri));
|
||||
|
||||
logger.info("Server started");
|
||||
logger.info("Use ctrl+c to stop ...");
|
||||
|
||||
// Signal handling
|
||||
@@ -91,8 +91,5 @@ public class RestServer {
|
||||
}
|
||||
|
||||
server.stop();
|
||||
|
||||
// broker.terminate();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user