From b64f31e7788599e55c50838575d2f16f2d8fddcd Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Mon, 28 Apr 2014 11:46:36 +0200 Subject: [PATCH] some more cleanups and fixes -- however still lots of bugs in there ! --- ch.psi.fda/pom.xml | 8 +- .../ch/psi/fda/rest/AcquisitionEngine.java | 9 ++ .../java/ch/psi/fda/rest/CdumpEngine.java | 99 ------------------- .../main/java/ch/psi/fda/rest/FdaqEngine.java | 90 ----------------- .../java/ch/psi/fda/rest/ResourceBinder.java | 8 +- .../psi/fda/rest/services/CDUMPService.java | 63 ------------ .../ch/psi/fda/rest/services/FDAQService.java | 58 ----------- .../src/test/resources/cdump.properties | 4 + 8 files changed, 23 insertions(+), 316 deletions(-) delete mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/rest/CdumpEngine.java delete mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/rest/FdaqEngine.java delete mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/rest/services/CDUMPService.java delete mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/rest/services/FDAQService.java create mode 100644 ch.psi.fda/src/test/resources/cdump.properties diff --git a/ch.psi.fda/pom.xml b/ch.psi.fda/pom.xml index 9f0c5db..fa78c44 100644 --- a/ch.psi.fda/pom.xml +++ b/ch.psi.fda/pom.xml @@ -13,23 +13,27 @@ 0.0.2 + ch.psi.fda ch.psi.fda.xscan 2.2.0 - ch.psi ch.psi.fda.cdump 1.0.1 - ch.psi ch.psi.fda.fdaq 1.0.5 + + ch.psi + jcae + 2.1.11 + com.google.inject diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/rest/AcquisitionEngine.java b/ch.psi.fda/src/main/java/ch/psi/fda/rest/AcquisitionEngine.java index 5929141..7530112 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/rest/AcquisitionEngine.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/rest/AcquisitionEngine.java @@ -27,6 +27,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.util.logging.Logger; import javax.inject.Inject; @@ -39,6 +40,8 @@ import ch.psi.jcae.ChannelService; */ public class AcquisitionEngine { + private static final Logger logger = Logger.getLogger(AcquisitionEngine.class.getName()); + private final AcquisitionConfiguration config; private final ChannelService cService; private final ZMQDataService zmqService; @@ -62,6 +65,7 @@ public class AcquisitionEngine { */ public void submit(String trackingId, EDescriptor edescriptor){ + logger.info("Submitting new scan with trackingId " + trackingId); if(erequests.keySet().contains(trackingId) && !erequests.get(trackingId).isDone()){ // Allow finished tracking ids to be reused for new scans throw new IllegalArgumentException("A request with tracking ID "+trackingId+" is already submitted"); } @@ -73,6 +77,7 @@ public class AcquisitionEngine { public void terminateAll() { + logger.info("Terminate all scans"); for(Future f: erequests.values()){ f.cancel(true); } @@ -93,6 +98,7 @@ public class AcquisitionEngine { * @param trackingId */ public void terminate(String trackingId){ + logger.info("Terminate scan with trackingId "+trackingId); final Future f = erequests.get(trackingId); if(f==null){ @@ -108,6 +114,7 @@ public class AcquisitionEngine { } public boolean isActive(String trackingId) { + logger.info("Checking whether trackingId "+trackingId+" is active."); Future f = erequests.get(trackingId); if(f==null){ throw new IllegalArgumentException("There is no request for tracking id "+trackingId); @@ -122,10 +129,12 @@ public class AcquisitionEngine { * @throws InterruptedException */ public void wait(String trackingId) throws InterruptedException, ExecutionException{ + logger.info("Waiting for termination for trackingId "+trackingId); Future f = erequests.get(trackingId); if(f==null){ throw new IllegalArgumentException("There is no request for tracking id "+trackingId); } f.get(); + logger.info("TrackingId "+trackingId+" terminated"); } } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/rest/CdumpEngine.java b/ch.psi.fda/src/main/java/ch/psi/fda/rest/CdumpEngine.java deleted file mode 100644 index e719ae2..0000000 --- a/ch.psi.fda/src/main/java/ch/psi/fda/rest/CdumpEngine.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * - * 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 . - * - */ -package ch.psi.fda.rest; - -import java.io.File; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import javax.inject.Inject; - -import ch.psi.fda.cdump.Cdump; -import ch.psi.fda.cdump.CdumpConfiguration; -import ch.psi.fda.rest.model.CdumpRequest; -import ch.psi.fda.serializer.SerializerTXT; -import ch.psi.jcae.ChannelService; - -import com.google.common.eventbus.AsyncEventBus; -import com.google.common.eventbus.EventBus; - -public class CdumpEngine { - - private Cdump cdump; - private EventBus bus; - - private ZMQDataService zmqService; - private ChannelService cservice; - private CdumpConfiguration configuration; - - private boolean stream = false; - - private ExecutorService eservice; - - - @Inject - public CdumpEngine(ChannelService cservice, ZMQDataService zmqService, CdumpConfiguration configuration){ - this.cservice = cservice; - this.zmqService = zmqService; - this.configuration = configuration; - - eservice = Executors.newSingleThreadExecutor(); - } - - - public void acquire(String trackingId, final CdumpRequest request){ - if(cdump!=null){ - throw new IllegalStateException("Cdump is already running"); - } - - bus = new AsyncEventBus(Executors.newSingleThreadExecutor()); - cdump = new Cdump(cservice,bus,configuration); - - SerializerTXT serializer = new SerializerTXT(new File(request.getFilename())); - serializer.setShowDimensionHeader(false); - bus.register(serializer); - - stream = (request.getStream()!=null && request.getStream().getIds().length>0) ; - if(stream){ - // Stream data via ZMQ - zmqService.setTrackingId(trackingId); - // TODO set id filter !!! - bus.register(zmqService); - } - - eservice.execute(new Runnable() { - @Override - public void run() { - cdump.acquire(request.getSamplingRate()); - } - }); - } - - - public void stop(){ - cdump.stop(); - cdump = null; - bus.unregister(zmqService); - } - - - public boolean isActive(){ - return cdump!=null; - } -} diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/rest/FdaqEngine.java b/ch.psi.fda/src/main/java/ch/psi/fda/rest/FdaqEngine.java deleted file mode 100644 index 2260766..0000000 --- a/ch.psi.fda/src/main/java/ch/psi/fda/rest/FdaqEngine.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * - * 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 . - * - */ -package ch.psi.fda.rest; - -import java.io.File; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import javax.inject.Inject; - -import ch.psi.fda.fdaq.FdaqConfiguration; -import ch.psi.fda.fdaq.FdaqService; -import ch.psi.fda.rest.model.FdaqRequest; -import ch.psi.fda.serializer.SerializerTXT; - -import com.google.common.eventbus.AsyncEventBus; -import com.google.common.eventbus.EventBus; - -/** - * - */ -public class FdaqEngine { - - private FdaqService fdaq; - private EventBus bus; - private ZMQDataService zmqService; - private boolean stream = false; - - private ExecutorService eservice; - - @Inject - public FdaqEngine(ZMQDataService zmqService){ - this.zmqService = zmqService; - - eservice = Executors.newSingleThreadExecutor(); - } - - public void acquire(String trackingId, FdaqRequest request){ - - if(fdaq!=null && fdaq.isRunning()){ - throw new IllegalStateException("FDAQ is already running"); - } - - bus = new AsyncEventBus(Executors.newSingleThreadExecutor()); - fdaq = new FdaqService(bus, new FdaqConfiguration()); - - SerializerTXT serializer = new SerializerTXT(new File(request.getFilename())); - serializer.setShowDimensionHeader(false); - bus.register(serializer); - - stream = (request.getStream()!=null && request.getStream().getIds().length>0) ; - if(stream){ - // Stream data via ZMQ - zmqService.setTrackingId(trackingId); - // TODO Set id filter !!!! - bus.register(zmqService); - } - - - eservice.execute(new Runnable() { - @Override - public void run() { - fdaq.acquire(); - } - }); - } - - public void stop(){ - fdaq.stop(); - bus.unregister(zmqService); - - // TODO check whether serializer also needs to be unregistered ... - } -} diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/rest/ResourceBinder.java b/ch.psi.fda/src/main/java/ch/psi/fda/rest/ResourceBinder.java index ddf95a7..27238ae 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/rest/ResourceBinder.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/rest/ResourceBinder.java @@ -7,7 +7,7 @@ import javax.inject.Singleton; import org.glassfish.hk2.utilities.binding.AbstractBinder; import ch.psi.fda.aq.AcquisitionConfiguration; -import ch.psi.fda.cdump.CdumpConfiguration; +//import ch.psi.fda.cdump.CdumpConfiguration; import ch.psi.jcae.ChannelService; import ch.psi.jcae.impl.DefaultChannelService; @@ -19,12 +19,12 @@ public class ResourceBinder extends AbstractBinder { bind(AcquisitionConfiguration.class).to(AcquisitionConfiguration.class).in(Singleton.class); bind(AcquisitionEngine.class).to(AcquisitionEngine.class).in(Singleton.class); - bind(FdaqEngine.class).to(FdaqEngine.class).in(Singleton.class); +// bind(FdaqEngine.class).to(FdaqEngine.class).in(Singleton.class); // ZMQ data service singleton bind(new ZMQDataService(10000)).to(ZMQDataService.class); - bind(CdumpEngine.class).to(CdumpEngine.class).in(Singleton.class); - bind(CdumpConfiguration.class).to(CdumpConfiguration.class).in(Singleton.class); +// bind(CdumpEngine.class).to(CdumpEngine.class).in(Singleton.class); +// bind(CdumpConfiguration.class).to(CdumpConfiguration.class).in(Singleton.class); } } \ No newline at end of file diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/rest/services/CDUMPService.java b/ch.psi.fda/src/main/java/ch/psi/fda/rest/services/CDUMPService.java deleted file mode 100644 index 455dcf1..0000000 --- a/ch.psi.fda/src/main/java/ch/psi/fda/rest/services/CDUMPService.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * - * Copyright 2013 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 . - * - */ - -package ch.psi.fda.rest.services; - -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.core.MediaType; - -import ch.psi.fda.rest.CdumpEngine; -import ch.psi.fda.rest.model.CdumpRequest; - -@Path("cdump") -public class CDUMPService { - - @Inject - private CdumpEngine cdumpE; - - @PUT - @Path("{trackingId}") - @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public void execute(@PathParam("trackingId") String trackingId, CdumpRequest request) throws InterruptedException{ - cdumpE.acquire(trackingId, request); - } - - @DELETE - @Path("{trackingId}") - public void stop(@PathParam("trackingId") String trackingId){ - terminateAll(); - } - - @DELETE - public void terminateAll(){ - cdumpE.stop(); - } - - @GET - public boolean isActive(){ - return cdumpE.isActive(); - } - -} diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/rest/services/FDAQService.java b/ch.psi.fda/src/main/java/ch/psi/fda/rest/services/FDAQService.java deleted file mode 100644 index 11e44b3..0000000 --- a/ch.psi.fda/src/main/java/ch/psi/fda/rest/services/FDAQService.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * - * Copyright 2013 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 . - * - */ - -package ch.psi.fda.rest.services; - - -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.core.MediaType; - - -import ch.psi.fda.fdaq.FdaqService; -import ch.psi.fda.rest.model.FdaqRequest; - -@Path("fdaq") -public class FDAQService { - - @Inject - private FdaqService fdaq; - - @PUT - @Path("{trackingId}") - @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public void execute(@PathParam("trackingId") String trackingId, FdaqRequest request) throws InterruptedException { - fdaq.acquire(); - } - - @DELETE - @Path("{trackingId}") - public void stop(@PathParam("trackingId") String trackingId) { - terminateAll(); - } - - @DELETE - public void terminateAll(){ - fdaq.stop(); - } -} diff --git a/ch.psi.fda/src/test/resources/cdump.properties b/ch.psi.fda/src/test/resources/cdump.properties new file mode 100644 index 0000000..1c786ca --- /dev/null +++ b/ch.psi.fda/src/test/resources/cdump.properties @@ -0,0 +1,4 @@ +ch.psi.fda.cdump.dataChannel=CDUMP:WAVE +ch.psi.fda.cdump.controlChannel=CDUMP:CONTROL +ch.psi.fda.cdump.samplingRateChannel=CDUMP:SAMPLING +ch.psi.fda.cdump.nelements=4