• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MariaDB 10.3 events

 
Ranch Hand
Posts: 218
5
MS IE Notepad Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I'd like to implement a dynamic vote system and need to combine PHP and Java with a MariaDB 10.3.

What I want to do:

When a user votes, the vote is added to the database, a random is generated and the user gets an email to verify the vote by click a link. When the vote is verified, the database should somehow send an event to a Java client so it gets notified about the data change so then the client on my system can update the overall votes. If possible, I'd like to not to poll the server frequent but idle and get an event. Maybe somehow know other ways to send an event from the PHP script to Java?
This might help: This is my root server - so if needed, I can do any modification to enable PHP to somehow talk to a socket or run a local binary - but for security reasons I'd like not to, or at least don't want to open security holes just to get this working.

Thanks in advance,

Matt


// edit
another possibility (if someone is willing to help) I could also setup an application server - but would need some help to get it working along already running apache httpd
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You didn't say what kind of Java client.

If it's a Java web application, the PHP server can simply post a web services API call to the Java webapp.

If it's an OSGi application, a web service might also work.

If it's a stand-alone application, you have several options. A popular one would be to use MQ services, which is how complex multi-component systems like the OpenStack cloud keep their components informed.

And there are many other possibilities.
 
Matt Wong
Ranch Hand
Posts: 218
5
MS IE Notepad Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry for not specifying it clear enough. Let me try:

Currently on my root runs an opensuse 15.1 with Apache2 httpd and PHP7 (both in distribution specific current versions - if needed I have to look them up). Also I setup an Apache James mail server v3.3.0 and some current sendmail as so called nullclient (that's it just takes messages dropped in local via sendmail command and forwards it to the james server wich handles all the MTA stuff). So Apache httpd is able to send mails via php mail() function.

Now I'd like to set up a voting system (reason doesn't matter here) wich works like this:

A user can choose from different vote options and has to provide a name and a valid e-mail-address (yes, I'm also setting up security to prevent this script gets misused as spam interface). When the user submit the vote, it is saved into the database but marked as non validated. To do so, the save script also generates a random token and sends it with the id of the newly created entry via mail the user has to interact with to verify. When this verify happen all that will done is that a flag in the dataset is flipped so it's marked as validated.

On the same time a stand-alone Java code runs on the same system also connected to the same database. In addition to that a code running on my PC is connected to this server code via simple TCP cinnection.

What should happen, when a user verifies a vote: an event should be triggered so that the java code run on server can send the just verified vote to the client on my PC wich then updates the total vote along with a possible message added to the vote.

Where I'm stuck: although it would be simple to add another flag to the dataset and poll those not yet polled, it's still polling. As I expect only low user count most of time/poll would be wasted. That's why I want it event based so that somehow the php script for verification also informs the java code without the java code has to poll the database all the time.

A way I could think of: use php socket() function to open a socket to the java code - although it's local I'd prefore to not to enable socket/files for php.
Another way I could think of would be a java application server: as I somehow then already be in java-land rest should be cake - although a fullblown app server seems overkill for a simple event.

Matt
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matt Wong wrote:As I expect only low user count most of time/poll would be wasted.



Wasted? Is the server which would be doing the polling fully committed to doing other things? I suspect it isn't. In which case there's nothing wrong with taking some time in which the server would have been doing nothing, and have it poll the database and find there's nothing to do.
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. I'm a little fuzzy here. What benefit is there to having this apparently stand-alone Java application forwarding events over having the PHP webapp cut out the middleman and doing it directly?

And I agree with Paul. Polling should be sufficient.
 
Matt Wong
Ranch Hand
Posts: 218
5
MS IE Notepad Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Short: I see active polling as bad concept when an event driven approach is possible.

Let's say we cut out Java and try it only with PHP -> my browser still has to poll the server every now and then, there simply is no technique available in stateless HTTP/1.1 so the server could trigger an event actively back in my browser without my browser polling it (also long-polling still requires active request from browser - only the response is just held back - wich could lead to timeout issues). Even if I set the poll timeout to 5 or 10 secounds - it's still simple waste of resources for power-intensive crypto just to get a "no update" instead of NIC-level TCP keep alive packets costing way less.

No way I try it - there is always some polling involved - unless I open potential security holes by allowing risky operations like fsockopen(). So, even may some think my way seems "even more stupid" - I think using mail() is a possible "active event" way.

How it works: The script checking the AUTH link calls mail() wich sends a mail local from apache to james - and my client simple keep IMAP IDLE and will get informed active by james wich generates an event I can process. IMAP IDLE by RFC is handled by TCP keep-alive as long as the client not issue other commands interrupting the IDLE - although it depends on server and client specific implementation to conform with RFC to not interrupt IDLE by fetching mails affected by change (new mails, flag changes, delete, etc).

This way I have an all-active forward only way of events:

user votes > user get mail to verify vote > user actively verifies > server sends mail local > mail-server trigger event on client wait in IDLE > my local client can process further actions - so I get rid of any polling (by RFC IMAP IDLE is not considered polling - as polling would require process of event and re-enter polling - wich imap IDLE does not when implemented correctly).

Topic solved!
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matt Wong wrote:Short: I see active polling as bad concept when an event driven approach is possible.



That sounds okay to me.

However I would consider describing an e-mail message as an "event" a bit, what should I call it, clumsy? Heavy duty? And besides there are things that can go wrong when using e-mail.

But if you're satisfied with it then I'm surely not going to complain.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic