On a Windows PC is it possible for a C++ program to know or find out which javabean is currently running in a separate Java program?
Now I don't know too much about what a javabean actually means or does beyond the basics, but I've been told that it might be possible. I don't think it will be, though, since Java runs in a virtual machine and all the classes are internal only.
It's impossible to know.
But you can create some framework to make it possible. Possible a socket communication.
You can create a Thread in your Java program that listen to this beans, and reply all information in a socket. Your C program, should listen this port, and reply all information.
Why you don't include your C code with JNI?
Related
I need to pass a signal from a .NET app to a Java app. No data is required, the signal itself is enough.
The most simple way that comes to my mind is by using a named synchronization object like this:
The .NET app creates a certain named synchronization object A.
The Java app creates a certain named synchronization object A - the name is the same as in (1).
The Java app has a thread waiting on the object to become signaled.
The .NET app signals the object.
The Java app thread awakens and acts upon the signal reception.
At least, this how I would do it if I knew how to create a named synchronization object in Java.
But looks like Java does not have any, which I find hard to believe. Does it mean that only Windows has named synchronization objects?
So, my question is this - how do I pass a simple signal (no data) from a non Java app to a Java app on Windows? Both processes run on the same host.
EDIT
Motivation - I want to signal to our headless Java process to terminate itself gracefully as soon as it can do so.
you can create a socket connection between your programs, and by send and receive specific pattern you can detect signal
I second thought, that i had done before by using ICE Framework, you can download and learn the ICE Framework from here,
ICE Framework is a cross framework for communication between processes a local system or on a network.
Download Ice Framework
For God's sake, I just want a single 1 bit signal from a C++/C# process to a Java process and there is no simple way to do it. I can't believe it.
Forget about it, I'll just use the file system. The C++/C# code is going to create an empty file at a well known location, which the Java code is going to poll every second.
Finito, end of story.
This question arises from a problem we have here, and we're looking for a way to solve it. We have a really old machine (running DOS 6.22) which needs to communicate with a serial application written in Java. But we have neither found a C/C++ event based rs232 library to implement the program for the DOS machine (yet), nor an already compiled program to do this job. But since we already have a working Java event based rs232 program, we were wondering if it's possible to compile it and make an .exe out of it to install it in the old machine.
That would be an easy way out of the problem if possible, but if it isn't, are there any rs232 libraries to build the program for our old machine? Thanks in advance.
Linux gcj is capable of compiling java programs into executable code that runs without a VM. So you can use gcj on a linux machine to crosscompile and create a .EXE for DOS. See http://gcc.gnu.org/java. And for the list of platforms it supports see http://gcc.gnu.org/install/specific.html, DOS would be the 7th item in the list.
That said, I don't think you're java based rs232 library is going to work, even if the rest of the program does work, and you'll have all sorts of other limitations Java will not easily live with, like the famous 640K memory limit, which you'll find in practice closer to 440K on actual systems.
Another complication you'll find with event-based programming is that DOS is single threaded. So you cannot easily use any form of event based programming except cooperative multitasking. This is not hard, but be aware of it.
In DOS you'll essentially be writing a serial device driver to communicate with the serial port, like an operating system driver, setting the registers and initiating data transfers the way a char driver would do it in linux. There is a wikibook on the subject which is quite informative at http://en.wikibooks.org/wiki/Serial_Programming/DOS_Programming.
Can I create on Java monitoring program of network traffic? The program must control all network traffic which goes from computer program (including OS modules) to Network driver and back. If yes, How?
NOTE:
I want not only to monitor traffic also to control it. I want to implement such system on windows NT. It cannot be fulfilled o purely on Java. How can I perform it with the help of JNI?
Or maybe another variant. I am not acquaint with windows services, but still. I will write a program on C++ and register it as windows service. Then I call from my Java application this service (I don't know how to do this) and request network traffic. On the C++ program part all the traffic will be blocked if there is no Java program (or it doesn't request traffic); on the other way transmitted to this program. May be the java part can be implemented and work on an Java server (Glass Fish, JBoss). The C++ part in turn will transmit traffic to localhost.
What do you think about these ways?
When "monitoring of network traffic" then pcap, I'd say.
Googling "pcap java" brought me that as first hit: jNetPcap.
Did not test it, but pcap is the standard solution for native C programs. Cannot tell if the Java wrapper is good, but at least its website looks nice. ;-)
I have a java program where certain parts are computationally intensive.
I wish to make that part (which essentially generates an image according to some text data) in C/D.
(Multiple instances of the C program might be running at the same time).
Now, I want to be able to track the progress of the C/D program, so the java code
needs to read the status (progess, errors) of the C/D program somehow.
My idea is to use the environment variables in the OS, to store the status, "TIME_LEFT=2h10m42s" sort of.
Questions:
Is this a good idea, or is there something really bad about this design?
Are there some alternatives, (using sockets, stdin/stdout, other)?
EDIT: The Java works as a front-end, so the C/D code should NOT include anything specifically written for Java. The C/D code is essentially a stand-alone program, Java (or other) provides with GUI.
You cannot use environment variables for this, as you cannot communicate environment variables to another program by other than setting it before you start a new process. So you can't run a C program that changes environment variables that your parent java program can see.
Write line based status to stdout in your C (or D) program rather and read it in your java program.
Using environment variables is a bad idea. Environment variables are inherited by new running processes. They aren't register-type variables that you can just pump and access from any process, so to speak :) You could use JNI and keep checking the time remaining in MS on the Java side, or have the C/D code poll the Java code with the time remaining in its loop (I prefer the other way, however).
Well you can do the other way around .From Java to poll the status of execution.On each 5 seconds to call via JNI the status (progress) of the heavy execution.
I agree with Chris Dennett that this is a bad idea. I would avoid JNI - it is a terrific way to introduce subtle bugs that crash your JVM.
I would implement this by creating a C/D HTTP server running on the local host. The server accepts a POST request to /image/ to start creating the image, a long running process. That POST request returns immediately with a token. I would then GET /image/token which would return either the progress information or the image, depending on if it is done or not. Your Java process can then poll the GET /image/token URL.
Instead of using environment variable use JNA. It is easier than JNI and reliable method to communicate with the program. Another approach is you use Message Queue like ActiveMQ for which C API also available and this is open source. It will decouple the application.
I am running System Verilog inside of an ASIC simulator. SV has an import/export mechanism to call C functions from SV, and for SV functions to be called from within C.
I'd like to send realtime-ish (a very slow stream) data from the simulation to a charting program that I will write in Java. What is the best way to call the Java with periodic updates from the simulator/C program?
After a quick glance here : http://java.sun.com/docs/books/jni/html/invoke.html, ...
Then consider this:
The simplest way is to write the data to a file, and write a java program
to read from the file as it grows. See this answer: Java IO implementation of unix/linux "tail -f"
Start them both separately, or use system() to start the java program from your plugin, passing the filename as an argument.
The best way would be to have the Java program listen on a TCP socket for updates from the C program which can send them. Have the C program connect to the Java program when it begins, and whenever there's an update, it can pass it along the connected socket. The Java program can then take the data and update whatever it needs to update.
This also has the nice advantage that the two programs don't even have to run on the same machine.
There is the java native interface which allows C programs to interact with java objects. But you need to write some C code to get this integrated into the ASIC simulator.