コード例 #1
0
ファイル: SubscriptionTests.cpp プロジェクト: 335/synergy
TEST(SubscriptionTests, decode_unrecognizedDigit_throwException)
{
	SubscriptionManager subscriptionManager;
	String serial("MOCK");

	EXPECT_THROW(subscriptionManager.decode(serial), XSubscription);
}
コード例 #2
0
ファイル: SubscriptionTests.cpp プロジェクト: 335/synergy
TEST(SubscriptionTests, decode_invalidLength_throwException)
{
	SubscriptionManager subscriptionManager;
	String serial("ABC");

	EXPECT_THROW(subscriptionManager.decode(serial), XSubscription);
}
コード例 #3
0
ファイル: SubManTest.cpp プロジェクト: NKSG/vn-sdm
int main(int argc, char ** argv)
{
	SubscriptionManager sm;
	SDMSubreqst sub_msg;
	SDMSerreqst ser_msg;
	SDMDeletesub del_msg;
	
	sub_msg.msg_id.setInterface(1);
	sub_msg.msg_id.setMessage(2);
	sub_msg.destination.setAddress(inet_addr("127.0.0.1"));
	sub_msg.destination.setPort(4050);
	sm.AddSubscription(sub_msg) ? printf("First added\n") : printf("First not added\n");
	sm.AddSubscription(sub_msg) ? printf("Second added\n") : printf("Second not added\n");
	
	ser_msg.reply_id.setInterface(1);
	ser_msg.reply_id.setMessage(3);
	sub_msg.destination.setAddress(inet_addr("127.0.0.1"));
	sub_msg.destination.setPort(4050);
	sm.AddSubscription(ser_msg) ? printf("Third added\n") : printf("Third not added\n");
	sub_msg.destination.setPort(4051);
	sm.AddSubscription(ser_msg) ? printf("Fourth added\n") : printf("Fourth not added\n");
	
	sm.Publish(1,3,"A",1);
	return 0;
}
コード例 #4
0
ファイル: SubscriptionTests.cpp プロジェクト: 335/synergy
TEST(SubscriptionTests, parsePlainSerial_expiredTrialSerial_throwException)
{
	SubscriptionManager subscriptionManager;
	String painText("{v1;trial;Bob;1;1398297600;1398384000}");
	SubscriptionKey key;

	EXPECT_THROW(subscriptionManager.parsePlainSerial(painText, key), XSubscription);
}
コード例 #5
0
ファイル: SubscriptionTests.cpp プロジェクト: 335/synergy
TEST(SubscriptionTests, parsePlainSerial_invalidSerial_throwException)
{
	SubscriptionManager subscriptionManager;
	String painText("{MOCK}");
	SubscriptionKey key;

	EXPECT_THROW(subscriptionManager.parsePlainSerial(painText, key), XSubscription);
}
コード例 #6
0
void* Listener(void * args)
{
	char buf[BUFSIZE];
	SDMSubreqst sub;
	SDMDeletesub del;
	MessageManager mm;
	mm.Async_Init(my_port);
	
	// Send one hearbeat, let the app fail
	SendHeartbeat();
	
	while(1)
	{
		if(mm.IsReady())
		{
			//SendHeartbeat();
#ifdef WIN32
			switch(mm.GetMsg(buf))
#else
			switch(mm.GetMessage(buf))
#endif
			{
			case SDM_Subreqst:
				sub.Unmarshal(buf);
				printf("Subscription Rec'd for %d\n",sub.msg_id.getInterfaceMessagePair()); fflush(NULL);
				pthread_mutex_lock(&subscription_mutex);
				subscriptions.AddSubscription(sub);
				pthread_mutex_unlock(&subscription_mutex);
				break;
			case SDM_Deletesub:
				printf("Cancel Rec'd\n");
				del.Unmarshal(buf);
				pthread_mutex_lock(&subscription_mutex);
				subscriptions.RemoveSubscription(del);
				pthread_mutex_unlock(&subscription_mutex);
				break;
			default:
				printf("Invalid Message found!\n");
				fflush(NULL);
				break;
			}
		}
		else
		{
			usleep(100000);
		}
	}
	return NULL;
}
コード例 #7
0
ファイル: qpid-perftest.cpp プロジェクト: ChugR/qpid-cpp
 /** Process messages from queue by applying a functor. */
 void process(size_t n, string queue,
              boost::function<void (const string&)> msgFn)
 {
     if (!opts.summary)
         cout << "Processing " << n << " messages from "
              << queue << " " << flush;
     LocalQueue lq;
     subs.setFlowControl(n, SubscriptionManager::UNLIMITED, false);
     subs.subscribe(lq, queue);
     for (size_t i = 0; i < n; ++i) {
         if (!opts.summary) cout << "." << flush;
         msgFn(lq.pop().getData());
     }
     if (!opts.summary) cout << " done." << endl;
 }
