Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010 Red Hat, Inc.
   * Red Hat licenses this file to you under the Apache License, version
   * 2.0 (the "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   *    http://www.apache.org/licenses/LICENSE-2.0
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  * implied.  See the License for the specific language governing
  * permissions and limitations under the License.
  */
 
 package org.hornetq.jms.server.recovery;
 
 

This class will have a simple Connection Factory and will listen for topology updates.

This Discovery is instantiated by HornetQRecoveryRegistry

Author(s):
clebertsuconic
 
 public class RecoveryDiscovery implements SessionFailureListener
 {
 
    private ServerLocator locator;
    private final XARecoveryConfig config;
    private final AtomicInteger usage = new AtomicInteger(0);
    private boolean started = false;
 
 
    public RecoveryDiscovery(XARecoveryConfig config)
    {
       this. = config;
    }
 
    public synchronized void start()
    {
       if (!)
       {
     	 ..debug("Starting RecoveryDiscovery on " + );
           = true;
 
           = .createServerLocator();
          .disableFinalizeCheck();
          try
          {
             // We are using the SessionFactoryInternal here directly as we don't have information to connect with an user and password
             // on the session as all we want here is to get the topology
             // in case of failure we will retry
             .addFailureListener(this);
 
             ..debug("RecoveryDiscovery started fine on " + );
          }
          catch (Exception startupError)
          {
         	..warn("Couldn't start recovery discovery on " +  + ", we will retry this on the next recovery scan");
             stop();
             HornetQRecoveryRegistry.getInstance().failedDiscovery(this);
          }
 
       }
    }
 
    public synchronized void stop()
    {
       internalStop();
    }

   
we may have several connection factories referencing the same connection recovery entry. Because of that we need to make a count of the number of the instances that are referencing it, so we will remove it as soon as we are done
 
    public int incrementUsage()
    {
       return .decrementAndGet();
    }
 
    public int decrementUsage()
    {
       return .incrementAndGet();
    }
   protected void finalize()
   {
      // I don't think it's a good thing to synchronize a method on a finalize,
      // hence the internalStop (no sync) call here
      internalStop();
   }
   protected void internalStop()
   {
      if ()
      {
          = false;
         try
         {
            if ( != null)
            {
               .close();
            }
         }
         catch (Exception ignored)
         {
        	 ..debug(ignoredignored);
         }
         try
         {
            .close();
         }
         catch (Exception ignored)
         {
        	 ..debug(ignoredignored);
         }
          = null;
          = null;
      }
   }
   static final class InternalListener implements ClusterTopologyListener
   {
      private final XARecoveryConfig config;
      public InternalListener(final XARecoveryConfig config)
      {
         this. = config;
      }
      public void nodeUP(TopologyMember topologyMemberboolean last)
      {
         // There is a case where the backup announce itself,
         // we need to ignore a case where getLive is null
         if (topologyMember.getLive() != null)
         {
            Pair<TransportConfigurationTransportConfigurationconnector =
                     new Pair<TransportConfigurationTransportConfiguration>(topologyMember.getLive(),
                                                                              topologyMember.getBackup());
            HornetQRecoveryRegistry.getInstance().nodeUp(topologyMember.getNodeId(), connector,
                                           .getUsername(), .getPassword());
         }
      }
      public void nodeDown(long eventUIDString nodeID)
      {
         // I'm not putting any node down, since it may have previous transactions hanging
      }
   }
   /* (non-Javadoc)
    * @see org.hornetq.core.remoting.FailureListener#connectionFailed(org.hornetq.api.core.HornetQException, boolean)
    */
   public void connectionFailed(HornetQException exceptionboolean failedOver)
   {
      if (exception.getType() == .)
      {
    	  ..warn("being disconnected for server shutdown"exception);
      }
      else
      {
    	  ..warn("Notified of connection failure in xa discovery, we will retry on the next recovery",
                                           exception);
      }
      internalStop();
      HornetQRecoveryRegistry.getInstance().failedDiscovery(this);
   }
   /* (non-Javadoc)
    * @see org.hornetq.api.core.client.SessionFailureListener#beforeReconnect(org.hornetq.api.core.HornetQException)
    */
   public void beforeReconnect(HornetQException exception)
   {
   }
   /* (non-Javadoc)
    * @see java.lang.Object#toString()
    */
   public String toString()
   {
      return "RecoveryDiscovery [config=" +  + ", started=" +  + "]";
   }
New to GrepCode? Check out our FAQ X