<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      EJB內部資參2

      [摘要]使用EJB你就不用你自己寫支持分布式的對象的框架了 Java Beans是個功能的部件,而不是一個可運行的程序, 不需要也不能發布它, 但它又必須有一個可依賴的環境來運行 EJB則是可發布的部件、發...
      使用EJB你就不用你自己寫支持分布式的對象的框架了


      Java Beans是個功能的部件,而不是一個可運行的程序, 不需要也不能發布它,
      但它又必須有一個可依賴的環境來運行
      EJB則是可發布的部件、發布到一個容器中, 裝配成更大的系統

      EJB和Applet和Servlet相似, Applet的容器是Browser, Servlet的容器是
      支持Java的Web Server, 而EJB的容器是Application Server
      EJB1.1  (2.0的規范已經發布了,請到sun去download)

      軟件生產工業化

      多層應用簡單化
      事務處理
      并發安全

      Enterprise beans當前兩個類型(2.0中有新內容, 我自己還沒理解,不多講了)


      Session Beans(又包括stateful 和stateless) 業務過程相關的邏輯,比如各種
      計算,查詢
      entity beans 數據相關的邏輯, 比如修改帳號的余額

      EJB的規范定義了一些你的Bean可以實現標準的接口。 這些接口強迫你實現其中
      特定方法。EJB的容器使用這些方法來管理你的Bean以及傳遞事件

      最基本的接口javax.ejb.EnterpriseBean
      public interface javax.ejb.EnterpriseBean extends java.io.Serializable

      {}
      這個接口中沒有方法,起到標示你的Bean是個Enterprise bean.

      sesssion beans 和entity beans有許多接口都是從這個特定的接口繼承來的(所
      以你的bean并不直接實現EnterpriseBean接口)。所有的session beans都從jav
      ax.ejb.SessionBean繼承,同理所有的EntityBean都從javax.ejb.EntityBean繼
      承。

      remote object 由MiddleSoftware提供的工具生成

      remote interface 遠程接口---客戶端的應用調用的接口
      java.ejb.EJBObject
      public interface EJBObject extends java.rmi.Remote {
      public abstract javax.ejb.EJBHome getEJBHome() throws java.rmi.RemoteE
      xception;
      public abstract javax.ejb.Handle getHandle() throws java.rmi.RemoteExc
      eption;
      //一個EJB的持續引用, 存儲起來重新構造
      public abstract java.lang.Object getPrimaryKey() throws java.rmi.Remot
      eException;
      //只用在Entity Beans
      public abstract boolean isIdentical(javax.ejb.EJBObject param1) throws
      java.rmi.RemoteException;
      public abstract void remove() throws java.rmi.RemoteException, javax.e
      jb.RemoveException;
      }



      home object -- EJB object factory, 由工具生成,是EJB container的一部分

      創建EJB objects
      發現已經存在的EJB objects (for entity beans)
      刪除EJB objects

      home interface --本地接口,
      定義創建的方法,查找的方法和析構的方法


      package javax.ejb;

      import java.rmi.Remote;
      import java.rmi.RemoteException;

      // Referenced classes of package javax.ejb:
      //      RemoveException, EJBMetaData, HomeHandle, Handle

      public interface EJBHome
        extends Remote
      {
        public abstract EJBMetaData getEJBMetaData()
          throws RemoteException;

        public abstract HomeHandle getHomeHandle()
          throws RemoteException;

        public abstract void remove(Object obj)
          throws RemoteException, RemoveException;

        public abstract void remove(Handle handle)
          throws RemoteException, RemoveException;

      }


      session bean

      package javax.ejb;

      import java.rmi.RemoteException;

      // Referenced classes of package javax.ejb:
      //      EJBException, EnterpriseBean, SessionContext

      public interface SessionBean
        extends EnterpriseBean
      {
        public abstract void ejbActivate()
          throws EJBException, RemoteException;

        public abstract void ejbPassivate()
          throws EJBException, RemoteException;

        public abstract void ejbRemove()
          throws EJBException, RemoteException;

        public abstract void setSessionContext(SessionContext sessionconte
      xt)
          throws EJBException, RemoteException;

      }

      setSessionContext(SessionContext sessioncontext)
      session context 是session bean 和container交互的通道, 通常的實現:

      import javax.ejb.*;
      public class MyBean implements SessionBean
      {
      private SessionBean sessiontext;
      public void setSessionContext(SessionContext sessioncontext)
           throws EJBException, RemoteException
          {
           this.sessiontext = sessiontext;
          }
          
          ......
      }


      public void ejbCreate(...)

      至少實現一個

      home object實現相應參數的一個create方法
      比如
      你的bean中有一個ejbCreate(int i)時
      home object中有
      public void create(int i)


      鈍化和激活 ---僅用于stateful session bean
        public abstract void ejbPassivate()
        public abstract void ejbActivate()
        
      當太多的session bean被事例化時,container做鈍化和激活操作, 釋放和打開資






      //stateless session bean

      對于所有的客戶端是相同的,所有的信息通過參數傳遞或從數據庫等外部得到
      初始化的唯一方式是無參數的 ejbCreate()方法
      home object 有相應的無參數create()方法


      客戶端調用過程:

      1、Look up a home object.
      2、Use the home object to create an EJB object.
      3、Call business methods on the EJB object.
      4、Remove the EJB object.

      Look up a home object
      your client code must use the JNDI. J2EE products exploit directory se
      rvices to stroe location infromation for resources that your applicati
      on code uses in an enterprise deployment. These resources could be EJB
      home objects, enterprise bean enviroment properties, database deriver
      s, message service drivers, and other resources. By using directory se
      rvices, you can writer application code that does not depend on specif
      ic machine names or locations. This is all part of EJB's location tran
      sparency, and it keeps your code portable. If later you decide thata r
      esources should be located elsewhere, your code will not need to be re
      built because the directory service can simply be updated to reflect t
      he new resource locations. This greatly enhances maintenance of a mult
      i-tier deployment that may evolve over time.

      There are two common steps that must be taken to find any resource in
      a J2EE deployment:
      1. Associate the resource with a "nickname" in your deployment descrip
      tor. Your J2EE product will bind the nickname to the resource.
      2. Clients of the resource can use the nickname with JNDI to look up t
      he resource across a deployment.

      目前的主要的分布式應用框架

      1、 Miscrosoft's Distribute interNet Appplications Architecture(DNA)
      相關的平臺和技術
      NT
      DCOM
      MSMQ
      MTS
      Microsoft Wolfpack
      Microsoft SQL Server
      Microsoft Internet Information Server
      Microsoft Management Console
      2、SUN's J2EE
      J2EE是規范而不是產品, 不至于讓用戶綁定到一個賣家(Microsoft)
      支持高端的Unix平臺
      內置的CORBA支持

      3、The Object Management Group's CORBA Standard
      Common Object Request Broker Architecture (CORBA)
      Internet Inter-ORB Protocol (IIOP)




      標簽:EJB內部資參2 
      日韩精品一区二区三区高清