storemanager.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 924 行 · 第 1/2 页

JAVA
924
字号
  public void access(HashKey objectId)    throws Exception  {    ClusterObject obj = getClusterObject(objectId);    if (obj != null)      obj.accessImpl();    else      accessImpl(obj.getObjectId());  }  /**   * Updates the object's objectAccess time.   *   * @param storeId the identifier of the storage group   * @param obj the object to updateImpl.   */  public void access(Store store, String id)    throws Exception  {    getClusterObject(store, id).objectAccess();  }    /**   * Updates the object's objectAccess time in the persistent objectStore.   *   * @param uniqueId the identifier of the object.   */  abstract public void accessImpl(HashKey objectId)    throws Exception;    /**   * Updates the object's objectAccess time in the persistent objectStore.   *   * @param uniqueId the identifier of the object.   */  public void accessImpl(ClusterObject obj)    throws Exception  {    accessImpl(obj.getObjectId());  }    /**   * Sets the timef for the expires interval.   *   * @param uniqueId the identifier of the object.   * @param long the time in ms for the expire   */  public void setExpireInterval(HashKey uniqueId, long expires)    throws Exception  {  }  /**   * Notify the object that the data has changed.   *    * @param objectId the identifier of the object to notify   */  public void invalidate(HashKey objectId)    throws Exception  {    ClusterObject obj = getClusterObject(objectId);    if (obj != null)      obj.updateImpl();  }  /**   * Updates the owner object.   *   * @param uniqueId the identifier of the storage group   */  public void updateOwner(ClusterObject objectId)    throws Exception  {      }    /**   * Saves the object to the cluster.   *   * @param storeId the identifier of the storage group   * @param obj the object to objectStore.   */  /*  public void objectStore(Store objectStore, HashKey objectId, Object value)    throws IOException  {    ClusterObject clusterObj = getClusterObject(objectId);    if (clusterObj != null) {    }    else if (objectStore.getObjectManager().isEmpty(value))      return;    else      clusterObj = createClusterObject(objectStore, objectId);        clusterObj.objectStore(value);  }   */  /**   * Returns the cluster object.   *   * @param storeId the identifier of the storage group   * @param obj the object to objectStore.   */  /*  ClusterObject createClusterObject(Store objectStore, String id)  {    HashKey key = _hashManager.generateHash(objectStore.getId(), id);    return createClusterObject(objectStore, key);  }   */  /**   * Creates the cluster object given the objectStore and id   *   * @param objectStore the owning persistent objectStore   * @param id the object's unique identifier in the objectStore   * @param primary the primary owning server   * @param secondary the secondary backup   * @param tertiary the tertiary backup   */  ClusterObject createClusterObject(Store store,                                    String id,                                    int primary,                                    int secondary,                                    int tertiary)  {    HashKey key = _hashManager.generateHash(store.getId(), id);    ClusterObject obj = createClusterObject(store, key,					    primary, secondary, tertiary);        obj.setObjectManagerKey(id);    return obj;  }   /**   * Returns the cluster object.   *   * @param objectStore the owning cluster objectStore   * @param id the object's unique identifier   * @param primary the object's owning server   * @param secondary the object's secondary backup   * @param tertiary the object's tertiary backup   */  ClusterObject createClusterObject(Store store,                                     HashKey key,                                    int primary,                                    int secondary,                                    int tertiary)  {    try {      synchronized (_clusterObjects) {	ClusterObject object = _clusterObjects.get(key);	if (object == null) {	  object = create(store, key, primary, secondary, tertiary);	  _clusterObjects.put(key, object);	}	return object;      }    } catch (Exception e) {      log.log(Level.WARNING, e.toString(), e);      return null;    }  }  /**   * Returns the cluster object.   *   * @param storeId the identifier of the storage group   * @param obj the object to objectStore.   */  ClusterObject getClusterObject(Store store, String id)  {    return getClusterObject(makeUniqueId(store, id));  }  /**   * Returns the cluster object.   *   * @param storeId the identifier of the storage group   * @param obj the object to objectStore.   */  ClusterObject getClusterObject(HashKey key)  {    synchronized (_clusterObjects) {      return _clusterObjects.get(key);    }  }  /**   * Returns the cluster object.   *   * @param storeId the identifier of the storage group   * @param obj the object to objectStore.   */  ClusterObject removeClusterObject(HashKey key)  {    synchronized (_clusterObjects) {      return _clusterObjects.remove(key);    }  }    /**   * Creates the cluster object.   */  protected ClusterObject create(Store store,                                  HashKey key,                                 int primary,                                 int secondary,                                 int tertiary)  {    return new ClusterObject(store, key, primary, secondary, tertiary);  }    /**   * Save the object to the objectStore.   *   * @param clusterObject the distributed handle   * @param tempStream the byte stream to the saved data   * @param dataHash the sha-1 hash of the data   * @param oldDataHash the previous hash value for the data   */  abstract protected void store(ClusterObject clusterObject,				TempOutputStream tempStream,				byte []dataHash, byte []oldDataHash)    throws Exception;    /**   * Handles a callback from an alarm, scheduling the timeout.   */  public void handleAlarm(Alarm alarm)  {    if (! _lifecycle.isActive())      return;    try {      clearOldObjects();    } catch (Throwable e) {      log.log(Level.WARNING, e.toString(), e);    } finally {      _alarm.queue(getIdleCheckTime());    }  }  /**   * When the object is no longer valid, objectRemove it from the backing objectStore.   *   * @param obj the object to objectRemove   */  public void remove(ClusterObject obj)    throws Exception  {      }  /**   * When the object is no longer valid, objectRemove it from the backing objectStore.   *   * @param objectStore the identifier of the storeage group   * @param objectId the identifier of the object to objectRemove   */  public void remove(Store store, String objectId)    throws Exception  {  }  /**   * Returns the unique id.   */  private HashKey makeUniqueId(Store store, String objectId)  {    return _hashManager.generateHash(store.getId(), objectId);  }  /**   * Returns the unique id.   */  private String makeUniqueId(String storeId, String objectId)  {    return storeId + ';' + objectId;  }  /**   * Returns the self servers.   */  protected int getSelfIndex()  {    return _selfIndex;  }  /**   * Returns the list of cluster servers.   */  protected ClusterServer []getServerList()  {    return _serverList;  }  /**   * Returns the cluster server which owns the object   */  protected ClusterServer getOwningServer(String objectId)  {    if (_cluster == null)      return null;        char ch = objectId.charAt(0);        ClusterServer []serverList = _serverList;    if (serverList.length > 0) {      int srunIndex = decode(ch) % serverList.length;      return serverList[srunIndex];    }    else      return null;  }    /**   * Handles the case where the environment is in the configuration   */  public void environmentConfigure(EnvironmentClassLoader loader)  {  }    /**   * Handles the case where the environment is activated.   */  public void environmentBind(EnvironmentClassLoader loader)  {  }    /**   * Handles the case where the environment is activated.   */  public void environmentStart(EnvironmentClassLoader loader)  {    try {      start();    } catch (Exception e) {      log.log(Level.WARNING, e.toString(), e);    }  }    /**   * Handles the case where the environment loader is stops   */  public void environmentStop(EnvironmentClassLoader loader)  {  }    /**   * Handles the case where the environment is activated.   */  public void classLoaderInit(DynamicClassLoader loader)  {  }    /**   * Handles the case where the environment loader is dropped.   */  public void classLoaderDestroy(DynamicClassLoader loader)  {    destroy();  }    /**   * Called at end of life.   */  public void destroy()  {    if (! _lifecycle.toDestroy())      return;        _alarm.dequeue();  }  @Override  public String toString()  {    return getClass().getSimpleName() + "[" + _serverId + "]";  }  static class ObjectKey {    private String _storeId;    private String _objectId;    ObjectKey()    {    }        ObjectKey(String storeId, String objectId)    {      init(storeId, objectId);    }    void init(String storeId, String objectId)    {      _storeId = storeId;      _objectId = objectId;    }    @Override    public int hashCode()    {      return _storeId.hashCode() * 65521 + _objectId.hashCode();    }    @Override    public boolean equals(Object o)    {      if (this == o)	return true;      else if (! (o instanceof ObjectKey))	return false;      ObjectKey key = (ObjectKey) o;      return _objectId.equals(key._objectId) && _storeId.equals(key._storeId);    }  }  static int decode(int code)  {    return DECODE[code & 0x7f];  }  /**   * Converts an integer to a printable character   */  private static char convert(long code)  {    code = code & 0x3f;        if (code < 26)      return (char) ('a' + code);    else if (code < 52)      return (char) ('A' + code - 26);    else if (code < 62)      return (char) ('0' + code - 52);    else if (code == 62)      return '_';    else      return '-';  }  static {    DECODE = new int[128];    for (int i = 0; i < 64; i++)      DECODE[(int) convert(i)] = i;  }}

⌨️ 快捷键说明

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