Java Reference
In-Depth Information
B
Send
notification
public void sendNotification( Notification notif )
{
try
{
String sql = "insert into Notifications ( message,
sequence_number, " + " source, timestamp, type,
user_data ) values ( ?,?,?,?,?,? )";
PreparedStatement ps = con.prepareStatement( sql );
ps.setString( 1, notif.getMessage() );
ps.setLong( 2, notif.getSequenceNumber() );
if( notif.getSource() != null &&
notif.getSource() instanceof Serializable )
ps.setObject( 3,notif.getSource() );
else
ps.setString( 3, "No Source" );
ps.setLong( 4, notif.getTimeStamp() );
ps.setString( 5, notif.getType() );
if( notif.getUserData() != null &&
notif.getUserData() instanceof Serializable )
ps.setObject( 6,notif.getUserData() );
else
ps.setString( 6, "No User Data" );
ps.executeUpdate();
con.commit();
}
catch( Exception e )
{
e.printStackTrace();
}
super.sendNotification( notif );
}
}
B
The sendNotification() method executes some simple JDBC code to persist the
outgoing notification before sending it. Be sure to notice that an implementation
like this one assumes the appropriate database tables already exist.
6.7 Notifications from the MBean server
When we first looked at the HTML adapter in chapter 2, you discovered that your
MBeanServer contained an MBean that you did not create. That MBean was
Search WWH ::




Custom Search