some more cleanups and fixes

-- however still lots of bugs in there !
This commit is contained in:
2014-04-28 11:46:36 +02:00
parent 43a8347924
commit b64f31e778
8 changed files with 23 additions and 316 deletions

View File

@@ -13,23 +13,27 @@
<version>0.0.2</version>
</dependency>
<!-- These 3 libraries are just needed for testing -->
<dependency>
<groupId>ch.psi.fda</groupId>
<artifactId>ch.psi.fda.xscan</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>ch.psi</groupId>
<artifactId>ch.psi.fda.cdump</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>ch.psi</groupId>
<artifactId>ch.psi.fda.fdaq</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>ch.psi</groupId>
<artifactId>jcae</artifactId>
<version>2.1.11</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>

View File

@@ -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");
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*
*/
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;
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*
*/
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 ...
}
}

View File

@@ -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);
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*
*/
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();
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*
*/
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();
}
}

View File

@@ -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