Adding notification push from Mysql server to Java application - java

Hi I have designed a desktop application in Java SE with netbeans and Mysql.I do not have any server coding for now since all my operations were of pull type. I need a push notification functionality. Previously I had a button that refreshed the notification but now I want the notifications to be updated automatically.
What would be best way to add this functionality without changing much of my present code.
Any help appreciated.
Thanks a lot

You really will have to change a lot about your architecture to have your application go the other direction. However, I think the best approach is to use a light weight JMS provider. That way your client can code to the JMS API which is really pretty straight forward, and your server can use JMS and its really pretty easy. It's not nearly as much effort as plumbing other options in.
The harder part is setting up the container in your application. It's not tremendously hard, but JMS has lots of options for configuration. Figuring out the point to point vs topic, durable vs non-durable and what's right for your application is a lot of research you have to do if you haven't done JMS before.
But, what this affords you is a very expressive control over messaging in your application. You can under the covers without modifying your code swap between polling or direct connections, message 1:1 or 1:many. If you need to send a message to one client vs. sending a message to all clients. You can segment messages between clients and create groups. Your messages can be durable or non-durable (survive client shutdown or server shutdown). The possibilities are endless, but you have to make a lot of architectural decisions. You also don't have to handle network topology and connectivity issues as much than if you used UDP multicast or TCP connections in reverse.
ActiveMQ and RabbitMQ can be easily embedded within a server using spring in a matter of 20 minutes. They also provide hooks for other platforms. It might sound overkill, but I've tried to do without JMS in the past when I should've used it and regretted not using it.

Related

How can I connect an android with a local server?

sorry if my english isn't perfect.
I'm trying to make an app and I need to exchange information between more devices.
I thought that could be a solution connect the devices on a server but I really don't have the idea where start.
What language I need to study to make this? There is a better solution?
This highly depends on what you are trying to achieve in the first place. It would be helpful if you could tell what you are trying to do, but I will still outline some general aspects:
You need to decide, what information is going to be exchanged and how this should happen
What information: Figure out, what exactly needs to be sent and received. Generic text messages? Images? Byte Streams?
How should this be done: Generally spoken, there are two approaches of getting information as a client: Polling and subscribing.
Polling: This approach means to periodically check an endpoint for new data. For example, HTTP uses this way: A web browser or any other client (REST-Client for example) periodically requests information from a HTTP-Server, using a connection just for this single request.
Subscribing / Sync / Notification: In some way or another, the client tells the server that it is interested in the information and wants to get notified when there is something new. The connection is initiated at the beginning and held open for further usage. The benefit of this approach is that changes are received immediately, but on the other hand a permanent connection needs to be maintained.
Things to study
At the beginning, get a good understanding of the TCP/IP Protocol, how Sockets work, how common Protocols do their job (e.g. HTTP, WebSockets)
Take a look at specific Protocols working on top of the basic ones
Tip: REST: Most common WebServices Protocol, providing a common way to exchange stateless data. Uses Polling.
WebSockets: Socket connection using Web Browsers. Commonly used to update information without needing to poll.
There is no specific language to learn for connections. It's more about understanding what the difficulties are and what ways have been invented to address this. Once you get to this point and know what you want to do, it's possible in every language.
Recommendation: As you seem to use Java/Android, I would try to use REST. A really great client-side library for REST on Android is Retrofit. For the server side use what fits for you .. common Java way would be to use Jersey, but you are free to choose from a lot of choices. If using Jersey is too hard for the beginning, maybe take a look at the JS/NodeJS world, those guys invented Express, which allows you to create a REST service out of just a database, wihtout having to code a lot.
First you need to decide if you want to go for an Android or an iOS application. There are other various mobile operating systems as well, but these are widely used . If you want to go for android which is most widely used in my opinion, then you need to learn Java. If you want to go for iOS application, then you need to learn swift or objectiveC. These languages provide the API to connect with various types of services such as Facebook, Firebase and Amazon etc. If you want to connect to some other local server who’s IP is known to you, then you can use socket programming to send messages.
There could be many ways you can implement this. One way will be using Web services. Of course REST might be a better option, if you follow this approach. You can implement Your service(server side code) with any language. I will recommend you use java since you are already using android.
Aside from this You might need to go through the basics of REST, its specifications and
some reference implementations for language of your preference.

