• Aucun résultat trouvé

Modeling Reusable Concurrent Passive Entity Objects in Colored Petri Nets

N/A
N/A
Protected

Academic year: 2022

Partager "Modeling Reusable Concurrent Passive Entity Objects in Colored Petri Nets"

Copied!
6
0
0

Texte intégral

(1)

Colored Petri Nets

Rowland Pitts and Hassan Gomaa

George Mason University, Fairfax, Virginia, USA {rpitts,hgomaa}@gmu.edu

Abstract. Concurrent software systems are growing increasingly large and complex; the risks associated with poor design and architectural choices are increasing as well. Building executable prototypes can help identify problems early and Colored Petri Nets are well suited to this purpose. This paper presents an approach to modeling reusable thread- safe passive entity objects in Colored Petri Nets, including public, private and static members, plus encapsulation and object composition.

Keywords: colored Petri nets, concurrency, rapid prototyping, passive entity object.

1 Introduction

Concurrent software systems are growing increasingly large and complex. Con- sequently, the risks associated with poor design and architectural choices are increasing as well. Assembling executable models can help to identify problems early, and Colored Petri Nets (CPN) [9] are well suited for building executable concurrent software models; additionally, the language primitives facilitate the modeling of reusable design pattern templates [7], as well as the passive entity objects they interact with.

In spite of the fact that failure is increasingly expensive [1], often little con- sideration is given to system performance or reliability until a project is already implemented; unplanned behavioral analysis is typically inefficient, unreliable and difficult to repeat [12].

CPNs routinely depict concurrent software systems as tokens moving through a series of operations (transitions), sequentially or navigating control structures, analogous to dynamic flow charts. This paper introduces an approach to mod- eling thread-safe objects, with an emphasis on object-oriented properties, such as information hiding, providing a public interface of operations, and reusability using CPN Tools [5].

This paper is organized as follows: Section 2 discusses related work, Section 3 introduces the modeling approach and Section 4 provides validation. Section 5 discusses conclusions and future work.

(2)

2 Related Work

There is much literature devoted to the analysis of concurrent software with CPNs, and some related to object modeling.

Bauskar and Mikolajczak modeled objects using CPN’s hierarchical capabil- ities [3]. Jensen and Kristensen have examined reusability using CPNs hierarchi- cal capabilities [9]. Costa and Gomes propose module replication, composition and defining interfaces [4]. Barros and Gomes discuss transitions as functions with input parameters and also the creation and destruction of objects [2]. Pettit, Fant and Gomaa have modeled behavioral design patterns and communication templates, including threads-of-control [7, 12, 11]. Lakos introduces Object Petri Nets, which incorporate inheritance, polymorphism, dynamic binding, and in- clude a single class hierarchy of both token and subnet types [10]. The Reference Net Workshop supports object references as tokens [13].

This paper focuses on combining a number of object-oriented properties while modeling concurrent objects, such as information hiding, providing a public in- terface of operations, static variables and operations, and reusability, as well as modeling threads-of-control by which a client can animate passive entity objects as needed.

3 Object Modeling in CPN

toString Out

STRING Out TS Outout

CTRL Out P

Outout CTRL Out

TS Inin

CTRL In

GN Inin

CTRL In GA

Inin CTRL In P

Inin CTRL In

GN Outout

CTRL Out nameIn

In STRING In

ageIn In

INT In

GA Outout

CTRL Out

age INT name STRING

setAge In

INT In

setName In

STRING In Const-

ructed

Person() setAge() toString() setName()

ctrl ctrl

ctrl ctrl

n a

a a1 a

n

ctrl ctrl

a

n^" Age:"^INT.mkstr(a)

n n1

n

ctrl

a ctrl n

Fig. 1.Person class definition in CPN.

3.1 Design Conventions

CPNs are not inherently object-oriented; however, the language primitives allow for almost infinite flexibility. To the extent that visual structure aids in conveying a designer’s intent, the following conventions, illustrated in Figure 1, are utilized for object modeling. The behavior otherwise modeled in Figure 1 is discussed in more detail in the next subsection.

(3)

Input and Output Parameters are depicted across the bottom of their class diagrams, grouped by operation, and indicated by a double-line, as opposed to a single line. This includes threads-of-control, which determine the sequence in which modeled operations execute. Placing tokens into the input places, and retrieving tokens from the output places, is the means by which clients commu- nicate with objects.

Operations comprising a class’ public interface are represented as transitions just above, and connected by arcs to, their respective inputs and outputs. Model- ing operations as transitions works well for multiple reasons: transitions perform conversions, and CPN Tools’ hierarchical capabilities facilitate the creation of reusable objects that effectively enforce communication through the defined pub- lic interface and otherwise prevent access to an object’s non-public members.

