1 4 package org.oddjob.monitor.control; 5 6 import java.beans.PropertyChangeEvent ; 7 import java.beans.PropertyChangeListener ; 8 import java.util.HashMap ; 9 import java.util.Map ; 10 import java.util.Observable ; 11 import java.util.Observer ; 12 13 import org.apache.log4j.Logger; 14 import org.oddjob.monitor.model.Describer; 15 import org.oddjob.monitor.model.DetailModel; 16 import org.oddjob.monitor.model.PropertyModel; 17 18 23 public class PropertyPolling implements PropertyChangeListener , Observer { 24 private static final Logger logger = Logger 25 .getLogger(PropertyPolling.class); 26 27 private Object subject; 28 private Object kick; 29 30 private PropertyModel propertyModel; 31 32 37 public PropertyPolling(Object kick) { 38 this.kick = kick; 39 } 40 41 45 public void poll() { 46 Object subject = getSubject(); 47 if (subject == null) { 48 if (propertyModel != null) { 49 propertyModel.setProperties(new HashMap ()); 50 } 51 } else { 52 Map props = null; 53 props = Describer.describe(subject); 54 propertyModel.setProperties(props); 55 } 56 } 57 58 64 public void propertyChange(PropertyChangeEvent e) { 65 synchronized (kick) { 66 kick.notifyAll(); 67 } 68 } 69 70 73 public synchronized Object getSubject() { 74 return subject; 75 } 76 77 81 public synchronized void setSubject(Object subject) { 82 logger.debug("Setting subject to [" + subject + "]"); 83 if (this.subject != null) { 84 PropertyChangeHelper.removePropertyChangeListener(this.subject, 85 this); 86 } 87 this.subject = subject; 88 if (this.subject != null) { 89 PropertyChangeHelper.addPropertyChangeListener(this.subject, this); 90 } 91 synchronized (kick) { 92 kick.notifyAll(); 93 } 94 } 95 96 99 public synchronized PropertyModel getPropertyModel() { 100 return propertyModel; 101 } 102 103 107 public synchronized void setPropertyModel(PropertyModel propertyModel) { 108 this.propertyModel = propertyModel; 109 } 110 111 118 public void update(Observable o, Object arg) { 119 DetailModel explorerModel = (DetailModel) o; 120 if (explorerModel.getTabSelected() != DetailModel.PROPERTIES_TAB 121 || explorerModel.getSelectedJob() == null) { 122 setSubject(null); 123 return; 124 } 125 setSubject(explorerModel.getSelectedJob()); 126 } 127 } 128 | Popular Tags |