#!/bin/bash
# IBM Confidential
# OCO Source Materials
# 5724-V51
#
# (c) Copyright IBM Corp. 2000, 2008 All Rights Reserved.
#
# The source code for this program is not published or otherwise
# divested of its trade secrets, irrespective of what has been
# deposited with the U.S. Copyright Office.
ME=$USER
TOMCAT_PORT=`grep appsvr_port $TOP/etc/default/common.properties | cut -d "=" -f2`

export CCD_APPSVR_DEBUG_PORT=`expr $TOMCAT_PORT + 30000`
export CCD_SCHEDULER_DEBUG_PORT=`expr $TOMCAT_PORT + 31000`
export CCD_ADMIN_DEBUG_PORT=`expr $TOMCAT_PORT + 32000`
export CCD_EVENTPROCESSOR_DEBUG_PORT=`expr $TOMCAT_PORT + 33000`
export CCD_WORKFLOW_DEBUG_PORT=`expr $TOMCAT_PORT + 34000`
export CCD_QUEUEMANAGER_DEBUG_PORT=`expr $TOMCAT_PORT + 35000`

case "$1" in
    on)
    JVM_DEBUG_OPTIONS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address="
    export CCD_APPSVR_JVM_DEBUG_OPTS="${JVM_DEBUG_OPTIONS}${CCD_APPSVR_DEBUG_PORT}"
    export CCD_SCHEDULER_JVM_DEBUG_OPTS="${JVM_DEBUG_OPTIONS}${CCD_SCHEDULER_DEBUG_PORT}"
    export CCD_ADMIN_JVM_DEBUG_OPTS="${JVM_DEBUG_OPTIONS}${CCD_ADMIN_DEBUG_PORT}"
    export CCD_EVENTPROCESSOR_JVM_DEBUG_OPTS="${JVM_DEBUG_OPTIONS}${CCD_EVENTPROCESSOR_DEBUG_PORT}"
    export CCD_WORKFLOW_JVM_DEBUG_OPTS="${JVM_DEBUG_OPTIONS}${CCD_WORKFLOW_DEBUG_PORT}"
    export CCD_QUEUEMANAGER_JVM_DEBUG_OPTS="${JVM_DEBUG_OPTIONS}${CCD_QUEUEMANAGER_DEBUG_PORT}"
    export JAVAC_DEBUG_ON_OFF="ON"

    echo "ccd debugging on"
    echo "ports used: "
    echo "  appsvr: ${CCD_APPSVR_DEBUG_PORT}"
    echo "  scheduler: ${CCD_SCHEDULER_DEBUG_PORT}"
    echo "  admin: ${CCD_ADMIN_DEBUG_PORT}"
    echo "  eventprocessor: ${CCD_EVENTPROCESSOR_DEBUG_PORT}"
    echo "  workflow: ${CCD_WORKFLOW_DEBUG_PORT}"
    echo "  queuemanager: ${CCD_QUEUEMANAGER_DEBUG_PORT}"
    ;;

    off)
    export CCD_APPSVR_JVM_DEBUG_OPTS=
    export CCD_SCHEDULER_JVM_DEBUG_OPTS=
    export CCD_ADMIN_JVM_DEBUG_OPTS=
    export CCD_EVENTPROCESSOR_JVM_DEBUG_OPTS=
    export CCD_WORKFLOW_JVM_DEBUG_OPTS=
    export CCD_QUEUEMANAGER_JVM_DEBUG_OPTS=
    export JAVAC_DEBUG_ON_OFF="OFF"
    echo "trigo debugging off"
    ;;

    on_appsvr)
       JVM_DEBUG_OPTIONS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address="
       export CCD_APPSVR_JVM_DEBUG_OPTS="${JVM_DEBUG_OPTIONS}${CCD_APPSVR_DEBUG_PORT}"
       
       echo "ccd debugging on for appsvr"
       echo "ports used: "
       echo "  appsvr: ${CCD_APPSVR_DEBUG_PORT}"
       ;;
    
    
    *)
    if [ "$CCD_APPSVR_JVM_DEBUG_OPTS" = "" ]; then
        echo "trigo debugging is off"
    else
        echo "ccd debugging is on"
	    echo "ports used: "
        echo "  appsvr: ${CCD_APPSVR_DEBUG_PORT}"
        echo "  scheduler: ${CCD_SCHEDULER_DEBUG_PORT}"
        echo "  admin: ${CCD_ADMIN_DEBUG_PORT}"
        echo "  eventprocessor: ${CCD_EVENTPROCESSOR_DEBUG_PORT}"
        echo "  workflow: ${CCD_WORKFLOW_DEBUG_PORT}"
        echo "  queuemanager: ${CCD_QUEUEMANAGER_DEBUG_PORT}"
    fi
    ;;
esac
