Ejemplo n.º 1
0
void
create_and_register_agent(
	so_5::environment_t & env,
	const std::string & parent_coop_name,
	int ordinal,
	int max_children,
	int level,
	int max_deep )
{
	so_5::coop_unique_ptr_t coop = env.create_coop(
			create_coop_name( parent_coop_name, level, ordinal ) );
	if( level )
		coop->set_parent_coop_name( parent_coop_name );

	coop->add_agent(
			new a_test_t(
					env,
					coop->query_coop_name(),
					parent_coop_name,
					max_children,
					level,
					max_deep ) );

	env.register_coop( std::move( coop ) );
}
Ejemplo n.º 2
0
void
reg_coop(
	so_5::environment_t & env )
{
	so_5::coop_unique_ptr_t coop =
		env.create_coop( "test_coop" );

	coop->add_agent( new a_ordinary_t( env ) );
	coop->add_agent( new a_ordinary_t( env ) );
	coop->add_agent( new a_ordinary_t( env ) );
	coop->add_agent( new a_ordinary_t( env ) );
	coop->add_agent( new a_ordinary_t( env ) );

	// This agent will throw an exception during binding for dispatcher.
	coop->add_agent(
		new a_throwing_t( env ),
		so_5::disp_binder_unique_ptr_t( new throwing_disp_binder_t ) );

	coop->add_agent( new a_ordinary_t( env ) );
	coop->add_agent( new a_ordinary_t( env ) );
	coop->add_agent( new a_ordinary_t( env ) );
	coop->add_agent( new a_ordinary_t( env ) );

	try
	{
		env.register_coop( std::move( coop ) );
	}
	catch(...) {}
}
Ejemplo n.º 3
0
// The SObjectizer Environment initialization.
void init( so_5::environment_t & env )
{
	// Creating and registering a cooperation.
	env.register_agent_as_coop( "coop", env.make_agent< a_hello_t >() );

	// Stopping SObjectizer.
	env.stop();
}
Ejemplo n.º 4
0
void
init( so_5::environment_t & env )
{
	auto coop = env.create_coop( "test" );
	coop->add_agent( new a_parent_t( env ) );
	coop->add_agent( new a_time_sentinel_t( env ) );

	env.register_coop( std::move( coop ) );
}
Ejemplo n.º 5
0
void
init( so_5::environment_t & env )
{
	auto coop = env.create_coop( "driver",
			so_5::disp::active_obj::create_disp_binder( "active_obj" ) );

	coop->add_agent( new a_driver_t( env ) );
	coop->add_agent( new a_time_sentinel_t( env ) );

	env.register_coop( std::move( coop ) );
}
Ejemplo n.º 6
0
void
init( so_5::environment_t & env )
{
	env.introduce_coop(
			so_5::disp::active_obj::create_private_disp( env )->binder(),
			[&]( so_5::coop_t & coop ) {
				const auto mbox = env.create_mbox();

				coop.make_agent< a_provider_t >( mbox );
				coop.make_agent< a_consumer_t >( mbox );
			} );
}
Ejemplo n.º 7
0
void
reg_coop(
	const std::string & coop_name,
	so_5::environment_t & env )
{
	so_5::coop_unique_ptr_t coop = env.create_coop( coop_name );

	coop->add_agent( new test_agent_t( env ) );
	coop->add_agent( new test_agent_t( env ) );

	env.register_coop( std::move( coop ) );
}
Ejemplo n.º 8
0
void
init( so_5::environment_t & env )
{
	env.introduce_coop( []( so_5::coop_t & coop ) {
			coop.make_agent< a_test_t >( coop.environment().create_mbox() );
		} );
}
Ejemplo n.º 9
0
void
do_check_wait_remove_oldest_impl(
	so_5::environment_t & env,
	const char * case_name,
	props::memory_usage_t memory )
{
	cout << "wait, remove_oldest, " << case_name << ": " << std::flush;

	auto ch = env.create_mchain(
			so_5::make_limited_with_waiting_mchain_params(
					3,
					memory,
					props::overflow_reaction_t::remove_oldest,
					wait_timeout ) );

	so_5::send< int >( ch, 1 );
	so_5::send< int >( ch, 2 );
	so_5::send< int >( ch, 3 );
	check_pause( [&] { so_5::send< int >( ch, 4 ); } );

	receive( from(ch).handle_n(4).empty_timeout(so_5::no_wait),
			[]( int i ) { UT_CHECK_CONDITION( i > 1 ); } );

	cout << "OK" << std::endl;
}
Ejemplo n.º 10
0
void
do_check_no_wait_throw_exception_impl(
	so_5::environment_t & env,
	const char * case_name,
	props::memory_usage_t memory )
{
	cout << "no_wait, throw_exception, " << case_name << ": " << std::flush;

	auto ch = env.create_mchain(
			so_5::make_limited_without_waiting_mchain_params(
					3,
					memory,
					props::overflow_reaction_t::throw_exception ) );

	so_5::send< int >( ch, 1 );
	so_5::send< int >( ch, 2 );
	so_5::send< int >( ch, 3 );
	try
	{
		so_5::send< int >( ch, 4 );
		UT_CHECK_CONDITION( !"An exception must be throw before this line!" );
	}
	catch( const so_5::exception_t & ex )
	{
		UT_CHECK_CONDITION( so_5::rc_msg_chain_overflow == ex.error_code() );
	}

	cout << "OK" << std::endl;
}
Ejemplo n.º 11
0
void
init( so_5::environment_t & env )
{
	reg_coop( env );

	env.stop();
}
Ejemplo n.º 12
0
void
init(
	so_5::environment_t & env )
	{
		auto coop = env.create_coop(
				"test_coop",
				so_5::disp::active_obj::create_disp_binder( "active_obj" ) );

		auto svc_mbox = env.create_mbox();

		coop->add_agent( new a_convert_service_t( env, svc_mbox ) );
		coop->add_agent( new a_convert_service_t( env, svc_mbox ) );
		coop->add_agent( new a_client_t( env, svc_mbox ) );
		coop->add_agent( new a_time_sentinel_t( env ) );

		env.register_coop( std::move( coop ) );
	}
Ejemplo n.º 13
0
void
init( so_5::environment_t & env )
{
	env.introduce_coop( []( so_5::coop_t & coop ) {
		coop.set_exception_reaction( so_5::shutdown_sobjectizer_on_exception );
		coop.make_agent< a_test_t >();
	} );
}
Ejemplo n.º 14
0
		a_test_t(
			so_5::environment_t & env,
			int & message_counter )
			:	base_type_t( env )
			,	m_message_counter( message_counter )
			,	m_mbox( env.create_mbox() )
		{
		}
Ejemplo n.º 15
0
		a_test_t(
			so_5::environment_t & env,
			const so_5::coop_reg_notificator_t & reg_notificator,
			const so_5::coop_dereg_notificator_t & dereg_notificator )
			:	base_type_t( env )
			,	m_reg_notificator( reg_notificator )
			,	m_dereg_notificator( dereg_notificator )
			,	m_mbox( env.create_mbox() )
		{}
Ejemplo n.º 16
0
void
init( so_5::environment_t & env )
{
	env.introduce_coop(
		so_5::disp::active_obj::create_private_disp( env )->binder(),
		[]( so_5::coop_t & coop ) {
			auto a_test = coop.make_agent< a_test_t >();
			coop.make_agent< a_request_initator_t >( a_test->so_direct_mbox() );
		} );
}
			static void
			send_delayed(
				so_5::environment_t & env,
				const so_5::mbox_t & to,
				std::chrono::steady_clock::duration pause,
				ARGS &&... args )
				{
					env.single_timer(
							so_5::details::make_message_instance< MESSAGE >(
								std::forward< ARGS >( args )...),
							to, pause );
				}
			static timer_id_t
			send_periodic(
				so_5::environment_t & env,
				const so_5::mbox_t & to,
				std::chrono::steady_clock::duration pause,
				std::chrono::steady_clock::duration period,
				ARGS &&... args )
				{
					return env.schedule_timer( 
							so_5::details::make_message_instance< MESSAGE >(
								std::forward< ARGS >( args )...),
							to, pause, period );
				}
Ejemplo n.º 19
0
void
init( so_5::environment_t & env )
{
	reg_coop( "test_coop_1", env );
	reg_coop( "test_coop_2", env );
	reg_coop( "test_coop_3", env );
	reg_coop( "test_coop_4", env );
	reg_coop( "test_coop_5", env );
	reg_coop( "test_coop_6", env );

	std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) );

	env.deregister_coop( "test_coop_1", so_5::dereg_reason::normal );

	env.deregister_coop( "test_coop_6", so_5::dereg_reason::normal );

	env.deregister_coop( "test_coop_3", so_5::dereg_reason::normal );

	std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) );

	env.stop();
}
Ejemplo n.º 20
0
void
init( so_5::environment_t & env )
{
	const std::string coop_name( "main_coop" );

	env.register_agent_as_coop( coop_name, new test_agent_t( env ) );

	bool exception_thrown = false;
	try
	{
		// Create a duplicate.
		env.register_agent_as_coop( coop_name, new test_agent_t( env ) );
	}
	catch( const so_5::exception_t & )
	{
		exception_thrown = true;
	}

	if( !exception_thrown )
		throw std::runtime_error( "duplicating coop should not be registered" );

	env.stop();
}
Ejemplo n.º 21
0
		virtual void
		on_deregistered(
			so_5::environment_t & env,
			const std::string & coop_name,
			const so_5::coop_dereg_reason_t &) override
		{
			{
				std::lock_guard< std::mutex > lock{ m_lock };

				m_names.erase( coop_name );
			}

			if( "a_0_0" == coop_name )
				env.stop();
		}
Ejemplo n.º 22
0
		a_test_t(
			so_5::environment_t & env,
			const std::string & self_name,
			const std::string & parent_coop_name,
			int max_children,
			int level,
			int max_deep )
			:	base_type_t( env )
			,	m_self_name( self_name )
			,	m_parent_coop_name( parent_coop_name )
			,	m_max_children( max_children )
			,	m_level( level )
			,	m_max_deep( max_deep )
			,	m_started_children( 0 )
			,	m_self_mbox( env.create_mbox( self_name ) )
		{
		}
Ejemplo n.º 23
0
		void
		init( so_5::environment_t & env )
		{
			auto on_reg =
					[this]( so_5::environment_t &,
							const std::string & )
					{
						m_reg_notify_received = true;
					};
			auto on_dereg =
					[this]( so_5::environment_t &,
							const std::string &,
							const so_5::coop_dereg_reason_t &)
					{
						m_dereg_notify_received = true;
					};

			env.register_agent_as_coop(
					"test",
					new a_test_t( env, on_reg, on_dereg ) );
		}
Ejemplo n.º 24
0
		a_driver_t(
			so_5::environment_t & env )
			:	so_5::agent_t( env )
			,	m_mbox( env.create_mbox() )
		{}
Ejemplo n.º 25
0
		test_mbox_t( so_5::environment_t & env )
			:	m_actual_mbox( env.create_mbox() )
			{
			}
