Basically I'm trying to build a Java WebApp that will interface an Arduino. Due to this "phisical" limitation I will have just one user at the time working with the microcontroller.
I would like to create a queue with all the requests and set a limit (i.e. 20 seconds) and then go with the next user. There will be probably in the future the option to have two users connected to "interact" each other.
How can I implement this infrastructure? JMS? Other ways?
I've used other mqs as Kestrel but just with "strings", and I've no clue on how to use it in my case. : /
(I will probably use JBoss if this is relevant, or helpful)
Thanks in advance!
There is an RXTX Java library that comes with Arduno and I would suggest to use that for Arduno interface.
Related
So I am making a program that will only run one instance at a time and am doing so by using this solution
However now I would like to make it so that if the user trys to launch another instance it will consume that attempt and notify the current instance to show its gui.
Currently I am thinking about doing this by the use of a file. Upon the launching of a second instance, a file called show.stage will be created. When the other instance detects that file it will show its gui and delete the file.
I know this works but I was wondering if there was a more graceful way to do this.
Could I some how set a environment flag that the other instance could check for or maybe notify it via a socket listener, although those seem to be discouraged by others. I get the feeling creating the file will be the easiest and most robust way but I am open to any suggestions
This program will be running on normal windows.
If you don't want to use a lock file (which I think is a perfectly good solution), you can use sockets.
Have your application create a socket server and listen at some port in localhost. If it fails to listen, it would mean that someone else is listening to that port already - most likely, another instance of your app. You can even connect to that port and send messages to notify the primary instance that a second instance tried to be spawned.
The caveat is that if another app legitimately uses that port your app would never be able to run - but I find that very unlikely to happen.
There are many ways to go about this:
as you already figured, the file system can be used as communication channel between two jvms. But that only works for jvms running on the same server.
thus the already suggested socket solution enables you to (later) apply the same solution to a distributed environment. The downside is that you have to implement a protocol on a very low level.
in the past, people often turned to message bus solutions (think ActiveMQ for example)
in 2018, the other alternative would be to implement a simple restful API, using jaxrs and jersey for example.
As said: the effort you want to put into this depends on your requirements. How long will it be used? What are the odds that your solution will grow and has to scale to more than one server?!
try to use pidfile as lock and process single like kill 9 as communication tool
So, say I have multiple instances of a java program running, and I need to get information from each instance, ie if the program is performing its function correctly and if its not I need to get information to the process on what to do, I essentially need to open a tunnel. How would I do so? I hope this question isn't to vague.
I'm basically writing a manager, the manager loads a bunch of clients and I need a way to communicate between the manager and each client.
Have you looked into Java Management Extensions? It's built-in and made for monitoring java processes:
http://openjdk.java.net/groups/jmx/
if you need to look at custom info for your processes (some state of execution, or some special log info), you can create your own info-providers (aka "MBeans"):
https://blogs.oracle.com/WebLogicServer/entry/developing_custom_mbeans_to_ma
hope that helps
Is there a IBM MQ JAVA API to move messages from one queue to another?
I am able to browse messages from the queue and put messages as well using Java APIs. But I want to move a message from one queue to another. Could you please give a sample code if there is any?
Or do we have to dequeue the message from queue1 and then put the message into queue2 for moving the messages?
You need to GET from queue 1 and then do a PUT on queue 2. If you just browse then there are chances that before yoy GET it out of queue 1, the consumer have already consumed it using GET. You can find sample code for many scenarios on this website.
I have faced the same issue and after lot of frustrating hours i have done it using tool "MQJExplorer_v0.16". Using this tool you can export/import all the messages(or a single message) from one queue to another queue.
If you are facing any issues while installation. Please make sure you are using the correct jdk version (I faced the same issue). You can check the java version in the MetaInf file of one of the downloaded artifacts, make sure you have the same jdk or newer version on your localmachine and just set the JAVA_HOME in the environment variables.
I'm new to OpenTSDB. I somehow managed to install and configure OpenTSDB, but I don't know how to put data into OpenTSDB from client. Can anyone of you help me?
Have you read the getting started guide
You have several options. Once started, and metrics created via ./tsdb mkmetric mymetric.data_1 mymetric.data_2 , you can batch import files written in the form
metric_name timestamp value tags e.g.
mymetric.data_1 1295643636 48 a=foo
then you can ./tsdb import file
An other way is to "telnet" commands to the server in the same form as above, but with the put keyword, like echo "put mymetric.data_1 1295643636 48 a=foo" | nc -w 15 tsdHost tsdPort (linux way :-) )
The short answer is that those "put name timestamp value [tags]" commands are the network protocol for adding data to OpenTSDB over TCP/IP. So from your Java program, you can open a TCP socket to the TSD port and start writing commands to add your data.
Obviously, that still leaves a lot of details an an excercise to the reader.
You didn't specify in your question how, or even if, you're collecting time series data that you want to store. How complicated it is to periodically push data into TSD from your application will depend on what you're doing there. If you're using the excellent Yammer/Coda Hale Metrics library to collect data (and in Java, there really isn't a slicker way to do it, that I know of)
Metrics includes a reporter interface with several implementations for other statistics repositories like Graphite and Ganglia. You can easily implement one for OpenTSDB (in fact, someone already has - I'm trying to find the pull request on github but failing; I'll update this when I find it).
Check out the OpenTSDB 2.0 documentation:
http://opentsdb.net/docs/build/html/
This will provide better insight in adding data into openTSDB. Moreover, openTSDB2.0 has HTTP api to put data.
You can read Input Methods in the documentation.
Also I find it useful for me to read Data Specification, to understand what every time series consists of.
I'm trying to implement a Cometd/Bayeux server on Android using iJetty. The Jetty implementation itself works just fine serving static pages along with servlets. I am trying to up the ante a bit and create a Bayeux application on the phone but I'm having some trouble. I can hit the page that has the dojo cometd scripts on it, but I am unable to subscribe to the channel. When I view firebug/chome developer tools, I see a series of posts/gets that last a couple of milliseconds (~14). However, when I run a cometd application on a normal machine, the posts/gets last several seconds (~14 seconds) before timing out and reopening the connection. This second scenario makes sense to me with my understanding of how continuation in HTTP works. So I'm thinking that something is not allowing those connections to hang open and prematurely returning a value and consequently closing the connection. I would post my source but I'm not sure what to post short of posting everything...(it is open source though so if you want to have a look it's at http://webtext-android.googlecode.com).
So my question is, does anybody think that there could be some underlying limitation imposed by the Android system that is preventing these servlets from working? Are there assumptions that are made by the Jetty Bayeux implementation with regards to the underlying system? Or is it more likely that somehow I have a bad implementation of the ContinuationCometdServelt? I should note that all of the posts/gets from the client return 200 OK messages so I'm not inclined to think that the Android system is simply terminating the connection.
I know this is a bit off the wall and I'm definitely trying to do something a bit out of the ordinary but any suggestions or tips would be greatly appreciated.
In case anybody discovers this and has similar problems (this applies to all cometd implementations regardless of host), I discovered that the issue was with using the Google js library. For some reason, the dojo scripts I was loading from Google (1.4) didn't have a valid implementation of cometd. I switched my dojo script to the one that was used by the jetty-1.6.23 example and it works perfectly.