473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Dynamic Response Generation

dmjpro
2,476 2GB
Is that possible to generate a response to a particular client using J2EE architecture. Suppose i am updating a database so that i want to notify a particular client who is running the application.
Mar 23 '09 #1
5 1404
chaarmann
785 Expert 512MB
You can make a database-trigger on the table that you want to be notified when it's updated.
This trigger then can execute java code directly in some databases (for example in Oracle) and this java code then can notify your application via RMI or via an EJB.

If your database can't execute java, but has triggers, then the trigger could update a small second table, for example RECENT_UPDATES, and write the current date inside. Then you can make a java background process (daemon) that polls this table, that means inqires it every minute to check if the date was changed. If yes, then notify your appplication.

If your database neither has triggers nor can call Java, then you can write an EJB and you must make sure that all manipulations of your database table goes through that bean. That means it won't work if the table would be changed from outside (like manually by the DBA, or through a remote connection from a second database, or through an external application...). That bean would propagate the update to all other clients, once a client calls a function of that bean that updates the table. (Business-layer)
Mar 23 '09 #2
dmjpro
2,476 2GB
Thanks for your help ..but now my application knows a change has occurred in database.
Is that possible to notify a client machine who is running my application currently?
I think my question sounds absurd ..in spite i trying to get the answer ;)
Mar 24 '09 #3
chaarmann
785 Expert 512MB
@dmjpro
You said your application knows that a change occurred in database, so it's already notified. So now you want to notify all other application that are running on the same machine? (You can't notify a "machine", therefore I assume you mean all processes running on the machine).
That's easily possible.
If it's a windows machine, you can use for example windows messaging. If it's a unix machine, you can use for example Corba. Just read more in wikipedia about "Inter-process communication". There are about 20 other possibilities listed (depending on your OS).

If you only want to notify other java-processe, you can use RMI (Java's Remote Method Invocation). Your EJB uses it internally, too, so why not simply execute functions of your EJB to notify all other processes?

If you want to make it OS-independent and process-independent, you can use the old-school-way:
Just open a file and write your message inside. Other processes are checking this file periodically and will scan for changes. if it is changed, they will read the message inside. Now they are notified.
Mar 25 '09 #4
dmjpro
2,476 2GB
Then how chats are possible .. i think you know about the Gmail chat.
How it is implemented ?
Mar 25 '09 #5
chaarmann
785 Expert 512MB
@dmjpro
You really think right. Because I programmed a google-like chat for an intranet of a big company from scratch.
There were 3 problems because of third-party-software: no EJB container and no session movement or application server control.

On the client side (browser), there runs an Ajax read-request every second that sends the actual lastDisplayedChatLineNumber over. It will then get all lines that are newer (or none if there is no new entry) from the server, display them and increase lastDisplayedChatLineNumber accordingly.
On the serverside, you can make a class Chat that has a static hashtable that holds all the chat data and a static variable lastChatLineNumber.
When a read-request from the client comes in, you compare lastDisplayedChatLineNumber with lastChatLineNumber and send the missing lines over. If a write-request comes in (if a user sends a new line from any client), you just increase lastChatLineNumber and store the new line in your hashtable.
It works without any further communication mechanism, because the static class data is shared among all threads. That's also the quickest communication.
So if you only have one application server (and one JVM instance), you don't need to worry further.

But it doesn't work if the sessions of two users in the same chat-room are on different application-servers. In this case, the simplest solution is to make sure that this can't happen. Either move the session from one application-server to the second, or make sure that all logins of different users to the same chat-room are only going to the same server.

If you can't control that (like in my case because of stupid third-party loadbalancer), then you must use Corba, RMI or something else (see post before) to communicate between the 2 threads. Because we had no EJB container and RMI crashed because of closed ports, I used the database-approach: I created a small table that holds the lastChatLineNumber column. All application-servers accessed the same (clustered) database. At every read-request, I read this number from DB and compared it with my own static lastChatLineNumber variable value. Then only in case it was different, I read the missing lines from a second, big table that holds all the chat-lines. At every write-request, I increased this number in the small database table and stored the corresponding line in the big table.

This works well, but isn't efficient for big traffic. If you still can't use corba or EJB, then at least you can use two tricks to minimize traffic:
Network-traffic: If a user doesn't type anything for at least 15 seconds, then his Ajax-requests will only inquire every minute instead of every second.
Database-traffic: Instead of doing it at every inquiry, an independent thread can synchronize the static variable lastChatLineNumber with the database every 3 seconds.
Mar 27 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Generic Usenet Account | last post by:
Most of the open source web-service products that I am reading about seem to require generation of client stub and server implementation ancestor classes from the WSDL file. The client application...
11
by: Marco Loskamp | last post by:
Dear list, I'm trying to dynamically generate functions; it seems that what I really want is beyond C itself, but I'd like to be confirmed here. In the minimal example below, I'd like to...
1
by: Scott Nichols | last post by:
Hello, I have an asp.net application. The application dynamically creates an invoice. It is important to see and approve the invoice before it is updated in the database. So...I was...
4
by: Venus | last post by:
Hello, Thanks for your reply. I understand that a control can be created dynamically in several ways: 1) using StringBuilder 2) using Controls.Add 3) using ASP PlaceHolder But this is just...
2
by: Ghada Al-Mashaqbeh via DotNetMonster.com | last post by:
Hi all, I am facing a problem in dynamic code generation at run time, the problem occurs when the dynmaic code use global data exist within the original application. Lets say that my...
5
by: pittendrigh | last post by:
There must be millions of dynamically generated html pages out there now, built by on-the-fly php code (and jsp, perl cgi, asp, etc). Programatic page generation is transparently useful. But...
3
by: Mukesh | last post by:
sir, i am developing a database, which will store the users profile both personal and professional which includes the address, telephone, gender and etc. in my main table i have created a column...
2
by: Amey Agnihotri | last post by:
Hi! I'm trying to run a few AT commands on a GSM modem. I'm doing this in C#.Net 2005. When I run a few commands one after the other, the response generation takes a long time. The response for...
10
by: Amey Agnihotri | last post by:
Hi! I'm trying to run a few AT commands on a GSM modem. I'm doing this in C#.Net 2005. When I run a few commands one after the other, the response generation takes a long time. The response for...
2
by: muriwai | last post by:
Hi, I am writing a web custom control that displays a dynamically generated image. Apparently I need to register an HTTP handler in web.config. Is there any way to register the handler...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.