0 Replies Latest reply on Feb 21, 2014 3:23 PM by mikebrungs

    UPDATED: PROPER way to tell ConnectionManager to destroy a connection

    mikebrungs

      ===> See followup to my original question below

       

      I have a ManagedConnection that manages a socket-based connection.  I have a method called send() that the

      client can use to send data to that socket.  If that routine senses that the client side of the socket has been

      closed, I want to be able to tell the connection manager (or something upstream) that it should destroy this connection.

       

      My first attempt was to iterate the ManagedConnection's event listeners and call the connectionErrorOccurred() method.

      That results in a ConcurrentModificationException as I believe the code behind the method calls removeConnectionEventListener()

      and the listener list is synchronized.  I show this code snippet below:

       

         for (ConnectionEventListener cel : listeners)

            cel.connectionErrorOccurred(event);

       

      So... you are using the list to call connectionErrorOccurred() which results in the eventual call to removeConnectionEventListener()

      which attemps to do a listeners.remove(listener) on the same synchronized list !  Hence the Concurrent Exception issue.

       

      So... im assuming there is a CORRECT way to do what i want to do which is to have the Managed Connection be able to tell

      someone upstream that the connection is no longer valid and should be destroyed.

       

      Can anyone help ?

       

      =========== FOLLOW UP =========

      In looking more into this... it looks like the ValidatingManagedConnectionFactory framework is what I need to use.

      However, the documentation around how to do that properly is scarce.  I tried adding that on to my ManagedConnectionFactory

      implementation, coded up a getInvalidConnections() method and added the following to my configuration:

               <validation>

                   <background-validation>true</background-validation>

                   <background-validation-millis>10000</background-validation-millis>

               </validation>

       

      I was expecting to see getInvalidConnections() called every 10 seconds but it was never called.  Once again, I'm sure

      I missing something.  Hopefully someone call tell me.

       

      Can anyone help ?

       

      =========== 2nd FOLLOW UP "The frustration builds" =========

      Turning on TRACE allowed me to get closer to the issue but.. im still in need of help.
      I see this line ""Attempting to  validate connections for pool" every 5 seconds.  This comes from the top

      SemaphoreArrayListManagedConnectionPool::validateConnections().  It looks to me that the next line,

      if (permits.tryAcquire(poolConfiguration.getBlockingTimeout(), TimeUnit.MILLISECONDS)) must never

      come back as true because I never see the line ""Checking for connection within frequency" that would

      be shown if it got into the "if statement".  That would then explain why my getInvalidConnections() is never called.

       

      So... thoughts on this line never evaluating as true ?

            if (permits.tryAcquire(poolConfiguration.getBlockingTimeout(), TimeUnit.MILLISECONDS))

       

      Message was edited by: Mike Brungs

       

      Message was edited by: Mike Brungs

       

      Message was edited by: Mike Brungs