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

📄 orbfunctional.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
  /**   * Get the local IOR for the given object, null if the object is not local.   */  public IOR getLocalIor(org.omg.CORBA.Object forObject)  {    Connected_objects.cObject rec = connected_objects.getKey(forObject);    if (rec == null)      return null;    else      return createIOR(rec);  }  /**   * Find and return the easily accessible CORBA object, addressed by name.   *   * @param name the object name.   * @return the object   *   * @throws org.omg.CORBA.ORBPackage.InvalidName if the given name is not   * associated with the known object.   */  public org.omg.CORBA.Object resolve_initial_references(String name)    throws InvalidName  {    org.omg.CORBA.Object object = null;    try      {        object = (org.omg.CORBA.Object) initial_references.get(name);        if (object == null && name.equals(NAME_SERVICE))          {            object = getDefaultNameService();            if (object != null)              initial_references.put(NAME_SERVICE, object);          }      }    catch (Exception ex)      {        InvalidName err = new InvalidName(name);        err.initCause(ex);        throw err;      }    if (object != null)      return object;    else      throw new InvalidName("Not found: '" + name + "'");  }  /**   * Start the ORBs main working cycle (receive invocation - invoke on the local   * object - send response - wait for another invocation).   *   * The method only returns after calling {@link #shutdown(boolean)}.   */  public void run()  {    running = true;    // Instantiate the port server for each socket.    Iterator iter = connected_objects.entrySet().iterator();    Map.Entry m;    Connected_objects.cObject obj;    while (iter.hasNext())      {        m = (Map.Entry) iter.next();        obj = (Connected_objects.cObject) m.getValue();        portServer subserver;        if (obj.identity == null)          {            subserver = new portServer(obj.port);            portServers.add(subserver);          }        else          subserver = (portServer) identities.get(obj.identity);                if (!subserver.isAlive())          {            // Reuse the current thread for the last portServer.            if (!iter.hasNext())              {                // Discard the iterator, eliminating lock checks.                iter = null;                subserver.run();                return;              }            else              subserver.start();          }      }  }    /**   * Start the server in a new thread, if not already running. This method is   * used to ensure that the objects being transfered will be served from the    * remote side, if required. If the ORB is started using this method, it   * starts as a daemon thread.   */  public void ensureRunning()  {    final OrbFunctional THIS = this;        if (!running)      {        Thread t = new Thread()        {          public void run()          {            THIS.run();          }        };        t.setDaemon(true);        t.start();      }  }  /**   * Shutdown the ORB server.   *   * @param wait_for_completion if true, the current thread is suspended until   * the shutdown process is complete.   */  public void shutdown(boolean wait_for_completion)  {    super.shutdown(wait_for_completion);    running = false;    if (!wait_for_completion)      {        for (int i = 0; i < portServers.size(); i++)          {            portServer p = (portServer) portServers.get(i);            p.close_now();          }      }  }  /**   * Find and return the CORBA object, addressed by the given IOR string   * representation. The object can (an usually is) located on a remote   * computer, possibly running a different (not necessary java) CORBA   * implementation.   *    * @param ior the object IOR representation string.   *    * @return the found CORBA object.   * @see object_to_string(org.omg.CORBA.Object)   */  public org.omg.CORBA.Object string_to_object(String an_ior)  {    return nameParser.corbaloc(an_ior, this);  }    /**   * Convert ior reference to CORBA object.   */  public org.omg.CORBA.Object ior_to_object(IOR ior)  {    org.omg.CORBA.Object object = find_local_object(ior);    if (object == null)      {        ObjectImpl impl = StubLocator.search(this, ior);        try          {            if (impl._get_delegate() == null)              impl._set_delegate(new IorDelegate(this, ior));          }        catch (BAD_OPERATION ex)          {            // Some colaborants may throw this exception            // in response to the attempt to get the unset delegate.            impl._set_delegate(new IorDelegate(this, ior));          }        object = impl;        // TODO remove commented out code below.        // connected_objects.add(ior.key, impl, ior.Internet.port, null);      }    return object;  }  /**   * Get the default naming service for the case when there no NameService   * entries.   */  protected org.omg.CORBA.Object getDefaultNameService()  {    if (initial_references.containsKey(NAME_SERVICE))      return (org.omg.CORBA.Object) initial_references.get(NAME_SERVICE);    IOR ior = new IOR();    ior.Id = NamingContextExtHelper.id();    ior.Internet.host = ns_host;    ior.Internet.port = ns_port;    ior.key = NamingServiceTransient.getDefaultKey();    IorObject iorc = new IorObject(this, ior);    NamingContextExt namer = NamingContextExtHelper.narrow(iorc);    initial_references.put(NAME_SERVICE, namer);    return namer;  }  /**   * Find and return the object, that must be previously connected to this ORB.   * Return null if no such object is available.   *    * @param key the object key.   * @param port the port where the object is connected.   *    * @return the connected object, null if none.   */  protected org.omg.CORBA.Object find_connected_object(byte[] key, int port)  {    Connected_objects.cObject ref = connected_objects.get(key);    if (ref == null)      return null;    if (port >= 0 && ref.port != port)      return null;    else      return ref.object;  }  /**   * Set the ORB parameters. This method is normally called from   * {@link #init(Applet, Properties)}.   *    * @param app the current applet.   *    * @param props application specific properties, passed as the second   * parameter in {@link #init(Applet, Properties)}. Can be <code>null</code>.   */  protected void set_parameters(Applet app, Properties props)  {    useProperties(props);    String[][] para = app.getParameterInfo();    if (para != null)      {        for (int i = 0; i < para.length; i++)          {            if (para[i][0].equals(LISTEN_ON))              Port = Integer.parseInt(para[i][1]);            if (para[i][0].equals(REFERENCE))              {                StringTokenizer st = new StringTokenizer(para[i][1], "=");                initial_references.put(st.nextToken(),                  string_to_object(st.nextToken()));              }            if (para[i][0].equals(ORB_ID))              orb_id = para[i][1];            if (para[i][0].equals(SERVER_ID))              server_id = para[i][1];            if (para[i][0].equals(NS_HOST))              ns_host = para[i][1];            if (para[i][0].equals(START_READING_MESSAGE))              TOUT_START_READING_MESSAGE = Integer.parseInt(para[i][1]);            if (para[i][0].equals(WHILE_READING))              TOUT_WHILE_READING = Integer.parseInt(para[i][1]);            if (para[i][0].equals(AFTER_RECEIVING))              TOUT_AFTER_RECEIVING = Integer.parseInt(para[i][1]);            try              {                if (para[i][0].equals(NS_PORT))                  ns_port = Integer.parseInt(para[i][1]);              }            catch (NumberFormatException ex)              {                BAD_PARAM bad = new BAD_PARAM("Invalid " + NS_PORT                  + "property, unable to parse '" + props.getProperty(NS_PORT)                  + "'");                bad.initCause(ex);                throw bad;              }          }      }  }  /**   * Set the ORB parameters. This method is normally called from   * {@link #init(String[], Properties)}.   *    * @param para the parameters, that were passed as the parameters to the   * <code>main(String[] args)</code> method of the current standalone   * application.   *    * @param props application specific properties that were passed as a second   * parameter in {@link init(String[], Properties)}). Can be <code>null</code>.   */  protected void set_parameters(String[] para, Properties props)  {    if (para.length > 1)      {        for (int i = 0; i < para.length - 1; i++)          {            if (para[i].endsWith("ListenOn"))              Port = Integer.parseInt(para[i + 1]);            if (para[i].endsWith("ORBInitRef"))              {                StringTokenizer st = new StringTokenizer(para[i + 1], "=");                initial_references.put(st.nextToken(),                  string_to_object(st.nextToken()));              }            if (para[i].endsWith("ORBInitialHost"))              ns_host = para[i + 1];            if (para[i].endsWith("ServerId"))              server_id = para[i++];            else if (para[i].endsWith("ORBid"))              orb_id = para[i++];            try              {                if (para[i].endsWith("ORBInitialPort"))                  ns_port = Integer.parseInt(para[i + 1]);              }            catch (NumberFormatException ex)              {                throw new BAD_PARAM("Invalid " + para[i]                  + "parameter, unable to parse '"                  + props.getProperty(para[i + 1]) + "'");              }          }      }    useProperties(props);  }  /**   * Create IOR for the given object references.   */  protected IOR createIOR(Connected_objects.cObject ref)    throws BAD_OPERATION  {    IOR ior = new IOR();    ior.key = ref.key;    ior.Internet.port = ref.port;    if (ref.object instanceof ObjectImpl)      {        ObjectImpl imp = (ObjectImpl) ref.object;        if (imp._ids().length > 0)          ior.Id = imp._ids() [ 0 ];      }    if (ior.Id == null)      ior.Id = ref.object.getClass().getName();    try      {        ior.Internet.host = InetAddress.getLocalHost().getHostAddress();        ior.Internet.port = ref.port;      }    catch (UnknownHostException ex)      {        throw new BAD_OPERATION("Cannot resolve the local host address");      }    return ior;  }  /**   * Prepare object for connecting it to this ORB.   *   * @param object the object being connected.   *   * @throws BAD_PARAM if the object does not implement the   * {@link InvokeHandler}).   */  protected void prepareObject(org.omg.CORBA.Object object, IOR ior)    throws BAD_PARAM  {    /*     * if (!(object instanceof InvokeHandler)) throw new     * BAD_PARAM(object.getClass().getName() + " does not implement     * InvokeHandler. " );     */    // If no delegate is set, set the default delegate.    if (object instanceof ObjectImpl)      {        ObjectImpl impl = (ObjectImpl) object;        try          {            if (impl._get_delegate() == null)              impl._set_delegate(new SimpleDelegate(this, ior));          }        catch (BAD_OPERATION ex)          {            // Some colaborants may throw this exception.            impl._set_delegate(new SimpleDelegate(this, ior));          }      }  }  /**   * Write the response message.   *   * @param net_out the stream to write response into   * @param msh_request the request message header   * @param rh_request the request header   * @param handler the invocation handler that has been used to invoke the   * operation   * @param sysEx the system exception, thrown during the invocation, null if   * none.   *   * @throws IOException   */  private void respond_to_client(OutputStream net_out,    MessageHeader msh_request, RequestHeader rh_request,    ResponseHandlerImpl handler, SystemException sysEx  ) throws IOException  {    // Set the reply header properties.    ReplyHeader reply = handler.reply_header;    if (sysEx != null)      reply.reply_status = ReplyHeader.SYSTEM_EXCEPTION;    else if (handler.isExceptionReply())      reply.reply_status = ReplyHeader.USER_EXCEPTION;    else      reply.reply_status = ReplyHeader.NO_EXCEPTION;    reply.request_id = rh_request.request_id;    BufferedCdrOutput out =      new BufferedCdrOutput(50 + handler.getBuffer().buffer.size());    out.setOrb(this);    out.setOffset(msh_request.getHeaderSize());    reply.write(out);    if (msh_request.version.since_inclusive(1, 2))      {        out.align(8);        // Write the reply data from the handler. The handler data already        // include the necessary heading zeroes for alignment.      }    handler.getBuffer().buffer.writeTo(out);    MessageHeader msh_reply = new MessageHeader();

⌨️ 快捷键说明

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