Java program that monitors system date and sends email automatically - java

I'm working on a system that does a bunch of stuff, as well as monitors the current date on a system, checks it against a stored date in a database, and if both dates are exactly the same, sends an email automatically to a bunch of users.
Now, I've been able to do everything else (the email sending, reading data from the database, you name it), except the monitoring part. What technique do I employ such that once the program is running, and the user is using the program, some part of that program is also carrying out checks on system date and the date stored in the database?
Any suggestions will be appreciated.
Thanks.

If you want your check to run periodically (for example, once per day), use java.util.Timer and java.util.TimerTask, or some kind of scheduler library like Quartz.
Each check would involve making a query against the database to check if the emails need to be sent.
See this article for more information, and examples: http://oreilly.com/java/archive/quartz.html

Instead of using scheduler (Quartz or cron), or start a thread at target time, I'd recommend you to use ScheduledExecutorService.scheduleAtFixedRate to check periodically.
Advantages against other approaches: 1. it will reflect latest DB change at the moment. 2. it is easier to implemnt. 3. the logic can be reused or unit tested

Get the target-date from the database, calculate the time from now to the target-time and start a thread that sleeps for the calculated time and triggers your main-program again, when the sleep-time (target-time) is reached.
This will work when no changes to the target-time (in the database) are expected.
Otherwise you have to check your database periodically and reset your sleeping-thread if needed.

you can use mailScheduler for this re fer this
http://www.oop-reserch.com/scheduler.html

Unless the timing of the email sending is critical, you could just add a cron job to start the check every hour or so, rather than continously run.
In terms of the check itself, you could store the values in the DB using the to string method in DateFormat, and when you perform the check revert the string to a Date using the String constructor and compare.

Related

How to clear unwanted records in Kinvey Database

I am having an Android app and I am planning to use Kinvey Database to store some data.
One of the record in the entry would be having the last used time period.
The last used time period will be set by my app when ever the app is opened.
What basically I am trying to achieve is to run a code at the end of each month and clear all the record whos value of the last used period is more than 10 days.
Can any one please tell me whether it is possible to do this?
The reason for doing this is to use the least Server storage space as they provide only 1 GB/Monthly in the free plan.
What I understand from this...
What basically I am trying to achieve is to run a code at the end of each month and clear all the record whos value of the last used period is more than 10 days.
Can any one please tell me whether it is possible to do this?
... is that you would like to have scheduled code, which will be executed once a month. Please take a further look at the Scheduled Code feature of Kinvey.
https://devcenter.kinvey.com/html5/tutorials/scheduled-code-getting-started
Edit: more information on the topic...
Kinvey Scheduled code allows you to execute one of your custom endpoints on a specific date in the future. It is commonly used to
Aggregate, archive, and cleanup data.
Pull data from a third-party API into Kinvey.
Send out a batch of e-mails or push notifications.
I would not bother describing step-by-step initializing of Scheduled Code, since those steps may change in the future. Please follow the steps from the link above, those should be fine to get you further.

How to get an elapsed time for this?

I am creating a Spigot (Performance savvy fork of Bukkit (Minecraft server software)) plugin that communicates with a Bungee (Proxy server for managing multiple spigot instances) server.
I have a functionality, that when you type a command "/setbar (time-in-seconds) (message)", it will use an API (BarAPI if you are familiar) to create a bar on every server connected to the Bungee instance.
The fault with this is that when a player joins one of the Spigot servers after the command was issued, the Bar is not there. I solve this by storing the bar's information on the Proxy level and sending these values to the specific Spigot instance the player attempts to join.
Okay, so enough background information. The problem I'm having is that I'm storing the time the admin (or whoever issued the command) requested in a variable. When the user joins, obviously the time will have decremented slightly (or a lot.) The way I've thought of making sure the user who is joining receives the proper elapsed time, (so the BarAPI knows how large the timer graphic needs to be), was by storing the time the command was executed in a variable (currentTimeMillis / currentTimeNano) and converting that to seconds then subtracting that from the time specified in the command.
I know there is a flaw with my logic here, and I can't seem to work out the math. I know this is rather simple, but any help you can provide would be extremely beneficial.
Thanks in advance.
Postscript: Any information I have failed to provide, please let me know and I will add it to this post.
I realize this is a bit of a "no-end" question as there isn't an exact answer provided I didn't actually give any code.
Here is how I solved it in plain English, though:
Store the time the command was executed the first in milliseconds.
When the command is executed next, remove the first value from the new value and divide it by 1000 to receive a seconds-value.
The seconds-value is the elapsed time. Once can find how much time is remaining by then subtracting the seconds-value from the initially provided seconds-value for the bar.
Erase the bar for the user in question; recreate same values but substitute seconds for the newly calculated seconds-value.