Ejemplo n.º 26
0
void
init( so_5::environment_t & env )
{
	CHECK_LAYER( env, 1 )
	CHECK_LAYER( env, 2 )
	CHECK_LAYER( env, 3 )
	CHECK_LAYER( env, 4 )
	CHECK_LAYER( env, 5 )
	CHECK_LAYER( env, 6 )
	CHECK_LAYER( env, 7 )
	CHECK_LAYER( env, 8 )
	CHECK_LAYER( env, 9 )
	CHECK_LAYER( env, 10 )
	CHECK_LAYER( env, 11 )
	CHECK_LAYER( env, 12 )
	CHECK_LAYER( env, 13 )
	CHECK_LAYER( env, 14 )
	CHECK_LAYER( env, 15 )
	CHECK_LAYER( env, 16 )
	CHECK_LAYER( env, 17 )
	CHECK_LAYER( env, 18 )
	CHECK_LAYER( env, 19 )
	CHECK_LAYER( env, 20 )
	CHECK_LAYER( env, 21 )
	CHECK_LAYER( env, 22 )
	CHECK_LAYER( env, 23 )
	CHECK_LAYER( env, 24 )
	CHECK_LAYER( env, 25 )
	CHECK_LAYER( env, 26 )
	CHECK_LAYER( env, 27 )
	CHECK_LAYER( env, 28 )
	CHECK_LAYER( env, 29 )
	CHECK_LAYER( env, 30 )
	CHECK_LAYER( env, 31 )
	CHECK_LAYER( env, 32 )
	CHECK_LAYER( env, 33 )
	CHECK_LAYER( env, 34 )
	CHECK_LAYER( env, 35 )
	CHECK_LAYER( env, 36 )
	CHECK_LAYER( env, 37 )
	CHECK_LAYER( env, 38 )
	CHECK_LAYER( env, 39 )
	CHECK_LAYER( env, 40 )
	CHECK_LAYER( env, 41 )
	CHECK_LAYER( env, 42 )
	CHECK_LAYER( env, 43 )
	CHECK_LAYER( env, 44 )
	CHECK_LAYER( env, 45 )
	CHECK_LAYER( env, 46 )
	CHECK_LAYER( env, 47 )
	CHECK_LAYER( env, 48 )
	CHECK_LAYER( env, 49 )
	CHECK_LAYER( env, 50 )
	CHECK_LAYER( env, 51 )
	CHECK_LAYER( env, 52 )
	CHECK_LAYER( env, 53 )
	CHECK_LAYER( env, 54 )
	CHECK_LAYER( env, 55 )
	CHECK_LAYER( env, 56 )
	CHECK_LAYER( env, 57 )
	CHECK_LAYER( env, 58 )
	CHECK_LAYER( env, 59 )
	CHECK_LAYER( env, 60 )
	CHECK_LAYER( env, 61 )
	CHECK_LAYER( env, 62 )
	CHECK_LAYER( env, 63 )

	CHECK_LAYER_EXISTS( env, 1 );
	CHECK_LAYER_EXISTS( env, 2 );
	CHECK_LAYER_EXISTS( env, 3 );
	CHECK_LAYER_EXISTS( env, 4 );
	CHECK_LAYER_EXISTS( env, 5 );
	CHECK_LAYER_EXISTS( env, 6 );
	CHECK_LAYER_EXISTS( env, 7 );
	CHECK_LAYER_EXISTS( env, 8 );
	CHECK_LAYER_EXISTS( env, 9 );
	CHECK_LAYER_EXISTS( env, 10 );
	CHECK_LAYER_EXISTS( env, 11 );
	CHECK_LAYER_EXISTS( env, 12 );
	CHECK_LAYER_EXISTS( env, 13 );
	CHECK_LAYER_EXISTS( env, 14 );
	CHECK_LAYER_EXISTS( env, 15 );
	CHECK_LAYER_EXISTS( env, 16 );
	CHECK_LAYER_EXISTS( env, 17 );
	CHECK_LAYER_EXISTS( env, 18 );
	CHECK_LAYER_EXISTS( env, 19 );
	CHECK_LAYER_EXISTS( env, 20 );
	CHECK_LAYER_EXISTS( env, 21 );
	CHECK_LAYER_EXISTS( env, 22 );
	CHECK_LAYER_EXISTS( env, 23 );
	CHECK_LAYER_EXISTS( env, 24 );
	CHECK_LAYER_EXISTS( env, 25 );
	CHECK_LAYER_EXISTS( env, 26 );
	CHECK_LAYER_EXISTS( env, 27 );
	CHECK_LAYER_EXISTS( env, 28 );
	CHECK_LAYER_EXISTS( env, 29 );
	CHECK_LAYER_EXISTS( env, 30 );
	CHECK_LAYER_EXISTS( env, 31 );
	CHECK_LAYER_EXISTS( env, 32 );
	CHECK_LAYER_EXISTS( env, 33 );
	CHECK_LAYER_EXISTS( env, 34 );
	CHECK_LAYER_EXISTS( env, 35 );
	CHECK_LAYER_EXISTS( env, 36 );
	CHECK_LAYER_EXISTS( env, 37 );
	CHECK_LAYER_EXISTS( env, 38 );
	CHECK_LAYER_EXISTS( env, 39 );
	CHECK_LAYER_EXISTS( env, 40 );
	CHECK_LAYER_EXISTS( env, 41 );
	CHECK_LAYER_EXISTS( env, 42 );
	CHECK_LAYER_EXISTS( env, 43 );
	CHECK_LAYER_EXISTS( env, 44 );
	CHECK_LAYER_EXISTS( env, 45 );
	CHECK_LAYER_EXISTS( env, 46 );
	CHECK_LAYER_EXISTS( env, 47 );
	CHECK_LAYER_EXISTS( env, 48 );
	CHECK_LAYER_EXISTS( env, 49 );
	CHECK_LAYER_EXISTS( env, 50 );
	CHECK_LAYER_EXISTS( env, 51 );
	CHECK_LAYER_EXISTS( env, 52 );
	CHECK_LAYER_EXISTS( env, 53 );
	CHECK_LAYER_EXISTS( env, 54 );
	CHECK_LAYER_EXISTS( env, 55 );
	CHECK_LAYER_EXISTS( env, 56 );
	CHECK_LAYER_EXISTS( env, 57 );
	CHECK_LAYER_EXISTS( env, 58 );
	CHECK_LAYER_EXISTS( env, 59 );
	CHECK_LAYER_EXISTS( env, 60 );
	CHECK_LAYER_EXISTS( env, 61 );
	CHECK_LAYER_EXISTS( env, 62 );
	CHECK_LAYER_EXISTS( env, 63 );

	env.stop();
}
Ejemplo n.º 27
0
	void
	init( so_5::environment_t & env )
	{
		env.register_agent_as_coop( "test_coop",
				new a_test_t( env, m_message_counter ) );
	}
Ejemplo n.º 28
0
void
init( so_5::environment_t & env )
{
	env.register_agent_as_coop( "test_coop", new test_agent_t( env ) );
}
Ejemplo n.º 29
0
		a_test_t(
			so_5::environment_t & env )
			:	base_type_t( env )
			,	m_mbox( env.create_mbox() )
		{
		}
Ejemplo n.º 30
0
void
init( so_5::environment_t & env )
{
	env.register_agent_as_coop( so_5::autoname,
			env.make_agent< a_test_t >() );
}