Hello Forks,
I'm tryimg to set up management rules.
I write MBean interface and MBean listed below.
package asap.action;
public interface SendMailActionMBean {
}
package asap.action;
import java.util.Date;
import java.util.Properties;
import java.util.logging.Logger;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.management.Notification;
import javax.management.NotificationListener;
import javax.mail.Message;
public class SendMailAction implements SendMailActionMBean,
NotificationListener {
@Override
public void handleNotification(Notification notification, Object handback) {
Logger log = Logger.getLogger("SendMailAction");
log.info("SendMailAction");
try {
Properties props = System.getProperties();
// set SMTP address
props.put("mail.smtp.host","localhost");
Session session = Session.getDefaultInstance(props, null);
MimeMessage mimeMessage = new MimeMessage(session);
// send from
mimeMessage.setFrom(
new InternetAddress("glasssfish_at_lab-wtomcat102d.db.xxxx.co.jp", "glassfish", "iso-2022-jp"));
mimeMessage.setRecipients(Message.RecipientType.TO, "susumu.majima_at_mail.xxxx.co.jp");
mimeMessage.setHeader("Content-type", "text/plain");
mimeMessage.setSubject("Message from GlassFish", "iso-2022-jp");
mimeMessage.setText("This is send by MBean");
mimeMessage.setSentDate(new Date());
Transport.send(mimeMessage);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
I change parts of my company name to xxxx.
I registered it by asadmin create-mbean command.
I create a management rule by admin console.
Rule Name:LifeCycleRule
Event Type:lifecycle
Event:ready
Action:SendMailActionBean(It's I registred)
I start up domain but nothing happen. No log,No mail I recieved.
Does someone try to this kind of management rule ?
Regards,
Susumu Majima