<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -358,7 +358,7 @@ public class AuctionEntry extends ActiveRecord implements Comparable&lt;AuctionEntr
   public void setServer(AuctionServerInterface newServer) {
     if(newServer != mServer) {
       //  &quot;CANCEL_SNIPE #{id}&quot;
-      if(isSniped()) getServer().cancelSnipe(this);
+      if(isSniped()) getServer().cancelSnipe(getIdentifier());
       mServer = newServer;
       if(isSniped()) getServer().setSnipe(this);
     }
@@ -1200,7 +1200,7 @@ public class AuctionEntry extends ActiveRecord implements Comparable&lt;AuctionEntr
       }
       setInteger(&quot;snipe_id&quot;, null);
       mSnipe = null;
-      getServer().cancelSnipe(this);
+      getServer().cancelSnipe(getIdentifier());
     } else {
       mSnipe = AuctionSnipe.create(snipe, quantity, 0);
       getServer().setSnipe(this);
@@ -1214,7 +1214,7 @@ public class AuctionEntry extends ActiveRecord implements Comparable&lt;AuctionEntr
    * @brief Refresh the snipe, so it picks up a potentially changed end time, or when initially loading items.
    */
   public void refreshSnipe() {
-    getServer().cancelSnipe(this);
+    getServer().cancelSnipe(getIdentifier());
     getServer().setSnipe(this);
   }
 </diff>
      <filename>src/com/jbidwatcher/auction/AuctionEntry.java</filename>
    </modified>
    <modified>
      <diff>@@ -121,5 +121,5 @@ public interface AuctionServerInterface {
 
   void setSnipe(AuctionEntry snipeOn);
 
-  void cancelSnipe(EntryInterface snipeCancel);
+  void cancelSnipe(String identifier);
 }</diff>
      <filename>src/com/jbidwatcher/auction/AuctionServerInterface.java</filename>
    </modified>
    <modified>
      <diff>@@ -60,7 +60,7 @@ public abstract class AuctionServer implements com.jbidwatcher.auction.AuctionSe
   public abstract void updateHighBid(AuctionEntry ae);
 
   public abstract void setSnipe(AuctionEntry snipeOn);
-  public abstract void cancelSnipe(EntryInterface snipeCancel);
+  public abstract void cancelSnipe(String identifier);
 
 
   /**</diff>
      <filename>src/com/jbidwatcher/auction/server/AuctionServer.java</filename>
    </modified>
    <modified>
      <diff>@@ -47,7 +47,6 @@ public final class ebayServer extends AuctionServer implements MessageQueue.List
 
   /** @noinspection FieldCanBeLocal*/
   private TimerHandler eQueue;
-  private Map&lt;String, AuctionQObject&gt; snipeMap = new HashMap&lt;String, AuctionQObject&gt;();
 
   /**&lt; The full amount of time it takes to request a single page from this site. */
   private long mPageRequestTime =0;
@@ -199,12 +198,6 @@ public final class ebayServer extends AuctionServer implements MessageQueue.List
           return;
         }
         break;
-      case AuctionQObject.CANCEL_SNIPE:
-        cancelSnipe((EntryInterface) ac.getData());
-        return;
-      case AuctionQObject.SET_SNIPE:
-        setSnipe((AuctionEntry) ac.getData());
-        return;
       case AuctionQObject.BID:
         bidMsg(ac);
         return;
@@ -293,36 +286,26 @@ public final class ebayServer extends AuctionServer implements MessageQueue.List
     MQFactory.getConcrete(&quot;Swing&quot;).enqueue(&quot;IGNORE &quot; + configBidMsg + ' ' + bidResultString);
   }
 
