Restarting Prolog engine from Java using JPL - java

In one java application that uses JPL to interact with Prolog, I want to be able to restart the prolog engine with different settings. As an example, I would like to change from SWI to YAP (I configure which engine to use this with the method JPL.setNativeLibraryDir with the path of the right native library I need to use).
So after changing the JPL configuration, I was trying to halt the already running prolog engine in order to restart it again afterwards with JPL.init().
First I took a look to JPL.halt(), but the documentation says it is deprecated and the comments in the source code of the method said that it is no-op.
Afterwards, I tried to just launch a query with 'halt', but although I see in the console "YAP execution halted" as expected, my java application is also halted (!).
Is there a way to restart the logic engine using JPL without killing my java application ?

why not using a batch file to run scripts. first you can have /Applications/swi -l your/swi/code and then use halt inside your prolog code so that it halts after execution. You can run your batch file inside java using runtime method.

Related

How can i setup end to end code debugging for JBPM application

Project uses bpmn files for handling main part of the flows.Currently i have set up code debugging for java part which this way is useless for bpmn files because hundreds of lines embedded to script tasks iniside bpmns.If i set up debug for bpmns it would be useless for java part.Question is to find some way to setup debugging for both.Thanks
This might depend on the jBPM version but jBPM Eclipse Plugin 6.0 comes with debugging capabilities as explained in 18.2 Debugging, however:
Note that we currently don't allow you to put breakpoints on the nodes within a process directly. You can however put breakpoints inside any Java code you might have (i.e. your application code that is invoking the engine or invoked by the engine, listeners, etc.) or inside rules (that could be evaluated in the context of a process). At these breakpoints, you can then inspect the internal state of all your process instances.
If installing Eclipse plugin is not possible you would have to debug through the Java code of jBPM engine. It's doable, but not pleasant experience.

Load a stand-alone jar in memory to query from a Python program

I have this stand-alone jar which I can use via the command line. I basically want to load this jar once and have a loop which will send in the queries (without loading the jar again and again).
I have a python script which takes in input from MongoDB, and I want that script to send that as input to this Jar (without loading it again as loading the jar takes ~1 minute and I have 55M input lines).
Any help is appreciated.
if i understood your problem correctly , i see it you are doing it wrong .
if you use a java tool and a java library , use it with java .
write java code that takes the input from mongodb , and write java code that will depend on this OpenIE lib to execute its functionality .
this way the classes will be loaded once into jvm and will be available fora furture use...
if you insist on using python , as i see it you cant do anything .
every time you run the jar , you re crate the JVM . and every time the code of the lib ends his run , the jvm is thrown.
if you still insist on using python to wrap around this library with different inputs , i would recommend to consider multi-threaded approach , so each thread runs its own instance of the library .

Can I open a REPL in the context of a Spring Web Application?

I'm working on a web application based on Spring MVC and Hibernate on Tomcat 8 (both for deployment and local development). The IDE is Spring Tool Suite (which is based on Eclipse).
I want to open a REPL (read-eval-print-loop, like Groovy's, Python's, Ruby's, etc) in the context of my application (while it's running on Tomcat locally), to speed up development by shortening the code -> test feedback loop.
That is, I want to be able to open a shell in the command line (or inside Eclipse) and do something like:
ClientDAO clientDAO = getAutowiredDAOFromSpringSomehow();
Client client = clientDAO.findByID(100);
client.setName("Another name");
clientDAO.save(client);
I can work around this a bit by setting a breakpoint somewhere in a controller and use Eclipse's debugger Display tab to execute arbitrary code, but this is a bit impractical and uncomfortable.
I'm open to using Groovy or Scala's shell if it's more convenient (I obviously still need access to my objects, though).
What are my options?
You may be able to do it using Spring Shell, JShell or BeanShell
Here's a project to embed a repl in an android app using BeanShell
I don't know if it's useful for your use-case but theoretically it should be possible to do this using CRaSH. It's a Shell like Bash on Linux but for your Java-Application and it's possible to create your own commands.

How do I make a custom windows service?

Actually I am having one java program. That returns "Hello World". I converted it to jar file. After that I changed the file type as .exe with the use of iexpress in my windows XP default sw.
I used the sc create command, for creating new service. I created the windows service successfully. But the thing is I am not able to run this. It is throwing the following error.
This error is coming not only for this javaservice.
I tried to run the chrome.exe as windows service, That time also it is throwing the same error.
Is it windows constraints? or Am I making mistake? Expecting the solution.,
Thanks in Advance...
You cannot just assign any arbitrary .exe file as-is to run as a service. There are specific API functions involved that services must use to interact with the Service Control Manager (SCM). That is why you are getting the errors - those .exe files are not using those APIs to interact with the SCM.
If you are not writing code specifically for SCM interaction (Java does not support creating Windows services), then all is not lost. In some situations (Chrome NOT being one of them!), you can use a separate wrapper to host non-service apps and handle the SCM interactions on their behalf:
Service wrapper
For Java apps, there are a few wrapper projects available:
Java Service Wrapper
Yet Another Java Service Wrapper
ow2

Executing a class in remote jvm

I have a small test class that I want to run on a particular jvm that's already up and running (basically it's an web application running on Tomcat) . The reason I want to do this is I want to execute a small test class (with the main method and all) within that jvm so that I get the same environment (loaded and initialized classes) for my test class.
Is it possible to indicate that ,say through a jvm parameter, that it should not initialize a new vm to execute my class but instead go and execute on the remote vm and show me the result here, on my console. So the local jvm acts as a kind of thin proxy ?
I am not aware in case there are some tools that should make this possible .Also heard somewhere that java 6 jvm comes with an option like this , is that true ?
Please help me.
Thanks,
After reading this question and the answers, I decided to roll my own little utility: remoteJunit
It is lightweight and dynamically loads classes from the client to the server JVM. It uses HTTP for communication.
You might want to take a look at btrace. It allows you to run code in an already started JVM provided you don't change the state of the variables inside that JVM. With this kind of tracing, you might be able solve your problem in a different way. Not by running extra code in form of a new class but by adding safe code to and existing class running inside a JVM.
For instance, you might System.out.println the name of the file when there is a call to File.exists.
You might find JMX useful. Register an MBean in the server process. Invoke it with visualvm (or jconsole). (tutorial) Never tried it myself, mind.
RMI would also do the magic.
http://java.sun.com/javase/6/docs/technotes/guides/rmi/index.html
Make your web application start an RMI registry and register your service
beans there.
Then in other JVM you can run a program that queries the RMI registry
started by your web application for the services you want to verify
and you are done.
I assume "small test class" is basically some debugging code you want to run to monitor your real application, which is deployed remotely on a Tomcat. If this is the case, you should connect your Eclipse debugger remotely to the Tomcat instance, so you can set a breakpoint at interesting locations and then use the Display view of Eclipse to run any arbitrary code you might need to perform advanced debugging code. As java supports Hot Code Replacement using the debug mechanism, you can also change existing code on the remote side with new code at runtime.

Categories

Resources