update a display jade object manager sysnotify endnotification beginnotification share price change...

14
Update a Display JADE Object Manager sysNotify endNotification BeginNotification Share price change $1.25 Brier ley (userNotify) (causeEv ent)

Upload: emery-lyons

Post on 29-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Update a Display JADE Object Manager sysNotify endNotification BeginNotification Share price change $1.25 Brierley (userNotify) (causeEve nt)

Update a Display

JADEObjectManager

sysNotify

endNotification

BeginNotification

Sharepricechange

$1.25Brierley

(userNotify)

(causeEvent)

Page 2: Update a Display JADE Object Manager sysNotify endNotification BeginNotification Share price change $1.25 Brierley (userNotify) (causeEve nt)

beginNotification

Process Communication

JADEObjectManager

userNotify

causeEventsystem

or a shared transient

object

process 1

process 2

(endNotification)

Page 3: Update a Display JADE Object Manager sysNotify endNotification BeginNotification Share price change $1.25 Brierley (userNotify) (causeEve nt)

Subscribing

• Object– specific object

for example, notify if Brierley price changes

– use beginNotification and endNotification

• Class– all objects in a class (or subclass)

for example, notify if any share price changes

– use beginClassNotification and endClassNotification

Page 4: Update a Display JADE Object Manager sysNotify endNotification BeginNotification Share price change $1.25 Brierley (userNotify) (causeEve nt)

System Notification

eventType - 0 (Any_System_Event)

- 3 (Object_Update_Event)

- 4 (Object_Create_Event)

- 6 (Object_Delete_Event)

theObject - Persistent object that was updated, created or deleted

eventTag - Integer specified in the beginNotification

or beginClassNotification

Note: System events are only available for persistent objects

sysNotify (eventType, theObject, eventTag)

Page 5: Update a Display JADE Object Manager sysNotify endNotification BeginNotification Share price change $1.25 Brierley (userNotify) (causeEve nt)

JADEObjectManager

sysNotify

endNotification

beginNotification

Sharepricechange

$1.25Brierley

Example - sysNotify

1

4

2

3

Page 6: Update a Display JADE Object Manager sysNotify endNotification BeginNotification Share price change $1.25 Brierley (userNotify) (causeEve nt)

load() updating;begin

self.beginClassNotification(Share, false, Object_Update_Event, Response_Continuous, 0);end; // Share Watch form

load() updating;begin

self.beginClassNotification(Share, false, Object_Update_Event, Response_Continuous, 0);end; // Share Watch form

sysNotify(eventType : Integer; theObject : Object; eventTag : Integer) updating; begin

app.msgBox(theObject.Share.name & " has changed", "Notification Message", MsgBox_OK_Only);

end; // Share Watch form

sysNotify(eventType : Integer; theObject : Object; eventTag : Integer) updating; begin

app.msgBox(theObject.Share.name & " has changed", "Notification Message", MsgBox_OK_Only);

end; // Share Watch form

unload() updating;begin

self.endClassNotification(Share, false, Object_Update_Event);end; // Share Watch form

unload() updating;begin

self.endClassNotification(Share, false, Object_Update_Event);end; // Share Watch form

1

3

4

Example - sysNotify

Page 7: Update a Display JADE Object Manager sysNotify endNotification BeginNotification Share price change $1.25 Brierley (userNotify) (causeEve nt)

User Notification

eventType - 16 to 232 -1 corresponding to integer

specified in the causeEvent method

theObject - Object causing the notification

eventTag - Integer specified in the beginNotification

or beginClassNotification method

userInfo - Primitive value or object reference

specified in causeEvent method

userNotify (eventType, theObject, eventTag, userInfo)

Page 8: Update a Display JADE Object Manager sysNotify endNotification BeginNotification Share price change $1.25 Brierley (userNotify) (causeEve nt)

Example - userNotify

JADEObjectManager

userNotify

endNotification

beginNotification

Sharepricechange

