Java Reference
In-Depth Information
if
( user.filter
##
null
||
user.filter.length()
##
0
||
from.indexOf(user.filter)>
#
0
||
subject.indexOf(user.filter)>
#
0){
String sms
#
from
!
"> "
!
subject
!
": ";
if
(msg.getContentType().startsWith
("text/plain"))
sms
!#
(String)msg.getContent();
else
sms
!#
"type: "
!
msg.getContentType();
sender.send(user.mobile,sms);
}
}
}
sender.close();
}
catch
(Exception dbe){
System.out.println("UbiMail notifier, Error: "
!
dbe.getMessage());
}
if
(Thread.interrupted()) break;
} // end notification loop
}
catch
(InterruptedException e){
// do nothing. An interrupted exception makes the
// execution exit the loop
}
try
{
conn.close();
}
catch
(Exception e){}
}
}
The class
Manager
instantiates a notifier object in its constructor and
creates a thread that executes the notifier.
public class
Manager {
// ...
public
Manager(DataSource p_dataSource,
long
interval) {
dataSource
#
p_dataSource;
try
{
Connection conn
#
dataSource.getConnection();
Statement stmt
#
conn.createStatement();
Notify nf
#
new Notify(conn,interval);
notifier
#
new Thread(nf,"UbiMailNotifier");
notifier.start();
}
catch
(Exception e){
lastError
#
e.getMessage();
}
}
// ...
}