Data synchronization between objects using the Publish/subscribe design pattern (ii)

Source: Internet
Author: User
Tags message queue ibm mq
Object | design | data | Data synchronization during the registration process, Subscriber is assigned a unique tag to identify subscriber in event channel. Event channel also uses this tag to index those subscriber. Although the sample application is used as a clutter-pulse jamming code for marking targets, I recommend using another method in your own program to produce a unique identifier (for example, generating a GUID).

Use the Directory menu to create 3 to 4 frmlist window instances. Create 3 or 4 instances of frmlist using the New Catalog menu option, then select an entry in one of the Windows, double-click the entry to enter editable mode, and type a new name. The form creates an event that describes the update of the data and sends it via event channel.

Private Sub Lvwlist_afterlabeledit (ByVal sender as _ Object,
ByVal e As _ System.Windows.Forms.LabelEditEventArgs) _
Handles Lvwlist.afterlabeledit
Dim Objevent as Clsdataevent
If e.label <> "" Then
objevent = New clsdataevent ()
With objevent
. Name = "Namechanged"
. Value = E.label
. Extradata = Lvwlist.items (E.item). Tag
. Origin = Me
End With
MyBase.EventChannel.PublishEvent (objevent)
End If
End Sub
The form that sends the event confirms that it is the founder of the event and sets the Origin property of the Clsdataevent class to itself. This can block other unwanted events to ensure that the event that the sender receives is already published. Finally, the publisher of the event noticed the change in the data.

All Subscribers will receive the event. In Eventapp, instances of each frmlist receive events and change the changed items in each listview:

Public Overrides Sub Eventraise (_ ByVal Newevent as _
Eventapp.clsevent)
Dim Objlistitem as ListViewItem

Select Case Newevent.name
Case "Namechanged"
For each objlistitem in Lvwlist.items
If Objlistitem.tag = Newevent.extradata Then
Objlistitem.text = Newevent.value
End If
Next
Case Else
' Handle other events
End Select
End Sub

This type of event system will give you a lot of flexibility. You can make any one in the application
Object publishes events, only those objects of interest to the updated information. can also change the event
Channel classes can be implemented by using a Web service or messaging system such as MS
Message Queue or IBM MQ series, sending events through the HTTP coprocessor.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.