Repository: ignite Updated Branches: refs/heads/ignite-1282 1dbb37f02 -> 4e143d7e4
IGNITE-1509: User must operate on IEnumerable in events API rather than on arrays. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/4e143d7e Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/4e143d7e Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/4e143d7e Branch: refs/heads/ignite-1282 Commit: 4e143d7e485aaebc795f96ed7e33e99d8f9f2b2c Parents: 1dbb37f Author: Pavel Tupitsyn <[email protected]> Authored: Thu Oct 8 16:18:28 2015 +0300 Committer: vozerov-gridgain <[email protected]> Committed: Thu Oct 8 16:18:28 2015 +0300 ---------------------------------------------------------------------- .../Apache.Ignite.Core.Tests/EventsTest.cs | 84 ++--- .../Apache.Ignite.Core/Events/EventType.cs | 372 +++++++++---------- .../dotnet/Apache.Ignite.Core/Events/IEvents.cs | 124 ++++++- .../Apache.Ignite.Core/Impl/Events/Events.cs | 76 +++- .../Impl/Events/EventsAsync.cs | 3 +- .../Events/EventsExample.cs | 4 +- 6 files changed, 415 insertions(+), 248 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/4e143d7e/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs index ec46dfe..9e82a09 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs @@ -102,21 +102,21 @@ namespace Apache.Ignite.Core.Tests { var events = _grid1.GetEvents(); - Assert.AreEqual(0, events.GetEnabledEvents().Length); - - Assert.IsFalse(EventType.EvtsCache.Any(events.IsEnabled)); + Assert.AreEqual(0, events.GetEnabledEvents().Count); + + Assert.IsFalse(EventType.EventsCache.Any(events.IsEnabled)); - events.EnableLocal(EventType.EvtsCache); + events.EnableLocal(EventType.EventsCache); - Assert.AreEqual(EventType.EvtsCache, events.GetEnabledEvents()); + Assert.AreEqual(EventType.EventsCache, events.GetEnabledEvents()); - Assert.IsTrue(EventType.EvtsCache.All(events.IsEnabled)); + Assert.IsTrue(EventType.EventsCache.All(events.IsEnabled)); - events.EnableLocal(EventType.EvtsTaskExecution); + events.EnableLocal(EventType.EventsTaskExecution); - events.DisableLocal(EventType.EvtsCache); + events.DisableLocal(EventType.EventsCache); - Assert.AreEqual(EventType.EvtsTaskExecution, events.GetEnabledEvents()); + Assert.AreEqual(EventType.EventsTaskExecution, events.GetEnabledEvents()); } /// <summary> @@ -127,7 +127,7 @@ namespace Apache.Ignite.Core.Tests { var events = _grid1.GetEvents(); var listener = EventsTestHelper.GetListener(); - var eventType = EventType.EvtsTaskExecution; + var eventType = EventType.EventsTaskExecution; events.EnableLocal(eventType); @@ -136,7 +136,7 @@ namespace Apache.Ignite.Core.Tests CheckSend(3); // 3 events per task * 3 grids // Check unsubscription for specific event - events.StopLocalListen(listener, EventType.EvtTaskReduced); + events.StopLocalListen(listener, EventType.EventTaskReduced); CheckSend(2); @@ -146,7 +146,7 @@ namespace Apache.Ignite.Core.Tests CheckNoEvent(); // Check unsubscription by filter - events.LocalListen(listener, EventType.EvtTaskReduced); + events.LocalListen(listener, EventType.EventTaskReduced); CheckSend(); @@ -166,7 +166,7 @@ namespace Apache.Ignite.Core.Tests { var events = _grid1.GetEvents(); var listener = EventsTestHelper.GetListener(); - var eventType = EventType.EvtsTaskExecution; + var eventType = EventType.EventsTaskExecution; events.EnableLocal(eventType); @@ -234,7 +234,7 @@ namespace Apache.Ignite.Core.Tests { yield return new EventTestCase { - EventType = EventType.EvtsCache, + EventType = EventType.EventsCache, EventObjectType = typeof (CacheEvent), GenerateEvent = g => g.GetCache<int, int>(null).Put(1, 1), VerifyEvents = (e, g) => VerifyCacheEvents(e, g), @@ -243,7 +243,7 @@ namespace Apache.Ignite.Core.Tests yield return new EventTestCase { - EventType = EventType.EvtsTaskExecution, + EventType = EventType.EventsTaskExecution, EventObjectType = typeof (TaskEvent), GenerateEvent = g => GenerateTaskEvent(g), VerifyEvents = (e, g) => VerifyTaskEvents(e), @@ -252,15 +252,15 @@ namespace Apache.Ignite.Core.Tests yield return new EventTestCase { - EventType = EventType.EvtsJobExecution, + EventType = EventType.EventsJobExecution, EventObjectType = typeof (JobEvent), GenerateEvent = g => GenerateTaskEvent(g), EventCount = 9 }; - + yield return new EventTestCase { - EventType = new[] {EventType.EvtCacheQueryExecuted}, + EventType = new[] {EventType.EventCacheQueryExecuted}, EventObjectType = typeof (CacheQueryExecutedEvent), GenerateEvent = g => GenerateCacheQueryEvent(g), EventCount = 1 @@ -268,7 +268,7 @@ namespace Apache.Ignite.Core.Tests yield return new EventTestCase { - EventType = new[] { EventType.EvtCacheQueryObjectRead }, + EventType = new[] { EventType.EventCacheQueryObjectRead }, EventObjectType = typeof (CacheQueryReadEvent), GenerateEvent = g => GenerateCacheQueryEvent(g), EventCount = 1 @@ -284,7 +284,7 @@ namespace Apache.Ignite.Core.Tests { var events = _grid1.GetEvents(); - var eventType = EventType.EvtsTaskExecution; + var eventType = EventType.EventsTaskExecution; events.EnableLocal(eventType); @@ -311,7 +311,7 @@ namespace Apache.Ignite.Core.Tests if (async) events = events.WithAsync(); - var eventType = EventType.EvtsTaskExecution; + var eventType = EventType.EventsTaskExecution; events.EnableLocal(eventType); @@ -340,27 +340,27 @@ namespace Apache.Ignite.Core.Tests waitTask.Wait(timeout); // Event types - waitTask = getWaitTask(() => events.WaitForLocal(EventType.EvtTaskReduced)); + waitTask = getWaitTask(() => events.WaitForLocal(EventType.EventTaskReduced)); Assert.IsTrue(waitTask.Wait(timeout)); Assert.IsInstanceOf(typeof(TaskEvent), waitTask.Result); - Assert.AreEqual(EventType.EvtTaskReduced, waitTask.Result.Type); + Assert.AreEqual(EventType.EventTaskReduced, waitTask.Result.Type); // Filter waitTask = getWaitTask(() => events.WaitForLocal( - new EventFilter<IEvent>((g, e) => e.Type == EventType.EvtTaskReduced))); + new EventFilter<IEvent>((g, e) => e.Type == EventType.EventTaskReduced))); Assert.IsTrue(waitTask.Wait(timeout)); Assert.IsInstanceOf(typeof(TaskEvent), waitTask.Result); - Assert.AreEqual(EventType.EvtTaskReduced, waitTask.Result.Type); + Assert.AreEqual(EventType.EventTaskReduced, waitTask.Result.Type); // Filter & types waitTask = getWaitTask(() => events.WaitForLocal( - new EventFilter<IEvent>((g, e) => e.Type == EventType.EvtTaskReduced), EventType.EvtTaskReduced)); + new EventFilter<IEvent>((g, e) => e.Type == EventType.EventTaskReduced), EventType.EventTaskReduced)); Assert.IsTrue(waitTask.Wait(timeout)); Assert.IsInstanceOf(typeof(TaskEvent), waitTask.Result); - Assert.AreEqual(EventType.EvtTaskReduced, waitTask.Result.Type); + Assert.AreEqual(EventType.EventTaskReduced, waitTask.Result.Type); } /// <summary> @@ -374,13 +374,13 @@ namespace Apache.Ignite.Core.Tests { foreach (var g in _grids) { - g.GetEvents().EnableLocal(EventType.EvtsJobExecution); - g.GetEvents().EnableLocal(EventType.EvtsTaskExecution); + g.GetEvents().EnableLocal(EventType.EventsJobExecution); + g.GetEvents().EnableLocal(EventType.EventsTaskExecution); } var events = _grid1.GetEvents(); - var expectedType = EventType.EvtJobStarted; + var expectedType = EventType.EventJobStarted; var remoteFilter = portable ? (IEventFilter<IEvent>) new RemoteEventPortableFilter(expectedType) @@ -399,7 +399,7 @@ namespace Apache.Ignite.Core.Tests CheckSend(3, typeof(JobEvent), expectedType); - _grid3.GetEvents().DisableLocal(EventType.EvtsJobExecution); + _grid3.GetEvents().DisableLocal(EventType.EventsJobExecution); CheckSend(2, typeof(JobEvent), expectedType); @@ -433,11 +433,11 @@ namespace Apache.Ignite.Core.Tests public void TestRemoteQuery([Values(true, false)] bool async) { foreach (var g in _grids) - g.GetEvents().EnableLocal(EventType.EvtsJobExecution); + g.GetEvents().EnableLocal(EventType.EventsJobExecution); var events = _grid1.GetEvents(); - var eventFilter = new RemoteEventFilter(EventType.EvtJobStarted); + var eventFilter = new RemoteEventFilter(EventType.EventJobStarted); var oldEvents = events.RemoteQuery(eventFilter); @@ -446,7 +446,7 @@ namespace Apache.Ignite.Core.Tests GenerateTaskEvent(); - var remoteQuery = events.RemoteQuery(eventFilter, EventsTestHelper.Timeout, EventType.EvtsJobExecution); + var remoteQuery = events.RemoteQuery(eventFilter, EventsTestHelper.Timeout, EventType.EventsJobExecution); if (async) { @@ -459,7 +459,7 @@ namespace Apache.Ignite.Core.Tests Assert.AreEqual(_grids.Length, qryResult.Count); - Assert.IsTrue(qryResult.All(x => x.Type == EventType.EvtJobStarted)); + Assert.IsTrue(qryResult.All(x => x.Type == EventType.EventJobStarted)); } /// <summary> @@ -575,7 +575,7 @@ namespace Apache.Ignite.Core.Tests Assert.AreEqual(locNode, evt.Node); Assert.AreEqual("msg", evt.Message); - Assert.AreEqual(EventType.EvtSwapSpaceCleared, evt.Type); + Assert.AreEqual(EventType.EventSwapSpaceCleared, evt.Type); Assert.IsNotNullOrEmpty(evt.Name); Assert.AreNotEqual(Guid.Empty, evt.Id.GlobalId); Assert.IsTrue((evt.Timestamp - DateTime.Now).TotalSeconds < 10); @@ -594,7 +594,7 @@ namespace Apache.Ignite.Core.Tests GenerateTaskEvent(); EventsTestHelper.VerifyReceive(repeat, eventObjectType ?? typeof (TaskEvent), - eventType.Any() ? eventType : EventType.EvtsTaskExecution); + eventType.Any() ? eventType : EventType.EventsTaskExecution); } /// <summary> @@ -649,7 +649,7 @@ namespace Apache.Ignite.Core.Tests // started, reduced, finished Assert.AreEqual( - new[] {EventType.EvtTaskStarted, EventType.EvtTaskReduced, EventType.EvtTaskFinished}, + new[] {EventType.EventTaskStarted, EventType.EventTaskReduced, EventType.EventTaskFinished}, e.Select(x => x.Type).ToArray()); } @@ -685,12 +685,12 @@ namespace Apache.Ignite.Core.Tests Assert.AreEqual(false, cacheEvent.HasOldValue); Assert.AreEqual(null, cacheEvent.OldValue); - if (cacheEvent.Type == EventType.EvtCacheObjectPut) + if (cacheEvent.Type == EventType.EventCacheObjectPut) { Assert.AreEqual(true, cacheEvent.HasNewValue); Assert.AreEqual(1, cacheEvent.NewValue); } - else if (cacheEvent.Type == EventType.EvtCacheEntryCreated) + else if (cacheEvent.Type == EventType.EventCacheEntryCreated) { Assert.AreEqual(false, cacheEvent.HasNewValue); Assert.AreEqual(null, cacheEvent.NewValue); @@ -767,7 +767,7 @@ namespace Apache.Ignite.Core.Tests /// <summary> /// Verifies received events against events events. /// </summary> - public static void VerifyReceive(int count, Type eventObjectType, params int[] eventTypes) + public static void VerifyReceive(int count, Type eventObjectType, ICollection<int> eventTypes) { // check if expected event count has been received; Wait returns false if there were none. Assert.IsTrue(ReceivedEvent.Wait(Timeout), @@ -930,7 +930,7 @@ namespace Apache.Ignite.Core.Tests /// <summary> /// Gets or sets the type of the event. /// </summary> - public int[] EventType { get; set; } + public ICollection<int> EventType { get; set; } /// <summary> /// Gets or sets the type of the event object. http://git-wip-us.apache.org/repos/asf/ignite/blob/4e143d7e/modules/platforms/dotnet/Apache.Ignite.Core/Events/EventType.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Events/EventType.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Events/EventType.cs index 5ac4330..1c56de2 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Events/EventType.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Events/EventType.cs @@ -17,11 +17,13 @@ namespace Apache.Ignite.Core.Events { - using System; + using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; + using Apache.Ignite.Core.Impl.Collections; + /// <summary> /// Contains event type constants. The decision to use class and not enumeration is dictated /// by allowing users to create their own events and/or event types which would be impossible with enumerations. @@ -37,556 +39,556 @@ namespace Apache.Ignite.Core.Events /// <summary> /// Built-in event type: checkpoint was saved. /// </summary> - public static readonly int EvtCheckpointSaved = 1; + public static readonly int EventCheckpointSaved = 1; /// <summary> /// Built-in event type: checkpoint was loaded. /// </summary> - public static readonly int EvtCheckpointLoaded = 2; + public static readonly int EventCheckpointLoaded = 2; /// <summary> /// Built-in event type: checkpoint was removed. Reasons are: timeout expired, or or it was manually removed, /// or it was automatically removed by the task session. /// </summary> - public static readonly int EvtCheckpointRemoved = 3; + public static readonly int EventCheckpointRemoved = 3; /// <summary> /// Built-in event type: node joined topology. New node has been discovered and joined grid topology. Note that /// even though a node has been discovered there could be a number of warnings in the log. In certain /// situations Ignite doesn't prevent a node from joining but prints warning messages into the log. /// </summary> - public static readonly int EvtNodeJoined = 10; + public static readonly int EventNodeJoined = 10; /// <summary> /// Built-in event type: node has normally left topology. /// </summary> - public static readonly int EvtNodeLeft = 11; + public static readonly int EventNodeLeft = 11; /// <summary> /// Built-in event type: node failed. Ignite detected that node has presumably crashed and is considered /// failed. /// </summary> - public static readonly int EvtNodeFailed = 12; + public static readonly int EventNodeFailed = 12; /// <summary> /// Built-in event type: node metrics updated. Generated when node's metrics are updated. In most cases this /// callback is invoked with every heartbeat received from a node (including local node). /// </summary> - public static readonly int EvtNodeMetricsUpdated = 13; + public static readonly int EventNodeMetricsUpdated = 13; /// <summary> /// Built-in event type: local node segmented. Generated when node determines that it runs in invalid network /// segment. /// </summary> - public static readonly int EvtNodeSegmented = 14; + public static readonly int EventNodeSegmented = 14; /// <summary> /// Built-in event type: client node disconnected. /// </summary> - public static readonly int EvtClientNodeDisconnected = 16; + public static readonly int EventClientNodeDisconnected = 16; /// <summary> /// Built-in event type: client node reconnected. /// </summary> - public static readonly int EvtClientNodeReconnected = 17; + public static readonly int EventClientNodeReconnected = 17; /// <summary> /// Built-in event type: task started. /// </summary> - public static readonly int EvtTaskStarted = 20; + public static readonly int EventTaskStarted = 20; /// <summary> /// Built-in event type: task finished. Task got finished. This event is triggered every time a task finished /// without exception. /// </summary> - public static readonly int EvtTaskFinished = 21; + public static readonly int EventTaskFinished = 21; /// <summary> /// Built-in event type: task failed. Task failed. This event is triggered every time a task finished with an /// exception. Note that prior to this event, there could be other events recorded specific to the failure. /// </summary> - public static readonly int EvtTaskFailed = 22; + public static readonly int EventTaskFailed = 22; /// <summary> /// Built-in event type: task timed out. /// </summary> - public static readonly int EvtTaskTimedout = 23; + public static readonly int EventTaskTimedout = 23; /// <summary> /// Built-in event type: task session attribute set. /// </summary> - public static readonly int EvtTaskSessionAttrSet = 24; + public static readonly int EventTaskSessionAttrSet = 24; /// <summary> /// Built-in event type: task reduced. /// </summary> - public static readonly int EvtTaskReduced = 25; + public static readonly int EventTaskReduced = 25; /// <summary> /// Built-in event type: Ignite job was mapped in {@link org.apache.ignite.compute.ComputeTask#map(List, Object)} /// method. /// </summary> - public static readonly int EvtJobMapped = 40; + public static readonly int EventJobMapped = 40; /// <summary> /// Built-in event type: Ignite job result was received by {@link /// org.apache.ignite.compute.ComputeTask#result(org.apache.ignite.compute.ComputeJobResult, List)} method. /// </summary> - public static readonly int EvtJobResulted = 41; + public static readonly int EventJobResulted = 41; /// <summary> /// Built-in event type: Ignite job failed over. /// </summary> - public static readonly int EvtJobFailedOver = 43; + public static readonly int EventJobFailedOver = 43; /// <summary> /// Built-in event type: Ignite job started. /// </summary> - public static readonly int EvtJobStarted = 44; + public static readonly int EventJobStarted = 44; /// <summary> /// Built-in event type: Ignite job finished. Job has successfully completed and produced a result which from the /// user perspective can still be either negative or positive. /// </summary> - public static readonly int EvtJobFinished = 45; + public static readonly int EventJobFinished = 45; /// <summary> /// Built-in event type: Ignite job timed out. /// </summary> - public static readonly int EvtJobTimedout = 46; + public static readonly int EventJobTimedout = 46; /// <summary> /// Built-in event type: Ignite job rejected during collision resolution. /// </summary> - public static readonly int EvtJobRejected = 47; + public static readonly int EventJobRejected = 47; /// <summary> /// Built-in event type: Ignite job failed. Job has failed. This means that there was some error event during job /// execution and job did not produce a result. /// </summary> - public static readonly int EvtJobFailed = 48; - + public static readonly int EventJobFailed = 48; + /// <summary> /// Built-in event type: Ignite job queued. Job arrived for execution and has been queued (added to passive queue /// during collision resolution). /// </summary> - public static readonly int EvtJobQueued = 49; + public static readonly int EventJobQueued = 49; /// <summary> /// Built-in event type: Ignite job cancelled. /// </summary> - public static readonly int EvtJobCancelled = 50; + public static readonly int EventJobCancelled = 50; /// <summary> /// Built-in event type: entry created. /// </summary> - public static readonly int EvtCacheEntryCreated = 60; + public static readonly int EventCacheEntryCreated = 60; /// <summary> /// Built-in event type: entry destroyed. /// </summary> - public static readonly int EvtCacheEntryDestroyed = 61; + public static readonly int EventCacheEntryDestroyed = 61; /// <summary> /// Built-in event type: entry evicted. /// </summary> - public static readonly int EvtCacheEntryEvicted = 62; + public static readonly int EventCacheEntryEvicted = 62; /// <summary> /// Built-in event type: object put. /// </summary> - public static readonly int EvtCacheObjectPut = 63; + public static readonly int EventCacheObjectPut = 63; /// <summary> /// Built-in event type: object read. /// </summary> - public static readonly int EvtCacheObjectRead = 64; + public static readonly int EventCacheObjectRead = 64; /// <summary> /// Built-in event type: object removed. /// </summary> - public static readonly int EvtCacheObjectRemoved = 65; + public static readonly int EventCacheObjectRemoved = 65; /// <summary> /// Built-in event type: object locked. /// </summary> - public static readonly int EvtCacheObjectLocked = 66; + public static readonly int EventCacheObjectLocked = 66; /// <summary> /// Built-in event type: object unlocked. /// </summary> - public static readonly int EvtCacheObjectUnlocked = 67; + public static readonly int EventCacheObjectUnlocked = 67; /// <summary> /// Built-in event type: cache object swapped from swap storage. /// </summary> - public static readonly int EvtCacheObjectSwapped = 68; + public static readonly int EventCacheObjectSwapped = 68; /// <summary> /// Built-in event type: cache object unswapped from swap storage. /// </summary> - public static readonly int EvtCacheObjectUnswapped = 69; + public static readonly int EventCacheObjectUnswapped = 69; /// <summary> /// Built-in event type: cache object was expired when reading it. /// </summary> - public static readonly int EvtCacheObjectExpired = 70; + public static readonly int EventCacheObjectExpired = 70; /// <summary> /// Built-in event type: swap space data read. /// </summary> - public static readonly int EvtSwapSpaceDataRead = 71; + public static readonly int EventSwapSpaceDataRead = 71; /// <summary> /// Built-in event type: swap space data stored. /// </summary> - public static readonly int EvtSwapSpaceDataStored = 72; + public static readonly int EventSwapSpaceDataStored = 72; /// <summary> /// Built-in event type: swap space data removed. /// </summary> - public static readonly int EvtSwapSpaceDataRemoved = 73; + public static readonly int EventSwapSpaceDataRemoved = 73; /// <summary> /// Built-in event type: swap space cleared. /// </summary> - public static readonly int EvtSwapSpaceCleared = 74; + public static readonly int EventSwapSpaceCleared = 74; /// <summary> /// Built-in event type: swap space data evicted. /// </summary> - public static readonly int EvtSwapSpaceDataEvicted = 75; + public static readonly int EventSwapSpaceDataEvicted = 75; /// <summary> /// Built-in event type: cache object stored in off-heap storage. /// </summary> - public static readonly int EvtCacheObjectToOffheap = 76; + public static readonly int EventCacheObjectToOffheap = 76; /// <summary> /// Built-in event type: cache object moved from off-heap storage back into memory. /// </summary> - public static readonly int EvtCacheObjectFromOffheap = 77; + public static readonly int EventCacheObjectFromOffheap = 77; /// <summary> /// Built-in event type: cache rebalance started. /// </summary> - public static readonly int EvtCacheRebalanceStarted = 80; + public static readonly int EventCacheRebalanceStarted = 80; /// <summary> /// Built-in event type: cache rebalance stopped. /// </summary> - public static readonly int EvtCacheRebalanceStopped = 81; + public static readonly int EventCacheRebalanceStopped = 81; /// <summary> /// Built-in event type: cache partition loaded. /// </summary> - public static readonly int EvtCacheRebalancePartLoaded = 82; + public static readonly int EventCacheRebalancePartLoaded = 82; /// <summary> /// Built-in event type: cache partition unloaded. /// </summary> - public static readonly int EvtCacheRebalancePartUnloaded = 83; + public static readonly int EventCacheRebalancePartUnloaded = 83; /// <summary> /// Built-in event type: cache entry rebalanced. /// </summary> - public static readonly int EvtCacheRebalanceObjectLoaded = 84; + public static readonly int EventCacheRebalanceObjectLoaded = 84; /// <summary> /// Built-in event type: cache entry unloaded. /// </summary> - public static readonly int EvtCacheRebalanceObjectUnloaded = 85; + public static readonly int EventCacheRebalanceObjectUnloaded = 85; /// <summary> /// Built-in event type: all nodes that hold partition left topology. /// </summary> - public static readonly int EvtCacheRebalancePartDataLost = 86; + public static readonly int EventCacheRebalancePartDataLost = 86; /// <summary> /// Built-in event type: query executed. /// </summary> - public static readonly int EvtCacheQueryExecuted = 96; + public static readonly int EventCacheQueryExecuted = 96; /// <summary> /// Built-in event type: query entry read. /// </summary> - public static readonly int EvtCacheQueryObjectRead = 97; + public static readonly int EventCacheQueryObjectRead = 97; /// <summary> /// Built-in event type: cache started. /// </summary> - public static readonly int EvtCacheStarted = 98; + public static readonly int EventCacheStarted = 98; /// <summary> /// Built-in event type: cache started. /// </summary> - public static readonly int EvtCacheStopped = 99; + public static readonly int EventCacheStopped = 99; /// <summary> /// Built-in event type: cache nodes left. /// </summary> - public static readonly int EvtCacheNodesLeft = 100; + public static readonly int EventCacheNodesLeft = 100; /// <summary> /// All events indicating an error or failure condition. It is convenient to use when fetching all events /// indicating error or failure. /// </summary> - private static readonly int[] EvtsError0 = + private static readonly ICollection<int> EventsError0 = new[] { - EvtJobTimedout, - EvtJobFailed, - EvtJobFailedOver, - EvtJobRejected, - EvtJobCancelled, - EvtTaskTimedout, - EvtTaskFailed, - EvtCacheRebalanceStarted, - EvtCacheRebalanceStopped - }; - - /// <summary> - /// All discovery events except for <see cref="EvtNodeMetricsUpdated" />. Subscription to <see - /// cref="EvtNodeMetricsUpdated" /> can generate massive amount of event processing in most cases is not + EventJobTimedout, + EventJobFailed, + EventJobFailedOver, + EventJobRejected, + EventJobCancelled, + EventTaskTimedout, + EventTaskFailed, + EventCacheRebalanceStarted, + EventCacheRebalanceStopped + }.AsReadOnly(); + + /// <summary> + /// All discovery events except for <see cref="EventNodeMetricsUpdated" />. Subscription to <see + /// cref="EventNodeMetricsUpdated" /> can generate massive amount of event processing in most cases is not /// necessary. If this event is indeed required you can subscribe to it individually or use <see - /// cref="EvtsDiscoveryAll0" /> array. + /// cref="EventsDiscoveryAll0" /> array. /// </summary> - private static readonly int[] EvtsDiscovery0 = + private static readonly ICollection<int> EventsDiscovery0 = new[] { - EvtNodeJoined, - EvtNodeLeft, - EvtNodeFailed, - EvtNodeSegmented, - EvtClientNodeDisconnected, - EvtClientNodeReconnected - }; + EventNodeJoined, + EventNodeLeft, + EventNodeFailed, + EventNodeSegmented, + EventClientNodeDisconnected, + EventClientNodeReconnected + }.AsReadOnly(); /// <summary> /// All discovery events. /// </summary> - private static readonly int[] EvtsDiscoveryAll0 = + private static readonly ICollection<int> EventsDiscoveryAll0 = new[] { - EvtNodeJoined, - EvtNodeLeft, - EvtNodeFailed, - EvtNodeSegmented, - EvtNodeMetricsUpdated, - EvtClientNodeDisconnected, - EvtClientNodeReconnected - }; + EventNodeJoined, + EventNodeLeft, + EventNodeFailed, + EventNodeSegmented, + EventNodeMetricsUpdated, + EventClientNodeDisconnected, + EventClientNodeReconnected + }.AsReadOnly(); /// <summary> /// All Ignite job execution events. /// </summary> - private static readonly int[] EvtsJobExecution0 = + private static readonly ICollection<int> EventsJobExecution0 = new[] { - EvtJobMapped, - EvtJobResulted, - EvtJobFailedOver, - EvtJobStarted, - EvtJobFinished, - EvtJobTimedout, - EvtJobRejected, - EvtJobFailed, - EvtJobQueued, - EvtJobCancelled - }; + EventJobMapped, + EventJobResulted, + EventJobFailedOver, + EventJobStarted, + EventJobFinished, + EventJobTimedout, + EventJobRejected, + EventJobFailed, + EventJobQueued, + EventJobCancelled + }.AsReadOnly(); /// <summary> /// All Ignite task execution events. /// </summary> - private static readonly int[] EvtsTaskExecution0 = + private static readonly ICollection<int> EventsTaskExecution0 = new[] { - EvtTaskStarted, - EvtTaskFinished, - EvtTaskFailed, - EvtTaskTimedout, - EvtTaskSessionAttrSet, - EvtTaskReduced - }; + EventTaskStarted, + EventTaskFinished, + EventTaskFailed, + EventTaskTimedout, + EventTaskSessionAttrSet, + EventTaskReduced + }.AsReadOnly(); /// <summary> /// All cache events. /// </summary> - private static readonly int[] EvtsCache0 = + private static readonly ICollection<int> EventsCache0 = new[] { - EvtCacheEntryCreated, - EvtCacheEntryDestroyed, - EvtCacheObjectPut, - EvtCacheObjectRead, - EvtCacheObjectRemoved, - EvtCacheObjectLocked, - EvtCacheObjectUnlocked, - EvtCacheObjectSwapped, - EvtCacheObjectUnswapped, - EvtCacheObjectExpired - }; + EventCacheEntryCreated, + EventCacheEntryDestroyed, + EventCacheObjectPut, + EventCacheObjectRead, + EventCacheObjectRemoved, + EventCacheObjectLocked, + EventCacheObjectUnlocked, + EventCacheObjectSwapped, + EventCacheObjectUnswapped, + EventCacheObjectExpired + }.AsReadOnly(); /// <summary> /// All cache rebalance events. /// </summary> - private static readonly int[] EvtsCacheRebalance0 = + private static readonly ICollection<int> EventsCacheRebalance0 = new[] { - EvtCacheRebalanceStarted, - EvtCacheRebalanceStopped, - EvtCacheRebalancePartLoaded, - EvtCacheRebalancePartUnloaded, - EvtCacheRebalanceObjectLoaded, - EvtCacheRebalanceObjectUnloaded, - EvtCacheRebalancePartDataLost - }; + EventCacheRebalanceStarted, + EventCacheRebalanceStopped, + EventCacheRebalancePartLoaded, + EventCacheRebalancePartUnloaded, + EventCacheRebalanceObjectLoaded, + EventCacheRebalanceObjectUnloaded, + EventCacheRebalancePartDataLost + }.AsReadOnly(); /// <summary> /// All cache lifecycle events. /// </summary> - private static readonly int[] EvtsCacheLifecycle0 = + private static readonly ICollection<int> EventsCacheLifecycle0 = new[] { - EvtCacheStarted, - EvtCacheStopped, - EvtCacheNodesLeft - }; + EventCacheStarted, + EventCacheStopped, + EventCacheNodesLeft + }.AsReadOnly(); /// <summary> /// All cache query events. /// </summary> - private static readonly int[] EvtsCacheQuery0 = + private static readonly ICollection<int> EventsCacheQuery0 = new[] { - EvtCacheQueryExecuted, - EvtCacheQueryObjectRead - }; + EventCacheQueryExecuted, + EventCacheQueryObjectRead + }.AsReadOnly(); /// <summary> /// All swap space events. /// </summary> - private static readonly int[] EvtsSwapspace0 = + private static readonly ICollection<int> EventsSwapspace0 = new[] { - EvtSwapSpaceCleared, - EvtSwapSpaceDataRemoved, - EvtSwapSpaceDataRead, - EvtSwapSpaceDataStored, - EvtSwapSpaceDataEvicted - }; + EventSwapSpaceCleared, + EventSwapSpaceDataRemoved, + EventSwapSpaceDataRead, + EventSwapSpaceDataStored, + EventSwapSpaceDataEvicted + }.AsReadOnly(); /// <summary> /// All Ignite events. /// </summary> - private static readonly int[] EvtsAll0 = GetAllEvents(); + private static readonly ICollection<int> EventsAll0 = GetAllEvents().AsReadOnly(); /// <summary> /// All Ignite events (<b>excluding</b> metric update event). /// </summary> - private static readonly int[] EvtsAllMinusMetricUpdate0 = - EvtsAll0.Where(x => x != EvtNodeMetricsUpdated).ToArray(); + private static readonly ICollection<int> EventsAllMinusMetricUpdate0 = + EventsAll0.Where(x => x != EventNodeMetricsUpdated).ToArray().AsReadOnly(); /// <summary> /// All events indicating an error or failure condition. It is convenient to use when fetching all events /// indicating error or failure. /// </summary> [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] - public static int[] EvtsError + public static ICollection<int> EventsError { - get { return CloneArray(EvtsError0); } + get { return EventsError0; } } /// <summary> /// All Ignite events (<b>excluding</b> metric update event). /// </summary> [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] - public static int[] EvtsAllMinusMetricUpdate + public static ICollection<int> EventsAllMinusMetricUpdate { - get { return CloneArray(EvtsAllMinusMetricUpdate0); } + get { return EventsAllMinusMetricUpdate0; } } /// <summary> /// All swap space events. /// </summary> [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] - public static int[] EvtsSwapspace + public static ICollection<int> EventsSwapspace { - get { return CloneArray(EvtsSwapspace0); } + get { return EventsSwapspace0; } } /// <summary> /// All cache query events. /// </summary> [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] - public static int[] EvtsCacheQuery + public static ICollection<int> EventsCacheQuery { - get { return CloneArray(EvtsCacheQuery0); } + get { return EventsCacheQuery0; } } /// <summary> /// All cache lifecycle events. /// </summary> [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] - public static int[] EvtsCacheLifecycle + public static ICollection<int> EventsCacheLifecycle { - get { return CloneArray(EvtsCacheLifecycle0); } + get { return EventsCacheLifecycle0; } } /// <summary> /// All cache rebalance events. /// </summary> [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] - public static int[] EvtsCacheRebalance + public static ICollection<int> EventsCacheRebalance { - get { return CloneArray(EvtsCacheRebalance0); } + get { return EventsCacheRebalance0; } } /// <summary> /// All cache events. /// </summary> [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] - public static int[] EvtsCache + public static ICollection<int> EventsCache { - get { return CloneArray(EvtsCache0); } + get { return EventsCache0; } } /// <summary> /// All Ignite task execution events. /// </summary> [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] - public static int[] EvtsTaskExecution + public static ICollection<int> EventsTaskExecution { - get { return CloneArray(EvtsTaskExecution0); } + get { return EventsTaskExecution0; } } /// <summary> /// All Ignite job execution events. /// </summary> [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] - public static int[] EvtsJobExecution + public static ICollection<int> EventsJobExecution { - get { return CloneArray(EvtsJobExecution0); } + get { return EventsJobExecution0; } } /// <summary> /// All discovery events. /// </summary> [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] - public static int[] EvtsDiscoveryAll + public static ICollection<int> EventsDiscoveryAll { - get { return CloneArray(EvtsDiscoveryAll0); } + get { return EventsDiscoveryAll0; } } /// <summary> - /// All discovery events except for <see cref="EvtNodeMetricsUpdated" />. Subscription to <see - /// cref="EvtNodeMetricsUpdated" /> can generate massive amount of event processing in most cases is not + /// All discovery events except for <see cref="EventNodeMetricsUpdated" />. Subscription to <see + /// cref="EventNodeMetricsUpdated" /> can generate massive amount of event processing in most cases is not /// necessary. If this event is indeed required you can subscribe to it individually or use <see - /// cref="EvtsDiscoveryAll0" /> array. + /// cref="EventsDiscoveryAll0" /> array. /// </summary> [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] - public static int[] EvtsDiscovery + public static ICollection<int> EventsDiscovery { - get { return CloneArray(EvtsDiscovery0); } + get { return EventsDiscovery0; } } /// <summary> /// All Ignite events. /// </summary> [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] - public static int[] EvtsAll + public static ICollection<int> EventsAll { - get { return CloneArray(EvtsAll0); } + get { return EventsAll0; } } /// <summary> @@ -599,19 +601,5 @@ namespace Apache.Ignite.Core.Events .Where(x => x.FieldType == typeof (int)) .Select(x => (int) x.GetValue(null)).ToArray(); } - - /// <summary> - /// Clones an array to return to the user. - /// </summary> - /// <param name="array">The array.</param> - /// <returns>Shallow copy of the array.</returns> - private static int[] CloneArray(int[] array) - { - var res = new int[array.Length]; - - Array.Copy(array, res, array.Length); - - return res; - } } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/4e143d7e/modules/platforms/dotnet/Apache.Ignite.Core/Events/IEvents.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Events/IEvents.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Events/IEvents.cs index e13513c..9676873 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Events/IEvents.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Events/IEvents.cs @@ -19,7 +19,6 @@ namespace Apache.Ignite.Core.Events { using System; using System.Collections.Generic; - using System.Diagnostics.CodeAnalysis; using Apache.Ignite.Core.Cluster; using Apache.Ignite.Core.Common; @@ -44,8 +43,19 @@ namespace Apache.Ignite.Core.Events /// <param name="types">Event types to be queried.</param> /// <returns>Collection of Ignite events returned from specified nodes.</returns> [AsyncSupported] - [SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists")] - List<T> RemoteQuery<T>(IEventFilter<T> filter, TimeSpan? timeout = null, params int[] types) + ICollection<T> RemoteQuery<T>(IEventFilter<T> filter, TimeSpan? timeout = null, params int[] types) + where T : IEvent; + + /// <summary> + /// Queries nodes in this cluster group for events using passed in predicate filter for event selection. + /// </summary> + /// <typeparam name="T">Type of events.</typeparam> + /// <param name="filter">Predicate filter used to query events on remote nodes.</param> + /// <param name="timeout">Maximum time to wait for result, null or 0 to wait forever.</param> + /// <param name="types">Event types to be queried.</param> + /// <returns>Collection of Ignite events returned from specified nodes.</returns> + [AsyncSupported] + ICollection<T> RemoteQuery<T>(IEventFilter<T> filter, TimeSpan? timeout = null, IEnumerable<int> types = null) where T : IEvent; /// <summary> @@ -86,10 +96,50 @@ namespace Apache.Ignite.Core.Events where T : IEvent; /// <summary> + /// Adds event listener for specified events to all nodes in the cluster group (possibly including local node + /// if it belongs to the cluster group as well). This means that all events occurring on any node within this + /// cluster group that pass remote filter will be sent to local node for local listener notifications. + /// <para/> + /// The listener can be unsubscribed automatically if local node stops, if localListener callback + /// returns false or if <see cref="StopRemoteListen"/> is called. + /// </summary> + /// <typeparam name="T">Type of events.</typeparam> + /// <param name="bufSize">Remote events buffer size. Events from remote nodes won't be sent until buffer + /// is full or time interval is exceeded.</param> + /// <param name="interval">Maximum time interval after which events from remote node will be sent. Events + /// from remote nodes won't be sent until buffer is full or time interval is exceeded.</param> + /// <param name="autoUnsubscribe">Flag indicating that event listeners on remote nodes should be automatically + /// unregistered if master node (node that initiated event listening) leaves topology. + /// If this flag is false, listeners will be unregistered only when <see cref="StopRemoteListen"/> + /// method is called, or the localListener returns false.</param> + /// <param name="localListener"> Listener callback that is called on local node. If null, these events will + /// be handled on remote nodes by passed in remoteFilter.</param> + /// <param name="remoteFilter"> + /// Filter callback that is called on remote node. Only events that pass the remote filter will be + /// sent to local node. If null, all events of specified types will be sent to local node. + /// This remote filter can be used to pre-handle events remotely, before they are passed in to local callback. + /// It will be auto-unsubscribed on the node where event occurred in case if it returns false. + /// </param> + /// <param name="types"> + /// Types of events to listen for. If not provided, all events that pass the provided remote filter + /// will be sent to local node. + /// </param> + /// <returns> + /// Operation ID that can be passed to <see cref="StopRemoteListen"/> method to stop listening. + /// </returns> + [AsyncSupported] + Guid RemoteListen<T>(int bufSize = 1, TimeSpan? interval = null, bool autoUnsubscribe = true, + IEventFilter<T> localListener = null, IEventFilter<T> remoteFilter = null, IEnumerable<int> types = null) + where T : IEvent; + + /// <summary> /// Stops listening to remote events. This will unregister all listeners identified with provided operation ID /// on all nodes defined by <see cref="ClusterGroup"/>. /// </summary> - /// <param name="opId">Operation ID that was returned from <see cref="RemoteListen{T}"/>.</param> + /// <param name="opId"> + /// Operation ID that was returned from + /// <see cref="RemoteListen{T}(int, TimeSpan?, bool, IEventFilter{T},IEventFilter{T},int[])"/>. + /// </param> [AsyncSupported] void StopRemoteListen(Guid opId); @@ -105,6 +155,15 @@ namespace Apache.Ignite.Core.Events /// <summary> /// Waits for the specified events. /// </summary> + /// <param name="types">Types of the events to wait for. + /// If not provided, all events will be passed to the filter.</param> + /// <returns>Ignite event.</returns> + [AsyncSupported] + IEvent WaitForLocal(IEnumerable<int> types); + + /// <summary> + /// Waits for the specified events. + /// </summary> /// <typeparam name="T">Type of events.</typeparam> /// <param name="filter">Optional filtering predicate. Event wait will end as soon as it returns false.</param> /// <param name="types">Types of the events to wait for. @@ -114,12 +173,29 @@ namespace Apache.Ignite.Core.Events T WaitForLocal<T>(IEventFilter<T> filter, params int[] types) where T : IEvent; /// <summary> + /// Waits for the specified events. + /// </summary> + /// <typeparam name="T">Type of events.</typeparam> + /// <param name="filter">Optional filtering predicate. Event wait will end as soon as it returns false.</param> + /// <param name="types">Types of the events to wait for. + /// If not provided, all events will be passed to the filter.</param> + /// <returns>Ignite event.</returns> + [AsyncSupported] + T WaitForLocal<T>(IEventFilter<T> filter, IEnumerable<int> types) where T : IEvent; + + /// <summary> /// Queries local node for events using of specified types. /// </summary> /// <param name="types">Event types to be queried. Optional.</param> /// <returns>Collection of Ignite events found on local node.</returns> - [SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists")] - List<IEvent> LocalQuery(params int[] types); + ICollection<IEvent> LocalQuery(params int[] types); + + /// <summary> + /// Queries local node for events using of specified types. + /// </summary> + /// <param name="types">Event types to be queried. Optional.</param> + /// <returns>Collection of Ignite events found on local node.</returns> + ICollection<IEvent> LocalQuery(IEnumerable<int> types); /// <summary> /// Records customer user generated event. All registered local listeners will be notified. @@ -143,6 +219,16 @@ namespace Apache.Ignite.Core.Events void LocalListen<T>(IEventFilter<T> listener, params int[] types) where T : IEvent; /// <summary> + /// Adds an event listener for local events. Note that listener will be added regardless of whether + /// local node is in this cluster group or not. + /// </summary> + /// <typeparam name="T">Type of events.</typeparam> + /// <param name="listener">Predicate that is called on each received event. If predicate returns false, + /// it will be unregistered and will stop receiving events.</param> + /// <param name="types">Event types for which this listener will be notified, should not be empty.</param> + void LocalListen<T>(IEventFilter<T> listener, IEnumerable<int> types) where T : IEvent; + + /// <summary> /// Removes local event listener. /// </summary> /// <typeparam name="T">Type of events.</typeparam> @@ -153,6 +239,16 @@ namespace Apache.Ignite.Core.Events bool StopLocalListen<T>(IEventFilter<T> listener, params int[] types) where T : IEvent; /// <summary> + /// Removes local event listener. + /// </summary> + /// <typeparam name="T">Type of events.</typeparam> + /// <param name="listener">Local event listener to remove.</param> + /// <param name="types">Types of events for which to remove listener. If not specified, then listener + /// will be removed for all types it was registered for.</param> + /// <returns>True if listener was removed, false otherwise.</returns> + bool StopLocalListen<T>(IEventFilter<T> listener, IEnumerable<int> types) where T : IEvent; + + /// <summary> /// Enables provided events. Allows to start recording events that were disabled before. /// Note that provided events will be enabled regardless of whether local node is in this cluster group or not. /// </summary> @@ -160,6 +256,13 @@ namespace Apache.Ignite.Core.Events void EnableLocal(params int[] types); /// <summary> + /// Enables provided events. Allows to start recording events that were disabled before. + /// Note that provided events will be enabled regardless of whether local node is in this cluster group or not. + /// </summary> + /// <param name="types">Events to enable.</param> + void EnableLocal(IEnumerable<int> types); + + /// <summary> /// Disables provided events. Allows to stop recording events that were enabled before. Note that specified /// events will be disabled regardless of whether local node is in this cluster group or not. /// </summary> @@ -167,10 +270,17 @@ namespace Apache.Ignite.Core.Events void DisableLocal(params int[] types); /// <summary> + /// Disables provided events. Allows to stop recording events that were enabled before. Note that specified + /// events will be disabled regardless of whether local node is in this cluster group or not. + /// </summary> + /// <param name="types">Events to disable.</param> + void DisableLocal(IEnumerable<int> types); + + /// <summary> /// Gets types of enabled events. /// </summary> /// <returns>Types of enabled events.</returns> - int[] GetEnabledEvents(); + ICollection<int> GetEnabledEvents(); /// <summary> /// Determines whether the specified event is enabled. http://git-wip-us.apache.org/repos/asf/ignite/blob/4e143d7e/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Events/Events.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Events/Events.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Events/Events.cs index 3972bb0..ad1157e 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Events/Events.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Events/Events.cs @@ -105,7 +105,7 @@ namespace Apache.Ignite.Core.Impl.Events public IClusterGroup ClusterGroup { get; private set; } /** <inheritDoc /> */ - public virtual List<T> RemoteQuery<T>(IEventFilter<T> filter, TimeSpan? timeout = null, params int[] types) + public virtual ICollection<T> RemoteQuery<T>(IEventFilter<T> filter, TimeSpan? timeout = null, params int[] types) where T : IEvent { IgniteArgumentCheck.NotNull(filter, "filter"); @@ -123,6 +123,13 @@ namespace Apache.Ignite.Core.Impl.Events } /** <inheritDoc /> */ + public ICollection<T> RemoteQuery<T>(IEventFilter<T> filter, TimeSpan? timeout = null, + IEnumerable<int> types = null) where T : IEvent + { + return RemoteQuery(filter, timeout, TypesToArray(types)); + } + + /** <inheritDoc /> */ public virtual Guid RemoteListen<T>(int bufSize = 1, TimeSpan? interval = null, bool autoUnsubscribe = true, IEventFilter<T> localListener = null, IEventFilter<T> remoteFilter = null, params int[] types) where T : IEvent @@ -156,6 +163,14 @@ namespace Apache.Ignite.Core.Impl.Events } /** <inheritDoc /> */ + public Guid RemoteListen<T>(int bufSize = 1, TimeSpan? interval = null, bool autoUnsubscribe = true, + IEventFilter<T> localListener = null, IEventFilter<T> remoteFilter = null, IEnumerable<int> types = null) + where T : IEvent + { + return RemoteListen(bufSize, interval, autoUnsubscribe, localListener, remoteFilter, TypesToArray(types)); + } + + /** <inheritDoc /> */ public virtual void StopRemoteListen(Guid opId) { DoOutOp((int) Op.StopRemoteListen, writer => @@ -171,6 +186,12 @@ namespace Apache.Ignite.Core.Impl.Events } /** <inheritDoc /> */ + public IEvent WaitForLocal(IEnumerable<int> types) + { + return WaitForLocal(TypesToArray(types)); + } + + /** <inheritDoc /> */ public virtual T WaitForLocal<T>(IEventFilter<T> filter, params int[] types) where T : IEvent { long hnd = 0; @@ -187,7 +208,13 @@ namespace Apache.Ignite.Core.Impl.Events } /** <inheritDoc /> */ - public List<IEvent> LocalQuery(params int[] types) + public T WaitForLocal<T>(IEventFilter<T> filter, IEnumerable<int> types) where T : IEvent + { + return WaitForLocal(filter, TypesToArray(types)); + } + + /** <inheritDoc /> */ + public ICollection<IEvent> LocalQuery(params int[] types) { return DoOutInOp((int) Op.LocalQuery, writer => WriteEventTypes(types, writer), @@ -195,6 +222,12 @@ namespace Apache.Ignite.Core.Impl.Events } /** <inheritDoc /> */ + public ICollection<IEvent> LocalQuery(IEnumerable<int> types) + { + return LocalQuery(TypesToArray(types)); + } + + /** <inheritDoc /> */ public void RecordLocal(IEvent evt) { throw new NotImplementedException("GG-10244"); @@ -211,6 +244,12 @@ namespace Apache.Ignite.Core.Impl.Events } /** <inheritDoc /> */ + public void LocalListen<T>(IEventFilter<T> listener, IEnumerable<int> types) where T : IEvent + { + LocalListen(listener, TypesToArray(types)); + } + + /** <inheritDoc /> */ public bool StopLocalListen<T>(IEventFilter<T> listener, params int[] types) where T : IEvent { lock (_localFilters) @@ -232,6 +271,18 @@ namespace Apache.Ignite.Core.Impl.Events } /** <inheritDoc /> */ + public bool StopLocalListen<T>(IEventFilter<T> listener, IEnumerable<int> types) where T : IEvent + { + return StopLocalListen(listener, TypesToArray(types)); + } + + /** <inheritDoc /> */ + public void EnableLocal(IEnumerable<int> types) + { + EnableLocal(TypesToArray(types)); + } + + /** <inheritDoc /> */ public void EnableLocal(params int[] types) { IgniteArgumentCheck.NotNullOrEmpty(types, "types"); @@ -248,7 +299,13 @@ namespace Apache.Ignite.Core.Impl.Events } /** <inheritDoc /> */ - public int[] GetEnabledEvents() + public void DisableLocal(IEnumerable<int> types) + { + DisableLocal(TypesToArray(types)); + } + + /** <inheritDoc /> */ + public ICollection<int> GetEnabledEvents() { return DoInOp((int)Op.GetEnabledEvents, reader => ReadEventTypes(reader)); } @@ -438,7 +495,7 @@ namespace Apache.Ignite.Core.Impl.Events /// <param name="writer">Writer.</param> private static void WriteEventTypes(int[] types, IPortableRawWriter writer) { - if (types.Length == 0) + if (types != null && types.Length == 0) types = null; // empty array means no type filtering writer.WriteIntArray(types); @@ -454,6 +511,17 @@ namespace Apache.Ignite.Core.Impl.Events } /// <summary> + /// Converts types enumerable to array. + /// </summary> + private static int[] TypesToArray(IEnumerable<int> types) + { + if (types == null) + return null; + + return types as int[] ?? types.ToArray(); + } + + /// <summary> /// Local user filter wrapper. /// </summary> private class LocalEventFilter : IInteropCallback http://git-wip-us.apache.org/repos/asf/ignite/blob/4e143d7e/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Events/EventsAsync.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Events/EventsAsync.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Events/EventsAsync.cs index 632d8b8..84bcb19 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Events/EventsAsync.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Events/EventsAsync.cs @@ -53,7 +53,8 @@ namespace Apache.Ignite.Core.Impl.Events } /** <inheritdoc /> */ - public override List<T> RemoteQuery<T>(IEventFilter<T> filter, TimeSpan? timeout = null, params int[] types) + public override ICollection<T> RemoteQuery<T>(IEventFilter<T> filter, TimeSpan? timeout = null, + params int[] types) { _lastAsyncOp.Value = (int) Op.RemoteQuery; http://git-wip-us.apache.org/repos/asf/ignite/blob/4e143d7e/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Events/EventsExample.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Events/EventsExample.cs b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Events/EventsExample.cs index 92a14ed..08ac0bd 100644 --- a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Events/EventsExample.cs +++ b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Events/EventsExample.cs @@ -63,7 +63,7 @@ namespace Apache.Ignite.Examples.Events Console.WriteLine(">>> Listening for a local event..."); var listener = new LocalListener(); - ignite.GetEvents().LocalListen(listener, EventType.EvtsTaskExecution); + ignite.GetEvents().LocalListen(listener, EventType.EventsTaskExecution); ExecuteTask(ignite); @@ -79,7 +79,7 @@ namespace Apache.Ignite.Examples.Events var remoteFilter = new RemoteFilter(); var listenId = ignite.GetEvents().RemoteListen(localListener: localListener, - remoteFilter: remoteFilter, types: EventType.EvtsJobExecution); + remoteFilter: remoteFilter, types: EventType.EventsJobExecution); ExecuteTask(ignite);