$12.25Brierley

1

4

2

3

causeEvent

Page 9: Update a Display JADE Object Manager sysNotify endNotification BeginNotification Share price change $1.25 Brierley (userNotify) (causeEve nt)

load() updating;constants Sell_Now = 43; // Sell_Now should be a Global constant

begin self.beginClassNotification(Share, false, Sell_Now, Response_Continuous, 0);end; // Share Watch form

load() updating;constants Sell_Now = 43; // Sell_Now should be a Global constant

begin self.beginClassNotification(Share, false, Sell_Now, Response_Continuous, 0);end; // Share Watch form

price(set : Boolean; _value : Decimal io) mapping;constants Sell_Now = 43 ; // Sell_Now should be a Global constant

begin if _value >= 10.00 then self.causeEvent(Sell_Now, true, 0); endif; end; // Share object

price(set : Boolean; _value : Decimal io) mapping;constants Sell_Now = 43 ; // Sell_Now should be a Global constant

begin if _value >= 10.00 then self.causeEvent(Sell_Now, true, 0); endif; end; // Share object

2

1

Example - userNotify

userNotify(eventType:Integer; theObject:Object; eventTag:Integer; userInfo:Any) updating;

begin

app.msgBox("Sell shares in " & theObject.Share.name, "Selling Instruction", MsgBox_OK_Only);

end; // Share Watch form

userNotify(eventType:Integer; theObject:Object; eventTag:Integer; userInfo:Any) updating;

begin

app.msgBox("Sell shares in " & theObject.Share.name, "Selling Instruction", MsgBox_OK_Only);

end; // Share Watch form

3

unload() updating;

constants Sell_Now = 43 ; // Sell_Now should be a Global constant

begin

self.endClassNotification(Share, false, Sell_Now);end; // Share Watch form

unload() updating;

constants Sell_Now = 43 ; // Sell_Now should be a Global constant

begin

self.endClassNotification(Share, false, Sell_Now);end; // Share Watch form

4

Page 10: Update a Display JADE Object Manager sysNotify endNotification BeginNotification Share price change $1.25 Brierley (userNotify) (causeEve nt)

Using userInfo

• Parameter passed by causeEvent method

• Parameter that can be read in userNotify event

• Can be used to hold reference to any class or primitive type information because it is of type of Any

• theObject parameter holds a reference to the object that caused the notification

Page 11: Update a Display JADE Object Manager sysNotify endNotification BeginNotification Share price change $1.25 Brierley (userNotify) (causeEve nt)

Why use Notifications

• Avoids the continual checking to see if something has happened

• No “sleep ... wake up ... check ...” sequence wasting processor cycles

• Decouples processes

• Handles random event sequences

• Easy to code and implement

Page 12: Update a Display JADE Object Manager sysNotify endNotification BeginNotification Share price change $1.25 Brierley (userNotify) (causeEve nt)

When to use Notifications

• When random events occur

• Want to avoid continual checking

• Displayed information has to be up to date

• Cache synchronisation

• Critical events must be monitored and acted upon instantly

• Do Not Overuse, always justify the use of a notification

• Consider object instead of class scope or even causeEvent

Page 13: Update a Display JADE Object Manager sysNotify endNotification BeginNotification Share price change $1.25 Brierley (userNotify) (causeEve nt)

Challenge #24• Load a custom ThreeDeeGraph control• Paint a Statistics form• Add a drawBarGraph method• Code load method of form

name mnuCustomerStatistics

caption &Statistics

• Add a menu item to MainMenu

name threeDeeGraph

Page 14: Update a Display JADE Object Manager sysNotify endNotification BeginNotification Share price change $1.25 Brierley (userNotify) (causeEve nt)

Challenge #25

• Subscribe to notifications on the Customer and BankAccount classes when the form is loaded

• Respond to notifications by redrawing the graph

• Unsubscribe to notifications when the form is closed

• Test the notifications by adding customers with the Statistics form open