summaryrefslogtreecommitdiff
path: root/ACE/examples/TMCast
diff options
context:
space:
mode:
Diffstat (limited to 'ACE/examples/TMCast')
-rw-r--r--ACE/examples/TMCast/Makefile.am13
-rw-r--r--ACE/examples/TMCast/Member/.cvsignore1
-rw-r--r--ACE/examples/TMCast/Member/Makefile.am45
-rw-r--r--ACE/examples/TMCast/Member/Member.mpc7
-rw-r--r--ACE/examples/TMCast/Member/README36
-rw-r--r--ACE/examples/TMCast/Member/member.cpp93
6 files changed, 195 insertions, 0 deletions
diff --git a/ACE/examples/TMCast/Makefile.am b/ACE/examples/TMCast/Makefile.am
new file mode 100644
index 00000000000..ad8cc650602
--- /dev/null
+++ b/ACE/examples/TMCast/Makefile.am
@@ -0,0 +1,13 @@
+## Process this file with automake to create Makefile.in
+##
+## $Id$
+##
+## This file was generated by MPC. Any changes made directly to
+## this file will be lost the next time it is generated.
+##
+## MPC Command:
+## /acebuilds/ACE_wrappers-repository/bin/mwc.pl -include /acebuilds/MPC/config -include /acebuilds/MPC/templates -feature_file /acebuilds/ACE_wrappers-repository/local.features -noreldefs -type automake -exclude build,Kokyu
+
+SUBDIRS = \
+ Member
+
diff --git a/ACE/examples/TMCast/Member/.cvsignore b/ACE/examples/TMCast/Member/.cvsignore
new file mode 100644
index 00000000000..fa6ecc72251
--- /dev/null
+++ b/ACE/examples/TMCast/Member/.cvsignore
@@ -0,0 +1 @@
+member
diff --git a/ACE/examples/TMCast/Member/Makefile.am b/ACE/examples/TMCast/Member/Makefile.am
new file mode 100644
index 00000000000..fe970a85ef5
--- /dev/null
+++ b/ACE/examples/TMCast/Member/Makefile.am
@@ -0,0 +1,45 @@
+## Process this file with automake to create Makefile.in
+##
+## $Id$
+##
+## This file was generated by MPC. Any changes made directly to
+## this file will be lost the next time it is generated.
+##
+## MPC Command:
+## /acebuilds/ACE_wrappers-repository/bin/mwc.pl -include /acebuilds/MPC/config -include /acebuilds/MPC/templates -feature_file /acebuilds/ACE_wrappers-repository/local.features -noreldefs -type automake -exclude build,Kokyu
+
+ACE_BUILDDIR = $(top_builddir)
+ACE_ROOT = $(top_srcdir)
+
+
+## Makefile.Member.am
+
+if BUILD_EXCEPTIONS
+if BUILD_THREADS
+if !BUILD_ACE_FOR_TAO
+
+noinst_PROGRAMS = member
+
+member_CPPFLAGS = \
+ -I$(ACE_ROOT) \
+ -I$(ACE_BUILDDIR) \
+ -I$(ACE_ROOT)/protocols
+
+member_SOURCES = \
+ member.cpp
+
+member_LDADD = \
+ $(ACE_BUILDDIR)/protocols/ace/TMCast/libACE_TMCast.la \
+ $(ACE_BUILDDIR)/ace/libACE.la
+
+endif !BUILD_ACE_FOR_TAO
+endif BUILD_THREADS
+endif BUILD_EXCEPTIONS
+
+## Clean up template repositories, etc.
+clean-local:
+ -rm -f *~ *.bak *.rpo *.sym lib*.*_pure_* core core.*
+ -rm -f gcctemp.c gcctemp so_locations *.ics
+ -rm -rf cxx_repository ptrepository ti_files
+ -rm -rf templateregistry ir.out
+ -rm -rf ptrepository SunWS_cache Templates.DB
diff --git a/ACE/examples/TMCast/Member/Member.mpc b/ACE/examples/TMCast/Member/Member.mpc
new file mode 100644
index 00000000000..29f274f51f3
--- /dev/null
+++ b/ACE/examples/TMCast/Member/Member.mpc
@@ -0,0 +1,7 @@
+// -*- MPC -*-
+// $Id$
+
+project: aceexe, tmcast {
+ exename = member
+}
+
diff --git a/ACE/examples/TMCast/Member/README b/ACE/examples/TMCast/Member/README
new file mode 100644
index 00000000000..6a62a107a77
--- /dev/null
+++ b/ACE/examples/TMCast/Member/README
@@ -0,0 +1,36 @@
+Member example shows how you can build a simple multicast group
+using transactional multicast (TMCast). Each member can be either
+a sender or a receiver.
+
+The sender sends small messages to the multicast group with a random
+wait period in [0, 1] second range. The receiver is simply receiving
+those messages and prints them out.
+
+To start the sender you can execute something like this:
+
+$ ./member s sender-1 239.255.0.1:10000
+
+Here the first argument ('s') indicates that new member will be
+a sender. The second argument ('sender-1') is an id of the new
+member (each member of the group should have a unique id). And
+the third argument ('239.255.0.1:10000') specifies IPv4 multicast
+address and port (you can choose you own).
+
+To start the receiver you can execute similar command:
+
+$ ./member r receiver-1 239.255.0.1:10000
+
+After you have started both the receiver and the sender you
+should see a sequence of messages printed by the receiver.
+
+Note, since the group can exist with only one member for a
+very short period of time you should start first two members
+virtually at the same time. See TMCast documentation for more
+information about why it behaves this way.
+
+You may want to add more than one sender to the group if you
+want to see how TMCast operates in a totally-ordered mode.
+
+
+--
+Boris Kolpackov <boris@dre.vanderbilt.edu>
diff --git a/ACE/examples/TMCast/Member/member.cpp b/ACE/examples/TMCast/Member/member.cpp
new file mode 100644
index 00000000000..f89c68564ea
--- /dev/null
+++ b/ACE/examples/TMCast/Member/member.cpp
@@ -0,0 +1,93 @@
+// file : TMCast/Member/member.cpp
+// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
+// cvs-id : $Id$
+
+#include "ace/Log_Msg.h"
+#include "ace/Time_Value.h"
+#include "ace/OS_NS_stdlib.h"
+#include "ace/OS_NS_unistd.h"
+#include "ace/OS_NS_stdio.h"
+#include "ace/OS_NS_time.h"
+#include "ace/OS_NS_string.h"
+
+#include "ace/TMCast/Group.hpp"
+
+class Args {};
+
+int
+ACE_TMAIN (int argc, ACE_TCHAR* argv[])
+{
+ int status = 0;
+ try
+ {
+ if (argc < 4) throw Args ();
+
+ bool receiver (true);
+
+ if (argv[1][0] == 'r') receiver = true;
+ else if (argv[1][0] == 's') receiver = false;
+ else throw Args ();
+
+ if (!receiver) ACE_OS::srand (ACE_OS::time ());
+
+ ACE_INET_Addr address (argv[3]);
+
+ ACE_TMCast::Group group (address, ACE_TEXT_ALWAYS_CHAR (argv[2]));
+
+ if (receiver)
+ {
+ for (char buffer[256];;)
+ {
+ group.recv (buffer, sizeof (buffer));
+
+ ACE_DEBUG ((LM_DEBUG, "%s\n", buffer));
+ }
+ }
+ else
+ {
+ char buffer[256];
+
+ for (unsigned long i = 0; i < 1000; i++)
+ {
+ // Sleep some random time around 1 sec.
+
+ ACE_UINT64 tmpl = 1000000U;
+ unsigned long t =
+ static_cast<unsigned long> (((tmpl * ACE_OS::rand ()) / RAND_MAX));
+
+ // ACE_DEBUG ((LM_DEBUG, "sleeping for %u\n", t));
+
+ ACE_OS::sleep (ACE_Time_Value (0, t));
+
+ ACE_OS::sprintf (buffer, "message # %lu", i);
+
+ try
+ {
+ group.send (buffer, ACE_OS::strlen (buffer) + 1);
+ }
+ catch (ACE_TMCast::Group::Aborted const&)
+ {
+ ACE_ERROR ((LM_ERROR, "%s has been aborted\n", buffer));
+ }
+ }
+ }
+ }
+ catch (Args const&)
+ {
+ ACE_ERROR ((LM_ERROR,
+ "Usage: member {r|s} <id> <IPv4 mcast address>:<port>\n"));
+ status++;
+ }
+ catch (ACE_TMCast::Group::Failed const&)
+ {
+ ACE_ERROR ((LM_ERROR,
+ "Group failure. Perhaps I am alone in the group.\n"));
+ status++;
+ }
+ catch (ACE_TMCast::Group::InsufficienSpace const&)
+ {
+ ACE_ERROR ((LM_ERROR, "Insufficient space in receive buffer.\n"));
+ status++;
+ }
+ return status;
+}