Latest ideas and tests for FDA NG
This commit is contained in:
@@ -78,6 +78,32 @@
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
</dependency>
|
||||
|
||||
<!-- For Testing NG functionality purposes -->
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.containers</groupId>
|
||||
<artifactId>jersey-container-grizzly2-http</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-sse</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-cli</groupId>
|
||||
<artifactId>commons-cli</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
*
|
||||
* 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.aq.ng;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.NotFoundException;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
@Path("/")
|
||||
public class AcquisitionEngineNGResource {
|
||||
|
||||
@Inject
|
||||
private AcquisitionEngineNG engine;
|
||||
|
||||
@Inject
|
||||
private LManager lmanager;
|
||||
|
||||
@PUT
|
||||
@Path("logic")
|
||||
public void execute(String logic){
|
||||
Map<String, ?> map = new HashMap<>();
|
||||
engine.execute(map, logic);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("logic/{id}")
|
||||
public void setLogic(@PathParam("id") String id, String logic){
|
||||
lmanager.getLogics().put(id, logic);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("logic/{id}")
|
||||
public String getLogic(@PathParam("id") String id){
|
||||
String logic = lmanager.getLogics().get(id);
|
||||
if(logic==null){
|
||||
throw new NotFoundException();
|
||||
}
|
||||
return logic;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("logic/{id}")
|
||||
public void executeLogic(@PathParam("id") String id, String logic){
|
||||
lmanager.getLogics().put(id, logic);
|
||||
}
|
||||
}
|
||||
36
ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/LManager.java
Normal file
36
ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/LManager.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
*
|
||||
* 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.aq.ng;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Logic Manager
|
||||
* Basically a map holding id->logic pairs
|
||||
*
|
||||
* also holds default resource profiles for logics (rprofiles)
|
||||
*/
|
||||
public class LManager {
|
||||
private final Map<String, String> logics = new HashMap<>();
|
||||
|
||||
public Map<String,String> getLogics(){
|
||||
return logics;
|
||||
}
|
||||
}
|
||||
119
ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/NGServer.java
Normal file
119
ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/NGServer.java
Normal file
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
*
|
||||
* 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.aq.ng;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
import javax.ws.rs.core.UriBuilderException;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.GnuParser;
|
||||
import org.apache.commons.cli.HelpFormatter;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.glassfish.grizzly.http.server.HttpServer;
|
||||
import org.glassfish.grizzly.http.server.StaticHttpHandler;
|
||||
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
|
||||
import org.glassfish.jersey.jackson.JacksonFeature;
|
||||
import org.glassfish.jersey.media.sse.SseFeature;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
|
||||
import sun.misc.Signal;
|
||||
import sun.misc.SignalHandler;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("restriction")
|
||||
public class NGServer {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(NGServer.class.getName());
|
||||
|
||||
/**
|
||||
* @param args
|
||||
* @throws ParseException
|
||||
* @throws UnknownHostException
|
||||
* @throws UriBuilderException
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public static void main(String[] args) throws ParseException, IllegalArgumentException, UriBuilderException, UnknownHostException {
|
||||
// Option handling
|
||||
int port = 8080;
|
||||
|
||||
Options options = new Options();
|
||||
options.addOption("h", false, "Help");
|
||||
options.addOption("p", true, "Server port (default: " + port + ")");
|
||||
|
||||
GnuParser parser = new GnuParser();
|
||||
CommandLine line = parser.parse(options, args);
|
||||
|
||||
if (line.hasOption("p")) {
|
||||
port = Integer.parseInt(line.getOptionValue("p"));
|
||||
}
|
||||
if (line.hasOption("h")) {
|
||||
HelpFormatter f = new HelpFormatter();
|
||||
f.printHelp("dae", options); // definition dae - http://www.urbandictionary.com/define.php?term=dae
|
||||
return;
|
||||
}
|
||||
|
||||
URI baseUri = UriBuilder.fromUri("http://" + InetAddress.getLocalHost().getHostName() + "/").port(port).build();
|
||||
|
||||
// final ResourceConfig resourceConfig = new
|
||||
// ResourceConfig(ServerSentEventsResource.class, SseFeature.class);
|
||||
ResourceConfig resourceConfig = new ResourceConfig(SseFeature.class, JacksonFeature.class);
|
||||
resourceConfig.packages(AcquisitionEngineNGResource.class.getPackage().getName());
|
||||
resourceConfig.register(new ResourceBinder());
|
||||
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
|
||||
|
||||
// Static content
|
||||
String home = System.getenv("DAE_BASE");
|
||||
if (home == null) {
|
||||
home = "src/main/assembly";
|
||||
}
|
||||
home = home + "/www";
|
||||
server.getServerConfiguration().addHttpHandler(new StaticHttpHandler(home), "/static");
|
||||
|
||||
logger.info("dae started");
|
||||
logger.info(String.format("Management interface available at %sstatic/", baseUri));
|
||||
logger.info("Use ctrl+c to stop ...");
|
||||
|
||||
// Signal handling
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Signal.handle(new Signal("INT"), new SignalHandler() {
|
||||
public void handle(Signal sig) {
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
// Wait for termination, i.e. wait for ctrl+c
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
|
||||
server.stop();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package ch.psi.fda.aq.ng;
|
||||
|
||||
import org.glassfish.hk2.utilities.binding.AbstractBinder;
|
||||
//import org.glassfish.jersey.media.sse.SseBroadcaster;
|
||||
|
||||
//import ch.psi.da.hub.model.Keystore;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
public class ResourceBinder extends AbstractBinder {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
// request scope binding
|
||||
// bind(MyInjectablePerRequest.class).to(MyInjectablePerRequest.class).in(RequestScope.class);
|
||||
// singleton binding
|
||||
// bind(MyInjectableSingleton.class).in(Singleton.class);
|
||||
// singleton instance binding
|
||||
|
||||
// KeystoreSerializer serializer = new KeystoreSerializer();
|
||||
// Keystore keystore = serializer.deserialize();
|
||||
|
||||
// bind(new SseBroadcaster()).to(SseBroadcaster.class);
|
||||
// bind(serializer).to(KeystoreSerializer.class);
|
||||
// bind(new KeystoreBroadcaster()).to(KeystoreBroadcaster.class);
|
||||
// bind(keystore).to(Keystore.class);
|
||||
|
||||
bind(new AcquisitionEngineNG(new DefaultChannelService())).to(AcquisitionEngineNG.class);
|
||||
bind(new LManager()).to(LManager.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -184,11 +184,11 @@ public class AcquisitionEngineNGTest {
|
||||
public void testCustomScript() {
|
||||
Map<String, Object> rdescriptors = new HashMap<>();
|
||||
rdescriptors.put("x", new ChannelDescriptor<>(Double.class, "MTEST-HW3:MOT1", false));
|
||||
rdescriptors.put("xr", new ChannelDescriptor<>(Double.class, "MTEST-HW3:MOT2.RBV", false));
|
||||
rdescriptors.put("xr", new ChannelDescriptor<>(Double.class, "MTEST-HW3:MOT1.RBV", false));
|
||||
String script = "for i in range(1,5,1):\n"+
|
||||
" x.setValueAsync(float(i))\n"+
|
||||
// " print xr.getValue()\n";
|
||||
" print 'done'\n";
|
||||
" x.setValueNoWait(float(i))\n"+
|
||||
" print xr.getValue()\n";
|
||||
// " print 'done'\n";
|
||||
|
||||
engine.execute(rdescriptors, script);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user