コード例 #8
0
ファイル: SubscriptionTests.cpp プロジェクト: 335/synergy
TEST(SubscriptionTests, parsePlainSerial_expiredBasicSerial_validSubscriptionKey)
{
	SubscriptionManager subscriptionManager;
	String painText("{v1;basic;Bob;1;[email protected];mock company;1398297600;1398384000}");
	SubscriptionKey key;
	subscriptionManager.parsePlainSerial(painText, key);

	EXPECT_EQ("basic", key.m_type);
	EXPECT_EQ("Bob", key.m_name);
	EXPECT_EQ(1, key.m_userLimit);
	EXPECT_EQ("[email protected]", key.m_email);
	EXPECT_EQ("mock company", key.m_company);
	EXPECT_EQ(1398297600, key.m_warnTime);
	EXPECT_EQ(1398384000, key.m_expireTime);
}
コード例 #9
0
ファイル: txshift.cpp プロジェクト: cajus/qpid-cpp-debian
 void subscribeToSource(SubscriptionManager manager)
 {
     sourceSettings.autoAck = 0;//will accept once at the end of the batch
     sourceSettings.flowControl = FlowControl::messageCredit(expected);
     sourceSubscription = manager.subscribe(*this, source, sourceSettings);
     QPID_LOG(info, "Subscribed to source: " << source << " expecting: " << expected);
 }
