private bool createSession() { if (d_session != null) { d_session.Stop(); } string authOptions = string.Empty; d_sessionOptions = new SessionOptions(); if (d_authOption == "APPLICATION") { // Set Application Authentication Option authOptions = "AuthenticationMode=APPLICATION_ONLY;"; authOptions += "ApplicationAuthenticationType=APPNAME_AND_KEY;"; // ApplicationName is the entry in EMRS. authOptions += "ApplicationName=" + d_name; } else if (d_authOption == "DIRSVC") { // Authenticate user using active directory service property authOptions = "AuthenticationType=DIRECTORY_SERVICE;"; authOptions += "DirSvcPropertyName=" + d_name; } else if (d_authOption == "NONE") { // do nothing } else { // Authenticate user using windows/unix login name authOptions = "AuthenticationType=OS_LOGON"; } System.Console.WriteLine("Authentication Options = " + authOptions); d_sessionOptions.AuthenticationOptions = authOptions; SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_hosts.Count]; int index = 0; System.Console.WriteLine("Connecting to port " + d_port.ToString() + " on host(s):"); foreach (string host in d_hosts) { servers[index] = new SessionOptions.ServerAddress(host, d_port); System.Console.WriteLine(host); } // auto restart on disconnect d_sessionOptions.ServerAddresses = servers; d_sessionOptions.AutoRestartOnDisconnection = true; d_sessionOptions.NumStartAttempts = d_hosts.Count; d_session = new Session(d_sessionOptions, new EventHandler(processEvent)); return(d_session.Start()); }
public void Run(String[] args) { if (!ParseCommandLine(args)) { return; } SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_hosts.Count]; for (int i = 0; i < d_hosts.Count; ++i) { servers[i] = new SessionOptions.ServerAddress(d_hosts[i], d_port); } SessionOptions sessionOptions = new SessionOptions(); sessionOptions.ServerAddresses = servers; sessionOptions.AuthenticationOptions = d_authOptions; sessionOptions.AutoRestartOnDisconnection = true; sessionOptions.NumStartAttempts = d_numRetry; Console.Write("Connecting to"); foreach (SessionOptions.ServerAddress server in sessionOptions.ServerAddresses) { Console.Write(" " + server); } Console.WriteLine(); if (d_role == Role.SERVER || d_role == Role.BOTH) { ProviderSession session = new ProviderSession(sessionOptions, ProcessServerEvent); ServerRun(session); } if (d_role == Role.CLIENT || d_role == Role.BOTH) { Session session = new Session(sessionOptions, ProcessClientEvent); ClientRun(session); } }
private Session CreateSession() { SessionOptions sessionOptions = new SessionOptions(); SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[serverHosts.Count]; for (int i = 0; i < serverHosts.Count; ++i) { servers[i] = new SessionOptions.ServerAddress(serverHosts[i], serverPort); } sessionOptions.ServerAddresses = servers; sessionOptions.AutoRestartOnDisconnection = true; sessionOptions.NumStartAttempts = serverHosts.Count; sessionOptions.AuthenticationOptions = authOptions; System.Console.WriteLine("Connecting to port " + serverPort + " on "); foreach (string host in serverHosts) { System.Console.WriteLine(host + " "); } Session session = new Session(sessionOptions); return(session); }
public void Run(String[] args) //throws Exception { if (!ParseCommandLine(args)) { return; } SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_hosts.Count]; for (int i = 0; i < d_hosts.Count; ++i) { servers[i] = new SessionOptions.ServerAddress(d_hosts[i], d_port); } SessionOptions sessionOptions = new SessionOptions(); sessionOptions.ServerAddresses = servers; sessionOptions.AuthenticationOptions = d_authOptions; sessionOptions.AutoRestartOnDisconnection = true; sessionOptions.NumStartAttempts = servers.Length; Console.Write("Connecting to"); foreach (SessionOptions.ServerAddress server in sessionOptions.ServerAddresses) { Console.Write(" " + server); } Console.WriteLine(); ProviderSession session = new ProviderSession( sessionOptions, ProcessEvent); if (!session.Start()) { Console.WriteLine("Failed to start session"); return; } Identity identity = null; if (d_authOptions != null) { bool isAuthorized = false; identity = session.CreateIdentity(); if (session.OpenService("//blp/apiauth")) { Service authService = session.GetService("//blp/apiauth"); if (Authorize(authService, identity, session, new CorrelationID())) { isAuthorized = true; } } if (!isAuthorized) { System.Console.Error.WriteLine("No authorization"); return; } } TopicList topicList = new TopicList(); topicList.Add( d_service + "/1245/4/5", new CorrelationID(new MyStream("1245/4/5"))); topicList.Add( d_service + "/330/1/1", new CorrelationID(new MyStream("330/1/1"))); session.CreateTopics( topicList, ResolveMode.AUTO_REGISTER_SERVICES, identity); // createTopics() is synchronous, topicList will be updated // with the results of topic creation (resolution will happen // under the covers) Publish(topicList, session); }
private bool parseCommandLine(string[] args) { for (int i = 0; i < args.Length; ++i) { if (string.Compare(args[i], "-t", true) == 0 && i + 1 < args.Length) { d_topics.Add(args[++i]); } else if (string.Compare(args[i], "-f", true) == 0 && i + 1 < args.Length) { d_fields.Add(args[++i]); } else if (string.Compare(args[i], "-o", true) == 0 && i + 1 < args.Length) { d_options.Add(args[++i]); } else if (string.Compare(args[i], "-s", true) == 0 && i + 1 < args.Length) { d_sessionOptions.DefaultSubscriptionService = args[++i]; } else if (string.Compare(args[i], "-ip", true) == 0 && i + 1 < args.Length) { d_hosts.Add(args[++i]); } else if (string.Compare(args[i], "-p", true) == 0 && i + 1 < args.Length) { d_port = int.Parse(args[++i]); } else if (string.Compare(args[i], "-qsize", true) == 0 && i + 1 < args.Length) { d_sessionOptions.MaxEventQueueSize = int.Parse(args[++i]); } else { printUsage(); return(false); } } if (d_hosts.Count == 0) { d_hosts.Add("localhost"); } if (d_fields.Count == 0) { d_fields.Add("LAST_PRICE"); } if (d_topics.Count == 0) { d_topics.Add("IBM US Equity"); } SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_hosts.Count]; for (int i = 0; i < d_hosts.Count; ++i) { servers[i] = new SessionOptions.ServerAddress(d_hosts[i], d_port); } d_sessionOptions.ServerAddresses = servers; d_sessionOptions.AutoRestartOnDisconnection = true; d_sessionOptions.NumStartAttempts = (d_hosts.Count > 1) ? 1 : 1000; // If only one host is provided, make many attempts to connect. // When multiple hosts are provided, it's expected that at // least one will be up and reachable at any given time, so // only try to connect to each server once. foreach (string topic in d_topics) { d_subscriptions.Add(new Subscription( topic, d_fields, d_options, new CorrelationID(topic))); } return(true); }
public void Run(String[] args) { if (!ParseCommandLine(args)) { return; } SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_serverHosts.Count]; for (int i = 0; i < d_serverHosts.Count; ++i) { servers[i] = new SessionOptions.ServerAddress(d_serverHosts[i], d_serverPort); } SessionOptions sessionOptions = new SessionOptions(); sessionOptions.ServerAddresses = servers; sessionOptions.AuthenticationOptions = d_authOptions; sessionOptions.AutoRestartOnDisconnection = true; sessionOptions.NumStartAttempts = d_serverHosts.Count; System.Console.Write("Connecting to"); foreach (SessionOptions.ServerAddress server in sessionOptions.ServerAddresses) { System.Console.Write(" " + server); } System.Console.WriteLine(); ProviderSession session = new ProviderSession(sessionOptions, ProcessEvent); if (!session.Start()) { Console.Error.WriteLine("Failed to start session"); return; } Identity identity = null; if (d_authOptions != null) { bool isAuthorized = false; identity = session.CreateIdentity(); if (session.OpenService("//blp/apiauth")) { Service authService = session.GetService("//blp/apiauth"); if (Authorize(authService, identity, session, new CorrelationID())) { isAuthorized = true; } } if (!isAuthorized) { System.Console.Error.WriteLine("No authorization"); return; } } TopicList topicList = new TopicList(); topicList.Add( d_serviceName + "/" + d_topic, new CorrelationID(new MyStream(d_topic))); session.CreateTopics( topicList, ResolveMode.AUTO_REGISTER_SERVICES, identity); List <MyStream> myStreams = new List <MyStream>(); for (int i = 0; i < topicList.Size; ++i) { if (topicList.StatusAt(i) == TopicList.TopicStatus.CREATED) { Topic topic = session.GetTopic(topicList.MessageAt(i)); MyStream stream = (MyStream)topicList.CorrelationIdAt(i).Object; stream.SetTopic(topic); myStreams.Add(stream); } } PublishEvents(session, myStreams); session.Stop(); }
public void Run(String[] args) { if (!ParseCommandLine(args)) { return; } SessionOptions sessionOptions = new SessionOptions(); SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_hosts.Count]; for (int i = 0; i < d_hosts.Count; ++i) { servers[i] = new SessionOptions.ServerAddress(d_hosts[i].host(), d_hosts[i].port()); } sessionOptions.ServerAddresses = servers; sessionOptions.AutoRestartOnDisconnection = true; sessionOptions.NumStartAttempts = d_hosts.Count; sessionOptions.AuthenticationOptions = d_authOptions; if (d_clientCredentials != null && d_trustMaterial != null) { using (System.Security.SecureString password = new System.Security.SecureString()) { foreach (var c in d_clientCredentialsPassword) { password.AppendChar(c); } TlsOptions tlsOptions = TlsOptions.CreateFromFiles(d_clientCredentials, password, d_trustMaterial); sessionOptions.TlsOptions = tlsOptions; } } System.Console.WriteLine("Connecting to: "); foreach (HostAndPort host in d_hosts) { System.Console.WriteLine(host.host() + ":" + host.port() + " "); } Session session = new Session(sessionOptions); if (!session.Start()) { System.Console.Error.WriteLine("Failed to start session."); return; } Identity identity = null; if (d_authOptions != null) { bool isAuthorized = false; identity = session.CreateIdentity(); if (session.OpenService("//blp/apiauth")) { Service authService = session.GetService("//blp/apiauth"); if (Authorize(authService, identity, session, new CorrelationID())) { isAuthorized = true; } } if (!isAuthorized) { System.Console.Error.WriteLine("No authorization"); } } }
public void Run(String[] args) { if (!ParseCommandLine(args)) { return; } SessionOptions sessionOptions = new SessionOptions(); SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_hosts.Count]; for (int i = 0; i < d_hosts.Count; ++i) { servers[i] = new SessionOptions.ServerAddress(d_hosts[i], d_port); } sessionOptions.ServerAddresses = servers; sessionOptions.AutoRestartOnDisconnection = true; sessionOptions.NumStartAttempts = d_hosts.Count; sessionOptions.DefaultSubscriptionService = d_service; sessionOptions.DefaultTopicPrefix = ""; // normally defaults to "ticker" sessionOptions.AuthenticationOptions = d_authOptions; System.Console.WriteLine("Connecting to port " + d_port + " on "); foreach (string host in d_hosts) { System.Console.WriteLine(host + " "); } Session session = new Session(sessionOptions); if (!session.Start()) { System.Console.Error.WriteLine("Failed to start session."); return; } Identity identity = null; if (d_authOptions.Length != 0) { EventQueue tokenEventQueue = new EventQueue(); session.GenerateToken(new CorrelationID(tokenEventQueue), tokenEventQueue); String token = null; const int timeoutMilliSeonds = 10000; Event eventObj = tokenEventQueue.NextEvent(timeoutMilliSeonds); if (eventObj.Type == Event.EventType.TOKEN_STATUS) { foreach (Message msg in eventObj) { System.Console.WriteLine(msg.ToString()); if (msg.MessageType == TOKEN_SUCCESS) { token = msg.GetElementAsString("token"); } } } if (token == null) { System.Console.WriteLine("Failed to get token"); System.Environment.Exit(1); } if (session.OpenService("//blp/apiauth")) { Service authService = session.GetService("//blp/apiauth"); Request authRequest = authService.CreateAuthorizationRequest(); authRequest.Set("token", token); EventQueue authEventQueue = new EventQueue(); identity = session.CreateIdentity(); session.SendAuthorizationRequest(authRequest, identity, authEventQueue, new CorrelationID(identity)); bool isAuthorized = false; while (!isAuthorized) { eventObj = authEventQueue.NextEvent(); if (eventObj.Type == Event.EventType.RESPONSE || eventObj.Type == Event.EventType.PARTIAL_RESPONSE || eventObj.Type == Event.EventType.REQUEST_STATUS) { foreach (Message msg in eventObj) { System.Console.WriteLine(msg.ToString()); if (msg.MessageType == AUTHORIZATION_SUCCESS) { isAuthorized = true; break; } else { System.Console.Error.WriteLine("Not authorized: " + msg); System.Environment.Exit(1); } } } } } } List <Subscription> subscriptions = new List <Subscription>(); // Short topic string; will get qualified by subscribe() using session // options: 'DefaultSubscriptionService' and 'DefaultTopicPrefix' // configured above String topic1 = "IBM Equity"; // Fully qualified topic String topic2 = d_service + "/RHAT Equity"; // Add a topic on unknown service to demonstrate event sequence String topic3 = d_service + "-unknown/RHAT Equity"; subscriptions.Add(new Subscription(topic1, new CorrelationID(topic1))); subscriptions.Add(new Subscription(topic2, new CorrelationID(topic2))); subscriptions.Add(new Subscription(topic3, new CorrelationID(topic3))); session.Subscribe(subscriptions, identity); ProcessSubscriptionResponse(session); }
public void Run(string[] args) //throws Exception { if (!ParseCommandLine(args)) { return; } SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_hosts.Count]; for (int i = 0; i < d_hosts.Count; ++i) { servers[i] = new SessionOptions.ServerAddress(d_hosts[i], d_port); } SessionOptions sessionOptions = new SessionOptions(); sessionOptions.ServerAddresses = servers; sessionOptions.AuthenticationOptions = d_authOptions; sessionOptions.AutoRestartOnDisconnection = true; sessionOptions.NumStartAttempts = servers.Length; Console.Write("Connecting to"); foreach (SessionOptions.ServerAddress server in sessionOptions.ServerAddresses) { Console.Write(" " + server); } Console.WriteLine(); ProviderSession session = new ProviderSession( sessionOptions, processEvent); if (!session.Start()) { Console.Error.WriteLine("Failed to start session"); return; } Identity identity = null; if (d_authOptions != null) { bool isAuthorized = false; identity = session.CreateIdentity(); if (session.OpenService("//blp/apiauth")) { Service authService = session.GetService("//blp/apiauth"); if (Authorize(authService, identity, session, new CorrelationID())) { isAuthorized = true; } } if (!isAuthorized) { System.Console.Error.WriteLine("No authorization"); return; } } ServiceRegistrationOptions serviceRegistrationOptions = new ServiceRegistrationOptions(); serviceRegistrationOptions.GroupId = d_groupId; serviceRegistrationOptions.ServicePriority = d_priority; if (!session.RegisterService(d_service, identity, serviceRegistrationOptions)) { Console.WriteLine("Failed to register " + d_service); return; } Console.WriteLine("Service registered " + d_service); //Publishing events for the active topics of the designated service. PublishEvents(session); session.Stop(); }
public void Run(String[] args) { if (!ParseCommandLine(args)) { return; } SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_serverHosts.Count]; for (int i = 0; i < d_serverHosts.Count; ++i) { servers[i] = new SessionOptions.ServerAddress(d_serverHosts[i], d_serverPort); } SessionOptions sessionOptions = new SessionOptions(); sessionOptions.ServerAddresses = servers; sessionOptions.AuthenticationOptions = d_authOptions; sessionOptions.AutoRestartOnDisconnection = true; sessionOptions.NumStartAttempts = d_serverHosts.Count; System.Console.Write("Connecting to"); foreach (SessionOptions.ServerAddress server in sessionOptions.ServerAddresses) { System.Console.Write(" " + server); } System.Console.WriteLine(); ProviderSession session = new ProviderSession(sessionOptions, ProcessEvent); if (!session.Start()) { Console.Error.WriteLine("Failed to start session"); return; } Identity identity = null; if (d_authOptions != null) { bool isAuthorized = false; identity = session.CreateIdentity(); if (session.OpenService("//blp/apiauth")) { Service authService = session.GetService("//blp/apiauth"); if (Authorize(authService, identity, session, new CorrelationID())) { isAuthorized = true; } } if (!isAuthorized) { System.Console.Error.WriteLine("No authorization"); return; } } TopicList topicList = new TopicList(); topicList.Add( d_serviceName + "/ticker/929903DF6 Corp", new CorrelationID(new MyStream("AUDEUR Curncy"))); topicList.Add( d_serviceName + "/ticker/EC070336 Corp", new CorrelationID(new MyStream("EC070336 Corp"))); topicList.Add( d_serviceName + "/ticker/6832348A9 Corp", new CorrelationID(new MyStream("6832348A9 Corp"))); session.CreateTopics( topicList, ResolveMode.AUTO_REGISTER_SERVICES, identity); Service service = session.GetService(d_serviceName); if (service == null) { System.Console.Error.WriteLine("Open service failed: " + d_serviceName); return; } List <MyStream> myStreams = new List <MyStream>(); for (int i = 0; i < topicList.Size; ++i) { if (topicList.StatusAt(i) == TopicList.TopicStatus.CREATED) { Topic topic = session.GetTopic(topicList.MessageAt(i)); MyStream stream = (MyStream)topicList.CorrelationIdAt(i).Object; stream.SetTopic(topic); myStreams.Add(stream); } } int iteration = 0; while (iteration++ < d_maxEvents) { if (!d_running) { break; } Event eventObj = service.CreatePublishEvent(); EventFormatter eventFormatter = new EventFormatter(eventObj); foreach (MyStream stream in myStreams) { eventFormatter.AppendMessage("MarketData", stream.GetTopic()); eventFormatter.SetElement(BID, stream.GetBid()); eventFormatter.SetElement(ASK, stream.GetAsk()); eventFormatter.SetElement(BID_SIZE, 1200); eventFormatter.SetElement(ASK_SIZE, 1400); } System.Console.WriteLine(System.DateTime.Now.ToString() + " -"); foreach (Message msg in eventObj) { System.Console.WriteLine(msg); } session.Publish(eventObj); Thread.Sleep(10 * 1000); } session.Stop(); }
public void Run(String[] args) { if (!ParseCommandLine(args)) { return; } SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_hosts.Count]; for (int i = 0; i < d_hosts.Count; ++i) { servers[i] = new SessionOptions.ServerAddress(d_hosts[i], d_port); } SessionOptions sessionOptions = new SessionOptions(); sessionOptions.ServerAddresses = servers; sessionOptions.AuthenticationOptions = d_authOptions; sessionOptions.AutoRestartOnDisconnection = true; sessionOptions.NumStartAttempts = servers.Length; System.Console.Write("Connecting to"); foreach (SessionOptions.ServerAddress server in sessionOptions.ServerAddresses) { System.Console.Write(" " + server); } System.Console.WriteLine(); ProviderSession session = new ProviderSession(sessionOptions, ProcessEvent); if (!session.Start()) { System.Console.Error.WriteLine("Failed to start session"); return; } Identity identity = null; if (d_authOptions != null) { if (!Authorize(out identity, session)) { return; } } if (d_groupId != null) { // NOTE: will perform explicit service registration here, instead of letting // createTopics do it, as the latter approach doesn't allow for custom // ServiceRegistrationOptions ServiceRegistrationOptions serviceRegistrationOptions = new ServiceRegistrationOptions(); serviceRegistrationOptions.GroupId = d_groupId; serviceRegistrationOptions.ServicePriority = d_priority; if (!session.RegisterService(d_service, identity, serviceRegistrationOptions)) { System.Console.Write("Failed to register " + d_service); return; } } TopicList topicList = new TopicList(); for (int i = 0; i < d_topics.Count; i++) { topicList.Add( d_service + "/" + d_topics[i], new CorrelationID(new MyStream(d_topics[i]))); } session.CreateTopics( topicList, ResolveMode.AUTO_REGISTER_SERVICES, identity); // createTopics() is synchronous, topicList will be updated // with the results of topic creation (resolution will happen // under the covers) List <MyStream> myStreams = new List <MyStream>(); for (int i = 0; i < topicList.Size; ++i) { MyStream stream = (MyStream)topicList.CorrelationIdAt(i).Object; if (topicList.StatusAt(i) == TopicList.TopicStatus.CREATED) { Message msg = topicList.MessageAt(i); stream.setTopic(session.GetTopic(msg)); myStreams.Add(stream); System.Console.WriteLine("Topic created: " + topicList.TopicStringAt(i)); } else { System.Console.WriteLine("Stream '" + stream.getId() + "': topic not resolved, status = " + topicList.StatusAt(i)); } } Service service = session.GetService(d_service); // Now we will start publishing Name eventName = Name.GetName("MarketDataEvents"); Name high = Name.GetName("HIGH"); Name low = Name.GetName("LOW"); long tickCount = 1; for (int eventCount = 0; eventCount < d_maxEvents; ++eventCount) { Event eventObj = service.CreatePublishEvent(); EventFormatter eventFormatter = new EventFormatter(eventObj); for (int index = 0; index < myStreams.Count; index++) { Topic topic = myStreams[index].getTopic(); if (!topic.IsActive()) { continue; } eventFormatter.AppendMessage(eventName, topic); if (1 == tickCount) { eventFormatter.SetElement("OPEN", 1.0); } else if (2 == tickCount) { eventFormatter.SetElement("BEST_BID", 3.0); } eventFormatter.SetElement(high, tickCount * 1.0); eventFormatter.SetElement(low, tickCount * 0.5); ++tickCount; } foreach (Message msg in eventObj) { System.Console.WriteLine(msg); } session.Publish(eventObj); Thread.Sleep(2 * 1000); } session.Stop(); }
public void Run(string[] args) //throws Exception { if (!parseCommandLine(args)) { return; } SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_hosts.Count]; for (int i = 0; i < d_hosts.Count; ++i) { servers[i] = new SessionOptions.ServerAddress(d_hosts[i], d_port); } SessionOptions sessionOptions = new SessionOptions(); sessionOptions.ServerAddresses = servers; sessionOptions.AuthenticationOptions = d_authOptions; sessionOptions.AutoRestartOnDisconnection = true; sessionOptions.NumStartAttempts = servers.Length; Console.Write("Connecting to"); foreach (SessionOptions.ServerAddress server in sessionOptions.ServerAddresses) { Console.Write(" " + server); } Console.WriteLine(); ProviderSession session = new ProviderSession( sessionOptions, processEvent); if (!session.Start()) { Console.Error.WriteLine("Failed to start session"); return; } Identity identity = null; if (d_authOptions.Length != 0) { Object tokenResponseMonitor = new Object(); lock (tokenResponseMonitor) { session.GenerateToken(new CorrelationID(tokenResponseMonitor)); long waitTime = 10 * 1000; long tokenResponseTimeout = System.DateTime.Now.Ticks / 10000 + waitTime; while (d_tokenGenerationResponse == null && waitTime > 0) { Monitor.Wait(tokenResponseMonitor, (int)waitTime); waitTime = tokenResponseTimeout - System.DateTime.Now.Ticks / 10000; } if (d_tokenGenerationResponse == null) { System.Console.Error.WriteLine("Timeout waiting for token"); System.Environment.Exit(1); } else if (d_tokenGenerationResponse == false || d_token == null) { System.Console.Error.WriteLine("Token generation failed"); System.Environment.Exit(1); } } Object authorizationResponseMonitor = new Object(); if (session.OpenService("//blp/apiauth")) { Service authService = session.GetService("//blp/apiauth"); Request authRequest = authService.CreateAuthorizationRequest(); authRequest.Set("token", d_token); identity = session.CreateIdentity(); d_authorizationResponseCorrelationId = new CorrelationID(authorizationResponseMonitor); lock (authorizationResponseMonitor) { session.SendAuthorizationRequest( authRequest, identity, d_authorizationResponseCorrelationId); long waitTime = 60 * 1000; long authorizationResponseTimeout = System.DateTime.Now.Ticks / 10000 + waitTime; while (d_authorizationResponse == null && waitTime > 0) { Monitor.Wait(authorizationResponseMonitor, 1000); waitTime = authorizationResponseTimeout - System.DateTime.Now.Ticks / 10000; } if (d_authorizationResponse == null) { System.Console.Error.WriteLine("Timeout waiting for authorization"); System.Environment.Exit(1); } else if (d_authorizationResponse == false) { System.Console.Error.WriteLine("Authorization failed"); System.Environment.Exit(1); } } } } //Registering for subscription start and stop messages. if (!session.RegisterService(d_service, d_identity)) { Console.WriteLine("Failed to register " + d_service); return; } Console.WriteLine("Service registered " + d_service); //Publishing events for the active topics of the designated service. PublishEvents(session); session.Stop(); }
public void Run(String[] args) { if (!ParseCommandLine(args)) { return; } SessionOptions sessionOptions = new SessionOptions(); SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_hosts.Count]; for (int i = 0; i < d_hosts.Count; ++i) { servers[i] = new SessionOptions.ServerAddress(d_hosts[i], d_port); } sessionOptions.ServerAddresses = servers; sessionOptions.AutoRestartOnDisconnection = true; sessionOptions.NumStartAttempts = d_hosts.Count; sessionOptions.DefaultSubscriptionService = d_service; sessionOptions.AuthenticationOptions = d_authOptions; if (d_clientCredentials != null && d_trustMaterial != null) { using (System.Security.SecureString password = new System.Security.SecureString()) { foreach (var c in d_clientCredentialsPassword) { password.AppendChar(c); } TlsOptions tlsOptions = TlsOptions.CreateFromFiles(d_clientCredentials, password, d_trustMaterial); sessionOptions.TlsOptions = tlsOptions; } } System.Console.WriteLine("Connecting to port " + d_port + " on "); foreach (string host in d_hosts) { System.Console.WriteLine(host + " "); } Session session = new Session(sessionOptions); if (!session.Start()) { System.Console.Error.WriteLine("Failed to start session."); return; } Identity identity = null; if (d_authOptions != null) { bool isAuthorized = false; identity = session.CreateIdentity(); if (session.OpenService("//blp/apiauth")) { Service authService = session.GetService("//blp/apiauth"); if (Authorize(authService, identity, session, new CorrelationID())) { isAuthorized = true; } } if (!isAuthorized) { System.Console.Error.WriteLine("No authorization"); return; } } List <Subscription> subscriptions = new List <Subscription>(); foreach (String topic in d_topics) { subscriptions.Add(new Subscription( d_service + topic, d_fields, d_options, new CorrelationID(topic))); } session.Subscribe(subscriptions, identity); ProcessSubscriptionResponse(session); }
public void Run(String[] args) { if (!ParseCommandLine(args)) { return; } SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_hosts.Count]; for (int i = 0; i < d_hosts.Count; ++i) { servers[i] = new SessionOptions.ServerAddress(d_hosts[i], d_port); } SessionOptions sessionOptions = new SessionOptions(); sessionOptions.ServerAddresses = servers; sessionOptions.AuthenticationOptions = d_authOptions; sessionOptions.AutoRestartOnDisconnection = true; sessionOptions.NumStartAttempts = servers.Length; Console.Write("Connecting to"); foreach (SessionOptions.ServerAddress server in sessionOptions.ServerAddresses) { Console.Write(" " + server); } Console.WriteLine(); ProviderSession session = new ProviderSession(sessionOptions, ProcessEvent); if (!session.Start()) { Console.Error.WriteLine("Failed to start session"); return; } Identity identity = null; if (d_authOptions != null) { bool isAuthorized = false; identity = session.CreateIdentity(); if (session.OpenService("//blp/apiauth")) { Service authService = session.GetService("//blp/apiauth"); if (Authorize(authService, identity, session, new CorrelationID())) { isAuthorized = true; } } if (!isAuthorized) { System.Console.Error.WriteLine("No authorization"); return; } } ServiceRegistrationOptions serviceRegistrationOptions = new ServiceRegistrationOptions(); serviceRegistrationOptions.GroupId = d_groupId; serviceRegistrationOptions.ServicePriority = d_priority; if (d_useSsc) { Console.WriteLine( String.Format( "Activating sub service code range [{0}, {1}] " + "@ priority: {2}", d_sscBegin, d_sscEnd, d_sscPriority)); try { serviceRegistrationOptions.AddActiveSubServiceCodeRange( d_sscBegin, d_sscEnd, d_sscPriority); } catch (Exception e) { Console.WriteLine( "FAILED to add active sub service codes. Exception " + e); } } bool wantAsyncRegisterService = true; if (wantAsyncRegisterService) { Object registerServiceResponseMonitor = new Object(); CorrelationID registerCID = new CorrelationID(registerServiceResponseMonitor); lock (registerServiceResponseMonitor) { if (d_verbose > 0) { Console.WriteLine("start registerServiceAsync, cid = " + registerCID); } session.RegisterServiceAsync( d_service, identity, registerCID, serviceRegistrationOptions); for (int i = 0; d_registerServiceResponse == null && i < 10; ++i) { Monitor.Wait(registerServiceResponseMonitor, 1000); } } } else { bool result = session.RegisterService( d_service, identity, serviceRegistrationOptions); d_registerServiceResponse = result; } Service service = session.GetService(d_service); if (service != null && d_registerServiceResponse == true) { Console.WriteLine("Service registered: " + d_service); } else { Console.Error.WriteLine("Service registration failed: " + d_service); return; } // Dump schema for the service if (d_verbose > 1) { Console.WriteLine("Schema for service:" + d_service); for (int i = 0; i < service.NumEventDefinitions; ++i) { SchemaElementDefinition eventDefinition = service.GetEventDefinition(i); Console.WriteLine(eventDefinition); } } // Now we will start publishing int eventCount = 0; long tickCount = 1; while (d_running) { Event eventObj; lock (d_topicSet) { if (d_topicSet.Count == 0) { Monitor.Wait(d_topicSet, 100); } if (d_topicSet.Count == 0) { continue; } eventObj = service.CreatePublishEvent(); EventFormatter eventFormatter = new EventFormatter(eventObj); bool publishNull = false; if (d_clearInterval > 0 && eventCount == d_clearInterval) { eventCount = 0; publishNull = true; } foreach (Topic topic in d_topicSet.Keys) { if (!topic.IsActive()) { System.Console.WriteLine("[WARNING] Publishing on an inactive topic."); } eventFormatter.AppendMessage("MarketDataEvents", topic); if (publishNull) { eventFormatter.SetElementNull("HIGH"); eventFormatter.SetElementNull("LOW"); } else { ++eventCount; if (1 == tickCount) { eventFormatter.SetElement("BEST_ASK", 100.0); } else if (2 == tickCount) { eventFormatter.SetElement("BEST_BID", 99.0); } eventFormatter.SetElement("HIGH", 100 + tickCount * 0.01); eventFormatter.SetElement("LOW", 100 - tickCount * 0.005); ++tickCount; } } } foreach (Message msg in eventObj) { Console.WriteLine(msg); } session.Publish(eventObj); Thread.Sleep(10 * 1000); if (tickCount % 3 == 0) { Deactivate(session); Thread.Sleep(10 * 1000); Activate(session); } } session.Stop(); }
public void Run(String[] args) { if (!ParseCommandLine(args)) { return; } SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_hosts.Count]; for (int i = 0; i < d_hosts.Count; ++i) { servers[i] = new SessionOptions.ServerAddress(d_hosts[i], d_port); } SessionOptions sessionOptions = new SessionOptions(); sessionOptions.ServerAddresses = servers; sessionOptions.AuthenticationOptions = d_authOptions; sessionOptions.AutoRestartOnDisconnection = true; sessionOptions.NumStartAttempts = servers.Length; System.Console.Write("Connecting to"); foreach (SessionOptions.ServerAddress server in sessionOptions.ServerAddresses) { System.Console.Write(" " + server); } System.Console.WriteLine(); ProviderSession session = new ProviderSession(sessionOptions, ProcessEvent); if (!session.Start()) { System.Console.Error.WriteLine("Failed to start session"); return; } Identity identity = null; if (d_authOptions.Length != 0) { Object tokenResponseMonitor = new Object(); lock (tokenResponseMonitor) { session.GenerateToken(new CorrelationID(tokenResponseMonitor)); long waitTime = 10 * 1000; long tokenResponseTimeout = System.DateTime.Now.Ticks / 10000 + waitTime; while (d_tokenGenerationResponse == null && waitTime > 0) { Monitor.Wait(tokenResponseMonitor, (int)waitTime); waitTime = tokenResponseTimeout - System.DateTime.Now.Ticks / 10000; } if (d_tokenGenerationResponse == null) { System.Console.Error.WriteLine("Timeout waiting for token"); System.Environment.Exit(1); } else if (d_tokenGenerationResponse == false || d_token == null) { System.Console.Error.WriteLine("Token generation failed"); System.Environment.Exit(1); } } Object authorizationResponseMonitor = new Object(); if (session.OpenService("//blp/apiauth")) { Service authService = session.GetService("//blp/apiauth"); Request authRequest = authService.CreateAuthorizationRequest(); authRequest.Set("token", d_token); identity = session.CreateIdentity(); d_authorizationResponseCorrelationId = new CorrelationID(authorizationResponseMonitor); lock (authorizationResponseMonitor) { session.SendAuthorizationRequest( authRequest, identity, d_authorizationResponseCorrelationId); long waitTime = 60 * 1000; long authorizationResponseTimeout = System.DateTime.Now.Ticks / 10000 + waitTime; while (d_authorizationResponse == null && waitTime > 0) { Monitor.Wait(authorizationResponseMonitor, 1000); waitTime = authorizationResponseTimeout - System.DateTime.Now.Ticks / 10000; } if (d_authorizationResponse == null) { System.Console.Error.WriteLine("Timeout waiting for authorization"); System.Environment.Exit(1); } else if (d_authorizationResponse == false) { System.Console.Error.WriteLine("Authorization failed"); System.Environment.Exit(1); } } } } ServiceRegistrationOptions serviceRegistrationOptions = new ServiceRegistrationOptions(); serviceRegistrationOptions.GroupId = d_groupId; serviceRegistrationOptions.ServicePriority = d_priority; bool wantAsyncRegisterService = true; if (wantAsyncRegisterService) { Object registerServiceResponseMonitor = new Object(); CorrelationID registerCID = new CorrelationID(registerServiceResponseMonitor); lock (registerServiceResponseMonitor) { if (d_verbose > 0) { System.Console.WriteLine("start registerServiceAsync, cid = " + registerCID); } session.RegisterServiceAsync(d_service, identity, registerCID, serviceRegistrationOptions); for (int i = 0; d_registerServiceResponse == null && i < 10; ++i) { Monitor.Wait(registerServiceResponseMonitor, 1000); } } } else { bool result = session.RegisterService(d_service, identity, serviceRegistrationOptions); d_registerServiceResponse = result; } Service service = session.GetService(d_service); if (service != null && d_registerServiceResponse == true) { System.Console.WriteLine("Service registered: " + d_service); } else { System.Console.Error.WriteLine("Service registration failed: " + d_service); System.Environment.Exit(1); } // Dump schema for the service if (d_verbose > 1) { System.Console.WriteLine("Schema for service:" + d_service); for (int i = 0; i < service.NumEventDefinitions; ++i) { SchemaElementDefinition eventDefinition = service.GetEventDefinition(i); System.Console.WriteLine(eventDefinition); } } // Now we will start publishing long tickCount = 1; while (g_running) { Event eventObj; lock (d_topicSet) { if (d_topicSet.Count == 0) { Monitor.Wait(d_topicSet, 100); } if (d_topicSet.Count == 0) { continue; } eventObj = service.CreatePublishEvent(); EventFormatter eventFormatter = new EventFormatter(eventObj); foreach (Topic topic in d_topicSet.Keys) { if (!topic.IsActive()) { continue; } eventFormatter.AppendMessage("MarketDataEvents", topic); if (1 == tickCount) { eventFormatter.SetElement("BEST_ASK", 100.0); } else if (2 == tickCount) { eventFormatter.SetElement("BEST_BID", 99.0); } eventFormatter.SetElement("HIGH", 100 + tickCount * 0.01); eventFormatter.SetElement("LOW", 100 - tickCount * 0.005); ++tickCount; } } foreach (Message msg in eventObj) { System.Console.WriteLine(msg); } session.Publish(eventObj); Thread.Sleep(10 * 1000); } session.Stop(); }