+  private static final int THIRTY_SECONDS = 30 * Constants.ONE_SECOND;
+  private static final long TWO_MINUTES = Constants.ONE_MINUTE * 2;
+
   public void setSnipe(AuctionEntry snipeOn) {
-    AuctionQObject currentlyExists = snipeMap.get(snipeOn.getIdentifier());
+    String identifier = snipeOn.getIdentifier();
+    Date endDate = snipeOn.getEndDate();
+    long snipeDelta = snipeOn.getSnipeTime();
     //  If we already have a snipe set for it, first cancel the old one, and then set up the new.
-    if(currentlyExists != null) {
-      _etqm.erase(null, currentlyExists);
-      _etqm.erase(null, snipeOn);
-      snipeMap.remove(snipeOn.getIdentifier());
-    }
-
-    long two_minutes = Constants.ONE_MINUTE*2;
-    AuctionQObject payload = new AuctionQObject(AuctionQObject.SNIPE, new Snipe(mLogin, mBidder, snipeOn), null);
+    _etqm.erase(identifier);
 
-    if (snipeOn.getEndDate() != null &amp;&amp; snipeOn.getEndDate() != Constants.FAR_FUTURE) {
-      _etqm.add(payload, mSnipeQueue, (snipeOn.getEndDate().getTime() - snipeOn.getSnipeTime()) - two_minutes);
-      _etqm.add(payload, mSnipeQueue, (snipeOn.getEndDate().getTime() - snipeOn.getSnipeTime()));
-      _etqm.add(snipeOn.getIdentifier(), &quot;drop&quot;, snipeOn.getEndDate().getTime() + 30 * Constants.ONE_SECOND);
-      snipeMap.put(snipeOn.getIdentifier(), payload);
+    if (endDate != null &amp;&amp; endDate != Constants.FAR_FUTURE) {
+      _etqm.add(identifier, mSnipeQueue, (endDate.getTime() - snipeDelta) - TWO_MINUTES);
+      _etqm.add(identifier, mSnipeQueue, (endDate.getTime() - snipeDelta));
+      _etqm.add(identifier, &quot;drop&quot;,       endDate.getTime() + THIRTY_SECONDS);
     }
   }
 
-  public void cancelSnipe(EntryInterface snipeCancel) {
-    String identifier = snipeCancel.getIdentifier();
-    AuctionQObject cancellable = snipeMap.get(identifier);
-
+  public void cancelSnipe(String identifier) {
     //  Erase the pending snipe
-    _etqm.erase(null, cancellable);
-    //  Erase the 30 seconds post-completion update
-    _etqm.erase(null, snipeCancel);
-
-    snipeMap.remove(identifier);
+    _etqm.erase(identifier);
   }
 
   public ebayServer(String site, String username, String password) {
@@ -613,43 +596,68 @@ public final class ebayServer extends AuctionServer implements MessageQueue.List
     MQFactory.getConcrete(&quot;Swing&quot;).enqueue(&quot;Done Getting Selling Items for &quot; + userId);
   }
 
-  //  TODO -- Wouldn't it be nice if this took an item number, and looked it up, instead of keeping a reference to the actual (potentially duplicated) object?
   private class SnipeListener implements MessageQueue.Listener {
+    private Map&lt;String, Snipe&gt; mSnipeMap = new HashMap&lt;String, Snipe&gt;();
+
+    /**
+     * Retrieve a stored Snipe object if one exists (containing the cookie information),
+     * or create a new one if one doesn't exist.
+     *
+     * @param identifier - The auction identifier to create the snipe for.
+     *
+     * @return - A Snipe object, either with a cookie object, or w/o. Returns
+     * null if the AuctionEntry associated with the identifier does not exist
+     * or is not sniped.
+     */
+    private Snipe getSnipe(String identifier) {
+      AuctionEntry ae = EntryCorral.getInstance().takeForRead(identifier);
+      if (ae == null || !ae.isSniped()) return null;
+
+      Snipe snipe;
+      if (mSnipeMap.containsKey(identifier)) {
+        snipe = mSnipeMap.get(identifier);
+      } else {
+        snipe = new Snipe(mLogin, mBidder, ae);
+        mSnipeMap.put(identifier, snipe);
+      }
+      return snipe;
+    }
+
     public void messageAction(Object deQ) {
-      AuctionQObject ac = (AuctionQObject) deQ;
-      if (ac.getCommand() == AuctionQObject.SNIPE) {
-        Snipe snipe = (Snipe) ac.getData();
-        int snipeResult = snipe.fire();
-        switch(snipeResult) {
-          case Snipe.RESNIPE:
-            /**
-             *  The formula for 'when' the next resnipe is, is a little complex.
-             * It's all in the code, though.  If we're 3 seconds or less away,
-             * give up.  Otherwise wait another 20% of the remaining time
-             * (minimum of 3 seconds), and retry.
-             */
-            long snipeIn = snipe.getItem().getEndDate().getTime() - _etqm.getCurrentTime();
-            if(snipeIn &gt; Constants.THREE_SECONDS) {
-              long retry_wait = (snipeIn / 10) * 2;
-              if(retry_wait &lt; Constants.THREE_SECONDS) retry_wait = Constants.THREE_SECONDS;
-
-              _etqm.add(deQ, mSnipeQueue, _etqm.getCurrentTime()+retry_wait);
-              break;
-            }
-            //  If there are less than 3 seconds left, give up by falling through to FAIL and DONE.
-            JConfig.log().logDebug(&quot;Resnipes failed, and less than 3 seconds away.  Giving up.&quot;);
-          case Snipe.FAIL:
-            _etqm.erase(null, deQ);
-            JConfig.log().logDebug(&quot;Snipe appears to have failed; cancelling.&quot;);
-            snipe.getItem().snipeFailed();
-            //  A failed snipe is a serious, hard error, and should fall through to being removed from the snipe map.
-          case Snipe.DONE:
-            snipeMap.remove(snipe.getItem().getIdentifier());
-            break;
-          case Snipe.SUCCESSFUL:
-          default:
+      String identifier = (String)deQ;
+      Snipe snipe = getSnipe(identifier);
+      if(snipe == null) return;
+
+      int snipeResult = snipe.fire();
+      switch (snipeResult) {
+        case Snipe.RESNIPE:
+          /**
+           *  The formula for 'when' the next resnipe is, is a little complex.
+           * It's all in the code, though.  If we're 3 seconds or less away,
+           * give up.  Otherwise wait another 20% of the remaining time
+           * (minimum of 3 seconds), and retry.
+           */
+          long snipeIn = snipe.getItem().getEndDate().getTime() - _etqm.getCurrentTime();
+          if (snipeIn &gt; Constants.THREE_SECONDS) {
+            long retry_wait = (snipeIn / 10) * 2;
+            if (retry_wait &lt; Constants.THREE_SECONDS) retry_wait = Constants.THREE_SECONDS;
+
+            _etqm.add(identifier, mSnipeQueue, _etqm.getCurrentTime() + retry_wait);
             break;
-        }
+          }
+          //  If there are less than 3 seconds left, give up by falling through to FAIL and DONE.
+          JConfig.log().logDebug(&quot;Resnipes failed, and less than 3 seconds away.  Giving up.&quot;);
+        case Snipe.FAIL:
+          _etqm.erase(identifier);
+          JConfig.log().logDebug(&quot;Snipe appears to have failed; cancelling.&quot;);
+          snipe.getItem().snipeFailed();
+          //  A failed snipe is a serious, hard error, and should fall through to being removed from any other lists.
+        case Snipe.DONE:
+          mSnipeMap.remove(identifier);
+          break;
+        case Snipe.SUCCESSFUL:
+        default:
+          break;
       }
     }
   }</diff>
      <filename>src/com/jbidwatcher/auction/server/ebay/ebayServer.java</filename>
    </modified>
    <modified>
      <diff>@@ -16,9 +16,6 @@ public class AuctionQObject extends QObject {
   public static final int BID = 5;
   public static final int LOAD_TITLE = 6;
   public static final int LOAD_STRINGS = 7;
-  public static final int SET_SNIPE = 8;
-  public static final int SNIPE = 9;
-  public static final int CANCEL_SNIPE = 10;
 
   public AuctionQObject() { super(); }
 </diff>
      <filename>src/com/jbidwatcher/util/queue/AuctionQObject.java</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>438a5ada17c43032ed7dca5651feee5076165ab4</id>
    </parent>
  </parents>
  <author>
    <name>Morgan Schweers</name>
    <email>cyberfox@jbidwatcher.com</email>
  </author>
  <url>http://github.com/cyberfox/jbidwatcher/commit/62a6aa88537e0feba33b81407fe94dbd6c34fd52</url>
  <id>62a6aa88537e0feba33b81407fe94dbd6c34fd52</id>
  <committed-date>2009-06-21T03:39:32-07:00</committed-date>
  <authored-date>2009-06-21T03:39:32-07:00</authored-date>
  <message>Make sniping use just the identifier, to simplify things.
Make cancelling snipes entirely based on just the identifier.

git-svn-id: svn://svn.jbidwatcher.com/jbidwatcher/trunk@962 b1acfa68-eb39-11db-b167-a3a8cd6b847e</message>
  <tree>e476d25eb5885696cf1604ec33fb74917dacaef7</tree>
  <committer>
    <name>Morgan Schweers</name>
    <email>cyberfox@jbidwatcher.com</email>
  </committer>
</commit>
