artjomka
artjomka

Reputation: 1229

Strategy to merge java applications in one

Situation : 2 small java applications both of them connecting to remote service and sending some data there (first application listens to local socket, process data, sends it for verification to remote service and process response; second application starts on scheduled time, process some data for database and send that data to remote service).The problem is that remote service allows only one connection (that connection is SMPP session), that mean if one application is running and other application starts and try to make connection then bad things will happens...

The idea is to combine that 2 applications in 1 (maybe there are other solutions?) and create some kind of control workflow functionality which responsibility will be to manages applications to avoid collisions in connecting to remote service. Can someone give me any advice about that idea? Maybe there is some kind of design pattern which allows me to avoid some pitfalls when I will be implementing that? (it would be even better if there are some open source applications which manages similar kind of problem so I could browse source code and gather some good information).

Thank you.

Upvotes: 0

Views: 206

Answers (2)

Rostislav Matl
Rostislav Matl

Reputation: 4543

Wrap data to classes together with necessary metadata.

Place your applications to separate threads and instead of sending the data add them to a queue.

Then, in another thread, read the queue and send data from the queue to the service.

I'd give a try to BlockingQueue (http://download.oracle.com/javase/1,5.0/docs/api/java/util/concurrent/BlockingQueue.html) .

Upvotes: 1

Ruslan Mukhamedov
Ruslan Mukhamedov

Reputation: 458

Most obvious solution is to write a simple reverse proxy server that will gather requests in to queue and send them one by one to your remote service. Or proxy could run new instance of service for each request. http://en.wikipedia.org/wiki/Reverse_proxy

Upvotes: 1

Related Questions