Package org.hornetq.tests.integration.cluster.util

Source Code of org.hornetq.tests.integration.cluster.util.SameProcessHornetQServer

/*
* 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.tests.integration.cluster.util;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import junit.framework.Assert;

import org.hornetq.api.core.HornetQException;
import org.hornetq.api.core.Interceptor;
import org.hornetq.api.core.client.ClientSession;
import org.hornetq.api.core.client.SessionFailureListener;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.core.server.cluster.impl.ClusterManagerImpl;

/**
* A SameProcessHornetQServer
*
* @author jmesnil
*
*
*/
public class SameProcessHornetQServer implements TestableServer
{
   private static Logger log = Logger.getLogger(SameProcessHornetQServer.class);
  
   private HornetQServer server;

   public SameProcessHornetQServer(HornetQServer server)
   {
      this.server = server;
   }

   public boolean isInitialised()
   {
      return server.isInitialised();
   }

   public void destroy()
   {
      //To change body of implemented methods use File | Settings | File Templates.
   }

   public void setIdentity(String identity)
   {
      server.setIdentity(identity);
   }
  
   public boolean isStarted()
   {
      return server.isStarted();
   }

   public void addInterceptor(Interceptor interceptor)
   {
      server.getRemotingService().addInterceptor(interceptor);
   }

   public void removeInterceptor(Interceptor interceptor)
   {
      server.getRemotingService().removeInterceptor(interceptor);
   }

   public void start() throws Exception
   {
      server.start();
   }

   public void stop() throws Exception
   {
      server.stop();
   }

   public void crash(ClientSession... sessions) throws Exception
   {
      crash(true, sessions);
   }

   public void crash(boolean waitFailure, ClientSession... sessions) throws Exception
   {
      final CountDownLatch latch = new CountDownLatch(sessions.length);

      class MyListener implements SessionFailureListener
      {
         public void connectionFailed(final HornetQException me, boolean failedOver)
         {
            log.debug("MyListener.connectionFailed failedOver=" + failedOver, me);
            latch.countDown();
         }

         public void beforeReconnect(HornetQException exception)
         {
            log.debug("MyListener.beforeReconnect", exception);
         }
      }
      for (ClientSession session : sessions)
      {
         session.addFailureListener(new MyListener());
      }

      ClusterManagerImpl clusterManager = (ClusterManagerImpl) server.getClusterManager();
      clusterManager.flushExecutor();
      clusterManager.clear();
      server.stop(true);

      if (waitFailure)
      {
         // Wait to be informed of failure
         boolean ok = latch.await(10000, TimeUnit.MILLISECONDS);
         Assert.assertTrue(ok);
      }
   }

   /* (non-Javadoc)
    * @see org.hornetq.tests.integration.cluster.util.TestableServer#getServer()
    */
   public HornetQServer getServer()
   {
      return server;
   }

   // Constants -----------------------------------------------------

   // Attributes ----------------------------------------------------

   // Static --------------------------------------------------------

   // Constructors --------------------------------------------------

   // Public --------------------------------------------------------

  
   // Package protected ---------------------------------------------

   // Protected -----------------------------------------------------

   // Private -------------------------------------------------------

   // Inner classes -------------------------------------------------

}
TOP

Related Classes of org.hornetq.tests.integration.cluster.util.SameProcessHornetQServer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.