I'm developing a web application which acts as an email client for mobile. In this application user can login and provide numerous email ids for monitoring.There are two main classes in the web application. 1.MailGetter 2.MailFormatter
Behaviour of MailGetter class:
- Timertask initiated which will execute for every 10 minutes
- Obtains the numerous email ids from database which are provided for monitoring
- establishes connection with mail server for the first email id and obtains recently arrived email message object
- passes the message object to MailFormatter class
Behavior of MailFormatter class:
- parses the email message object
- various recursive calls made if the message has many multiparts inorder to parse parts one by one
- downloads also attachments along with this message
- returns an xml string to the MailGetter class which will be stored as simple text file with the following content:
Example:
<mail>
<from>FromEmailID</from>
<to>ToEmailID</to>
<subject>Subject</subject>
<body>Email Body</body>
<attachments>
attachment
</attachments>
</mail>
MobileResponderServlet: A separate servlet is also coded in the web application which will read the simple xml text file and send the read content to mobile
The main demerit of this application might be "MailGetter" class will be waiting until all the functions (including recursive calls) of "MailFormatter" class finishes execution.Once the control is returned from "MailFormatter" class to "MailGetter" class, it will obtain the next message object from mail server and passes it to "MailFormatter" class.So intimating about new emails to the mobile user consumes time. Even when "MailFormatter" class is implemented as a separate thread,consider in a case if there are 1000 new emails in a single inbox (for a single emailid) which will be invocating 1000 "MailFormatter" threads, which will make the process more resource intensive.
So I'm deciding to unplug "MailFormatter" from "MailGetter". "MailGetter" will be running as a separate web application in one server whereas "MailFormatter" will be running as a separate web application in another server. After obtaining the recent email message object "MailGetter" web application persists (via message.writeTo(FileOutputstream)) the message object in a location which is also common to "MailFormatter". "MailFormatter" class then reads (via MimeMessage(Session,InputStream) constructor) and parses the message object one by one and then stores the "XML Content" in another location which will be read by "MobileResponderServlet" and sent to mobile.
Will this process be efficient in real time? Will this be arising problems especially while sharing message objects between "MailGetter" and "MailFormatter" web applications? Please do let me know if there are any other ways. This web application will be handling more than 5000 users (minimum) who have provided numerous email ids for monitoring.