Instance Variables are depicted as places in the space above the public in- terface operations, or as objects as described herein, and are maintained by the public operations or by other internal functions.

3.2 A Simple Class Example

Figure 1 is the class definition for a simple Person class. Two places near the top represent instance variables for age and name. Four public operations are provided: Person(), setAge(), toString() and setName(), and each is rep- resented by a transition. Their various inputs and outputs are represented by places across the bottom.

Concurrency: No two operations can simultaneously access an object’s val- ues. No operation can execute until the constructor has been initially executed.

Furthermore, the constructor cannot re-execute after the object is created.

Encapsulation: When used, a Person object’s data elements and functionality are encapsulated within the object, providing the client with only indirect access through the defined public operations. An example Employee object is depicted in the uppermost region of Figure 2.

Reusability: Any number of Person objects may be used within a CPN.

3.3 A More Complex Example

Figure 2 represents an Employee class definition, which features a composed ob- ject (Person1), a static variable (employeeCount) and associated static accessor method (getCount()), and a meta-variable (lock) used for synchronization. Em- ployee also includes a constructor (Employee()) and a toString() operation.

(4)

Given the relative complexity of this example, representing an operation with a single transition is insufficient. Treating these as atomic actions would result in the thread-of-control being released to the client prematurely, and potentially cause concurrency issues. Therefore, an inbound transition fires to initiate the behavior sequence, and a return transition fires when the process is complete, releasing the thread-of-control and return values at the appropriate time.

For simplicity, a minimal number of operations have been modeled; however, more could easily be added. For example, setAge() and setName() could be added, and connected to the otherwise unused equivalents inPerson1.

lock emp

ID INT

TS out

CTRL person

toString STRING TS

in CTRL CP

out CTRL CP

in CTRL person

name STRING person

age INT employee

Count Static

INT 0

GA in CTRL

setAge In INT

GA out CTRL

GN out

CTRL

setName In

STRING

GN in CTRL

E Inin

CTRL In

TSe Outout

CTRL Out E

Outout CTRL Out Num

Emp's Out

INT Out

toString Employee Out

STRING Out C'tor

Employee In Age

INT In GC Outout

CTRL Out

TSe Inin

CTRL In C'tor

Employee In Name

STRING In GC

Inin CTRL In

getCount() Employee() Constructor

Return toString() toString

Return Person1

Person Person

c a

c+1 ctrl ctrl

ctrl

c+1 n ctrl

ctrl ctrl ctrl

c str^" ID:"

^INT.mkstr(id) ctrl a

ctrl ctrl n

c id

Const- ructed

str Static

Fig. 2.Employee class definition, with composed Person object and static members.

Concurrency: The Employee class employs a more explicit locking mechanism.

When the constructor executes, a token is moved to thelock place. To ensure mutually exclusive access, each instance-method must acquire the lock before executing and return it when finished [8]. Therefore, no two can execute simul- taneously (given the scope of this short paper, only one such method is depicted, but any additional methods would acquire and release the lock token in the same way). Non-static methods cannot execute until the constructor has been invoked to create the object, and the constructor cannot re-execute once the object is created.

(5)

Encapsulation: An Employee object’s data elements, including a Person ob- ject, and functionality are encapsulated. Employee provides only indirect access to itself through the defined public operations.

Reusability: Any number of Employee objects may be used within a CPN;

additionally, each Employee object also re-uses a Person object.

Static Behavior: TheemployeeCountplace is effectively made static by defin- ing it as a fusion place, facilitated by CPN Tools. Its initial marking is zero (simulating an initialized value), and is incremented each time an instance of Employee’s constructor is invoked. The value in the fusion place is shared by all instances of Employee; therefore, invoking the getCount() method in any instance of Employee will return the same value.

4 Validation

The limited length of this short paper permits only a brief description of the validation carried out; however, tests were conducted to determine that each modeled object’s operations execute correctly and that the synchronization con- siderations ensure that there is no detrimental conflict for shared data. A unit testing approach was employed, because it offers “the most effective means to test individual software components for boundary value behavior" [6]. Figure 3 is a depiction of one such test scenario

P in CTRL ageIn

INT nameIn

STRING P out CTRL

GA in CTRL

GA out

CTRL GN

in CTRL

GN out

CTRL setName

STRING

TS in CTRL

TS out CTRL toString STRING setAge

INT

setup Age

INT 25

setup Name

STRING

"JohnDoe"

new Age

INT 50

new Name

STRING

"JaneDoe"

ToC CTRL

1

Output STRING

ToC CTRL TestPerson

