⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gcpastimpl.java

📁 pastry的java实现的2.0b版
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
              storage.getObject(gid,                new StandardContinuation(this) {                  public void receiveResult(Object o) {                    if (o != null) {                      trash.store(gid, storage.getMetadata(gid), (Serializable) o,                        new StandardContinuation(parent) {                          public void receiveResult(Object o) {                            storage.unstore(gid, parent);                          }                        });                    } else {                      storage.unstore(gid, this);                    }                  }                });            } else {              storage.unstore(gid, this);            }          } else {            parent.receiveResult(Boolean.TRUE);          }        }      };    remove.receiveResult(null);  }  // ---- REPLICATION MANAGER METHODS -----  /**   * This upcall is invoked to tell the client to fetch the given id, and to   * call the given command with the boolean result once the fetch is completed.   * The client *MUST* call the command at some point in the future, as the   * manager waits for the command to return before continuing.   *   * @param id The id to fetch   * @param hint DESCRIBE THE PARAMETER   * @param command DESCRIBE THE PARAMETER   */  public void fetch(final Id id, NodeHandle hint, Continuation command) {    if (logger.level <= Logger.FINER) {      logger.log("Sending out replication fetch request for the id " + id);    }    final GCId gcid = (GCId) id;    if (gcid.getExpiration() < environment.getTimeSource().currentTimeMillis()) {      command.receiveResult(Boolean.TRUE);    } else if (storage.exists(gcid.getId())) {      GCPastMetadata metadata = (GCPastMetadata) storage.getMetadata(gcid.getId());      if (metadata == null) {        storage.getObject(gcid.getId(),          new StandardContinuation(command) {            public void receiveResult(Object o) {              GCPastContent content = (GCPastContent) o;              storage.setMetadata(content.getId(), content.getMetadata(gcid.getExpiration()), parent);            }          });      } else if (metadata.getExpiration() < gcid.getExpiration()) {        storage.setMetadata(gcid.getId(), metadata.setExpiration(gcid.getExpiration()), command);      } else {        command.receiveResult(Boolean.TRUE);      }    } else {      policy.fetch(gcid.getId(), hint, backup, this,        new StandardContinuation(command) {          public void receiveResult(Object o) {            if (o == null) {              if (logger.level <= Logger.WARNING) {                logger.log("Could not fetch id " + id + " - policy returned null in namespace " + instance);              }              parent.receiveResult(new Boolean(false));            } else {              GCPastContent content = (GCPastContent) o;              if (logger.level <= Logger.FINEST) {                logger.log("inserting replica of id " + id);              }              storage.getStorage().store(gcid.getId(), content.getMetadata(gcid.getExpiration()), content, parent);            }          }        });    }  }  /**   * This upcall is to notify the client that the given id can be safely removed   * from the storage. The client may choose to perform advanced behavior, such   * as caching the object, or may simply delete it.   *   * @param id The id to remove   * @param command DESCRIBE THE PARAMETER   */  public void remove(Id id, Continuation command) {    super.remove(((GCId) id).getId(), command);  }  /**   * This upcall should return the set of keys that the application currently   * stores in this range. Should return a empty IdSet (not null), in the case   * that no keys belong to this range.   *   * @param range the requested range   * @return DESCRIBE THE RETURN VALUE   */  public IdSet scan(IdRange range) {    GCIdRange gcRange = (GCIdRange) range;    return new GCIdSet(storage.getStorage().scan(gcRange.getRange()), storage.getStorage().scanMetadata(gcRange.getRange()));  }  /**   * This upcall should return the set of keys that the application currently   * stores. Should return a empty IdSet (not null), in the case that no keys   * belong to this range.   *   * @return DESCRIBE THE RETURN VALUE   */  public IdSet scan() {    return new GCIdSet(storage.getStorage().scan(), storage.getStorage().scanMetadata());  }  /**   * This upcall should return whether or not the given id is currently stored   * by the client.   *   * @param id The id in question   * @return Whether or not the id exists   */  public boolean exists(Id id) {    if (id instanceof GCId) {      return storage.getStorage().exists(((GCId) id).getId());    } else {      return storage.getStorage().exists(id);    }  }  /**   * DESCRIBE THE METHOD   *   * @param id DESCRIBE THE PARAMETER   * @param command DESCRIBE THE PARAMETER   */  public void existsInOverlay(Id id, Continuation command) {    if (id instanceof GCId) {      super.existsInOverlay(((GCId) id).getId(), command);    } else {      super.existsInOverlay(id, command);    }  }  /**   * DESCRIBE THE METHOD   *   * @param id DESCRIBE THE PARAMETER   * @param command DESCRIBE THE PARAMETER   */  public void reInsert(final Id id, Continuation command) {    if (id instanceof GCId) {      // what if the GCId's expiration is different than the metadata's?      storage.getObject(((GCId) id).getId(),        new StandardContinuation(command) {          public void receiveResult(final Object o) {            insert((PastContent) o, ((GCId) id).getExpiration(),              new StandardContinuation(parent) {                public void receiveResult(Object result) {                  Boolean results[] = (Boolean[]) result;                  for (int i = 0; i < results.length; i++) {                    if (results[i].booleanValue()) {                      parent.receiveResult(Boolean.TRUE);                      return;                    }                  }                  parent.receiveResult(Boolean.FALSE);                }              });          }        });    } else {      GCPastMetadata metadata = (GCPastMetadata) storage.getMetadata(id);      if (metadata == null) {        // no metadata, just reinsert with no expiration        super.reInsert(id, command);      } else {        reInsert(new GCId(id, metadata.getExpiration()), command);      }    }  }  /**   * DESCRIBE THE CLASS   *   * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $   * @author jeffh   */  protected class GCPastDeserializer extends PastDeserializer {    /**     * DESCRIBE THE METHOD     *     * @param buf DESCRIBE THE PARAMETER     * @param type DESCRIBE THE PARAMETER     * @param priority DESCRIBE THE PARAMETER     * @param sender DESCRIBE THE PARAMETER     * @return DESCRIBE THE RETURN VALUE     * @exception IOException DESCRIBE THE EXCEPTION     */    public Message deserialize(InputBuffer buf, short type, byte priority, NodeHandle sender) throws IOException {      try {        switch (type) {          case GCInsertMessage.TYPE:            return GCInsertMessage.buildGC(buf, endpoint, contentDeserializer);          case GCLookupHandlesMessage.TYPE:            return GCLookupHandlesMessage.buildGC(buf, endpoint);          case GCRefreshMessage.TYPE:            return GCRefreshMessage.build(buf, endpoint);        }      } catch (IOException e) {        if (logger.level <= Logger.SEVERE) {          logger.log("Exception in deserializer in " + GCPastImpl.this.endpoint.toString() + ":" + instance + " " + e);        }        throw e;      }      return super.deserialize(buf, type, priority, sender);    }  }  /**   * DESCRIBE THE CLASS   *   * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $   * @author jeffh   */  protected class ReplicaMap {    /**     * DESCRIBE THE FIELD     */    protected HashMap map = new HashMap();    /**     * Gets the Replicas attribute of the ReplicaMap object     *     * @return The Replicas value     */    public Iterator getReplicas() {      return map.keySet().iterator();    }    /**     * Gets the Ids attribute of the ReplicaMap object     *     * @param replica DESCRIBE THE PARAMETER     * @return The Ids value     */    public GCIdSet getIds(NodeHandle replica) {      return (GCIdSet) map.get(replica);    }    /**     * Adds a feature to the Replica attribute of the ReplicaMap object     *     * @param handle The feature to be added to the Replica attribute     * @param id The feature to be added to the Replica attribute     */    public void addReplica(NodeHandle handle, GCId id) {      IdSet set = (IdSet) map.get(handle);      if (set == null) {        set = new GCIdSet(realFactory);        map.put(handle, set);      }      set.addId(id);    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -