#!/bin/sh
RTDIR=/tmp/$SAM_PROJECT
mkdir -p $RTDIR || exit 1
sam establish consumer --appname="demo" --appversion=1 \
 --rtfile=$RTDIR/cid.out.$$ || exit 1
sam establish process --cid=`cut -f2 -d' ' $RTDIR/cid.out.$$` \
 --rtfile=$RTDIR/cpid.out.$$ || exit 1
fno=0
while true; do
 sam get next file --cpid=`cut -f2 -d' ' $RTDIR/cpid.out.$$` \
   --rtfile=$RTDIR/file.out.$$ || exit 1
 theFile=`cut -f2 -d' ' $RTDIR/file.out.$$`
 if [ -z "$theFile" \
      -o "$theFile" = "END" \
      -o "$theFile" = "ERROR" ]; then break; fi
 fno=`expr $fno + 1`
 echo "Got file $fno $theFile"
 sleep 60
 sam release --file=`basename $theFile` \
  --status=ok --cpid=`cut -f2 -d' ' $RTDIR/cpid.out.$$`
done

