static async Task Main() { var subscriptionName = "Samples.ASB.NativeIntegration.NativeSubscriberA"; Console.Title = subscriptionName; #region EventOneSubscription await TopologyManager.CreateSubscription( ConnectionString, subscriptionName, ruleName : "event-one", sqlFilter : new SqlFilter($"[NServiceBus.EnclosedMessageTypes] LIKE '%{typeof(EventOne).FullName}%'") ); #endregion var subscription = new SubscriptionClient(ConnectionString, "bundle-1", subscriptionName); subscription.RegisterMessageHandler((m, _) => { var messageType = (string)m.UserProperties[EnclosedMessageTypesHeader]; var bodyJson = Encoding.UTF8.GetString(m.Body); Console.WriteLine($"Received: {messageType}"); Console.WriteLine(bodyJson); return(Task.CompletedTask); }, e => Task.CompletedTask); Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
public async System.Threading.Tasks.Task TestParallelAsync() { var breaker = _cluster.GrainFactory.GetGrain <ITestHelper>(this.GetType().Namespace); StaticTestHelper.Reset(); StaticTestHelper.TempFailTest("Initial fail of the test"); var conf = new TopologyConfiguration(); conf.TimeCharacteristic = CoreOSP.TimePolicy.None; var mgr = new TopologyManager(conf); var ds = mgr.AddSource(typeof(TestSource), 1); var wds = ds.WindowAggregate(typeof(TestEventBasedAggregationM)); var terminationds = mgr.AddSource(typeof(TestSource1), 1); wds.AddInput(terminationds); var sink = wds.Sink(typeof(TestSink), 1); JobManager jmgr = new JobManager(); await jmgr.StartJob(mgr, _cluster.Client); Thread.Sleep(10000); var result = StaticTestHelper.GetStatus(); Assert.False(result.Item1, result.Item2); }
/// <summary> /// Only used when adding source operator, because it cannot be paralelized. /// </summary> /// <param name="t"></param> /// <param name="mgr">Topology manager reference for saving new operators</param> internal OperatorNode(TopologyManager mgr, Type t, int outputStreamCount, PartitionPolicy partitionPolicy) { OperatorGUIDs.Add(Guid.NewGuid()); OperatorType = t; StreamGUID = Guid.NewGuid(); SetPartitioner(partitionPolicy); OutputStreamCount = outputStreamCount; _mgr = mgr; mgr.Operators.Add(this); }
public async Task StartJob(TopologyManager mgr) { tpm = mgr; foreach (var s in mgr.Operators) { var curr = s; foreach (var guid in curr.OperatorGUIDs) { await GrainFactory.GetGrain <IOperator>(guid, curr.OperatorType.FullName).Init(this.GetPrimaryKey(), GetType(), s.Partitioner); } } }
internal OperatorNode(TopologyManager mgr, OperatorNode previous, Type t, int parallelism, int outputStreamCount, PartitionPolicy partitionPolicy) { for (int i = 0; i < parallelism; i++) { OperatorGUIDs.Add(Guid.NewGuid()); } Prev.Add(previous); OperatorType = t; StreamGUID = Guid.NewGuid(); Parallelism = parallelism; SetPartitioner(partitionPolicy); OutputStreamCount = outputStreamCount; _mgr = mgr; mgr.Operators.Add(this); }
public async System.Threading.Tasks.Task TestWatermark() { StaticTestHelper.Reset(); StaticTestHelper.TempFailTest("Init test fail"); var conf = new TopologyConfiguration(); var mgr = new TopologyManager(conf); var ds = mgr.AddSource(typeof(TestSource), 1); var sink = ds.Sink(typeof(TestSink), 1); JobManager jmgr = new JobManager(); await jmgr.StartJob(mgr, _cluster.Client); Thread.Sleep(7000); var result = StaticTestHelper.GetStatus(); Assert.False(result.Item1, result.Item2); }
public async System.Threading.Tasks.Task TestParallelFail2Async() { var breaker = _cluster.GrainFactory.GetGrain <ITestHelper>(this.GetType().Namespace); StaticTestHelper.Reset(); var conf = new TopologyConfiguration(); var mgr = new TopologyManager(conf); var ds = mgr.AddSource(typeof(TestSource2), 2); ds.Sink(typeof(TestSink1), 2); JobManager jmgr = new JobManager(); await jmgr.StartJob(mgr, _cluster.Client); Thread.Sleep(1000); var result = StaticTestHelper.GetStatus(); Assert.True(result.Item1, result.Item2); }
public async System.Threading.Tasks.Task TestSourceFilterSinkRunAsync() { StaticTestHelper.Reset(); StaticTestHelper.TempFailTest("Initial fail of test"); var conf = new TopologyConfiguration(); var mgr = new TopologyManager(conf); var ds = mgr.AddSource(typeof(TestSource1)); ds.Filter(typeof(TestFilter)).Sink(typeof(TestSink1)); JobManager jmgr = new JobManager(); await jmgr.StartJob(mgr, _cluster.Client); Thread.Sleep(1000); var result = StaticTestHelper.GetStatus(); Assert.False(result.Item1, result.Item2); }
public async System.Threading.Tasks.Task TestParallelMoreStreams() { var breaker = _cluster.GrainFactory.GetGrain <ITestHelper>(this.GetType().Namespace); StaticTestHelper.Reset(); var conf = new TopologyConfiguration(); var mgr = new TopologyManager(conf); var ds = mgr.AddSource(typeof(TestSource), 3); ds.Sink(typeof(TestSink1), 3); JobManager jmgr = new JobManager(); await jmgr.StartJob(mgr, _cluster.Client); Thread.Sleep(1000); var result = StaticTestHelper.GetStatus(); Assert.True(result.Item1, result.Item2); //must break because messages go 1,2,1,2 and there are 3 sinks 1->first 2->second 1->third 2->first = fail }
public DeformableMesh(Vector3[] points, int[] ids, Vector3[] normals) { Points = points; Ids = ids; Normals = normals; Topology = new TopologyManager(points, ids); spatialContainer = new SpatialContainer(points, 3, 16); normalCalculator = new NormalCalculator(Topology.Vertices, points, ids); deformation = new Vector3[points.Length]; deformationMask = new bool[points.Length]; normalsToUpdateMask = new bool[points.Length]; running = true; new Thread( new ThreadStart(UpdateNormalsLoop) ).Start(); }
private static async Task Test1(IClusterClient client) { var streamProvider = client.GetStreamProvider("SMSProvider"); var guid = new Guid(); var photoStream = streamProvider.GetStream <string>(guid, "Photo"); var tagStream = streamProvider.GetStream <string>(guid, "Tag"); var gpsStream = streamProvider.GetStream <string>(guid, "GPS"); TopologyConfiguration conf = new TopologyConfiguration(); TopologyManager tpm = new TopologyManager(conf); var a = tpm.AddSource(typeof(TestSourceA)); a.Sink(typeof(GenericPrintSink)); JobManager jmgr = new JobManager(); await jmgr.StartJob(tpm, client); await DataDriver.Run(photoStream, tagStream, gpsStream, 1600, 0); }
public async System.Threading.Tasks.Task StartJob(TopologyManager tpm, IClusterClient client) { await client.GetGrain <IJob>(Guid.NewGuid(), typeof(Job).FullName).StartJob(tpm); foreach (var stream in tpm.Operators) { if (stream.OperatorType.GetInterfaces().Contains(typeof(IWindowJoin))) { var window = client.GetGrain <IWindowJoin>(stream.OperatorGUIDs.First(), stream.OperatorType.FullName); await window.SetSources(stream.Prev.SelectMany(x => x.OperatorGUIDs).ToList(), stream.SourceBPrev.SelectMany(x => x.OperatorGUIDs).ToList()); } if (stream.OperatorType.GetInterfaces().Contains(typeof(ISource))) { var s = client.GetGrain <ISource>(stream.OperatorGUIDs.First(), stream.OperatorType.FullName); await s.InitSource(tpm.Conf.TimeCharacteristic); } else { foreach (var g in stream.OperatorGUIDs) { var s = client.GetGrain <IOperator>(g, stream.OperatorType.FullName); await s.GetSubscribedStreams(); } } } foreach (var stream in tpm.Operators) { if (stream.OperatorType.GetInterfaces().Contains(typeof(ISource))) { var s = client.GetGrain <ISource>(stream.OperatorGUIDs.First(), stream.OperatorType.FullName); await s.Start(); } } }
static async Task Main() { var subscriptionName = "Samples.ASB.NativeIntegration.NativeSubscriberB"; Console.Title = subscriptionName; await TopologyManager.CreateSubscription(ConnectionString, subscriptionName, "all-events", new TrueFilter()); var subscription = new SubscriptionClient(ConnectionString, "bundle-1", subscriptionName); subscription.RegisterMessageHandler((m, _) => { var messageType = (string)m.UserProperties[EnclosedMessageTypesHeader]; var bodyJson = Encoding.UTF8.GetString(m.Body); Console.WriteLine($"Received: {messageType}"); Console.WriteLine(bodyJson); return(Task.CompletedTask); }, e => Task.CompletedTask); Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
/// <summary>Register a topology listener with the topology manager.</summary> /// <param name="manager">The topology manager to add the listener to</param> /// <param name="listener">the listener to register</param> public static void AddTopologyListener(this TopologyManager manager, BaseDotnetTopologyListener listener) { manager.addTopologyListener(new DotnetTopologyListenerWrapper(new DotnetTopologyEventDispatcher(listener))); }
/// <summary>Initialize this job monitor with the specified update mode, refresh interval, topology manager and listeners</summary> /// <param name="topologyRefreshInterval">the interval in millis between refreshes of the topology</param> /// <param name="jvmHealthRefreshInterval">the interval in millis between refreshes of the JVM health data</param> /// <param name="client">the JPPF client used internally</param> /// <param name="listeners">the listeners to register</param> public DotnetJobMonitor(JobMonitorUpdateMode mode, long period, TopologyManager topologyManager, params BaseDotnetJobMonitoringListener[] listeners) : base(mode, period, topologyManager, ToJavaListeners(listeners)) { }
static void Main(string[] args) { JPPFClient client = null; TopologyManager manager = null; JobMonitor jobMonitor = null; try { // initialize the .Net bridge with verbose/quiet mode JPPFDotnet.Init(false); // initialize a topology manager and register a listener for topology events manager = new DotnetTopologyManager(new MyTopologyListener()); // initialize a topology manager and register a listener for topology events jobMonitor = new DotnetJobMonitor(manager, new MyJobMonitoringListener()); // wait until the topology manager and job monitor are fully initialized while (jobMonitor.getJobDrivers().size() <= 0) { Thread.Sleep(10); } JobDriver jobDriver = jobMonitor.getJobDrivers().get(0) as JobDriver; while (jobDriver.getTopologyDriver().getChildCount() <= 0) { Thread.Sleep(10); } // initialize the JPPF client client = manager.getJPPFClient(); // print the number of nodes connected to the server PrintNbNodes(client); // provision a slave node for each .Net-capable master node //ProvisionNodes(client, 1); // subscribe to job notifications emitted by the JPPF server //RegisterJobNotificationListener(client); // subscribe to task completion notifications emitted by the JPPF nodes RegisterTaskNotificationListener(client); // uncomment to test an executor service //SubmitWithExecutor(client); // uncomment to test a completion service //SubmitWithCompletionService(client); JPPFJob job = new JPPFJob(); job.setName(".NET job"); // execute the job only on nodes which successfully initialized the .Net bridge job.getSLA().setExecutionPolicy(new Equal("jppf.dotnet.bridge.initialized", true)); int n = 5; for (int i = 0; i < n; i++) { job.add(new MyDotnetTask(1000)).setId("task " + (i + 1)); } MyDotnetTask myTask = new MyDotnetTask(3000); // this .Net task will time out after 1.5 second myTask.TimeoutSchedule = new JPPFSchedule(1500); job.add(myTask).setId("task " + (n + 1)); // alternatively: job.add(new MyDotnetTask(3000)).setTimeoutSchedule(new JPPFSchedule(1500)); // add a job listner that prints job events to the console job.addJobListener(new MyJobListener()); Console.WriteLine("created job"); // submit the job to the grid and get the execution results java.util.List results = client.submitJob(job); Console.WriteLine("got job results"); for (int i = 0; i < results.size(); i++) { Task task = (Task)results.get(i); //BaseDotnetTask dotnetTask = job.asBaseDotnetTask(task); BaseDotnetTask dotnetTask = task.AsBaseDotnetTask(); if (dotnetTask != null) // if .Net task { if (dotnetTask.Exception != null) { Console.WriteLine("got exception for task " + dotnetTask + " : " + dotnetTask.Exception); Console.WriteLine(dotnetTask.Exception.StackTrace); } else if (dotnetTask.Result != null) { Console.WriteLine("got result for task " + dotnetTask + " : " + dotnetTask.Result); } else { Console.WriteLine("no result or exception for task " + dotnetTask); } } } } catch (Exception e) { Console.WriteLine(e.ToString()); } if (!Console.IsInputRedirected && !Console.IsOutputRedirected) { Console.WriteLine("Please press ESC to terminate"); do { while (!Console.KeyAvailable) { } } while (Console.ReadKey(true).Key != ConsoleKey.Escape); } else { Console.WriteLine("Waiting 5 seconds ..."); Thread.Sleep(5000); } if (client != null) { client.close(); } }
/// <summary>Initialize this job monitor with the specified topology manager and listeners</summary> /// <param name="topologyManager">topologyManager</param> /// <param name="listeners">the listeners to register</param> public DotnetJobMonitor(TopologyManager topologyManager, params BaseDotnetJobMonitoringListener[] listeners) : this(JobMonitorUpdateMode.IMMEDIATE_NOTIFICATIONS, 0L, topologyManager, listeners) { }