Example #1
0
void processCommandLineOptions( int argc, char* argv[] )
{
	int iargs = 1;
	authenticationToken.clear();
	newauthenticationToken.clear();
	authenticationExtended.clear();

	while ( iargs < argc )
	{
		if ( 0 == strcmp( "-?", argv[iargs] ) )
		{
			printUsage();
		}
		else if ( strcmp( "-at", argv[iargs] ) == 0 )
		{
			++iargs; if ( iargs == argc ) printUsage();

			authenticationToken.set(argv[iargs++]);
		}
		else if ( strcmp( "-newat", argv[iargs] ) == 0 )
		{
			++iargs; if ( iargs == argc ) printUsage();

			newauthenticationToken.set(argv[iargs++]);
		}
		else if ( strcmp( "-aid", argv[iargs] ) == 0 )
		{
			++iargs; if ( iargs == argc ) printUsage();

			appId.set(argv[iargs++]);
		}
		else if (strcmp("-ax", argv[iargs]) == 0)
		{
			++iargs; if (iargs == argc) printUsage();

			authenticationExtended.set(argv[iargs++]);
		}
		else
		{
			cout << "Invalid argument: " << argv[iargs] << endl;

			printUsage();
		}

		if (authenticationToken.empty())
		{
			cout << "Missing Authentication Token." << endl;

			printUsage();
		}
	}
}
Example #2
0
int main( int argc, char* argv[] )
{
	try {
		authenticationToken.clear();
		newauthenticationToken.clear();
		authenticationExtended.clear();
		processCommandLineOptions( argc, argv );
		printActiveConfig();
		AppLoginClient loginClient;

		EmaBuffer authnExtendedBuf;

		Login::LoginReq loginMsg;

		OmmConsumerConfig consumerConfig;

		loginMsg.name(authenticationToken).applicationId(appId).nameType(USER_AUTH_TOKEN);
		if (!authenticationExtended.empty())
		{
			authnExtendedBuf.setFrom(authenticationExtended.c_str(), authenticationExtended.length());
			loginMsg.authenticationExtended(authnExtendedBuf);
		}
			
		
		consumerConfig.addAdminMsg(loginMsg.getMessage());

		AppClient appClient;
		OmmConsumer consumer( consumerConfig, loginClient);
		
		
		consumer.registerClient( ReqMsg().serviceName( "DIRECT_FEED" ).name( "TRI.N" ), appClient );
		
		for (int i = 0; i < 60; i++)
		{
			
			if (loginClient._TTReissue != 0 && getCurrentTime() >= loginClient._TTReissue)
			{
				loginMsg.clear().name(authenticationToken).applicationId(appId).nameType(USER_AUTH_TOKEN);
				if (!authenticationExtended.empty())
				{
					loginMsg.authenticationExtended(authnExtendedBuf);
				}

				consumer.reissue(loginMsg.getMessage(), loginClient._handle);
				loginClient._TTReissue = 0;
			}
			
			sleep(1000);
			if ( i == 3 )
			{
				cout << endl << "SEND PAUSE USING first TOKEN" << endl;
					loginMsg.clear().name(authenticationToken).applicationId(appId).nameType(USER_AUTH_TOKEN).pause(true);
				consumer.reissue(loginMsg.getMessage(), loginClient._handle);
			}
			if ( i == 10 )
			{
				cout << endl << "Renew new TOKEN with PAUSE falg" << endl;
					loginMsg.clear().name(newauthenticationToken).applicationId(appId).nameType(USER_AUTH_TOKEN).pause(true);
				consumer.reissue(loginMsg.getMessage(), loginClient._handle);
			}
			if ( i == 13 )
			{
				cout << endl << "SEND RESUME USING second TOKEN" << endl;
					loginMsg.clear().name(newauthenticationToken).applicationId(appId).nameType(USER_AUTH_TOKEN).pause(false);
				consumer.reissue(loginMsg.getMessage(), loginClient._handle);
			}
		}

	}
	catch ( const OmmException& excp ) {
		cout << excp << endl;
	}
	return 0;
}
void ChannelCallbackClient::initialize( RsslRDMLoginRequest* loginRequest, RsslRDMDirectoryRequest* dirRequest )
{
	RsslReactorOMMConsumerRole consumerRole;
	rsslClearOMMConsumerRole( &consumerRole );

	consumerRole.pLoginRequest = loginRequest;
	consumerRole.pDirectoryRequest = dirRequest;
	consumerRole.dictionaryDownloadMode = RSSL_RC_DICTIONARY_DOWNLOAD_NONE;
	consumerRole.loginMsgCallback = OmmConsumerImpl::loginCallback;
	consumerRole.directoryMsgCallback = OmmConsumerImpl::directoryCallback;
	consumerRole.dictionaryMsgCallback = OmmConsumerImpl::dictionaryCallback;
	consumerRole.base.channelEventCallback = OmmConsumerImpl::channelCallback;
	consumerRole.base.defaultMsgCallback = OmmConsumerImpl::itemCallback;
	consumerRole.watchlistOptions.channelOpenCallback = OmmConsumerImpl::channelOpenCallback;
	consumerRole.watchlistOptions.enableWatchlist = RSSL_TRUE;
	consumerRole.watchlistOptions.itemCountHint = _ommConsImpl.getActiveConfig().itemCountHint;
	consumerRole.watchlistOptions.obeyOpenWindow = _ommConsImpl.getActiveConfig().obeyOpenWindow > 0 ? RSSL_TRUE : RSSL_FALSE;
	consumerRole.watchlistOptions.postAckTimeout = _ommConsImpl.getActiveConfig().postAckTimeout;
	consumerRole.watchlistOptions.requestTimeout = _ommConsImpl.getActiveConfig().requestTimeout;
	consumerRole.watchlistOptions.maxOutstandingPosts = _ommConsImpl.getActiveConfig().maxOutstandingPosts;
		
	EmaVector< ChannelConfig* > &consumerActivecfgChannelSet = _ommConsImpl.getActiveConfig().configChannelSet;
	unsigned int channelCfgSetLastIndex = consumerActivecfgChannelSet.size() - 1;

	RsslReactorConnectInfo      *reactorConnectInfo = new RsslReactorConnectInfo[consumerActivecfgChannelSet.size()];
	RsslReactorConnectOptions connectOpt;
	rsslClearReactorConnectOptions( &connectOpt );
	connectOpt.connectionCount = consumerActivecfgChannelSet.size();
	connectOpt.reactorConnectionList = reactorConnectInfo;
	connectOpt.reconnectAttemptLimit = consumerActivecfgChannelSet[channelCfgSetLastIndex]->reconnectAttemptLimit;
	connectOpt.reconnectMinDelay = consumerActivecfgChannelSet[channelCfgSetLastIndex]->reconnectMinDelay;
	connectOpt.reconnectMaxDelay = consumerActivecfgChannelSet[channelCfgSetLastIndex]->reconnectMaxDelay;
	connectOpt.initializationTimeout = 5;

	EmaString channelParams;
	EmaString temp( "Attempt to connect using ");
	if(connectOpt.connectionCount > 1)
		temp = "Attempt to connect using the following list";
	UInt32 supportedConnectionTypeChannelCount = 0;
	EmaString errorStrUnsupportedConnectionType("Unknown connection type. Passed in type is");

	EmaString channelNames;

	
	for(unsigned int i = 0; i < connectOpt.connectionCount; ++i)
	{
		rsslClearReactorConnectInfo(&reactorConnectInfo[i]);

		if ( consumerActivecfgChannelSet[i]->connectionType == RSSL_CONN_TYPE_SOCKET   ||
			consumerActivecfgChannelSet[i]->connectionType == RSSL_CONN_TYPE_HTTP ||
			consumerActivecfgChannelSet[i]->connectionType == RSSL_CONN_TYPE_ENCRYPTED ||
			consumerActivecfgChannelSet[i]->connectionType == RSSL_CONN_TYPE_RELIABLE_MCAST)
		{
			Channel* pChannel = Channel::create( _ommConsImpl, consumerActivecfgChannelSet[i]->name, _pRsslReactor );

			reactorConnectInfo[i].rsslConnectOptions.userSpecPtr = (void*)pChannel;
			consumerActivecfgChannelSet[i]->pChannel = pChannel;

			reactorConnectInfo[i].rsslConnectOptions.majorVersion = RSSL_RWF_MAJOR_VERSION;
			reactorConnectInfo[i].rsslConnectOptions.minorVersion = RSSL_RWF_MINOR_VERSION;
			reactorConnectInfo[i].rsslConnectOptions.protocolType = RSSL_RWF_PROTOCOL_TYPE;		
			reactorConnectInfo[i].rsslConnectOptions.connectionType = consumerActivecfgChannelSet[i]->connectionType;
			reactorConnectInfo[i].rsslConnectOptions.pingTimeout = consumerActivecfgChannelSet[i]->connectionPingTimeout;
			reactorConnectInfo[i].rsslConnectOptions.guaranteedOutputBuffers = consumerActivecfgChannelSet[i]->guaranteedOutputBuffers;
			reactorConnectInfo[i].rsslConnectOptions.sysRecvBufSize = consumerActivecfgChannelSet[i]->sysRecvBufSize;
			reactorConnectInfo[i].rsslConnectOptions.sysSendBufSize = consumerActivecfgChannelSet[i]->sysSendBufSize;
			reactorConnectInfo[i].rsslConnectOptions.numInputBuffers = consumerActivecfgChannelSet[i]->numInputBuffers;

			EmaString strConnectionType;
			switch ( reactorConnectInfo[i].rsslConnectOptions.connectionType )
			{
			case RSSL_CONN_TYPE_SOCKET:
				{
				reactorConnectInfo[i].rsslConnectOptions.compressionType = consumerActivecfgChannelSet[i]->compressionType;
				reactorConnectInfo[i].rsslConnectOptions.connectionInfo.unified.address = (char*)static_cast<SocketChannelConfig*>(consumerActivecfgChannelSet[i])->hostName.c_str();
				reactorConnectInfo[i].rsslConnectOptions.connectionInfo.unified.serviceName = (char*)static_cast<SocketChannelConfig*>(consumerActivecfgChannelSet[i])->serviceName.c_str();
				reactorConnectInfo[i].rsslConnectOptions.tcpOpts.tcp_nodelay = static_cast<SocketChannelConfig*>(consumerActivecfgChannelSet[i])->tcpNodelay;
				reactorConnectInfo[i].rsslConnectOptions.connectionInfo.unified.interfaceName = (char*)consumerActivecfgChannelSet[i]->interfaceName.c_str();
				reactorConnectInfo[i].rsslConnectOptions.connectionInfo.unified.unicastServiceName = (char *) "";
				break;
				}
			case RSSL_CONN_TYPE_ENCRYPTED:
				{
				reactorConnectInfo[i].rsslConnectOptions.compressionType = consumerActivecfgChannelSet[i]->compressionType;
				reactorConnectInfo[i].rsslConnectOptions.connectionInfo.unified.address = (char*)static_cast<EncryptedChannelConfig*>(consumerActivecfgChannelSet[i])->hostName.c_str();
				reactorConnectInfo[i].rsslConnectOptions.connectionInfo.unified.serviceName = (char*)static_cast<EncryptedChannelConfig*>(consumerActivecfgChannelSet[i])->serviceName.c_str();
				reactorConnectInfo[i].rsslConnectOptions.tcpOpts.tcp_nodelay = static_cast<EncryptedChannelConfig*>(consumerActivecfgChannelSet[i])->tcpNodelay;
				reactorConnectInfo[i].rsslConnectOptions.objectName = (char*) static_cast<EncryptedChannelConfig*>(consumerActivecfgChannelSet[i])->objectName.c_str();
				reactorConnectInfo[i].rsslConnectOptions.connectionInfo.unified.interfaceName = (char*)consumerActivecfgChannelSet[i]->interfaceName.c_str();
				reactorConnectInfo[i].rsslConnectOptions.connectionInfo.unified.unicastServiceName = (char *) "";
				break;
				}
			case RSSL_CONN_TYPE_HTTP:
				{
				reactorConnectInfo[i].rsslConnectOptions.compressionType = consumerActivecfgChannelSet[i]->compressionType;
				reactorConnectInfo[i].rsslConnectOptions.connectionInfo.unified.address = (char*)static_cast<HttpChannelConfig*>(consumerActivecfgChannelSet[i])->hostName.c_str();
				reactorConnectInfo[i].rsslConnectOptions.connectionInfo.unified.serviceName = (char*)static_cast<HttpChannelConfig*>(consumerActivecfgChannelSet[i])->serviceName.c_str();
				reactorConnectInfo[i].rsslConnectOptions.tcpOpts.tcp_nodelay = static_cast<HttpChannelConfig*>(consumerActivecfgChannelSet[i])->tcpNodelay;
				reactorConnectInfo[i].rsslConnectOptions.objectName = (char*) static_cast<HttpChannelConfig*>(consumerActivecfgChannelSet[i])->objectName.c_str();
				reactorConnectInfo[i].rsslConnectOptions.connectionInfo.unified.interfaceName = (char*)consumerActivecfgChannelSet[i]->interfaceName.c_str();
				reactorConnectInfo[i].rsslConnectOptions.connectionInfo.unified.unicastServiceName = (char *) "";
				strConnectionType = "RSSL_CONN_TYPE_HTTP";
				break;
				}
			case RSSL_CONN_TYPE_RELIABLE_MCAST:
				{
				ReliableMcastChannelConfig *relMcastCfg = static_cast<ReliableMcastChannelConfig*>(consumerActivecfgChannelSet[i]);
				if(consumerActivecfgChannelSet[i]->interfaceName.empty())
					reactorConnectInfo[i].rsslConnectOptions.connectionInfo.segmented.interfaceName = 0;
				else 
					reactorConnectInfo[i].rsslConnectOptions.connectionInfo.segmented.interfaceName = (char*)consumerActivecfgChannelSet[i]->interfaceName.c_str();
				reactorConnectInfo[i].rsslConnectOptions.connectionInfo.segmented.recvAddress = (char*) relMcastCfg->recvAddress.c_str();
				reactorConnectInfo[i].rsslConnectOptions.connectionInfo.segmented.recvServiceName = (char*) relMcastCfg->recvServiceName.c_str();
				reactorConnectInfo[i].rsslConnectOptions.connectionInfo.segmented.unicastServiceName = (char*) relMcastCfg->unicastServiceName.c_str();
				reactorConnectInfo[i].rsslConnectOptions.connectionInfo.segmented.sendAddress = (char*) relMcastCfg->sendAddress.c_str();
				reactorConnectInfo[i].rsslConnectOptions.connectionInfo.segmented.sendServiceName = (char*) relMcastCfg->sendServiceName.c_str();
				reactorConnectInfo[i].rsslConnectOptions.multicastOpts.disconnectOnGaps = relMcastCfg->disconnectOnGap;
				reactorConnectInfo[i].rsslConnectOptions.multicastOpts.hsmInterface = (char *) relMcastCfg->hsmInterface.c_str();
				reactorConnectInfo[i].rsslConnectOptions.multicastOpts.hsmMultAddress = (char *) relMcastCfg->hsmMultAddress.c_str();
				reactorConnectInfo[i].rsslConnectOptions.multicastOpts.hsmPort = (char *) relMcastCfg->hsmPort.c_str();
				reactorConnectInfo[i].rsslConnectOptions.multicastOpts.hsmInterval =  relMcastCfg->hsmInterval;
				reactorConnectInfo[i].rsslConnectOptions.multicastOpts.packetTTL =  relMcastCfg->packetTTL;
				reactorConnectInfo[i].rsslConnectOptions.multicastOpts.tcpControlPort = (char *) relMcastCfg->tcpControlPort.c_str();
				reactorConnectInfo[i].rsslConnectOptions.multicastOpts.ndata =  relMcastCfg->ndata;
				reactorConnectInfo[i].rsslConnectOptions.multicastOpts.nmissing =  relMcastCfg->nmissing;
				reactorConnectInfo[i].rsslConnectOptions.multicastOpts.nrreq =  relMcastCfg->nrreq;
				reactorConnectInfo[i].rsslConnectOptions.multicastOpts.tdata =  relMcastCfg->tdata;
				reactorConnectInfo[i].rsslConnectOptions.multicastOpts.trreq =  relMcastCfg->trreq;
				reactorConnectInfo[i].rsslConnectOptions.multicastOpts.twait =  relMcastCfg->twait;
				reactorConnectInfo[i].rsslConnectOptions.multicastOpts.tpphold =  relMcastCfg->tpphold;
				reactorConnectInfo[i].rsslConnectOptions.multicastOpts.tbchold =  relMcastCfg->tbchold;
				break;
				}
			default :
				break;
			}

			pChannel->setChannelState( Channel::ChannelDownEnum );
			_channelList.addChannel( pChannel );
			supportedConnectionTypeChannelCount++;

			channelNames += pChannel->getName();
			if(i < channelCfgSetLastIndex)
			{
				channelNames.append(", ");
				consumerActivecfgChannelSet[i]->reconnectAttemptLimit = connectOpt.reconnectAttemptLimit;
				consumerActivecfgChannelSet[i]->reconnectMaxDelay = connectOpt.reconnectMaxDelay;
				consumerActivecfgChannelSet[i]->reconnectMinDelay = connectOpt.reconnectMinDelay;
				consumerActivecfgChannelSet[i]->xmlTraceFileName =  consumerActivecfgChannelSet[channelCfgSetLastIndex]->xmlTraceFileName;
				consumerActivecfgChannelSet[i]->xmlTraceToFile = consumerActivecfgChannelSet[channelCfgSetLastIndex]->xmlTraceToFile;
				consumerActivecfgChannelSet[i]->xmlTraceToStdout = consumerActivecfgChannelSet[channelCfgSetLastIndex]->xmlTraceToStdout;
				consumerActivecfgChannelSet[i]->xmlTraceToMultipleFiles = consumerActivecfgChannelSet[channelCfgSetLastIndex]->xmlTraceToMultipleFiles;
				consumerActivecfgChannelSet[i]->xmlTraceWrite = consumerActivecfgChannelSet[channelCfgSetLastIndex]->xmlTraceWrite;
				consumerActivecfgChannelSet[i]->xmlTraceRead = consumerActivecfgChannelSet[channelCfgSetLastIndex]->xmlTraceRead;
				consumerActivecfgChannelSet[i]->xmlTraceMaxFileSize = consumerActivecfgChannelSet[channelCfgSetLastIndex]->xmlTraceMaxFileSize;
				consumerActivecfgChannelSet[i]->msgKeyInUpdates = consumerActivecfgChannelSet[channelCfgSetLastIndex]->msgKeyInUpdates;
			}

			if ( OmmLoggerClient::VerboseEnum >= _ommConsImpl.getActiveConfig().loggerConfig.minLoggerSeverity )
			{
				channelParams.clear();
				channelParametersToString(consumerActivecfgChannelSet[i], channelParams);
				temp.append( CR ).append(i+1).append("] ").append(channelParams);
					if(i == (connectOpt.connectionCount -1))
						_ommConsImpl.getOmmLoggerClient().log( _clientName, OmmLoggerClient::VerboseEnum, temp );
			}
		}
		else
		{
			reactorConnectInfo[i].rsslConnectOptions.userSpecPtr = 0;
			errorStrUnsupportedConnectionType.append( consumerActivecfgChannelSet[i]->connectionType )
			.append(" for ")
			.append(consumerActivecfgChannelSet[i]->name);
			if(i < channelCfgSetLastIndex)
				errorStrUnsupportedConnectionType.append(", ");
		}
	} 

	if(supportedConnectionTypeChannelCount > 0)
	{
		connectOpt.rsslConnectOptions.userSpecPtr = (void*) consumerActivecfgChannelSet[0]->pChannel;

		RsslErrorInfo rsslErrorInfo;
		if ( RSSL_RET_SUCCESS != rsslReactorConnect( _pRsslReactor, &connectOpt, (RsslReactorChannelRole*)(&consumerRole), &rsslErrorInfo ) )
		{

			EmaString temp( "Failed to add RsslChannel(s) to RsslReactor. Channel name(s) " );
			temp.append(channelNames ).append( CR )
				.append( "Consumer Name " ).append( _ommConsImpl.getConsumerName() ).append( CR )
				.append( "RsslReactor " ).append( ptrToStringAsHex( _pRsslReactor ) ).append( CR )
				.append( "RsslChannel " ).append( (UInt64)rsslErrorInfo.rsslError.channel ).append( CR )
				.append( "Error Id " ).append( rsslErrorInfo.rsslError.rsslErrorId ).append( CR )
				.append( "Internal sysError " ).append( rsslErrorInfo.rsslError.sysError ).append( CR )
				.append( "Error Location " ).append( rsslErrorInfo.errorLocation ).append( CR )
				.append( "Error Text " ).append( rsslErrorInfo.rsslError.text );

			if ( OmmLoggerClient::ErrorEnum >= _ommConsImpl.getActiveConfig().loggerConfig.minLoggerSeverity )
				_ommConsImpl.getOmmLoggerClient().log( _clientName, OmmLoggerClient::ErrorEnum, temp.trimWhitespace() );

			for(unsigned int i = 0; i < connectOpt.connectionCount; ++i)
			{
				Channel *pChannel =(Channel *) reactorConnectInfo[i].rsslConnectOptions.userSpecPtr;
				if(pChannel)
					Channel::destroy( pChannel );
			}

			delete [] reactorConnectInfo;
			throwIueException( temp );

			return;
		}

		_ommConsImpl.setState( OmmConsumerImpl::RsslChannelDownEnum );
		

		if ( OmmLoggerClient::VerboseEnum >= _ommConsImpl.getActiveConfig().loggerConfig.minLoggerSeverity )
		{
			EmaString temp( "Successfully created a Reactor and Channel(s)" );
			temp.append( CR )
				.append(" Channel name(s) " ).append( channelNames ).append( CR )
				.append( "Consumer Name " ).append( _ommConsImpl.getConsumerName() );
			_ommConsImpl.getOmmLoggerClient().log( _clientName, OmmLoggerClient::VerboseEnum, temp );
		}	

		if(supportedConnectionTypeChannelCount < connectOpt.connectionCount)
			_ommConsImpl.getOmmLoggerClient().log( _clientName, OmmLoggerClient::WarningEnum, errorStrUnsupportedConnectionType );
	}
	else
	{
		delete [] reactorConnectInfo;
		throwIueException( errorStrUnsupportedConnectionType );
	}
	delete [] reactorConnectInfo;
}