Examples of LoadBalancePolicy


Examples of org.jboss.ha.client.loadbalance.LoadBalancePolicy

      super.start();
     
      // Set up the proxy to ourself. Needs to be clustered so it can load
      // balance requests (EJBTHREE-1375). We use the home load balance policy.
     
      LoadBalancePolicy factoryLBP = null;
      if (clustered.homeLoadBalancePolicy() == null || clustered.homeLoadBalancePolicy().equals(ClusteredDefaults.LOAD_BALANCE_POLICY_DEFAULT))
      {
         factoryLBP = new RoundRobin();
      }
      else
View Full Code Here

Examples of org.jboss.ha.client.loadbalance.LoadBalancePolicy

     
      MockNextInterceptor interceptor = new MockNextInterceptor();
      interceptor.setReturnValue(OK);
     
      Object oid = new Object();
      LoadBalancePolicy lbp = new RoundRobin();
      InvokerLocator uri = new InvokerLocator(MOCK_URI);
      ClusteredPojiProxy proxy = new ClusteredPojiProxy(oid, uri, new Interceptor[]{interceptor}, wrapper, lbp, FAMILY_BASE, originTarget);
     
      assertEquals(OK, proxy.invoke(this, Object.class.getDeclaredMethod("toString", new Class[]{}), new Object[]{}));
     
View Full Code Here

