2 Replies Latest reply on May 7, 2004 6:39 AM by tbrandt

    Socket connections in stateful session bean

    tbrandt Newbie

      Hi,

      We are trying to connect a legacy server from a stateful session bean via tcp/ip sockets. The server is an interpreter which provides applications itself (in a binary protocol). As we want to provide these applications on the web, we built a stateful bean which acts as a client to this server.

      The server usuallly interacts with a windows client or a java applet. When these clients are terminated the server also terminates the application it is providing on the server side. On the web, situations may occur where I do not notice that a session was terminated by the client. So I would like to configure my bean to close the socket connection after a certain timeout.

      I hoped I could rely on the configurable timeout for session beans in JBoss. But although I configured the container as follows:
      ....
      <cache-policy-conf>
      <min-capacity>2</min-capacity>
      <max-capacity>3</max-capacity>
      <remover-period>1800</remover-period>
      <max-bean-life>60</max-bean-life>
      <overager-period>300</overager-period>
      <max-bean-age>600</max-bean-age>
      <resizer-period>400</resizer-period>
      <max-cache-miss-period>60</max-cache-miss-period>
      <min-cache-miss-period>1</min-cache-miss-period>
      <cache-load-factor>0.75</cache-load-factor>
      </cache-policy-conf>
      ....
      (I have to add that I turned of bean passivation, as it makes no sense in case of this legacy system)

      the beans do not seem to be moved to the Not-Exist-State. Thus, the connections to the legacy server are kept open forever and in addition to the beans which are kept in memory the legacy server keeps all applications/processes in memory, too, as it assumes they are still active.

      Is there something wrong with the cache-configuration? Can I rely on the socket connection being closed when the bean is removed after timeout? Or should I implement a timer which removes the beans after a certain amount of time myself? I guess, the container should do this...

      I am rather new to ejbs so any help is appreciated.

      Thanks in advance and regards,
      Tobias

        • 1. Re: Socket connections in stateful session bean
          Darran Lofthouse Master

          Unless you are happy ignoring the J2EE specification session beans must not open socket connections.

          You should be looking at JCA or possible MBeans to handle the connections.

          • 2. Re: Socket connections in stateful session bean
            tbrandt Newbie

            "An enterprise bean must not attempt to listen on a socket, accept connections on a socket, or use a socket for multicast."

            This is what the ejb spec (2.1) says. I do not listen on a socket, nor do I accept connections nor do I use a socket for multicast. I am connecting to a socket (Socket.connect).

            Is there a way how the container can provide me with a persistent socket connection to a specific machine on a specific port? Or do I have to write and configure my own resource adapter to handle these connections properly?

            Regards,
            Tobias