コード例 #10
0
ファイル: SubscriptionTests.cpp プロジェクト: 335/synergy
TEST(SubscriptionTests, parsePlainSerial_validSerialWithoutCompany_validSubscriptionKey)
{
	// valid until 2 March 2049
	SubscriptionManager subscriptionManager;
	String painText("{v1;trial;Bob;1;[email protected];;2147483647;2147483647}");
	SubscriptionKey key;
	subscriptionManager.parsePlainSerial(painText, key);

	EXPECT_EQ("trial", key.m_type);
	EXPECT_EQ("Bob", key.m_name);
	EXPECT_EQ(1, key.m_userLimit);
	EXPECT_EQ("[email protected]", key.m_email);
	EXPECT_EQ("", key.m_company);
	EXPECT_EQ(2147483647, key.m_warnTime);
	EXPECT_EQ(2147483647, key.m_expireTime);
}
コード例 #11
0
ファイル: topic_publisher.cpp プロジェクト: AlainRoy/htcondor
void Listener::consume() 
{ 
  Message lMsg;
  lMsg = subscriptions.get(string("condor_queue"));
  newMessage = lMsg.getData();
  cout << "\n consume() => " <<newMessage <<endl; 
} 
コード例 #12
0
ファイル: topic_publisher.cpp プロジェクト: AlainRoy/htcondor
/*
FUNCTION : prepareQueue
DESC: not used!
*/
void Listener::prepareQueue(std::string queue, std::string exchange, std::string routing_key) {

  std::cout << "Subscribing to queue " << queue << std::endl;
  //subscriptions.subscribe(*this, queue);
  // Will not acquire messages but instead browse them.
  //  subscriptions.setAcquireMode(message::ACQUIRE_MODE_NOT_ACQUIRED);
  subscriptions.subscribe(local_queue, string("condor_queue"));
}
コード例 #13
0
ファイル: topic_publisher.cpp プロジェクト: AlainRoy/htcondor
void Listener::dequeue() {
  subscriptions.subscribe(local_queue, string("condor_queue"));   
  Message lMsg;
  int size = 10;
  size = local_queue.size();

  local_queue.get(lMsg,10000);
  newMessage = lMsg.getData();
}
コード例 #14
0
ファイル: topic_publisher.cpp プロジェクト: AlainRoy/htcondor
/*
FUNCTION : received()
DESC : function to process the new message listened to from the qpid broker queue
*/
void Listener::received(Message& message) {

  char* prevStateFileName = "tempLRM.dat";
  ofstream prevStateFile ;
  prevStateFile.open(prevStateFileName,ios::out);
  prevStateFile << message.getData();
  prevStateFile.close();
  rename(prevStateFileName,"LRM.dat");
  string msgTxt = message.getData();
  newMessage = message.getData();

  if (message.getData() == "") {
    std::cout << "Shutting down listener for " << message.getDestination() << std::endl;
    subscriptions.cancel(message.getDestination());
  }
  subscriptions.stop();
  subscriptions.cancel(message.getDestination());

}
コード例 #15
0
ファイル: ThemeManager.cpp プロジェクト: Ancaro/stepmania
void ThemeManager::Subscribe( IThemeMetric *p )
{
	g_Subscribers.Subscribe( p );

	// It's ThemeManager's responsibility to make sure all of its subscribers
	// are updated with current data.  If a metric is created after 
	// a theme is loaded, ThemeManager should update it right away (not just
	// when the theme changes).
	if( THEME && THEME->GetCurThemeName().size() )
		p->Read();
}
コード例 #16
0
ファイル: topic_publisher.cpp プロジェクト: AlainRoy/htcondor
bool Listener::initListen() {
  // Receive messages
  //Added to test for init on recovery ***********************
  subscriptions.subscribe(local_queue, string("condor_queue"),SubscriptionSettings(FlowControl::unlimited(), ACCEPT_MODE_NONE, ACQUIRE_MODE_NOT_ACQUIRED));   
  Message lMsg;
  // sleep so that the local queue can get the message from the main condor
  // queue
  sleep(2);
  int size = 10;
  size = local_queue.size();
  local_queue.get(lMsg,10000);
  newMessage = lMsg.getData();
  subscriptions.stop();
  subscriptions.cancel(lMsg.getDestination());
  cout << "\n initListen(): size of the queue is : " << size <<endl;
  if(size > 0){
    //message queue has unprocessed message
    return false;
  }
  else{
    // message queue is empty:read from the file and send to the main condor_queue
    return true;
  }
}
コード例 #17
0
ファイル: LuaReference.cpp プロジェクト: BitMax/openitg
LuaReference::LuaReference( const LuaReference &cpy )
{
	m_Subscribers.Subscribe( this );

	if( cpy.m_iReference == LUA_NOREF )
		m_iReference = LUA_NOREF;
	else
	{
		/* Make a new reference. */
		Lua *L = LUA->Get();
		lua_rawgeti( L, LUA_REGISTRYINDEX, cpy.m_iReference );
		m_iReference = luaL_ref( L, LUA_REGISTRYINDEX );
		LUA->Release( L );
	}
}
コード例 #18
0
void* Publisher(void * args)
{
	int published = 0;
	short data;
	while(1)
	{
		data = (short)(rand()&0x00FF);
		pthread_mutex_lock(&subscription_mutex);
		if (subscriptions.Publish(1,1,(char*)&data,2))
		{
			published++;
		}
		pthread_mutex_unlock(&subscription_mutex);
		printf("Produced %d\tPublished %d\n",data,published);
		sleep(1);
	}
	return NULL;
}
コード例 #19
0
ファイル: producer.cpp プロジェクト: NKSG/vn-sdm
void* Publisher(void * args)
{
	int published = 0;
	short data;
	while(published < 10)
	{
		data = (short)(rand()&0x00FF);
		char bufdata[2];
		PUT_SHORT(bufdata, data);
		pthread_mutex_lock(&subscription_mutex);
		if (subscriptions.Publish(1,1,bufdata,2))
		{
			published++;
		}
		pthread_mutex_unlock(&subscription_mutex);
		printf("Produced %d\tPublished %d / 10\n",data,published);
		sleep(1);
	}
	return NULL;
}
コード例 #20
0
ファイル: PrefsManager.cpp プロジェクト: TaroNuke/openitg
void PrefsManager::Unsubscribe( IPreference *p )
{
    m_Subscribers.Unsubscribe( p );
}
コード例 #21
0
ファイル: qpid-perftest.cpp プロジェクト: ChugR/qpid-cpp
    void run() {                // Controller
        try {
            // Wait for subscribers to be ready.
            process(opts.totalSubs, fqn("sub_ready"), boost::bind(expect, _1, "ready"));

            LocalQueue pubDone;
            LocalQueue subDone;
            subs.setFlowControl(0, SubscriptionManager::UNLIMITED, false);
            subs.subscribe(pubDone, fqn("pub_done"));
            subs.subscribe(subDone, fqn("sub_done"));

            double txrateTotal(0);
            double mbytesTotal(0);
            double pubRateTotal(0);
            double subRateTotal(0);

            for (size_t j = 0; j < opts.iterations; ++j) {
                AbsTime start=now();
                send(opts.totalPubs, fqn("pub_start"), "start"); // Start publishers
                if (j) {
                    send(opts.totalSubs, fqn("sub_iteration"), "next"); // Start subscribers on next iteration
                }

                Stats pubRates;
                Stats subRates;

                process(opts.totalPubs, pubDone, fqn("pub_done"), boost::ref(pubRates));
                process(opts.totalSubs, subDone, fqn("sub_done"), boost::ref(subRates));

                AbsTime end=now();
                double time=secs(start, end);
		if (time <= 0.0) {
		  throw Exception("ERROR: Test completed in zero seconds. Try again with a larger message count.");
		}
                double txrate=opts.transfers/time;
                double mbytes=(txrate*opts.size)/(1024*1024);

                if (!opts.summary) {
                    cout << endl << "Total " << opts.transfers << " transfers of "
                         << opts.size << " bytes in "
                         << time << " seconds." << endl;
                    cout << endl << "Publish transfers/sec:    " << endl;
                    pubRates.print(cout);
                    cout << endl << "Subscribe transfers/sec:  " << endl;
                    subRates.print(cout);
                    cout << endl
                         << "Total transfers/sec:      " << txrate << endl
                         << "Total Mbytes/sec: " << mbytes << endl;
                }
                else {
                    cout << pubRates.mean() << "\t"
                         << subRates.mean() << "\t"
                         << txrate << "\t"
                         << mbytes << endl;
                }

                txrateTotal += txrate;
                mbytesTotal += mbytes;
                pubRateTotal += pubRates.mean();
                subRateTotal += subRates.mean();
            }
            if (opts.iterations > 1) {
                cout << "Averages: "<< endl
                     << (pubRateTotal / opts.iterations) << "\t"
                     << (subRateTotal / opts.iterations) << "\t"
                     << (txrateTotal / opts.iterations) << "\t"
                     << (mbytesTotal / opts.iterations) << endl;
            }
        }
        catch (const std::exception& e) {
            cout << "Controller exception: " << e.what() << endl;
        }
    }
コード例 #22
0
ファイル: topic_publisher.cpp プロジェクト: AlainRoy/htcondor
/*
FUNCTION:listen()
DESC: function to acquire/dequeue messages from the qpid borker queue by giving control over to run -not used!
*/
void Listener::listen() {
  subscriptions.run();
}
コード例 #23
0
ファイル: ThemeManager.cpp プロジェクト: Ancaro/stepmania
void ThemeManager::Unsubscribe( IThemeMetric *p )
{
	g_Subscribers.Unsubscribe( p );
}
コード例 #24
0
ファイル: topic_publisher.cpp プロジェクト: AlainRoy/htcondor
void Listener::browse() 
{ 
  subscriptions.subscribe(*this, "condor_queue", SubscriptionSettings(FlowControl::unlimited(), ACCEPT_MODE_NONE, ACQUIRE_MODE_NOT_ACQUIRED));     
  subscriptions.run(); 
}
コード例 #25
0
ファイル: LuaReference.cpp プロジェクト: BitMax/openitg
LuaReference::LuaReference()
{
	m_iReference = LUA_NOREF;
	m_Subscribers.Subscribe( this );
}
コード例 #26
0
ファイル: LuaReference.cpp プロジェクト: BitMax/openitg
LuaReference::~LuaReference()
{
	Unregister();
	m_Subscribers.Unsubscribe( this );
}
コード例 #27
0
ファイル: LuaBinding.cpp プロジェクト: KingMew/stepmania
LuaBinding::~LuaBinding()
{
	m_Subscribers.Unsubscribe( this );
}
コード例 #28
0
ファイル: LuaBinding.cpp プロジェクト: KingMew/stepmania
LuaBinding::LuaBinding()
{
	m_Subscribers.Subscribe( this );
}
コード例 #29
0
ファイル: txshift.cpp プロジェクト: cajus/qpid-cpp-debian
 void subscribeToControl(SubscriptionManager manager)
 {
     controlSettings.flowControl = FlowControl::messageCredit(1);
     controlSubscription = manager.subscribe(*this, control, controlSettings);
     QPID_LOG(info, "Subscribed to job queue");
 }