Person Person

Create Person

Invoke setAge

Invoke setName

Invoke toString

Observe Output

a n

a n ctrl ctrl ctrl

a a

n

n ctrl

ctrl

ctrl

n

n ctrl

ctrl ctrl ctrl

Fig. 3.Unit test of a Person object.

For clarity, the object under test, including the input and output places associated with its public operations, is depicted with bolder lines. The elements otherwise associated with the testing operations are depicted normally.

(6)

Test Scenario: From left to right in Figure 3, a Person object is created, after which the setAge() and setName()operations are invoked. Finally, the toString() operation is invoked in order to observe the expected output.

5 Conclusions and Future Work

Objects can be effectively modeled with CPNs, as shown in the examples above.

The unit tests conducted confirm that they perform as expected. Modeling single- and multithreaded active objects is the logical next direction related to this short paper. Modeling inheritance would pose an interesting challenge as well.

This work is part of a larger project to model concurrent distributed appli- cations and middleware. The ultimate goal of the overarching research effort is to provide a suite of executable architectural components and communications templates for a variety of software design patterns.

References

1. Ammann, P., Offutt, J.: Introduction to Software Testing. Cambridge University Press (2016)

2. Barros, J.P., Gomes, L.: On the Use of Coloured Petri Nets for Object-Oriented Design, pp. 117–136. Springer Berlin Heidelberg, Berlin, Heidelberg (2004) 3. Bauskar, B.E., Mikolajczak, B.: Abstract node method for integration of object

oriented design with colored Petri nets. In: Third International Conference on Information Technology: New Generations (ITNG’06). pp. 680–687 (April 2006) 4. Costa, A., Gomes, L.: Module composition within Petri nets model-based devel-

opment. In: 2007 International Symposium on Industrial Embedded Systems. pp.

316–319 (July 2007)

5. CPN Tools website (May 2017),http://cpntools.org

6. Ellims, M., Bridges, J., Ince, D.C.: Unit testing in practice. In: 15th International Symposium on Software Reliability Engineering. pp. 3–13 (Nov 2004)

7. Fant, J.S., Gomaa, H., Pettit, R.G.: A comparison of executable model based approaches for embedded systems. In: 2012 Second International Workshop on Software Engineering for Embedded Systems (SEES). pp. 16–22 (June 2012) 8. Gomaa, H.: Real-Time Software Design for Embedded Systems. Cambridge Uni-

versity Press (2016)

9. Jensen, K., Kristensen, L.M.: Colored Petri nets: A graphical language for formal modeling and validation of concurrent systems. Commun. ACM 58(6), 61–70 (May 2015)

10. Lakos, C.: Object Oriented Modelling with Object Petri Nets, pp. 1–37. Springer Berlin Heidelberg, Berlin, Heidelberg (2001)

11. Pettit, R.G., Gomaa, H., Fant, J.S.: Modeling and prototyping of concurrent soft- ware architectural designs with colored Petri nets. In: International Workshop on Petri Nets and Software Engineering. pp. 67–79 (2009)

12. Pettit, R.G., Gomaa, H.: Modeling behavioral design patterns of concurrent ob- jects. In: Proceedings of the 28th International Conference on Software Engineer- ing. pp. 202–211. ICSE ’06, ACM, New York, NY, USA (2006)

13. The reference net workshop website (May 2017),http://www.renew.de

Références

Documents relatifs

For this thesis, a colored Petri net N is defined as N = (P, T, A, C, V, a) where: (P, T, A) is a Petri-net structure; C is a set of attributes called colors; V is a set of

In timed nets [65], [70], [83], firing times are associated with transitions, and transition firings are real–time events, i.e., tokens are removed from input places at the beginning

Fig.19 shows one of possible Petri net models for such a tool with a dual–blade robot; the double use of chamber 2 in each cycle is represented by two unload/load transitions (t 2a

THROUGHPUT IN TIMED COLORED NETS Intuitively, throughput of a place color (p, c) in a timed net T is equal to the average number of (colored) tokens entering (or leaving) the place p

To verify the reachability of the previously given marking (h1 + 2 + 2i.Send), the backward reacha- bility analysis is performed using the inverse CPN, illustrated in Fig.8.. Those

- Level 3 provides a complete solution for train localization (calculated onboard using Eurobalises also and transmitted by radio to trackside equipments) transmission of move-

In this paper we present mcc, a tool designed for the single task of un- folding the models of High-Level Petri nets, given in the PNML syntax, into equivalent Place/Transition

ABSTRACT: This paper deals with a formal method for the study of the backward reachability analysis applied on Colored Petri Nets (CPN). The proposed method proceeds in two steps :