Multiple iCalendar VEvents or VTODOs for the same meeting

My application needs to have a feature which would allow the creation of sort of like a project, where you put the total number of hours you need to work on it, the start date, the end date and how long each activity takes(additional constraints might be included as well).
What is the best way to create multiple VEvents according to those constraints with an option to change those VEvents? Also what's the best method to check the current iCalendar if the date is busy or not? Can I somehow retrieve all the busy dates from ics file and then just kind of check if the time gap is free or busy?
Typically, projects are described in terms of tasks (VTODO) instead of events. See http://www.calconnect.org/7_things_tasks.shtml for an introduction on tasks. This document also describes how tasks can be grouped together.
The second part of your question is a bit fuzzy. With a library like ical4j, you can make freebusy requests within a stream of vtodos. The other option would be to rely on a CalDAV server to store those.

Equal today date to date after a year

I am trying to license my product(java app) with a simple technique by comparing two dates.I want to know how should I increment the date when I give the app to my client.I need to increment the date everyday,so that when it expires it doesnt work.
I dont want to use the system date,cause there are chances the client might change that.So could anyone provide me any suggestions.
Since the java app is going to be running on your client, you have basically two options (simplistically speaking).
Option1. Use a (possibly) encrypted file on your client's filesystem to store the date you want to store and compare against your expire date.
Option2. Upon registering, register to a server. Now the server knows when you registered, so it should be able to determine when you expire. Each time the application starts, make a call to the server asking if it has expired. This way, you have transferred part of the expiry logic to the server.
Keep in mind that both approaches in their simplistic form can be easily circumvented but that is most of the time the case when you have an app running on clients' computers.
One way i can think of is
Use webservice to get current date in your client
earthtools.org provides a free web service to get the time zone from a city here:
http://www.earthtools.org/webservices.htm#timezone
You just pass in the long/lat values like this: (This is for New York)
http://www.earthtools.org/timezone-1.1/40.71417/-74.00639
Use java Rest client to get date in your code
http://www.mkyong.com/webservices/jax-rs/restfull-java-client-with-java-net-url/

User matching with current data

I have a database full of two different types of users (Mentors and Mentees), whereby I want the second group (Mentees) to be able to "search" for people in the first group (Mentors) who match their profile. Mentors and Mentees can both go in and change items in their profile at any point in time.
Currently, I am using Apache Mahout for the user matching (recommender.mostSimilarIDs()). The problem I'm running into is that I have to reload the user data every single time anyone searches. By itself, this doesn't take that long, but when Mahout processes the data it seems to take a very long time (14 minutes for 3000 Mentors and 3000 Mentees). After processing, matching takes mere seconds. I also get the same INFO message over and over again while it's processing ("Processed 2248 users"), while looking at the code shows that the message should only be outputted every 10000 users.
I'm using the GenericUserBasedRecommender and the GenericDataModel, along with the NearestNUserNeighborhood, AveragingPreferenceInferrer and PearsonCorrelationSimilarity. I load mentors from the database, add the mentee to the list of POJOs and convert them to a FastByIDMap to give to the DataModel.
Is there a better way to be doing this? The product owner needs the data to be current for every search.
(I'm the author.)
You shouldn't need to ask it to reload the data every time, why's that?
14 minutes sounds way, way too long to load such a small amount of data too, something's wrong. You might follow up with more info at user#mahout.apache.org.
You are seeing log messages from a DataModel, which you can disable in your logging system of choice. It prints one final count. This is nothing to worry about.
I would advise you against using a PreferenceInferrer unless you absolutely know you want it. Do you actually have ratings here? I might suggest LogLikelihoodSimilarity if not.

Categories