コード例 #30
0
ファイル: qrsh.cpp プロジェクト: KeithLatteri/awips2
/*
 *  argv[1] host
 *  argv[2] port
 *  argv[3] server name
 *  argv[4] command name
 *  argv[5..N] args to the command
 */
int
main ( int argc, char ** argv )
{
    const char* host = argv[1];
    int port = atoi(argv[2]);


    Connection connection;

    try
    {
        connection.open ( host, port );
        Session session = connection.newSession ( );

        // Make a queue and bind it to fanout.
        string myQueue = session.getId().getName();

        session.queueDeclare ( arg::queue=myQueue,
                               arg::exclusive=true,
                               arg::autoDelete=true
                             );

        session.exchangeBind ( arg::exchange="amq.fanout",
                               arg::queue=myQueue,
                               arg::bindingKey="my-key"
                             );

        // Get ready to listen for the wait-response.
        // or maybe a get-response.
        // ( Although this may not be one of those types
        // of command, get ready anyway.
        SubscriptionManager subscriptions ( session );
        ResponseListener responseListener ( subscriptions );
        subscriptions.subscribe ( responseListener, myQueue );

        bool response_command = false;
        if(! strcmp("exec_wait", argv[4] ))
            response_command = true;
        else
        if(! strcmp("exited", argv[4] ))
            response_command = true;
        else
        if(! strcmp("get", argv[4] ))
            response_command = true;

        // Send the payload message.
        // Skip "qrsh host_name port"
        Message message;
        stringstream ss;
        for ( int i = 3; i < argc; ++ i )
            ss << argv[i] << ' ';

        message.setData ( ss.str() );

        session.messageTransfer(arg::content=message,
                                arg::destination="amq.fanout");

        if ( response_command )
            subscriptions.run();

        session.close();
        connection.close();
        return responseListener.exitCode;
    }
    catch ( exception const & e)
    {
        cerr << e.what() << endl;
    }

    return 1;
}