Java Reference
In-Depth Information
operations performed by the new thread are defined in the run() method. It
creates an SMSSender object that encapsulates the details of SMS message
sending. The constructor of the notifier requires a Connection to the data-
base and the mail server sampling interval.
package UbiMail;
import java.sql.*;
import javax.mail.*;
import sms.SMSSender;
class Notify implements Runnable {
Connection conn;
long interval;
SMSSender sender;
public Notify(Connection connection, long p_interval) {
conn # connection;
interval # (p_interval<1000?1000:p_interval);
// too low an interval would consume all the server
// resources
try {
// creates an SMSSender object used to send SMS
// messages
SMSSender sender # new SMSSender();
} catch (Exception ex){
System.out.println("UbiMail notifier,
Error: " ! ex.getMessage());
}
}
public void run(){
try {
while (sender! # null ){ // notification loop
Thread.sleep(interval);
try {
Statement stmt # conn.createStatement();
ResultSet rs # stmt.executeQuery(
"SELECT * FROM ubimailuser WHERE sms # 'Y'");
sender.open();
while (rs.next()){
User user # new User(rs);
Folder folder # user.openPopServer();
if (folder ## null ) throw
new Exception("Cannot connect to mail server.");
int n # folder.getMessageCount();
int newCount # folder.getNewMessageCount();
for ( int i # n-newCount; i<n; !! i){
Message msg # folder.getMessage(i ! 1);
String from # msg.getFrom()[0].toString();
String subject # msg.getSubject();
Search WWH ::




Custom Search