Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3b1d70dbda8aaf2c68e593aad1d8bccad532cb06 (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
113
114
115
116
117
118
119
120
121
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 {
						"long s = Long.valueOf(data.timeStamp);"
						"p.println(\"Timestamp: \" + Long.toString(s-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 setLogLevel(l: int32)
			Message close()
			Message log(data: LogData)
			Message internalLog(data: InternalLogData)
		}
		outgoing { }
		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();"
			}
			handle setLogLevel {
				"logLevel=l;"
				"if (logLevel > LOG_LEVEL_HIGH) logLevel=LOG_LEVEL_HIGH;"
			}
			handle log {
				"long s;"
				"if (data.logLevel>this.logLevel){"
				"d.userString=data.userString;"
				"s=System.currentTimeMillis();"
				"d.timeStamp=Long.toString(s);"
				"d.sender=getInstancePath();"
				"if (getPeerAddress()!=null)"
				"getPeerMsgReceiver().receive(new EventWithDataMessage(getPeerAddress(), IN_internalLog, d));"
				"}"
			}
		}
	}

	DataClass LogData {
		Attribute logLevel: int32
		Attribute userString: string
	}

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

}

Back to the top