0 Replies Latest reply on Mar 5, 2002 9:56 AM by fuseboy

    Non-Reentrant Proxy Methods

    fuseboy

      How can an entity bean instance safely determine if a remote reference to an entity bean of the same type refers to itself, in a way guaranteed not to involve reentrance problems?

      As far as I can tell, there isn't one. Any comparision necessarily involves invoking methods on the remote reference, and the EJB 1.1 spec doesn't seem to require that any/all of the EJBObject methods be implemented in a guaranteed non-reentrant manner.

      An an example of a non-reentrant method, calling .toString() on a remote entity bean reference doesn't seem to involve any network overhead, since the proxy has enough information locally to carry out this request. Thus an entity bean could call .toString() on a remote reference to itself without violating non-reentrancy.

      Ways of doing the test that spring to mind:
      [pre]
      if(getEntityContext().getEJBObject().isIdentical(otherEntity))
      {
      // they are the same
      }

      if(primaryKey.equals(otherEntity.getPrimaryKey())
      {
      // they are the same if they have the same home
      }
      [/pre]
      In the first case, the call to .isIdentical() could theoretically cause reentrance on some proxy implementations, because the spec doesn't require that .isIdentical() be executed locally to the proxy.

      In the second case, calling .getPrimaryKey() on the other method could violate reentrance if the remote proxy makes a network call to the EJB server instead of using the primary key stored locally.

      The EJB 1.1. spec, on page 120, states:
      "If the entity bean is specified as non-reentrant in the deployment descriptor, the Container must reject an attempt to re-enter the instance via the entity bean’s remote interface while the instance is executing a business method." (emphasis mine)

      I can't find a definition for business method that explicitly states that the EJBObject interface methods are not business methods, nor can I find information on what the container is required to do when you invoke non-business methods entity bean marked non-reentrant.

      The closest thing I can find is this, in section 9.3.3, but a strict reading doesn't offer the guarantee I'm looking for:
      "The entity EJBObject class, which is generated by deployment tools, implements the entity bean’s remote interface. It implements the methods of the javax.ejb.EJBObject interface and the business methods specific to the entity bean." (emphasis mine)