[thrift] highly concurrent Erlang goodness

Summary:
 * shim to use object-oriented code as gen_servers
 * high(er) performance Erlang-style server and transport
 * sane packaging based on otp-base, i.e. Makefiles and real structure

Test Plan: tutorial server offers the same (subset of) functionality as previous version

Revert Plan: ok


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665164 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/erl/tools/utilities/appgen b/lib/erl/tools/utilities/appgen
new file mode 100755
index 0000000..b619222
--- /dev/null
+++ b/lib/erl/tools/utilities/appgen
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+
+if [ $# -ne 2 ];then
+	echo ""
+	echo "usage: $0 <appname> <prefix>"
+	echo ""
+	echo "appname is the title of the application to be generated"
+	echo "prefix is the prefix that will be appended to all files in"
+	echo "the application due to erlangs lack of a package structure.  The prefix"
+	echo "is typicaly the first letter of each word in the name of the application"
+	echo ""
+	echo "example: $0 chat_server cs"
+	echo ""
+	exit 1
+fi
+
+APP_NAME=$1
+APP_NAME_UPPER_CASE=$(echo $APP_NAME | tr a-z A-Z)
+PREFIX=$2
+
+cd ../.appgen
+echo `pwd`
+
+cp -r blank_app $APP_NAME
+cp -r blank_app_rel "$APP_NAME"_rel
+
+cd "$APP_NAME"_rel
+ls blank_app* | ../rename.sh blank_app $APP_NAME
+cd ..
+
+# The base directory of the release
+./substitute.sh %%APP_NAME%% $APP_NAME "$APP_NAME"_rel/"$APP_NAME"_rel.rel.src
+
+
+cd $APP_NAME/src
+ls ba* | ../../rename.sh ba $PREFIX
+ls blank_app* | ../../rename.sh blank_app $APP_NAME
+cd -
+
+# The base directory of the application
+./substitute.sh %%APP_NAME_UPPER_CASE%% $APP_NAME_UPPER_CASE $APP_NAME/Makefile
+./substitute.sh %%APP_NAME_UPPER_CASE%% $APP_NAME_UPPER_CASE $APP_NAME/vsn.mk
+
+# The src directory of the application
+./substitute.sh %%APP_NAME%% $APP_NAME $APP_NAME/src/Makefile
+./substitute.sh %%APP_NAME_UPPER_CASE%% $APP_NAME_UPPER_CASE $APP_NAME/src/Makefile
+./substitute.sh %%PFX%% $PREFIX $APP_NAME/src/Makefile
+
+./substitute.sh %%APP_NAME%% $APP_NAME $APP_NAME/src/"$APP_NAME".erl
+./substitute.sh %%PFX%% $PREFIX $APP_NAME/src/"$APP_NAME".erl
+./substitute.sh %%PFX%% $PREFIX $APP_NAME/src/"$PREFIX"_sup.erl
+./substitute.sh %%APP_NAME%% $APP_NAME $APP_NAME/src/"$PREFIX"_sup.erl
+./substitute.sh %%PFX%% $PREFIX $APP_NAME/src/"$PREFIX"_server.erl
+./substitute.sh %%APP_NAME%% $APP_NAME $APP_NAME/src/"$PREFIX"_server.erl
+
+# include directory
+mv $APP_NAME/include/blank_app.hrl $APP_NAME/include/"$APP_NAME".hrl
+
+find $APP_NAME -name ".svn" | xargs rm -r
+mv $APP_NAME ../../lib
+mv "$APP_NAME"_rel ../../release
+
+echo ""
+echo "$APP_NAME has been generated and placed under lib/$APP_NAME"
+echo $APP_NAME"_rel has been generated and placed under release/$APP_NAME""_rel"
+echo ""
+
+cd ../utilities
diff --git a/lib/erl/tools/utilities/clean_release b/lib/erl/tools/utilities/clean_release
new file mode 100755
index 0000000..9202690
--- /dev/null
+++ b/lib/erl/tools/utilities/clean_release
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+if [ $# -eq 1 ]; then
+	RELEASE_NAME=$1
+else
+	RELEASE_NAME=$(basename $(dirname $(dirname $(dirname $(which $0)))))
+fi
+
+LOCAL=$(dirname $(which $0))
+
+echo $LOCAL
+echo $RELEASE_NAME
+cd $LOCAL
+
+echo "
+-module(clean_release). 
+-export([clean_release/1]). 
+
+clean_release([ReleaseName]) -> 
+    RelFile = atom_to_list(ReleaseName) ++ \".rel\",
+    case file:consult(RelFile) of
+	{ok, [{release, {RelName, RelVsn}, ErtsSpec, ReleaseSpecs}]} -> do_rest(RelFile, ReleaseSpecs);
+	{error, Reason} -> io:format(\"ERROR - Could not find file ~s~n\", [RelFile]), exit(Reason)
+    end,
+    os:cmd(\"cd ../;rm -rf \" ++ string:strip(os:cmd(\"basename `pwd`\"))).
+	     
+do_rest(RelFile, ReleaseSpecs) ->
+    io:format(\"Finding Orphans in ~p among current release specs ~p~n\", [RelFile, ReleaseSpecs]),
+    {ok, FileNameList}    = file:list_dir(\"../\"),
+    Dirs = [FileName || FileName <- FileNameList, filelib:is_dir(\"../\" ++ FileName)] --
+	   [string:strip(os:cmd(\"basename `pwd`\"), right, $\n)],
+    BigListOfReleaseSpecs = lists:foldl(fun(Dir, Acc) -> 
+						OtherRelFile = \"../\" ++ Dir ++ \"/\" ++ RelFile,
+						io:format(\"Checking external release file ~p~n\", [OtherRelFile]),
+						case file:consult(OtherRelFile) of
+						    {ok, [{release, {RelName, RelVsn}, ErtsSpec, ReleaseSpecs_}]} -> 
+							Acc ++ ReleaseSpecs_;
+						    _  -> 
+							Acc
+						end end, [], Dirs),
+    Orphans = ReleaseSpecs -- BigListOfReleaseSpecs,
+    io:format(\"Removing orphan release specs ~p from ../../lib ~n\", [Orphans]),
+    lists:foreach(fun(Orphan) -> 
+			  os:cmd(\"rm -rf ../../lib/\" ++ atom_to_list(element(1, Orphan)) ++ \"-\" ++ element(2, Orphan)) 
+		  end, Orphans).
+" > clean_release.erl
+
+erlc clean_release.erl
+
+CMD="erl -s clean_release clean_release $RELEASE_NAME -s erlang halt -noshell"
+$CMD
diff --git a/lib/erl/tools/utilities/edoc b/lib/erl/tools/utilities/edoc
new file mode 100755
index 0000000..632f261
--- /dev/null
+++ b/lib/erl/tools/utilities/edoc
@@ -0,0 +1,16 @@
+#!/bin/sh
+if [ "$#" -ne "1" ]
+then
+	echo $USAGE
+	exit 1
+fi
+
+CURRENT_DIR=`pwd`
+echo $CURRENT_DIR
+
+# Establish the otp base directory.
+MY_CMD=`which $0`
+MY_CMD_DIR=`dirname $MY_CMD`
+OTP_BASE_DIR=$MY_CMD_DIR/../..
+
+erl -noshell -pz $OTP_BASE_DIR/lib/fslib/ebin -s fs_lib s_apply edoc application "$1".  "\"../../$1"\". []." " -s init stop | egrep "(EXIT|terminating)"