Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Papyrus for Real Time » Access message recipients programmatically(Using EMF )
Access message recipients programmatically [message #1752111] Wed, 18 January 2017 22:35 Go to next message
John Dawes is currently offline John DawesFriend
Messages: 19
Registered: November 2016
Junior Member
Hi,

I am working in the developer version of Papyrus-RT. As part of my project, I am trying to figure out programmatically what a 'Port' instance is connected with. The bigger picture of my goal is to find out the recipients of a message signal in the code level. For example, let us consider the following message sending statement:

portA.msg().send();

Using the EMF tool, I am trying to figure out what are the possible recipients of the signal that is sent through the 'portA' protocol role. I am stuck here for a while and will highly appreciate any help in this regard.


John
Re: Access message recipients programmatically [message #1752630 is a reply to message #1752111] Wed, 25 January 2017 16:33 Go to previous messageGo to next message
Peter Cigehn is currently offline Peter CigehnFriend
Messages: 49
Registered: September 2014
Member
Hi,

I am not sure that I can provide detailed information about which API calls to use to achieve this, but I could at least give some input to how I see what conceptually needs to be done:

1) Locate all capsule parts in the model that is typed by the capsule with the port of interest. Since there is no direct reference from the capsule to the capsule part which by it is typed, you need to search the model or use some cross-reference mechanism. I hope that someone else can give a hint how this is best achieved programmatically.
2) For each of those capsule parts you need to traverse any delegation connector connected to that port on the capsule part.
3) At the other end of the connector you will now find relay port on the capsule and you can now go back to step 1 and repeat the process of traversing the delegation connectors "going outside".
4) Eventually at step 2 you will locate an assembly connector, i.e. a connector between port on two capsule parts. Now you need to start "going inside" instead.
5) If the capsule typing the capsule part is a relay port and it has a delegation connector, then locate the port on the capsule part at the other end of this delegation connector.
6) Now repeat step 5 again until you locate a behavior port, instead of a relay port. You have now located a potential receiver of the message sent on the port that you started this traversal.

I hope that this gives you at least some idea about what you need to do on a higher conceptual level. If you have more detailed questions, please ask, and hopefully I or someone else can fill in the details if needed.

