Help me Convert an RMI Server to a Enterprise Java Bean

Discussions

EJB design: Help me Convert an RMI Server to a Enterprise Java Bean

  1. Hello Dear Reader,

    I have an RMI Server that uses an extensive thread handling
    with synchronization at all levels.Also an extensive
    use of non final static fields are also put to use.
    I am planning to convert this into a Bean that will
    give the same functionality as that of the RMI Server.
    Please help and mail me to
    srini at savvion dot com

    Thanks
    Sreenivas Gopal
  2. Srinivas, your question is pretty open and here I am trying my level best to answer as elaborate as I can.

    Firstly, I would suggest you spend this weekend reading Ed Roman's Mastering Enterprise Java Bean book. It is available for download in the Resources section on this website. This is one of the best books ever written on the subject.

    Apart from this, let me give you some hints on migration path from RMI to EJB.

    Any code that is being migrated from RMI to EJB should get rid of multi-thread access to data i.e. thread synchronization. Reason is that is handled by EJB container in a seamless way. So what you would be doing first is removing all the synchronize keywords from your RMI Server code.

    You will have to create one extra interface apart from your already existing remote interface. Please refer to EJB specification either the book I suggested, to get hold of exact semantics of defining this interface. Still to give you an idea, this interface is termed as Home interface and it defines methods that would be used to create and locate instances of remote objects. These remote objects are implementation of your RMI remote interface and this implementation is generated by EJB container when you deploy your EJB. Home interface extends from javax.ejb.EJBHome interface.

    You will have to make some changes to your RMI remote interface in order to make it comply with EJB specification. Your RMI remote interface will have to extend from javax.ejb.EJBObject interface that extends java.rmi.Remote interface. That is the only change you got to make to your already written RMI remote interface that usually consist of business methods. This second interface is known simply as Remote interface in the EJB world.

    Then your RMI server class will have to be modified to implement javax.ejb.Enterprisebean derived interfaces (based on what type of enterprise bean you are implementing i.e. EntityBean or SessionBean).

    Now regarding static attributes in your RMI server implementation. I think you should understand the implications they have before you decide to keep them. I am sure that you may have to get rid of static attributes once you understand EJB architecture like Bean class pooling, Just In Time Activation/Passivation. In your case, you are left with no choice but to understand the architecture fully. Please refer to the book above to understand implications of keeping static attributes in a bean class (which is analogous to server class in RMI implementation).

    Hope this helps.
  3. Hi Reema,
    Thanks for your time and suggestions,
    I will make sure I go through them and
    try to get the most from it.
    Thanks again,
    Sreenivas Gopal
  4. BTW sirini EJB doesn't fit really well when it comes to port a mutithreaded application. Do you really think you can get any benefit by porting it to EJB. I don't know what kind of services your RMI server provide to clients...it depends.

    Thanks,
    Rashid.
  5. BTW sirini EJB doesn't fit really well when it comes to port a mutithreaded application. Do you really think you can get any benefit by porting it to EJB. I don't know what kind of services your RMI server provide to clients...it depends.

    Thanks,
    Rashid.