#!/bin/csh
# Launch the MMC portal service. The portal has two IP interfaces;
# the "public address" is the IP address used by shore-based clients
# of the portal. The "private address" is the address used by the
# deployed at-sea platform (e.g. a PPP-RF interfaces). 
#
# This script accepts a "-start" option, which allows the user to
# specify a packet retrieval criterion based on sensor packet timestamp.
# The portal will only attempt to retrieve packets that have a timestamp
# which is later than the "-start" time.

if (!($?LOG4J_THRESHOLD)) setenv LOG4J_THRESHOLD DEBUG

# By default, retrieve all packets from beginning of time.
set startTime = "0"
set publish = ""
set logDirectory = "$SIAM_HOME/logs"

# Process leading options
while ($#argv > 0)
  if ("$argv[1]" == "-since" || "$argv[1]" == "-start") then
    shift  # Get start time
    set startTime = $argv[1]:q

  else if ("$argv[1]" == "-publish") then
    set publish = "-publish"

  else if ("$argv[1]" == "-logdir") then
    shift  # Get log directory
    set logDirectory = $argv[1]:q
  else
    break  # End of options
  endif

  shift   # Check next argument

end

# Maximum interval for DGC of local heap
set dgcClientInterval = 7200000  # 2 hours

# Minimum download interval in seconds
set downloadInterval = 900  # 15 minutes

echo "Starting MMC portal service"

$JAVA $JAVA_OPTIONS -cp $SIAM_HOME/jars/log4j-1.2.8.jar:$SIAM_HOME/classes:.:$SIAM_HOME/jars/ssds-client-pub-predator.jar:$SIAM_HOME/jars/ssds-client-pub-prey.jar -Djava.security.policy=$SIAM_HOME/properties/policy -Dsun.rmi.dgc.client.gcInterval=$dgcClientInterval -Dlog4j.threshold=$LOG4J_THRESHOLD -DdownloadInterval=$downloadInterval moos.operations.portal.Portal $publish -start $startTime:q -logdir $logDirectory $argv 