/Peter Cigéhn
Re: Access message recipients programmatically [message #1752638 is a reply to message #1752111] Wed, 25 January 2017 17:05 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 438
Registered: March 2011
Senior Member
Are you working directly with a UML model element in your code, or with an xtumlrt model element (the latter is the code generator's intermediate representation)?

Also, in your code do you have a reference to what type of model element? A capsule that contains the port in question, a capsule part that has the port role (or port instance)? Something else?
Re: Access message recipients programmatically [message #1752646 is a reply to message #1752638] Wed, 25 January 2017 17:46 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 438
Registered: March 2011
Senior Member
Rereading the original post it looks like you have access to the port role (i.e. the instance of the port in a part).

Assuming that you are working with a UML element, you can get the recipients as follows: a port role is represented in UML as a ConnectorEnd. A ConnectorEnd is owned by a Connector (itself owned by a Capsule) and has two references: "partWithPort" and "role". The "partWithPort" points to the part that owns the "port role", while the "role" points to the actual port owned by some other capsule.

So suppose you have a model like this (using our textual syntax for UML-RT, which will hopefully be self-explanatory):

model M
{
    protocol P {}
    capsule A
    {
        port p : P;          // (1)
    }
    capsule B
    {
        conjugate port q : P;
    }
    capsule Top
    {
        part a : A;
        part b : B;
        connect a:p to b:q;      // (2)
    }
}


In this syntax, you see a connector in (2) with two ConnectorEnds: a:p and b:q. The first one has partWithPort == a and role == p. So p must be a port in the (Capsule) type of part a, and you can see that in line (1). Similarly, b:q has partWithPort == b and role == q.

So if you have access to a ConnectorEnd, you can get its owner, the Connector, which has a list "ends" of size 2 (in UML-RT it's always 2, in general UML, it can be larger than 2). You can use this to get the other connector-end.

In Java, this could be something like this

	ConnectorEnd getOtherEnd(ConnectorEnd element) {
		Connector conn = (Connector)element.getOwner();
		int elementIndex = conn.getEnds().indexOf(element);
		int otherEndIndex = elementIndex == 0 ? 1 : 0;
		return conn.getEnds().get(otherEndIndex);
	}


Once you have the other end of the connector, you can navigate to the part or to the port, and via either of them, to the capsule:

getOtherEnd(element).getPartWithPort().getType()


or

getOtherEnd(element).getRole().getOwner()


I hope this helps.
Re: Access message recipients programmatically [message #1752756 is a reply to message #1752646] Thu, 26 January 2017 21:48 Go to previous messageGo to next message
John Dawes is currently offline John DawesFriend
Messages: 19
Registered: November 2016
Junior Member
Hi Peter & Ernesto,

Thank you very much for your replies. I followed the following steps to retrieve it:

1. I get the type of the port; the port is typed by the corresponding Protocol
2. Then I checked if the port is conjugated or not.
3. Having these information, I traversed through all the capsules in the model and look for ports that are typed by the same protocol and that have a conjugation status that is opposite to the one in step 2
4. Finally I retrieved the owner capsule of the ports. And, this gives me the list of possible recipients of the sent message signal.

As I am working with uml-rt models and uml-rt only supports two roles: base and conjugate, I hope my approach would work fine. Please let me know if you think this approach may go wrong in certain scenarios.

Re: Access message recipients programmatically [message #1752758 is a reply to message #1752756] Thu, 26 January 2017 22:01 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 438
Registered: March 2011
Senior Member
Hi John. So you have actually a Port to start your search, rather than a Port instance (role)?

In that case, then yes, your approach seems feasible, but of course that gives you only a list of *candidates*. And that's natural because when you have a reference to a Port, you are referring to a *definition*, as opposed to a point of use or instance (e.g. a "port in a capsule part"). And of course, a definition can be used in many different contexts, so at the point of definition you do not know who are all the possible recipients. That's why you need to traverse the model.

My previous reply assumed that you had a reference to the port in a part, rather than the port itself. In that case, as indicated, it is rather easy to get to the other end of a connector.

Two comments:

1) When you talk of "the owner of the capsule of the ports" sounds that you are using "capsule" to refer to a *capsule part*, i.e. a property whose type is a Capsule, or in other words the point of use of a Capsule, where you have Capsule instances, whereas a "Capsule" is the definition of the Capsule type itself. Just want to make sure the terminology is clear.

2) It's OK to look for conjugated ports, but beware that you may be missing a special case: symmetric protocols: a symmetric protocol is a protocol where all messages are "inout". In that case, it is possible to connect two ports of the same conjugation.


Re: Access message recipients programmatically [message #1752797 is a reply to message #1752758] Fri, 27 January 2017 12:15 Go to previous messageGo to next message
Peter Cigehn is currently offline Peter CigehnFriend
Messages: 49
Registered: September 2014
Member
Hi John,

As Ernesto pointed out, your approach only gives potential receivers, since you are not traversing any connectors in the model (as I tried to describe in my post). If you really want to make sure, then you should traverse all delegation connectors "going outside" until you find the assembly connector and the traverse all delegation connectors "going inside" until you reach the final behavior port again. But sure, if the port you have is an SAP or an SPP, then you're approach is perfectly okay, since an SAP/SPP is unwired (isWired = false) and never have a connector and the communicatoion is established based on a name based approach, i.e. an SAP is connected to the SPP registered with the same name.

But if the port that you are starting your traversal at is a wired port (isWired = true), then you should really follow the connectors in the model as I tried to describe, to find the (behavior) port(s) in the other end of that chain of connectors to truly locate the intended receiver.

Regarding the conjugation aspect, the tooling in Papyrus-RT should give you guidance to ensure that the conjugation of the ports always are correct when you create a connector, i.e. ports at the ends of a delegation connector always have the same conjugation, and ports at the ends of an assembly connector always have the opposite conjugation. Ernesto mentions the special case of symmetrical protocols, but personally I find that special case to be a bit too "theoretical". In practice >I would recommend that you should always follow those simple rules delegation connector -> same conjugation, assembly connector -> opposite conjugation, since those rules always works disregarding if the protocol is symmetrical or asymmetrical.

/Peter Cigéhn
Re: Access message recipients programmatically [message #1752861 is a reply to message #1752797] Mon, 30 January 2017 01:10 Go to previous messageGo to next message
John Dawes is currently offline John DawesFriend
Messages: 19
Registered: November 2016
Junior Member
Thank you guys! Your responses were really helpful.

Ernesto, just to be confirmed about my understanding, when you mention about the term "Port role", do you mean "Protocol role"? Or, are they two different terminologies? The way I understand it, in uml-rt, a protocol can have two roles: base and conjugate. And, a port is an instance of one of these roles. So, a port instance is represented by a protocol role. Please let me know if I get anything wrong here.
Re: Access message recipients programmatically [message #1752873 is a reply to message #1752861] Mon, 30 January 2017 08:07 Go to previous messageGo to next message
Peter Cigehn is currently offline Peter CigehnFriend
Messages: 49
Registered: September 2014
Member
John Dawes wrote on Mon, 30 January 2017 01:10

Ernesto, just to be confirmed about my understanding, when you mention about the term "Port role", do you mean "Protocol role"? Or, are they two different terminologies? The way I understand it, in uml-rt, a protocol can have two roles: base and conjugate. And, a port is an instance of one of these roles. So, a port instance is represented by a protocol role. Please let me know if I get anything wrong here.


What Ernesto refers to as "port role" is the aspect of ports on capsule parts, where you must distinguish between the same port being available on different capsule parts.

Unfortunately this is a bit confusing since the UML 2.X meta-model does not have a concept of "port role". In an older legacy version of UML-RT (used in Rose RealTime), which were based on UML 1.X, it existed a "port role" concept, where each capsule part (or "capsule role" as it was called back then) had a number of "port roles" which were the "projection" of the corresponding port on the capsule used for typing the capsule part.

In UML 2.X this was simplified/changed and there are no longer a "port role" on the capsule part. But to be able to distinguish between the same port on different capsule parts, it has instead become responsibility of the connector end, and thus it now have two references, the "role" which references the port (as owned by the capsule), and the "partWithPort" which references the specific capsule part (typed by the capsule).

In this way the connector end unambiguously can reference a port on a specific capsule part, even though the same port can be available on another capsule part (typed by the same capsule or possibly a subclass capsule).

I hope this clarifies this about "port role". Personally though, I think that we shall stay away from talking about "port role" since that concept no longer exist in the UML 2 meta-model which UML-RT is based on. It is better to talk about the connector end and how it distinguishes between (potentially the same) port on different capsule parts.

/Peter Cigéhn
Re: Access message recipients programmatically [message #1752912 is a reply to message #1752873] Mon, 30 January 2017 15:25 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 438
Registered: March 2011
Senior Member
Indeed, Peter's description is what I was referring to.

Basically it's the difference between the definition of an element and it's point of use. To make an analogy with Java, you could declare a method in a class, and that would be it's definition, but a call to that method, its point of use, would be a "method role" (if we invented such terminology).

As Peter points out, and what I explained in my original solution was that a UML ConnectorEnd is the element that represents a Port role, i.e. the "projection" of the port in a part in some other context.

The "Protocol roles" of base and conjugated are a different aspect.
icon14.gif  Re: Access message recipients programmatically [message #1753003 is a reply to message #1752912] Wed, 01 February 2017 03:40 Go to previous message
John Dawes is currently offline John DawesFriend
Messages: 19
Registered: November 2016
Junior Member
Thank you guys for the clarification.
Previous Topic:list of RTS services?
Next Topic:Model validation error
Goto Forum:
  


Current Time: Tue Dec 10 09:34:34 GMT 2024

Powered by FUDForum. Page generated in 0.04521 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top