Examples of org.jboss.ha.client.loadbalance.LoadBalancePolicy

   }

   public Object invoke(org.jboss.aop.joinpoint.Invocation invocation)
   throws Throwable
   {
      LoadBalancePolicy lb = (LoadBalancePolicy) invocation.getMetaData(CLUSTERED_REMOTING, LOADBALANCE_POLICY);
      FamilyWrapper family = (FamilyWrapper) invocation.getMetaData(CLUSTERED_REMOTING, CLUSTER_FAMILY_WRAPPER);

      // we give the opportunity, to any server interceptor, to know if this a
      // first invocation to a node or if it is a failovered call
      //
      int failoverCounter = 0;
      String familyName = family.get().getFamilyName();
      invocation.getMetaData().addMetaData(CLUSTERED_REMOTING, CLUSTER_FAMILY, familyName, PayloadKey.AS_IS);
      InvokerLocator target = null;
      if (lb instanceof AopLoadBalancePolicy)
      {
         target = (InvokerLocator) ((AopLoadBalancePolicy) lb).chooseTarget(family.get(), invocation);
      }
      else
      {
         target = (InvokerLocator) lb.chooseTarget(family.get());
      }
     
      Throwable lastException = null;
      while (target != null)
      {
         invocation.getMetaData().addMetaData(CLUSTERED_REMOTING, FAILOVER_COUNTER, new Integer(failoverCounter), PayloadKey.AS_IS);
         invocation.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR, target, PayloadKey.AS_IS);
         invocation.getMetaData().addMetaData(CLUSTERED_REMOTING, CLUSTER_VIEW_ID, new Long(family.get().getCurrentViewId()), PayloadKey.AS_IS);

         boolean definitivlyRemoveNodeOnFailure = true;
         lastException = null;
         try
         {
            Object rsp = invocation.invokeNext();
            ArrayList newReplicants = (ArrayList) invocation.getResponseAttachment("replicants");
            if (newReplicants != null)
            {
               long newViewId = ((Long) invocation.getResponseAttachment("viewId")).longValue();
               family.get().updateClusterInfo(newReplicants, newViewId);
            }
            return rsp;
         }
         catch(DispatcherConnectException dce)
         {
            //In case of graceful shutdown, the target object will no longer exist in the Dispatcher,
            //fail over to another server if we can...
            //For now remove the node "definitely"
            lastException = dce;
         }
         catch (CannotConnectException ex)
         {
            lastException = ex;
         }
         catch (GenericClusteringException gce)
         {
            lastException = gce;
            // this is a generic clustering exception that contain the
            // completion status: usefull to determine if we are authorized
            // to re-issue a query to another node
            //
            if (gce.getCompletionStatus() == GenericClusteringException.COMPLETED_NO)
            {
               // we don't want to remove the node from the list of failed
               // node UNLESS there is a risk to indefinitively loop
               //
               if (family.get().getTargets().size() >= failoverCounter)
               {
                  if (!gce.isDefinitive())
                     definitivlyRemoveNodeOnFailure = false;
               }
            }
            else
            {
               throw new RuntimeException("Clustering exception thrown", gce);
            }
         }
         catch (Throwable t)
         {
            // Just in case this get wrapped in a Throwable. This can happen when
            // the exception is generated inside the container and it is wrapped in
            // a ForwardId exception.
            if(t.getCause() instanceof GenericClusteringException)
            {
               GenericClusteringException gce = (GenericClusteringException)t.getCause();
               lastException = gce;
               // this is a generic clustering exception that contain the
               // completion status: usefull to determine if we are authorized
               // to re-issue a query to another node
               //
               if (gce.getCompletionStatus() == GenericClusteringException.COMPLETED_NO)
               {
                  // we don't want to remove the node from the list of failed
                  // node UNLESS there is a risk to indefinitively loop
                  //
                  if (family.get().getTargets().size() >= failoverCounter)
                  {
                     if (!gce.isDefinitive())
                        definitivlyRemoveNodeOnFailure = false;
                  }
               }
               else
               {
                  throw new RuntimeException("Clustering exception thrown", gce);
               }
            } else
            {
               throw t;
            }
         }

         // If we reach here, this means that we must fail-over
         family.get().removeDeadTarget(target);
         if (!definitivlyRemoveNodeOnFailure)
         {
            family.get().resetView();
         }

         target = (InvokerLocator) lb.chooseTarget(family.get());
         if (target == null)
         {
            if (lastException != null)
            {
               throw new RuntimeException("cluster invocation failed, last exception was: ", lastException);
View Full Code Here

Examples of org.jboss.ha.client.loadbalance.LoadBalancePolicy

      super.start();
     
      // Set up the proxy to ourself. Needs to be clustered so it can load
      // balance requests (EJBTHREE-1375). We use the home load balance policy.
     
      LoadBalancePolicy factoryLBP = null;
      if (clustered.homeLoadBalancePolicy() == null || clustered.homeLoadBalancePolicy().equals(ClusteredDefaults.LOAD_BALANCE_POLICY_DEFAULT))
      {
         factoryLBP = new RoundRobin();
      }
      else
View Full Code Here

Examples of org.jboss.ha.client.loadbalance.LoadBalancePolicy

     
      assert lbpClass != null && !lbpClass.trim().equals("") : LoadBalancePolicy.class.getSimpleName()
            + " class name is required, but is not specified; improperly bound reference in JNDI";
     
      ClassLoader tccl = Thread.currentThread().getContextClassLoader();
      LoadBalancePolicy loadBalancePolicy = (LoadBalancePolicy) tccl.loadClass(lbpClass).newInstance();
     
      FamilyWrapper wrapper = getFamilyWrapper(name, refAddrs);
     
      Class<?>[] interfaces = {this.getProxyFactoryClass()};
      Interceptor[] interceptors = { IsLocalProxyFactoryInterceptor.singleton,
View Full Code Here

Examples of org.jboss.ha.client.loadbalance.LoadBalancePolicy

      String lbpClass = bci.getHomeLoadBalancePolicy().getName();

      assert lbpClass != null && !lbpClass.trim().equals("") : LoadBalancePolicy.class.getSimpleName()
            + " class name is required, but is not available in ProxyClusteringInfo";

      LoadBalancePolicy loadBalancePolicy;
      try
      {
         log.debug("Instantiating loadbalancer policy " + lbpClass + " for remote proxyfactory bound at key "
               + proxyFactoryKey);
         loadBalancePolicy = (LoadBalancePolicy) cl.loadClass(lbpClass).newInstance();
View Full Code Here

Examples of org.jboss.ha.client.loadbalance.LoadBalancePolicy

      Class<? extends LoadBalancePolicy> lbpClass = clusteringInfo.getHomeLoadBalancePolicy();

      assert lbpClass != null : " LoadBalancePolicy is required, but is not available in the ProxyClusteringInfo "
            + clusteringInfo;

      LoadBalancePolicy loadBalancePolicyInstance = null;

      try
      {
         // create a loadbalancer policy instance using the classloader associated with the
         // previous proxy
View Full Code Here

Examples of org.jboss.ha.client.loadbalance.LoadBalancePolicy

   }

   public Object invoke(org.jboss.aop.joinpoint.Invocation invocation)
   throws Throwable
   {
      LoadBalancePolicy lb = (LoadBalancePolicy) invocation.getMetaData(CLUSTERED_REMOTING, LOADBALANCE_POLICY);
      FamilyWrapper family = (FamilyWrapper) invocation.getMetaData(CLUSTERED_REMOTING, CLUSTER_FAMILY_WRAPPER);

      // we give the opportunity, to any server interceptor, to know if this a
      // first invocation to a node or if it is a failovered call
      //
      int failoverCounter = 0;
      String familyName = family.get().getFamilyName();
      invocation.getMetaData().addMetaData(CLUSTERED_REMOTING, CLUSTER_FAMILY, familyName, PayloadKey.AS_IS);
      InvokerLocator target = null;
      if (lb instanceof AopLoadBalancePolicy)
      {
         target = (InvokerLocator) ((AopLoadBalancePolicy) lb).chooseTarget(family.get(), invocation);
      }
      else
      {
         target = (InvokerLocator) lb.chooseTarget(family.get());
      }
     
      Throwable lastException = null;
      while (target != null)
      {
         invocation.getMetaData().addMetaData(CLUSTERED_REMOTING, FAILOVER_COUNTER, new Integer(failoverCounter), PayloadKey.AS_IS);
         invocation.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR, target, PayloadKey.AS_IS);
         invocation.getMetaData().addMetaData(CLUSTERED_REMOTING, CLUSTER_VIEW_ID, new Long(family.get().getCurrentViewId()), PayloadKey.AS_IS);

         boolean definitivlyRemoveNodeOnFailure = true;
         lastException = null;
         try
         {
            Object rsp = invocation.invokeNext();
            ArrayList newReplicants = (ArrayList) invocation.getResponseAttachment("replicants");
            if (newReplicants != null)
            {
               long newViewId = ((Long) invocation.getResponseAttachment("viewId")).longValue();
               family.get().updateClusterInfo(newReplicants, newViewId);
            }
            return rsp;
         }
         catch(DispatcherConnectException dce)
         {
            //In case of graceful shutdown, the target object will no longer exist in the Dispatcher,
            //fail over to another server if we can...
            //For now remove the node "definitely"
            lastException = dce;
         }
         catch (CannotConnectException ex)
         {
            lastException = ex;
         }
         catch (GenericClusteringException gce)
         {
            lastException = gce;
            // this is a generic clustering exception that contain the
            // completion status: usefull to determine if we are authorized
            // to re-issue a query to another node
            //
            if (gce.getCompletionStatus() == GenericClusteringException.COMPLETED_NO)
            {
               // we don't want to remove the node from the list of failed
               // node UNLESS there is a risk to indefinitively loop
               //
               if (family.get().getTargets().size() >= failoverCounter)
               {
                  if (!gce.isDefinitive())
                     definitivlyRemoveNodeOnFailure = false;
               }
            }
            else
            {
               throw new RuntimeException("Clustering exception thrown", gce);
            }
         }
         catch (Throwable t)
         {
            // Just in case this get wrapped in a Throwable. This can happen when
            // the exception is generated inside the container and it is wrapped in
            // a ForwardId exception.
            if(t.getCause() instanceof GenericClusteringException)
            {
               GenericClusteringException gce = (GenericClusteringException)t.getCause();
               lastException = gce;
               // this is a generic clustering exception that contain the
               // completion status: usefull to determine if we are authorized
               // to re-issue a query to another node
               //
               if (gce.getCompletionStatus() == GenericClusteringException.COMPLETED_NO)
               {
                  // we don't want to remove the node from the list of failed
                  // node UNLESS there is a risk to indefinitively loop
                  //
                  if (family.get().getTargets().size() >= failoverCounter)
                  {
                     if (!gce.isDefinitive())
                        definitivlyRemoveNodeOnFailure = false;
                  }
               }
               else
               {
                  throw new RuntimeException("Clustering exception thrown", gce);
               }
            } else
            {
               throw t;
            }
         }

         // If we reach here, this means that we must fail-over
         family.get().removeDeadTarget(target);
         if (!definitivlyRemoveNodeOnFailure)
         {
            family.get().resetView();
         }

         target = (InvokerLocator) lb.chooseTarget(family.get());
         if (target == null)
         {
            if (lastException != null)
            {
               throw new RuntimeException("cluster invocation failed, last exception was: ", lastException);
View Full Code Here

Examples of org.jboss.ha.client.loadbalance.LoadBalancePolicy

   public void testInitialSelection()
   {
      testCount++;
      FamilyClusterInfo fci = ClusteringTargetsRepository.initTarget(FAMILY_BASE + testCount, Arrays.asList(TARGETS));
     
      LoadBalancePolicy lbp = getLoadBalancePolicy();
      Object target = lbp.chooseTarget(fci);
     
      for (int i = 0; i < 10000; i++)
      {
         assertSame(target, getLoadBalancePolicy().chooseTarget(fci));
      }
View Full Code Here

Examples of org.jboss.ha.client.loadbalance.LoadBalancePolicy

   public void testIdenticalAfterFailover()
   {
      testCount++;
      FamilyClusterInfo fci = ClusteringTargetsRepository.initTarget(FAMILY_BASE + testCount, Arrays.asList(TARGETS));
     
      LoadBalancePolicy lbp1 = getLoadBalancePolicy();
      Object target1 = lbp1.chooseTarget(fci);
     
      LoadBalancePolicy lbp2 = getLoadBalancePolicy();
     
      assertSame(target1, lbp2.chooseTarget(fci));
     
      fci.removeDeadTarget(target1);
     
      Object target3 = lbp1.chooseTarget(fci);
     
      assertFalse(target1.equals(target3));
     
      assertSame(target3, lbp2.chooseTarget(fci));
     
   }
View Full Code Here
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.