package foodplanet.management.listeners;

import foodplanet.management.action.Action;
import javax.management.Notification;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class LowStockListener implements NotificationListener, NotificationFilter{
    Log log = LogFactory.getLog(LowStockListener.class);
    private Action action;
    
    public void handleNotification(Notification notification, Object handback) {
        log.info("*** LOW_STOCK Notification Received: dispatching  notification handler ***");
        action.setMessage(notification.getMessage());
        action.act();
    }

    public boolean isNotificationEnabled(Notification notification) {
        return (notification.getType().equals("LOW_STOCK")) ? true : false;
    }
    
    public void setAction(Action action) {
        this.action = action;
    }
}
