<commit_before>set_java_cmd() {
  if [ ! -z "$JAVA_CMD" ]; then
    if [ ! -x "$JAVA_CMD" ]; then
      echo "Error: $JAVA_CMD isn't executable "
      exit 1
    fi
  elif [ ! -z "$JAVA_HOME" ]; then
    JAVA_CMD=$JAVA_HOME/bin/java
  else
    # No JAVA_HOME, try to find java in the path
    JAVA_CMD=`which java 2>/dev/null`
    if [ ! -x "$JAVA_CMD" ]; then
      # No java executable in the path either
      echo "Error: Cannot find a JRE or JDK. Please set JAVA_HOME"
      exit 1
    fi
  fi
}

build_classpath() {
  _CLASSPATH=""
  #XXX find -printf isn't in POSIX
  _JARS=$(find lib -follow -name "*.jar" -xtype f -printf %p: 2>/dev/null)
  _ZIPS=$(find lib -follow -name "*.zip" -xtype f -printf %p: 2>/dev/null)
  _CLASSPATH=${_JARS}${_ZIPS}
  #Remove the trailing ":"
  _CLASSPATH=${_CLASSPATH%:}
  echo "${_CLASSPATH}"
}

load_default_config() {
  # Read generic opengamma settings
  [ -f /etc/sysconfig/opengamma/defaults ] && . /etc/sysconfig/opengamma/defaults
  [ -f /etc/default/opengamma/defaults ] && . /etc/default/opengamma/defaults
  [ -f $HOME/.opengamma/defaults ] && . $HOME/.opengamma/defaults
}

load_component_config() {
  local _PROJECT _COMPONENT
  _PROJECT=$1; shift
  _COMPONENT=$1; shift

  # Read project/service specific settings
  [ -f /etc/sysconfig/opengamma/${_PROJECT}/${_COMPONENT} ] && . /etc/sysconfig/opengamma/${_PROJECT}/${_COMPONENT}
  [ -f /etc/default/opengamma/${_PROJECT}/${_COMPONENT} ] && . /etc/default/opengamma/${_PROJECT}/${_COMPONENT}
  [ -f $HOME/.opengamma/${_PROJECT}/${_COMPONENT} ] && . $HOME/.opengamma/${_PROJECT}/${_COMPONENT}

  PIDFILE=${PIDFILE:-${_COMPONENT}.pid}
  LOGFILE=${LOGFILE:-${_COMPONENT}-console.log}
  MEM_OPTS=${MEM_OPTS:--Xms4096m -Xmx4096m}
  GC_OPTS=${GC_OPTS:--XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing}
  EXTRA_JVM_OPTS=${EXTRA_JVM_OPTS:-""}
  LOGBACK_CONFIG=${LOGBACK_CONFIG:-engine-logback.xml}
  SHUTDOWN_WAIT=${SHUTDOWN_WAIT:-15}
}

set_commandmonitor_opts() {
  COMMAND_PORT=${COMMAND_PORT:-8079}
  COMMAND_SECRET=${COMMAND_SECRET:-""}

  if [ x${COMMAND_SECRET} != x"" ]; then
    COMMANDMONITOR_OPTS="-Dcommandmonitor.secret=$COMMAND_SECRET -Dcommandmonitor.port=$COMMAND_PORT"
  else
    COMMANDMONITOR_OPTS=""
  fi
}

start() {
  RETVAL=0
  echo -n "Starting ${COMPONENT}"
  set_java_cmd
  set_commandmonitor_opts
  if [ -z ${CONFIG} ]; then
    echo " - CONFIG variable not specified"
    RETVAL=6
    return
  fi
  exec setsid $JAVA_CMD $MEM_OPTS $EXTRA_JVM_OPTS $COMMANDMONITOR_OPTS \
  -Dlogback.configurationFile=$LOGBACK_CONFIG \
  -cp $CLASSPATH \
  com.opengamma.component.OpenGammaComponentServer \
  -q ${CONFIG} > ${LOGFILE} 2>&1 < /dev/null &
  echo $! >$PIDFILE
  echo
}

debug() {
  RETVAL=0
  echo -n "Starting ${COMPONENT}"
  set_java_cmd
  set_commandmonitor_opts
  if [ -z ${CONFIG} ]; then
    echo " - CONFIG variable not specified"
    RETVAL=6
    return
  fi
  $JAVA_CMD $MEM_OPTS $EXTRA_JVM_OPTS $COMMANDMONITOR_OPTS \
  -Dlogback.configurationFile=$LOGBACK_CONFIG \
  -cp $CLASSPATH \
  com.opengamma.component.OpenGammaComponentServer \
  -q ${CONFIG} 
}

