www.espertech.comDocumentation

Appendix J. NEsper .NET -Specific Information

This section provides information for NEsper .NET users.

System.Collections.IEnumerable and System.Collections.Generic.IEnumerable<T> are honored in most places where a collection would be taken.

In respect to DateTime differences, the baseline for CLR datetimes is 1/1/0001 12:00:00AM. DateTimes are converted to ticks and then to milliseconds.

Annotations are implemented using .NET attributes. Annotations must derive from System.Attribute and must use .NET attribute naming conventions e.g. @Hint is implemented as HintAttribute.

NEsper provides a lock manager that is configurable once per AppDomain: com.espertech.esper.compat.threading.LockManager is used for lock provision.

com.espertech.esper.compat.threading.ReaderWriterLockManager is used for RW lock management.

In NEsper there is a container that is provided or created during initialization.

DefaultReaderWriterLockManager rwLockManager = (DefaultReaderWriterLockManager) container.RWLockManager();

Once the application has the lock manager, it can set the DefaultLockTimeout property on it.

rwLockManager.DefaultLockTimeout = 1000000L;

The lock manager relies on a factory. The default factory can be overridden by setting the DefaultLockFactory property.

rwLockManager.DefaultLockFactory = (lockTImeout) => ...();

If the application would like to control this by type, it can register a specific lock factory for a given type.

rwLockManager.RegisterLockFactory(typeof(foo), (lockTimeout) => myCustomerLock());

There are no per-type lock timeouts.

com.espertech.esper.compat.threading.ThreadLocalManager is used for thread local management.

com.espertech.esper.util.EsperSectionHandler is provided to read Esper configuration from standard .NET configuration. It must be added as a configSection in order to be used.

For items not handled under the Esper configuration use com.espertech.esper.compat.CompatSettings. These are often applied for the entire AppDomain meaning they are effectively static for the container. These cover the following items:


Event classes provide accessors (getter methods) and mutators (setter methods) by means of auto-implemented properties or read write properties.

Below an example using auto-implemented properties:

class NewEmployeeEvent {
  public string FirstName { get; set; }
  public Address Address { get; set; }	
}

Below an example using read write properties:

class NewEmployeeEvent {
  private string firstName = "N/A";
  private Address address = 0;

  public string FirstName
  {
    get
    {
      return firstName;
    }
    set
    {
      firstName = value;
    }
  }

  public Address Address
  {
    get
    {
      return address;
    }
    set
    {
      address = value;
    }
  }
}

The case conversion is uppercase as dictated by .NET property conventions.

Mapped indexes are handled through the indexing operator.

For .NET the events can be represented by objects that implement the IDictionary interface.

XML events are represented by System.Xml and System.Xml.Linq.

Objects need to follow the .NET property conventions. Objects can follow modified conventions for Java-style accessors and mutators using Get and Set respectively.

There are no differences between Esper and NEsper in respect to basic concepts.

The data types are sbyte, byte, short, ushort, int, uint, long, ulong, float, double, decimal.

.NET uses ADO-based drivers to accomplish the same work.

NEsper exposes the Events events on EPStatement objects.

UpdateListener is replaced by UpdateEventHandler in .NET. Subscriber objects must implement the Update method or subscriber objects must be a delegate with an appropriate number of arguments.

The setSubscriber method is replaced with the Subscriber property. This property can take an object or a delegate.

Iterator is replaced with GetEnumerator. SafeIterator is replaced with GetSafeEnumerator.

In NEsper you can assign a delegate to a subscriber using lamba this way:

statement.Subscriber = new Action<TradeReportEvent, NesperTest>((a, b) => {
  Debug.Print("got here");
});

Listeners are replaced with UpdateEventHandlers, for example countStatement.Events += (sender, args) => { DoWork(); }.

When using internal timer (and not the application provided external time), please note:

Connections are obtained by selecting a DbDriver, which are a NEsper-construct.

Log4j is replaced by .NET Commons Logging.