Advanced programming


In the previous two chapters, the class ACRef<T> and the interface IACPoint<T> were explained.

ACRef<T> provides a one-way reference to an ACComponent instance.

The PAPoint class that implements IACPoint<T> can store multiple PAEdge instances in the ConnectionList property. The PAEdge class, in turn, represents a two-way connection between two connection points (indirectly two components).

With these means you can now store several two-way relationships in a list - but only between instances from the same application domain!

In concrete terms, this means that the two points (or ACComponent instances) need to know each other - regardless of whether an instance of it is a real or proxy instance. A relationship to an unknown instance from another application domain cannot be mapped with this technique. This is where so-called service points come into play.

A concrete example is that a user on machine A uses a business object (open program in the tab) that wants to receive events from a real instance (server side) that runs on machine B. The server-side instance cannot know the client's memory space (machine A) or the business object instance (because it can be open multiple times, for example). In addition, many other clients may also be interested in the event of this server-side instance.

Before we delve into the event points that will be covered in the next chapter, let's first look at the

(blue dotted frame):

 

IACPointNetServiceObject<T> inherits from two interfaces:

  1. IACPointNet<T, W> - A network-capable IACPoint<W> that is able to transfer its ConnectionList property over the network.
  2. IACPointNetService<T, W>, that represents a "service point". A service point provides a service for its ConnectionList entries in the abstract sense. This interface is also the basis for providing Events and asynchronous methods.

The ACPointServiceACObject class implements IACPointNetServiceObject<T>. ACPointServiceACObject-instances allow components to provide a service where consumers can enter tasks in the ConnectionList that the component works through. Consumers (components from the same or a remote application domain) cannot populate the ConnectionList directly, but need the IACPointNetClientObject interface:

IACPointNetClientObject<T> inherits from two interfaces:

  1. IACPointNet<T, W> - A network-capable IACPoint<W> that is able to transfer its ConnectionList property over the network.
  2. IACPointNetClient, which represents a "client point". In the abstract sense, a client point represents a consumer who uses service points. This interface is also the basis for subscribing events and calling asynchronous methods.

The ACPointClientACObject class implements IACPointNetClientObject<T>.


The following code shows an example of how to use the ACPointServiceACObject class. This service point is used in a component that is intended to represent a machine. The machine can only be used or reserved by a consumer or worker at one point. Therefore, above the definition of the MappingServicePoint property, the ACPropertyPoint attribute class with a capacity of "1" was declared:

 

By setting the SetMethod delegate with the OnSetMappingServicePoint method, the method is called whenever a new entry has been made to the ConnectionList of the service point. In the example above, the ConnectionList can contain only one item because it was limited by limit = "1".


The consumer, on the other hand, who wants to occupy the machine exclusively for himself, uses ACPointClientACObject by calling the AddToServicePoint() method. RemoveFromServicePoint() removes the reservation:

 

The AddToServicePoint() method returns an ACPointPointWrapObject<ACComponent> instance with a state of PointProcessingState.Accepted if the service point has accepted this request. The ACPointNetWrapObject<ACComponent> instance is in both ConnectionList (both service point and client point). Please note that you cannot compare ACPointNetWrapObject<ACComponent> instances with the "==" equality operator because network transfers (in the background) give them new memory addresses. You can make a comparison by using the CompareTo() method or by comparing the RequestID property.