Package org.jvnet.glassfish.comms.replication.sessmgmt

Source Code of org.jvnet.glassfish.comms.replication.sessmgmt.ExtendedReplicationUtil$SipCLBListenerClass

/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) Ericsson AB, 2004-2008. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License").  You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code.  If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license."  If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above.  However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/

package org.jvnet.glassfish.comms.replication.sessmgmt;

import java.util.logging.Level;
import java.util.logging.Logger;

import com.ericsson.ssa.sip.SipApplicationSessionUtil;
import com.sun.enterprise.ee.web.sessmgmt.DynamicOwnershipManager;
import com.sun.enterprise.ee.web.sessmgmt.ReplicationHealthChecker;
import com.sun.enterprise.ee.web.sessmgmt.ReplicationMessageRouter;
import com.sun.enterprise.ee.web.sessmgmt.ReplicationState;
import com.sun.enterprise.ee.web.sessmgmt.ReplicationUtil;
import com.sun.logging.LogDomains;

import org.jvnet.glassfish.comms.gms.EventListener;
import com.ericsson.ssa.container.datacentric.DataCentricUtilHolder;


/**
*
* @author lwhite
*/
public class ExtendedReplicationUtil extends ReplicationUtil {

    /**
     * Gets the actual server instance (i.e, with respect to the actual
     * cluster shape) to which the given SipApplicationSession id currently
     * maps.
     *
     * @param sasId the SipApplicationSession id to be mapped
     *
     * @return the server instance to which the specified
     * SipApplicationSession id currently maps
     */
    @Override
    public String getActualServerInstance(String sasId) {
        return SipApplicationSessionUtil.getActualServerInstance(sasId);
    }
   
    /**
     * Gets the actual server instance (i.e, with respect to the actual
     * cluster shape) to which the given beKey currently
     * maps.
     *
     * @param beKey the beKey to be mapped
     *
     * @return the server instance to which the specified
     * beKey currently maps
     */
    @Override
    public String getActualServerInstanceForBeKey(String beKey) {
        return SipApplicationSessionUtil.getActualServerInstanceForBeKey(beKey);
    }
   
    /**
     * Extracts the application (hash) key portion of the given
     * SipApplicationSession id and returns it.
     *
     * Format: see {@link #createSasId(String, String, String)}
     *
     * @param sasId the SipApplicationSession id
     *
     * @return the application (hash) key portion of the given
     * SipApplicationSession id
     */
    @Override
    public String getSipApplicationKey(String sasId) {
        return SipApplicationSessionUtil.getSipApplicationKey(sasId);
    }   
   
    @Override
    public boolean isInstanceLoadBalancedByCLB() {
        return SipReplicationUtil.isInstanceLoadBalancedByCLB();
    }

    /**
     * Gets the server instance that would be mapped to the specified key in case the current
     * instance handling the request becomes unhealthy. So instance is selected from exsiting
     * set of working instances, excluding current instance.
     * @param beKey the key
     * @return the fail-over server instance that is mapped to the specified key
     */
    @Override
    public String getFailoverServerInstanceForBeKey(String beKey) {
        return SipApplicationSessionUtil.getFailoverServerInstanceForBeKey(beKey);
    }

    // Nodes in the CLB can be enabled/disable independently of GMS
    // We listen to their events here and generate reconfiguration calls if
    // warranted
    public static class SipCLBListenerClass implements EventListener {
  private final static Logger _logger = Logger.getLogger(ReplicationState.LOGGER_MEM_REP);
  private static SipCLBListenerClass instance = new SipCLBListenerClass();
  private ReplicationMessageRouter router =
        ReplicationMessageRouter.createInstance();

  private SipCLBListenerClass() {
  }

  // This is from the CLI when a node is added to the cluster.
  // We'll get a GMS event when the node is started, so even if
  // enabled==true here, we don't do anything.
  public void onAdd(String clusterName, String instanceName,
        boolean enabled) {
      if (logger.isLoggable(Level.FINE)) {
          logger.fine("Handled DCU reconfigure add event for " + instanceName + ", enabled=" + enabled);
      }
  }

  // A node can't be deleted if it is alive, so we don't need anything here
  public void onDelete(String clusterName, String instanceName) {
      if (logger.isLoggable(Level.FINE)) {
          logger.fine("Handled DCU reconfigure delete event for " + instanceName);
      }
  }

  // This comes from the CLI disable-converged-lb-server. Note that
  // if the instance is down, we don't get this event. Hence, the
  // lbStateChange is always true: we are always changing from "up"
  // (we're alive and getting CLB requests) to "down" (we're alive
  // but no longer getting CLB requests.)
  public void onDisable(String clusterName, String instanceName) {
      if (logger.isLoggable(Level.FINE)) {
          logger.fine("Handled DCU reconfigure disable event for " + instanceName);
      }
      router.handleDynamicOwnershipChanges(
      DynamicOwnershipManager.Event.FAILURE,
      instanceName, true);
  }

  // This comes from the GMS FAIL event
  public void onFailure(String clusterName, String instanceName,
      boolean isClusterShutdown) {
      if (logger.isLoggable(Level.FINE)) {
          logger.fine("Handled DCU reconfigure failure event for " + instanceName);
      }
      router.handleDynamicOwnershipChanges(
      DynamicOwnershipManager.Event.FAILURE,
      instanceName,
      ReplicationHealthChecker.isServerLbEnabled(instanceName));
  }

  // This comes from the CLI enable-converged-lb-server. Note that
  // we never get this event if the instance is down, so
  // this is always an lb state change.
  public void onEnable(String clusterName, String instanceName) {
      if (logger.isLoggable(Level.FINE)) {
          logger.fine("Handled DCU reconfigure enable event for " + instanceName);
      }
      router.handleDynamicOwnershipChanges(
      DynamicOwnershipManager.Event.JOIN,
      instanceName, true);
  }

  // This comes from GMS JOINEDANDREADY event
  public void onRecovery(String clusterName, String instanceName,
        boolean isClusterStartup) {
      if (logger.isLoggable(Level.FINE)) {
          logger.fine("Handled DCU recovery enable event for " + instanceName);
      }
      router.handleDynamicOwnershipChanges(
      (isClusterStartup) ?
          DynamicOwnershipManager.Event.CLUSTER_STARTUP :
          DynamicOwnershipManager.Event.JOIN,
      instanceName,
      ReplicationHealthChecker.isServerLbEnabled(instanceName));
  }
    }

    protected void doConfigureLoadBalancer() {
  EventListener l = SipCLBListenerClass.instance;
        DataCentricUtilHolder.addEventListener(l);
    }
}
TOP

Related Classes of org.jvnet.glassfish.comms.replication.sessmgmt.ExtendedReplicationUtil$SipCLBListenerClass

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.