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

📄 serverimpl.java

📁 一个类似于openJMS分布在ObjectWeb之下的JMS消息中间件。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * JORAM: Java(TM) Open Reliable Asynchronous Messaging * Copyright (C) 2001 - ScalAgent Distributed Technologies * Copyright (C) 1996 - Dyade * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or any later version. *  * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. *  * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 * USA. * * Initial developer(s): Sofiane Chibani * Contributor(s): David Feliot, Nicolas Tachker */package fr.dyade.aaa.jndi2.impl;import java.io.*;import java.util.*;import javax.naming.*;import fr.dyade.aaa.util.*;import org.objectweb.util.monolog.api.BasicLevel;import org.objectweb.util.monolog.api.Logger;public class ServerImpl {  /**   * Identifier of this server.   */  private Object serverId;  /**   * Identifier of the server that owns   * the root naming context.   */  private Object rootOwnerId;  /**   * Optional update listener.   * May be <code>null</code>.   */  private UpdateListener updateListener;    /**   * A context manager for the factory   * operations (new, delete). It also   * handles a cache and the persistency.   */  private ContextManager contextManager;  /**   * Constructs a <code>ServerImpl</code>   *   * @param transaction Transactional context that    * provides atomicity for the write operations   * performed during a request.   *   * @param serverId Identifier of this server.   *   * @param rootOwnerId Identifier of the server    * that owns the root naming context.   */  public ServerImpl(Transaction transaction,                    Object serverId,                    Object rootOwnerId) {     this.serverId = serverId;    this.rootOwnerId = rootOwnerId;    contextManager = new ContextManager(      transaction, serverId, rootOwnerId);  }  public void setUpdateListener(UpdateListener updateListener) {    this.updateListener = updateListener;  }    public void initialize() throws Exception {    contextManager.initialize();    // Creates the root naming context if this    // server owns it.    if (rootOwnerId.equals(serverId)) {      NamingContext rootNc =         contextManager.getRootNamingContext();      if (rootNc == null) {        contextManager.newNamingContext(          serverId,           null,           new CompositeName());      }    }  }    /**   * Binds an object to the specified path.   *   * @param path the path of the object   *   * @param obj the object to bind   *   * @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 bind(CompositeName path,                    Object obj) throws NamingException {    if (Trace.logger.isLoggable(BasicLevel.DEBUG))      Trace.logger.log(BasicLevel.DEBUG, "ServerImpl.bind(" +                        path + ',' +                        obj + ',' + ')');    // The root context is (in a way) already bound since    // it is already a context.    if (path.size() == 0) throw new NameAlreadyBoundException();    path = (CompositeName)path.clone();    String lastName = (String)path.remove(path.size() - 1);    NamingContext nc = contextManager.getNamingContext(path);    bind(nc, lastName, obj, serverId);        if (updateListener != null) {      updateListener.onUpdate(        new BindEvent(nc.getId(), lastName, obj));    }  }  public void bind(NamingContext nc,                    String lastName,                    Object obj,                   Object ownerId) throws NamingException {    if (Trace.logger.isLoggable(BasicLevel.DEBUG))      Trace.logger.log(BasicLevel.DEBUG,                        "ServerImpl.bind(" +                        nc + ',' +                       lastName + ',' +                        obj + ',' +                        ownerId + ')');    if (! nc.getOwnerId().equals(ownerId)) {      throw new NotOwnerException(        nc.getOwnerId());    }    Record r = nc.getRecord(lastName);    if (r != null) throw new NameAlreadyBoundException();    else {      nc.addRecord(new ObjectRecord(lastName, obj));      contextManager.storeNamingContext(nc);          }  }  /**   * Rebinds an object to the specified path.   *   * @param path the path of the object   *   * @param obj the object to rebind   *   * @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 NamingException if the specified path   * is bound to a naming context.   */  public void rebind(CompositeName path,                      Object obj) throws NamingException {    if (Trace.logger.isLoggable(BasicLevel.DEBUG))      Trace.logger.log(BasicLevel.DEBUG, "ServerImpl.rebind(" +                        path + ',' +                        obj + ',' + ')');    // The root context cannot become a name-value pair.    if (path.size() == 0) throw new NamingException("Cannot rebind the root context");    path = (CompositeName)path.clone();    String lastName = (String)path.remove(path.size() - 1);    NamingContext nc = contextManager.getNamingContext(path);        rebind(nc, lastName, obj, serverId);    if (updateListener != null) {      updateListener.onUpdate(        new RebindEvent(nc.getId(), lastName, obj));    }  }  public void rebind(NamingContext nc,                      String lastName,                      Object obj,                     Object ownerId) throws NamingException {    if (Trace.logger.isLoggable(BasicLevel.DEBUG))      Trace.logger.log(BasicLevel.DEBUG,                        "ServerImpl.rebind(" +                        nc + ',' +                       lastName + ',' +                        obj + ',' +                        ownerId + ')');    if (! nc.getOwnerId().equals(ownerId)) {      throw new NotOwnerException(        nc.getOwnerId());    }    Record r = nc.getRecord(lastName);    if (r != null) {      if (r instanceof ContextRecord) {        // DF: seems not consistent to delete recursively the whole        // context (empty or not) as the reverse operation is not possible        // (create a context with a name already bound).         // So prefer to raise an error.        // Have to check the spec.        throw new NamingException("Cannot rebind a context");      } else {        ObjectRecord or = (ObjectRecord)r;        or.setObject(obj);      }    } else {      nc.addRecord(new ObjectRecord(lastName, obj));    }    contextManager.storeNamingContext(nc);      }  /**   * Looks up the specified path.   *   * @param path the path to look up   *   * @exception NameNotFoundException if some of the   * names (intermediate and final) in the path don't exist.   *    * @exception NotOwnerException if the owner of the    * parent context is checked and is not the local   * naming server.   *   * @return <code>null</code> if the bound object is a context.   *   * @exception NameNotFoundException    */  public Record lookup(CompositeName path) throws NamingException {    if (Trace.logger.isLoggable(BasicLevel.DEBUG))      Trace.logger.log(BasicLevel.DEBUG, "ServerImpl.lookup(" + path + ')');        if (path.size() == 0) {      return null;    }    path = (CompositeName)path.clone();    String lastName = (String)path.remove(path.size() - 1);    NamingContext nc = contextManager.getNamingContext(path);        Record r = nc.getRecord(lastName);    if (r == null) {      NameNotFoundException nnfe =         new NameNotFoundException();      nnfe.setResolvedName(path);      throw new MissingRecordException(        nc.getId(), nc.getOwnerId(), nnfe);    } else if (r instanceof ObjectRecord) {            return r;    } else {      return null;    }  }  /**   * Unbinds the specified path. This operation is   * idempotent: does nothing if the final name of   * the path is not found.   *   * @param path the path to unbind   *   * @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 NamingException if the specified path   * is bound to a naming context.   */  public void unbind(CompositeName path) throws NamingException {    if (Trace.logger.isLoggable(BasicLevel.DEBUG))

⌨️ 快捷键说明

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