jbossas/jboss-ejb-client — pull request #18 by jaikiran (2012-10-18 15:05:18+00:00)
Title: [master branch] Introduce a way to cleanup the remoting resources that are associated with a EJBClientContext

One of the features of the EJB client API is to "auto" create remoting connections, endpoints which ultimately lead to EJBReceiver being created. This auto creation typically happens when the default EJB client context selector picks up certain properties and starts creating the receivers. Right now, there's no way to cleanup the EJB client context and it's associated "auto" created resources if the user decides to switch to a different context and never come back to this one. This leads to various resource leaks since the only time we close these resources is during JVM shutdown via a shutdown hook.

The commits in this PR, introduce a way to better handle the EJBClientContext lifecycle by introducing a close() method on it. The close() on the EJBClientContext doesn't do anything in itself but notifies any previously registered EJBClientContextListener(s) about the context close. It's these EJBClientContextListener(s) which are responsible for doing the actual close of the remoting resources. These listeners can/will be registered by whoever auto creates these receivers (connections, endpoints) for the EJB client context.

The close() will now allow users to have an explicit control on the lifecycle of the context that they are allowed access to. A closed context will no longer be functional for EJB invocations.

This should solve https://issues.jboss.org/browse/EJBCLIENT-48 and other similar issues reported in the community.