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

📄 serverimpl.java

📁 一个类似于openJMS分布在ObjectWeb之下的JMS消息中间件。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      Trace.logger.log(BasicLevel.DEBUG, "ServerImpl.unbind(" +                        path + ')');    // The root context cannot be deleted.    if (path.size() == 0) throw new NamingException("Cannot unbind the root context");    path = (CompositeName)path.clone();        String lastName = (String)path.remove(path.size() - 1);    NamingContext nc = contextManager.getNamingContext(path);        if (unbind(nc, lastName, serverId)) {      if (updateListener != null) {        updateListener.onUpdate(          new UnbindEvent(nc.getId(), lastName));      }    }  }  public boolean unbind(NamingContext nc,                        String lastName,                        Object ownerId) throws NamingException {    if (Trace.logger.isLoggable(BasicLevel.DEBUG))      Trace.logger.log(BasicLevel.DEBUG,                        "ServerImpl.unbind(" +                        nc + ',' +                       lastName + ',' +                        ownerId + ')');    if (! nc.getOwnerId().equals(ownerId)) {      throw new NotOwnerException(        nc.getOwnerId());    }    Record r = nc.getRecord(lastName);    if (r != null) {       if (r instanceof ContextRecord) {        throw new NamingException("Cannot unbind a context");      } else {        nc.removeRecord(lastName);        contextManager.storeNamingContext(nc);                return true;      }    } else {      // else do nothing (idempotency)      return false;    }  }  public NameClassPair[] list(CompositeName path) throws NamingException {    if (Trace.logger.isLoggable(BasicLevel.DEBUG))      Trace.logger.log(BasicLevel.DEBUG, "ServerImpl.list(" + path + ')');    NamingContext nc = contextManager.getNamingContext(path);    return nc.getNameClassPairs();  }  public Binding[] listBindings(CompositeName path) throws NamingException {    if (Trace.logger.isLoggable(BasicLevel.DEBUG))      Trace.logger.log(BasicLevel.DEBUG, "ServerImpl.listBindings(" + path + ')');    NamingContext nc = contextManager.getNamingContext(path);    return nc.getBindings();  }  public void createSubcontext(CompositeName path)     throws NamingException {    createSubcontext(path, serverId);  }  /**   * Create a subcontext.   *   * @param path the path of the subcontext   *   * @param subcontextOwner identifier of the owner of   * the subcontext (<code>null</code> if the    * owner is the local naming server).   *   * @exception NameAlreadyBoundException if the name of   * the subcontext is already bound.   *    * @exception NameNotFoundException if some of the   * intermediate names in the path don't exist.   *    * @exception NotOwnerException if the owner of the    * parent context is checked and is not the local   * naming server.   */  public void createSubcontext(CompositeName path,                               Object subcontextOwnerId)     throws NamingException {    if (Trace.logger.isLoggable(BasicLevel.DEBUG))      Trace.logger.log(        BasicLevel.DEBUG,         "ServerImpl.createSubcontext(" +         path + ',' + subcontextOwnerId + ')');    // The root already exists.    if (path.size() == 0) throw new NameAlreadyBoundException();    CompositeName parentPath = (CompositeName)path.clone();        String lastName =       (String)parentPath.remove(parentPath.size() - 1);    NamingContext parentNc =       contextManager.getNamingContext(parentPath);    NamingContextId ncid = createSubcontext(      parentNc, lastName, path, null,      subcontextOwnerId, serverId);    if (updateListener != null) {      updateListener.onUpdate(        new CreateSubcontextEvent(          parentNc.getId(), lastName, path, ncid,           subcontextOwnerId));    }  }      public NamingContextId createSubcontext(    NamingContext parentNc,     String lastName,    CompositeName path,    NamingContextId ncid,    Object subcontextOwnerId,    Object ownerId)     throws NamingException {    if (Trace.logger.isLoggable(BasicLevel.DEBUG))      Trace.logger.log(BasicLevel.DEBUG,                        "ServerImpl.createSubcontext(" +                        parentNc + ',' +                       lastName + ',' +                        path + ',' +                        ncid + ',' +                        subcontextOwnerId + ',' +                       ownerId + ')');    if (! parentNc.getOwnerId().equals(ownerId)) {      throw new NotOwnerException(        parentNc.getOwnerId());    }    if (parentNc.getRecord(lastName) != null)       throw new NameAlreadyBoundException();        NamingContext nc =       contextManager.newNamingContext(        subcontextOwnerId, ncid, path);    parentNc.addRecord(new ContextRecord(      lastName, nc.getId()));    contextManager.storeNamingContext(parentNc);    return nc.getId();  }  /**   * Destroy a subcontext. This operation is   * idempotent: does nothing if the final name of   * the path is not found.   *   * @param path the path of the subcontext   *   * @exception NameAlreadyBoundException if the name of   * the subcontext is already bound.   *    * @exception NameNotFoundException if some of the   * intermediate names in the path don't exist.   *    * @exception NotOwnerException if the owner of the    * parent context is checked and is not the local   * naming server.   *    * @exception NotContextException if the specified path   * isn't bound to a context.   */  public void destroySubcontext(CompositeName path) throws NamingException {    if (Trace.logger.isLoggable(BasicLevel.DEBUG))      Trace.logger.log(BasicLevel.DEBUG,                        "ServerImpl.destroySubcontext(" +                        path + ')');    if (path.size() == 0)       throw new NamingException("Cannot delete root context.");    CompositeName parentPath = (CompositeName)path.clone();    String lastName = (String)parentPath.remove(parentPath.size() - 1);    NamingContext parentNc = contextManager.getNamingContext(parentPath);        try {      NamingContext nc = contextManager.getNamingContext(path);      if (nc.size() > 0) {        if (Trace.logger.isLoggable(BasicLevel.DEBUG))          Trace.logger.log(BasicLevel.DEBUG,                            " -> not empty: nc = " + nc);        throw new ContextNotEmptyException();      }    } catch (MissingRecordException exc) {      // else do nothing (idempotency)      return;    }    if (destroySubcontext(parentNc, lastName, path, serverId)) {      if (updateListener != null) {        updateListener.onUpdate(          new DestroySubcontextEvent(            parentNc.getId(), lastName, path));      }    }  }  public boolean destroySubcontext(NamingContext parentNc,                                                                       String lastName,                                   CompositeName path,                                   Object ownerId)     throws NamingException {    if (Trace.logger.isLoggable(BasicLevel.DEBUG))      Trace.logger.log(BasicLevel.DEBUG,                        "ServerImpl.destroySubcontext(" +                        parentNc + ',' +                       lastName + ',' +                        path + ',' +                       ownerId + ')');    if (! parentNc.getOwnerId().equals(ownerId)) {      throw new NotOwnerException(        parentNc.getOwnerId());    }    Record r = parentNc.getRecord(lastName);    if (r != null) {      if (r instanceof ContextRecord) {                ContextRecord cr = (ContextRecord)r;        NamingContextId ctxId = cr.getId();        contextManager.delete(ctxId, path);                // Remove from the parent context        parentNc.removeRecord(lastName);        contextManager.storeNamingContext(parentNc);                return true;      } else {        throw new NotContextException();      }    } else {      // else do nothing (idempotency)      return false;    }  }  /**   * Returns copies of the naming contexts owned by the server   * which identifier is specified.   *   * @param serverId the identifier of the server that owns   * the naming contexts to get.   */  public NamingContextInfo[] copyNamingContexts(Object serverId)     throws NamingException {    if (Trace.logger.isLoggable(BasicLevel.DEBUG))    Trace.logger.log(BasicLevel.DEBUG,                      "ServerImpl.copyNamingContexts(" + serverId + ')');    return contextManager.copyNamingContexts(serverId);  }  public NamingContext getNamingContext(NamingContextId ncid)    throws NamingException {    return contextManager.getNamingContext(ncid);  }  public void addNamingContext(NamingContextInfo ncInfo)    throws NamingException {    if (Trace.logger.isLoggable(BasicLevel.DEBUG))      Trace.logger.log(BasicLevel.DEBUG,                        "ServerImpl.addNamingContext(" +                        ncInfo + ')');    contextManager.addNamingContext(ncInfo);  }  public void changeOwner(Object formerOwnerId)    throws NamingException {    NamingContextInfo[] contexts =       contextManager.changeOwner(        formerOwnerId, serverId);        if (updateListener != null) {      updateListener.onUpdate(        new ChangeOwnerEvent(          formerOwnerId,          contexts));    }  }  public void resetNamingContext(NamingContext context)    throws NamingException {    contextManager.resetNamingContext(context);  }  public void writeBag(ObjectOutputStream out)    throws IOException {    contextManager.writeBag(out);  }  public void readBag(ObjectInputStream in)     throws IOException, ClassNotFoundException {    contextManager.readBag(in);  }}  

⌨️ 快捷键说明

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