Inter-process-communication between a Java application and a local server

Firstly Cheers to all PROGRAMMERS [ Today = Programmers day :) ]
Secondly,
I'm working on a project where the specifications require using a server as a front end and an application in the back end. The project is an advanced smart home system. The server will handle commands coming from the client through the internet (let's say like a remote control from outside the house) and send them (through a channel of communication) to the application (planning on using JAVA application) which will handle the main logic like controlling hardware stuff (lights ...) , reading from a microphone (local mic) and accessing a database to act as a speech recognition system (offline).
Now I'm still in the planning phase and I'm not sure which technologies are the best for this project. I'm thinking to use Node.js or Apache as the server and a JAVA application as the back end and any SQL database for the application's SRS.
I hope this illustration demonstrates clearly how the system works:
The main question is:
What is the best way to make the Java application communicate with the server (communication channel [must be bidirectional]) ?
and Do you recommend a specific server other than the mentioned ones for this job ?
What crossed my mind so far:
1- JSP and servlets (making the server is the application too). But I don't want a server to handle the offline stuff and I'm not sure if java servlets can access hardware interface. I also want the server to be separate from making critical decisions (different layer for security reasons and since it won't be used as frequently as the local [offline] system).
2- Communication channel :
A- A shared file, but it's a bad idea since I don't want the application to check if the file contents changed (command received) or not from time to time (excessive operations).
B- A an inter-process-communication through a port (socket communication) seems the best solution but I don't know how that would turn in terms of operation cost and communication errors.
OS used : Linux Raspbian
EDIT:
I'm sure ZMQ+Apache is good enough for this task, but how is it in comparison to WebServices (like SOAP) ? Would WebServices be a better solution in terms of standard implementation and security ?
All related suggestions are welcomed, TQ
ZeroMQ is great for internal communications, or any other similar communication solutions.
For specifically your case, I can see that ZeroMQ would be a best fit.
Reasons:
You offline server have to be agnostic to web solution.
Communication can be reliable and bi-directional, possibly another patterns like (pub>sub, req<>res, etc).
Restarting any of sides would not require to restart the sockets (connection) on other side, as messages are queued.
Possibility to scale not just on same hardware, but as well to local area network or even through internet.
Big community of support. It might look a bit hard to get into, but in reality it is dead simple, just go to examples and once concept understood - it is very easy and neat to work with.
ZeroMQ has lots drivers for most popular languages, that includes Java and Node.js.
Considerations:
You need to think over packets and data will be sent. So some popular data protocols like XML or JSON is good way of thinking.
Responsibilities over different services - make sure they are not dependant on each other too much. Or if main offline server - is a core of system, make sure it does not depend on web facing service, so that web face can be removed/replaced/improved etc.
Few more points to think about:
Why Java, and what about modular approach? For example if you want to expand and scale - add more sensors into smart home solutions, then having one giant application would require to change it, it is harder to maintain as well as maintain different clients with own needs. Think modular way - some core functionality for offline stuff, but many aggregator processes that would talk to different sensors. This makes easier to support different setups and environments, as well maintain the system as a whole by improving independent components.

JMS/AMQP brokers comparison

After reading some interesting posts here on SO, and many pages found on google, I would like to ask you for help with decision what JMS/AMQP broker to choose. We are facing simple problem in our company. We need to use reliable message-based system for communication of nodes in cluster. Since we have "our own" solution for this, it's becoming quite clutter for us as we are trying to add more and more functionality into it (plus, it's buggy :)).
I really don't want to raise another question about which broker is better/worse, I would rather like to ask you about your personal experience and observation about reliability/complexity/flexibility of JMS/AMQP brokers. (i.e. I've found some confusing information about ActiveMQ, saying it's not stable yet many people consider it to be best JMS solution out there)
Currently, our system sends approx. 100 mps, so it's not big load, yet we need to be able to scale it in the future as more and more nodes will be added into cluster. Each node should be will be sending and receiving messages. We need to find as reliable solution as possible.
Thank you for your answers.
Generally speaking the more robust brokers are commercial ones. I have used ActiveMQ in production and it had a few problems I was able to work around. It supported up to 20K messages per second. I would use it again.
I'll start with the broker I know most about.
TIBCO EMS
Pros
Very stable
Has a c#, c and java api
Good support
Mature, has lots of nice enhancements, these manifest themselves in little things such as how it distributes messages to consumers on a queue etc.
Cons
Expensive
Not much information out there on the web
My boss helped develop the AMQP spec and he rates RabbitMQ very highly. I have not used it in anger so cannot comment.
Of course the one big advantage of AMQP over a JMS broker is interoperability ie a message sent from one vendors broker can be read by any other AMQP broker implementation
We used IBM Websphere MQ for larger installtions - its commercial only - but a robust, scalable solution. For little to medium we used ActiveMQ and OpenMQ.

