Not logged in. · Lost password · Register
Forum: MatriX RSS
Biwax #1
Member since Feb 2012 · 2 posts
Group memberships: Members
Show profile · Link to this post
Subject: Clean architecture with MatriX

First congratulations for this wonderful library. I am considering using it in a project as this is the best library I've seen.

My question is more on how to use Matrix in an existing project than on how Matrix works. Since all operations in Matrix are done asynchronously (except if we use SendIqSynchronous), we would need to subscribe from the UI to a lot of events to know if the operation was successful (for some we don't care, like sending a message, however for others like creating a chat room, we want to know if the creation process was successful).
So in the end, we would have dozens of events like RoomCreated, RoomJoined, ParticipantStatusChanged, etc.
This design makes it difficult to execute a sequence of commands like: connect, join room enter room. We end up with a kind of state machine (at each step, the UI gets the next event).

So my question is: is there a way to have a clean design with such an aynchronous design? I didn't find the answer in the examples nor in this forum. So thank you if someone can explain me how to have a clean and efficient design.
Alex #2
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
There are many solutions.

So first XMPP is an asynchronous protocol, this is why I think working with the events makes sense. In some cases you need synchronous calls, in this case you can write an wrapper with AutoResetEvents or similar technologies with only some lines of code.

Many of our customers use their own wrappers around XmppClient and add their state machine there. In all my projects I use XmppClient directly without any wrappers.

For IQs its pretty easy. Every Iq packet must have a response. When using the IqFilter you can always define a callback for the result.

For Muc its also pretty easy and you don't need much events. In GUI projects I create always a user control for my complete chatroom. To this control I pass a reference to the XmppClient and a MucManager. Then I setup MessageFilter and PresenceFilter with either a BareJidComparer or FullJidComparer. Then I get only the presence and messages events which belong to this chat room in my user control object.

ParticipantStatusChanged: this is in your OnPresene handler then.
RoomJoined: this is also handled in the OnPresence event. When you join the room you get a presence of yourself which includes special status codes.

Or is your app more like a bot without any user interface?

I am always open to requests from users. And I am happy to add new classes and stuff when they make programming easier and produce code which is clean and easy to read.

Biwax #3
Member since Feb 2012 · 2 posts
Group memberships: Members
Show profile · Link to this post
Ok, thank you for your advices.

I think I will implement some state machines in my wrapper to hide complexity from the UI layer. I prefer to stick on events than having to manage threads and AutoResetEvents.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: MatriX RSS