Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3a946c1ce3f645222b0d2050d7061fa541beff1e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
RoomModel room.basic.service.logging {
	
	import room.basic.types.java.* from "JavaTypes.room"
	
	ActorClass ALogService {
		Interface {
			SPP log: Log
		}
		Structure {
			usercode1 {
				"import java.io.*;"
				"import java.util.*;"
			}
			usercode2 {
				"FileOutputStream file = null;"
				"PrintStream p = null;"
				"static long tStart = System.currentTimeMillis();"
			} ServiceImplementation of log
		}
		Behavior {
			Operation destroyUser() {
				"if (p!= null) {"
				"p.flush();"
				"p.close();"
				"p=null;"
				"}"
			}
			StateMachine {
				Transition init: initial -> closed { }
				Transition open: closed -> opened {
					triggers {
						<open: log>
					}
					action {
						"Date d=new Date(tStart);"
						"try{"
						"file=new FileOutputStream(fileName);"
						"p=new PrintStream(file);"
						"p.println(\"Log opened at \"+ d.toString());"
						"p.println(\"--------------------------------------------------\");"
						"} catch (Exception e){"
						"System.out.println(\"Log file not opened !\");"
						"}"
					}
				}
				Transition tr0: opened -> closed {
					triggers {
						<close: log>
					}
					action {
						"p.flush();"
						"p.close();"
						"p=null;"
					}
				}
				Transition tr1: opened -> opened {
					triggers {
						<internalLog: log>
					}
					action {
						"p.println(\"Timestamp: \" + Long.toString(data.timeStamp-tStart) + \"ms\");"
						"p.println(\"SenderInstance: \"+ data.sender);"
						"p.println(\"UserString: \" + data.userString);"
						"p.println(\"--------------------------------------------------\");"
						"System.out.printf(data.userString);"
					}
				}
				State closed
				State opened
			}
		}
	}

	ProtocolClass Log {
		incoming {
			Message open(fileName: string)
			Message close()
			private Message internalLog(data: InternalLogData)
		}

		conjugate PortClass {
			usercode {
				"public static final int LOG_LEVEL_LOW = 1;"
				"public static final int LOG_LEVEL_MEDIUM = 2;"
				"public static final int LOG_LEVEL_HIGH = 3;"
				"static int logLevel=0;"
				"InternalLogData d = new InternalLogData();"
			}
			Operation setLogLevel(l: int32) {
				"logLevel=l;"
				"if (logLevel > LOG_LEVEL_HIGH) logLevel=LOG_LEVEL_HIGH;"
			}
			Operation log(logLevel: int32, userString: string) sends internalLog {
				"long s;"
				"if (logLevel>this.logLevel){"
				"d.userString=userString;"
				"d.timeStamp=System.currentTimeMillis();"
				"d.sender=getInstancePath();"
				"if (getPeerAddress()!=null)"
				"getPeerMsgReceiver().receive(new EventWithDataMessage(getPeerAddress(), IN_internalLog, d));"
				"}"
			}
		}
	}

	DataClass InternalLogData {
		Attribute userString: string
		Attribute sender: string
		Attribute timeStamp: int64
	}

}

Back to the top