How can I implement a good Client-Server approach?

I'm developing a distributed application, and I need to connect a client Java based to a server C++ based. Both of them will need to send information to each other, but I need them to be able to do things while waiting for the information, and they don't know when they are gonna get new information, or send information.
How can I achieve this? Now I'm trying to implement a basic communication with Sockets, but I don't really get to communicate them. I have read that using sockets + threads is usually a good approach for client-server apps.
Could you please recommend me some web or book to read about this, or send me some example code to learn?
Do you think that i should use other approach, better than sockets? maybe a higher level library (i would need it for c++ and java) or a totally different way?
EDIT:
I will add some extra information.
What I would love to achieve is the following:
My C++ program has a main loop, where I would like to have a call like GetUpdatedDataFromRemoteDevice() where I read the new values of some numerical variables that previously got updated from the net (the socket, for example).
Eventually, the C++ program will need to send a message to the remote device, to tell him to send other kind of data, and after that, keep getting the updated values.
From the Java program (remote device) the application running is an interactive touchable screen, that cant get blocked by the network transmissions, because it must keep working for the user, so all the networking should be done in a separated thread.
That thread, should connect to the server, and when a button is pushed, start to send the data (4 changing numerical values) in a loop until another event happens.
It would be nice also to be easily re-connectable to the server.
ICE is a modern and good library for distributed applications:
many languages as C++ and Java
many platforms
GNU GPL
good performance
easy to use
First, you define the messages you want to exchange between server and client.
Then, you implement the C++ and Java source code to handle these messages.
More info at http://zeroc.com/ice.html
Have fun ;-)
EDIT: I have to use ACE in some projects. I can tell ACE is very old, maybe mature, but uses outdated C++ coding rules :-(
Therefore ACE is not as easy to use as STL or BOOST. Moreover, ACE is not really efficient... I prefer ICE ;-)
I don't know what your application is but robust client server socket programming is pretty hairy task to do properly. Hardware byte order, String encoding, Network errors, retries, duplicate messages, acks etc.. require lots of good design and careful programming. You need to get it work well as single-threaded before even thinking using multiple threads.
Unless you need instant notifications from server to client I suggest that you use HTTP as protocol between client and server. Client can poll server occasionally for new messages.
Anyway the problem has been solved multiple times already.
http://activemq.apache.org/
http://www.rabbitmq.com/devtools.html
http://www.cs.wustl.edu/~schmidt/ACE-overview.html
I did something of this sort once. In my case it was easier to connect my C++ app to a local Java app using JNI and then have the two Java apps talk to each other.

Remote system event Notification Library

Hi I am looking for some sort of library that will allow:
- multiple remote applications to register with the system on which events it is interested in
- When this event occurs, the system will sent out notification to these remote applications regarding this event
- Objects, or hash tables information should be able to be exchanged as well between the system and the remote application
The system will be implemented in either Python, or Java, and it will serve as a middleware between a database and external applications. I am not sure if such a library exists, or if it will most suited to implement this as message exchanges. I have heard of twisted, pyro, but not sure of the extent of their capabilities. I had used RPyC previously, but it don't seem to fit the picture naturally. If someone can also point out what is available on the java side as well, I would really appreciated.
Plz advise, thnx!
I think you are looking for a queuing system. Give JMS a try.

Categories

Resources