|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
JESS: firePropertyChange IneffectiveWhen I call firePropertyChange from my Java object after setting an attribute the working memory of my engine is not updated. I know this because I loop through the facts before and after the setting of the attribute, and "round" is set to "0" both times.
My Java and Jess code is below (if you're wondering why I have a class just to wrap an int and string, it's to tie into some 3rd party code I don't have control over). Any idea what I'm doing wrong? ######## JAVA CLASS ######## package game.server; import java.beans.*; import java.io.*; import java.nio.*; import java.util.*; import jess.*; public class Round implements Serializable { private static final long serialVersionUID = 1L; private int round; private String gameName; private PropertyChangeSupport propertyChange; protected Round(int round, String game) { this.round = round; gameName = game; propertyChange = new PropertyChangeSupport(this); } public int getRound() { return round; } public void setRound(int round) { if (this.round != round) { int oldValue = this.round; this.round = round; // Fire property change event so Jess working memory is updated propertyChange.firePropertyChange("round", new Integer(oldValue), new Integer(this.round)); } } public String getGameName() { return gameName; } public void setGameName(String game) { gameName = game; } public void addPropertyChangeListener(PropertyChangeListener listener) { propertyChange.addPropertyChangeListener(listener); } public void removePropertyChangeListener(PropertyChangeListener listener) { propertyChange.removePropertyChangeListener(listener); } public boolean equals(Object obj) { boolean equal = false; if (obj instanceof Round) { Round objRound = (Round)obj; equal = ((objRound.getRound() == round) && (objRound.getGameName() == gameName)); } return equal; } public int hashCode() { // Game name never changes so hashCode is mutable return gameName.hashCode(); } } ######## JESS RULES ######## (import game.server.*) (deftemplate Round (declare (from-class Round))) (defrule process-round (Round {round >= 0} (round ?round)) => (printout t "Round " ?round crlf) ) |
|
|
Re: JESS: firePropertyChange IneffectiveThe only thing here that's clearly wrong is the equals() method -- you
can't (generally) compare Strings with equals -- you want to use the equals() method instead. But otherwise from Jess's perspective I think things should be fine. How are you adding the objects to working memory? Using "add" or "definstance"? Can I see that line of code? On Aug 21, 2009, at 11:20 AM, Pierre Bezuhov wrote: > When I call firePropertyChange from my Java object after setting an > attribute the working memory of my engine is not updated. I know > this because I loop through the facts before and after the setting > of the attribute, and "round" is set to "0" both times. > > My Java and Jess code is below (if you're wondering why I have a > class just to wrap an int and string, it's to tie into some 3rd > party code I don't have control over). Any idea what I'm doing wrong? > > ######## JAVA CLASS ######## > package game.server; > > import java.beans.*; > import java.io.*; > import java.nio.*; > import java.util.*; > import jess.*; > > public class Round implements Serializable > { > private static final long serialVersionUID = 1L; > private int round; > private String gameName; > private PropertyChangeSupport propertyChange; > > protected Round(int round, String game) > { > this.round = round; > gameName = game; > propertyChange = new PropertyChangeSupport(this); > } > > public int getRound() > { > return round; > } > > public void setRound(int round) > { > if (this.round != round) > { > int oldValue = this.round; > this.round = round; > > // Fire property change event so Jess working memory is > updated > propertyChange.firePropertyChange("round", new > Integer(oldValue), new Integer(this.round)); > } > } > > public String getGameName() > { > return gameName; > } > > public void setGameName(String game) > { > gameName = game; > } > > > public void addPropertyChangeListener(PropertyChangeListener > listener) > { > propertyChange.addPropertyChangeListener(listener); > } > > public void removePropertyChangeListener(PropertyChangeListener > listener) > { > propertyChange.removePropertyChangeListener(listener); > } > > public boolean equals(Object obj) > { > boolean equal = false; > > if (obj instanceof Round) > { > Round objRound = (Round)obj; > equal = ((objRound.getRound() == round) && > (objRound.getGameName() == gameName)); > } > > return equal; > } > > public int hashCode() > { > // Game name never changes so hashCode is mutable > return gameName.hashCode(); > } > } > > > ######## JESS RULES ######## > (import game.server.*) > > (deftemplate Round (declare (from-class Round))) > > (defrule process-round > (Round {round >= 0} (round ?round)) > => > (printout t "Round " ?round crlf) > ) --------------------------------------------------------- Ernest Friedman-Hill Informatics & Decision Sciences, Sandia National Laboratories PO Box 969, MS 9012, Livermore, CA 94550 http://www.jessrules.com -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users you@...' in the BODY of a message to majordomo@..., NOT to the list (use your own address!) List problems? Notify owner-jess-users@.... -------------------------------------------------------------------- |
|
|
Re: JESS: firePropertyChange IneffectiveYeah, this being my first major Java project the String.equals mistake is one I've probably made half a dozen times. Below is the code where I add the object to working memory.
private void setEngine(Rete engine) { this.engine = engine; // Set round after retrieving it from game Game game = (Game)AppContext.getDataManager().getBinding(gameName); round = game.getRound(); // Add round to engine and run try { engine.removeFacts("Round"); // Remove any existing Round objects from working memory (needed to eliminate objects added by aborted transactions) factId = this.engine.definstance("Round", round, true); this.engine.run(); } catch (JessException e) { logger.log(Level.WARNING, "Error setting round"); } } On Fri, Aug 21, 2009 at 11:48 AM, Ernest Friedman-Hill <ejfried@...> wrote: The only thing here that's clearly wrong is the equals() method -- you can't (generally) compare Strings with equals -- you want to use the equals() method instead. But otherwise from Jess's perspective I think things should be fine. |
|
|
Re: JESS: firePropertyChange IneffectiveAs I said before, the firePropertyChange method was ineffective. Now however, after changing around some code (none of the code listed in this post), I'm getting the following error when firePropertyChange is called.
java.lang.NullPointerException at jess.de.propertyChange(Unknown Source) at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:339) at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:276) at geogame.server.Round.setRound(Round.java:61) at geogame.server.Game.advanceRound(Game.java:987) at geogame.server.Game.advanceTimer(Game.java:910) at geogame.server.Game.run(Game.java:889) at com.sun.sgs.impl.service.task.PendingTask.run(PendingTask.java:224) at com.sun.sgs.impl.service.task.TaskServiceImpl$TaskRunner.run(TaskServiceImpl.java:1081) at com.sun.sgs.impl.kernel.TransactionSchedulerImpl.executeTask(TransactionSchedulerImpl.java:579) at com.sun.sgs.impl.kernel.TransactionSchedulerImpl.access$500(TransactionSchedulerImpl.java:70) at com.sun.sgs.impl.kernel.TransactionSchedulerImpl$TaskConsumer.run(TransactionSchedulerImpl.java:487) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) I thought that maybe this meant that the object for which firePropertyChange was being called was not added to the engine. However I verified that a Round object is being added and that the corresponding fact shows up. Anyone know what's going on here? On Fri, Aug 21, 2009 at 11:48 AM, Ernest Friedman-Hill <ejfried@...> wrote: The only thing here that's clearly wrong is the equals() method -- you can't (generally) compare Strings with equals -- you want to use the equals() method instead. But otherwise from Jess's perspective I think things should be fine. |
|
|
Re: JESS: firePropertyChange IneffectiveWhat version of Jess are you using? For the most current version, the
only thing I see that could possibly give that stack trace would be if the PropertyChangeEvent event object being sent to Jess was itself null, but that seems unlikely given that you're using PropertyChangeSupport. If you're using some older version, perhaps you're seeing an old bug that's already been fixed. On Aug 23, 2009, at 5:00 PM, Pierre Bezuhov wrote: > As I said before, the firePropertyChange method was ineffective. > Now however, after changing around some code (none of the code > listed in this post), I'm getting the following error when > firePropertyChange is called. > > java.lang.NullPointerException > at jess.de.propertyChange(Unknown Source) > at > java > .beans > .PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java: > 339) > at > java > .beans > .PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java: > 276) > at geogame.server.Round.setRound(Round.java:61) > at geogame.server.Game.advanceRound(Game.java:987) > at geogame.server.Game.advanceTimer(Game.java:910) > at geogame.server.Game.run(Game.java:889) > at > com.sun.sgs.impl.service.task.PendingTask.run(PendingTask.java:224) > at com.sun.sgs.impl.service.task.TaskServiceImpl > $TaskRunner.run(TaskServiceImpl.java:1081) > at > com > .sun > .sgs > .impl > .kernel > .TransactionSchedulerImpl.executeTask(TransactionSchedulerImpl.java: > 579) > at com.sun.sgs.impl.kernel.TransactionSchedulerImpl.access > $500(TransactionSchedulerImpl.java:70) > at com.sun.sgs.impl.kernel.TransactionSchedulerImpl > $TaskConsumer.run(TransactionSchedulerImpl.java:487) > at java.util.concurrent.Executors > $RunnableAdapter.call(Executors.java:441) > at java.util.concurrent.FutureTask > $Sync.innerRun(FutureTask.java:303) > at java.util.concurrent.FutureTask.run(FutureTask.java:138) > at java.util.concurrent.ThreadPoolExecutor > $Worker.runTask(ThreadPoolExecutor.java:886) > at java.util.concurrent.ThreadPoolExecutor > $Worker.run(ThreadPoolExecutor.java:908) > at java.lang.Thread.run(Thread.java:619) > > I thought that maybe this meant that the object for which > firePropertyChange was being called was not added to the engine. > However I verified that a Round object is being added and that the > corresponding fact shows up. Anyone know what's going on here? > > > On Fri, Aug 21, 2009 at 11:48 AM, Ernest Friedman-Hill <ejfried@... > > wrote: > The only thing here that's clearly wrong is the equals() method -- > you can't (generally) compare Strings with equals -- you want to use > the equals() method instead. But otherwise from Jess's perspective I > think things should be fine. > > How are you adding the objects to working memory? Using "add" or > "definstance"? Can I see that line of code? > > > > On Aug 21, 2009, at 11:20 AM, Pierre Bezuhov wrote: > > When I call firePropertyChange from my Java object after setting an > attribute the working memory of my engine is not updated. I know > this because I loop through the facts before and after the setting > of the attribute, and "round" is set to "0" both times. > > My Java and Jess code is below (if you're wondering why I have a > class just to wrap an int and string, it's to tie into some 3rd > party code I don't have control over). Any idea what I'm doing wrong? > > ######## JAVA CLASS ######## > package game.server; > > import java.beans.*; > import java.io.*; > import java.nio.*; > import java.util.*; > import jess.*; > > public class Round implements Serializable > { > private static final long serialVersionUID = 1L; > private int round; > private String gameName; > private PropertyChangeSupport propertyChange; > > protected Round(int round, String game) > { > this.round = round; > gameName = game; > propertyChange = new PropertyChangeSupport(this); > } > > public int getRound() > { > return round; > } > > public void setRound(int round) > { > if (this.round != round) > { > int oldValue = this.round; > this.round = round; > > // Fire property change event so Jess working memory is > updated > propertyChange.firePropertyChange("round", new > Integer(oldValue), new Integer(this.round)); > } > } > > public String getGameName() > { > return gameName; > } > > public void setGameName(String game) > { > gameName = game; > } > > > public void addPropertyChangeListener(PropertyChangeListener > listener) > { > propertyChange.addPropertyChangeListener(listener); > } > > public void removePropertyChangeListener(PropertyChangeListener > listener) > { > propertyChange.removePropertyChangeListener(listener); > } > > public boolean equals(Object obj) > { > boolean equal = false; > > if (obj instanceof Round) > { > Round objRound = (Round)obj; > equal = ((objRound.getRound() == round) && > (objRound.getGameName() == gameName)); > } > > return equal; > } > > public int hashCode() > { > // Game name never changes so hashCode is mutable > return gameName.hashCode(); > } > } > > > ######## JESS RULES ######## > (import game.server.*) > > (deftemplate Round (declare (from-class Round))) > > (defrule process-round > (Round {round >= 0} (round ?round)) > => > (printout t "Round " ?round crlf) > ) > > --------------------------------------------------------- > Ernest Friedman-Hill > Informatics & Decision Sciences, Sandia National Laboratories > PO Box 969, MS 9012, Livermore, CA 94550 > http://www.jessrules.com > > > > > > > > -------------------------------------------------------------------- > To unsubscribe, send the words 'unsubscribe jess-users > you@...' > in the BODY of a message to majordomo@..., NOT to the list > (use your own address!) List problems? Notify owner-jess-users@... > . > -------------------------------------------------------------------- > > --------------------------------------------------------- Ernest Friedman-Hill Informatics & Decision Sciences, Sandia National Laboratories PO Box 969, MS 9012, Livermore, CA 94550 http://www.jessrules.com -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users you@...' in the BODY of a message to majordomo@..., NOT to the list (use your own address!) List problems? Notify owner-jess-users@.... -------------------------------------------------------------------- |
|
|
Re: JESS: firePropertyChange IneffectiveI'm using an academic license of the newest version, 7.1p2. I still can't seem to figure it out.
On Mon, Aug 24, 2009 at 3:54 PM, Ernest Friedman-Hill <ejfried@...> wrote: What version of Jess are you using? For the most current version, the only thing I see that could possibly give that stack trace would be if the PropertyChangeEvent event object being sent to Jess was itself null, but that seems unlikely given that you're using PropertyChangeSupport. If you're using some older version, perhaps you're seeing an old bug that's already been fixed. |
| Free embeddable forum powered by Nabble | Forum Help |