stop() {
  local count kpid
  RETVAL=7
  echo -n "Stopping ${COMPONENT}"
  set_java_cmd
  set_commandmonitor_opts
  # If the command interface is in use try to shutdown the server nicely<commit_msg>Newline after debug init msg<commit_after>set_java_cmd() {
  if [ ! -z "$JAVA_CMD" ]; then
    if [ ! -x "$JAVA_CMD" ]; then
      echo "Error: $JAVA_CMD isn't executable "
      exit 1
    fi
  elif [ ! -z "$JAVA_HOME" ]; then
    JAVA_CMD=$JAVA_HOME/bin/java
  else
    # No JAVA_HOME, try to find java in the path
    JAVA_CMD=`which java 2>/dev/null`
    if [ ! -x "$JAVA_CMD" ]; then
      # No java executable in the path either
      echo "Error: Cannot find a JRE or JDK. Please set JAVA_HOME"
      exit 1
    fi
  fi
}

build_classpath() {
  _CLASSPATH=""
  #XXX find -printf isn't in POSIX
  _JARS=$(find lib -follow -name "*.jar" -xtype f -printf %p: 2>/dev/null)
  _ZIPS=$(find lib -follow -name "*.zip" -xtype f -printf %p: 2>/dev/null)
  _CLASSPATH=${_JARS}${_ZIPS}
  #Remove the trailing ":"
  _CLASSPATH=${_CLASSPATH%:}
  echo "${_CLASSPATH}"
}

load_default_config() {
  # Read generic opengamma settings
  [ -f /etc/sysconfig/opengamma/defaults ] && . /etc/sysconfig/opengamma/defaults
  [ -f /etc/default/opengamma/defaults ] && . /etc/default/opengamma/defaults
  [ -f $HOME/.opengamma/defaults ] && . $HOME/.opengamma/defaults
}

load_component_config() {
  local _PROJECT _COMPONENT
  _PROJECT=$1; shift
  _COMPONENT=$1; shift

  # Read project/service specific settings
  [ -f /etc/sysconfig/opengamma/${_PROJECT}/${_COMPONENT} ] && . /etc/sysconfig/opengamma/${_PROJECT}/${_COMPONENT}
  [ -f /etc/default/opengamma/${_PROJECT}/${_COMPONENT} ] && . /etc/default/opengamma/${_PROJECT}/${_COMPONENT}
  [ -f $HOME/.opengamma/${_PROJECT}/${_COMPONENT} ] && . $HOME/.opengamma/${_PROJECT}/${_COMPONENT}

  PIDFILE=${PIDFILE:-${_COMPONENT}.pid}
  LOGFILE=${LOGFILE:-${_COMPONENT}-console.log}
  MEM_OPTS=${MEM_OPTS:--Xms4096m -Xmx4096m}
  GC_OPTS=${GC_OPTS:--XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing}
  EXTRA_JVM_OPTS=${EXTRA_JVM_OPTS:-""}
  LOGBACK_CONFIG=${LOGBACK_CONFIG:-engine-logback.xml}
  SHUTDOWN_WAIT=${SHUTDOWN_WAIT:-15}
}

set_commandmonitor_opts() {
  COMMAND_PORT=${COMMAND_PORT:-8079}
  COMMAND_SECRET=${COMMAND_SECRET:-""}

  if [ x${COMMAND_SECRET} != x"" ]; then
    COMMANDMONITOR_OPTS="-Dcommandmonitor.secret=$COMMAND_SECRET -Dcommandmonitor.port=$COMMAND_PORT"
  else
    COMMANDMONITOR_OPTS=""
  fi
}

start() {
  RETVAL=0
  echo -n "Starting ${COMPONENT}"
  set_java_cmd
  set_commandmonitor_opts
  if [ -z ${CONFIG} ]; then
    echo " - CONFIG variable not specified"
    RETVAL=6
    return
  fi
  exec setsid $JAVA_CMD $MEM_OPTS $EXTRA_JVM_OPTS $COMMANDMONITOR_OPTS \
  -Dlogback.configurationFile=$LOGBACK_CONFIG \
  -cp $CLASSPATH \
  com.opengamma.component.OpenGammaComponentServer \
  -q ${CONFIG} > ${LOGFILE} 2>&1 < /dev/null &
  echo $! >$PIDFILE
  echo
}

debug() {
  RETVAL=0
  echo -n "Starting ${COMPONENT}"
  set_java_cmd
  set_commandmonitor_opts
  if [ -z ${CONFIG} ]; then
    echo " - CONFIG variable not specified"
    RETVAL=6
    return
  fi
  echo
  $JAVA_CMD $MEM_OPTS $EXTRA_JVM_OPTS $COMMANDMONITOR_OPTS \
  -Dlogback.configurationFile=$LOGBACK_CONFIG \
  -cp $CLASSPATH \
  com.opengamma.component.OpenGammaComponentServer \
  -q ${CONFIG} 
}

stop() {
  local count kpid
  RETVAL=7
  echo -n "Stopping ${COMPONENT}"
  set_java_cmd
  set_commandmonitor_opts
  # If the command interface is in use try to shutdown the server nicely
{'fraction_non_alphanumeric': 0.14724480578139115, 'fraction_numerical': 0.008431195423065342, 'mean_word_length': 3.738231098430813, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '254375', 'n_tokens_mistral': 2647, 'n_tokens_neox': 2602, 'n_words': 496}