time to live specifications

3
Specifying Evictor Types: To specify time to live (Evictor) types on the map level, we can use the time to live types: .NONE, .LUT and .LAT. 1) Entries into a map whose name ends in .NONE do not expire. To remove the entries from the map, you must delete them. 2) Entries into a map whose name ends in .LUT allows the entries to be evicted from the map based on a time to live and the Last Update Time specification. Entries that haven't been updated for longer than the time to live will be removed from the map. 3) Entries into a map whose name ends in .LAT allow the entries to be evicted from the map based on a time to live and the Last Access Time specification. Entries that haven't been accessed for longer than the time to live will be removed from the map. On top of these three time to live types, there are also two more specifications that can help define the map which are Optimistic Locking and Pessimistic Locking. Optimistic Locking: Optimistic locking is best used when there isn't a large chance of collisions (Someone else modifying the data you are modifying). This map type does not lock values meaning other users can modify the data you are working with, if not coordinated. One can define Optimistic Locking by adding another definition after the time to live type, which is .O. For example to define a map with no time to live expiration and optimistic locking it would look like this: (Map Name).NONE.O where (Map Name) is a specified map name. Pessimistic Locking: Pessimistic locking is best used when there may be a higher chance of collisions. This map definition locks any value that a user is reading so that it cannot be modified by anyone else using the map. Once the user has read, modified and puts the modified data back into the map the data becomes available to other users. One can define Pessimistic Locking by adding another definition after the time to live type, which is .P. For example to define a map with Last Update Time, time to live expiration and pessimistic locking would look like this: (Map Name).LUT.P where (Map Name) is a specified map name.

Upload: paul-chen

Post on 22-Jan-2018

66 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Time To Live Specifications

Specifying Evictor Types:

To specify time to live (Evictor) types on the map level, we can use the time to live types: .NONE, .LUT and .LAT.

1) Entries into a map whose name ends in .NONE do not expire. To remove the entries from the map, you must delete them.

2) Entries into a map whose name ends in .LUT allows the entries to be evicted from the map based on a time to live and the Last Update Time specification. Entries that haven't been updated for longer than the time to live will be removed from the map.

3) Entries into a map whose name ends in .LAT allow the entries to be evicted from the map based on a time to live and the Last Access Time specification. Entries that haven't been accessed for longer than the time to live will be removed from the map.

On top of these three time to live types, there are also two more specifications that can help define the map which are Optimistic Locking and Pessimistic Locking.

Optimistic Locking:

Optimistic locking is best used when there isn't a large chance of collisions (Someone else modifying the data you are modifying). This map type does not lock values meaning other users can modify the data you are working with, if not coordinated. One can define Optimistic Locking by adding another definition after the time to live type, which is .O. For example to define a map with no time to live expiration and optimistic locking it would look like this:

(Map Name).NONE.O

where (Map Name) is a specified map name.

Pessimistic Locking:

Pessimistic locking is best used when there may be a higher chance of collisions. This map definition locks any value that a user is reading so that it cannot be modified by anyone else using the map. Once the user has read, modified and puts the modified data back into the map the data becomes available to other users. One can define Pessimistic Locking by adding another definition after the time to live type, which is .P. For example to define a map with Last Update Time, time to live expiration and pessimistic locking would look like this:

(Map Name).LUT.P

where (Map Name) is a specified map name.

Page 2: Time To Live Specifications

Sample Code:

In the sample created we have enabled the ability to change through each of the time to live types with either optimistic locking or pessimistic locking and a time to live of 60 minutes. One should note that the time to live is set in seconds.

1) Create a map:

String MapType=".NONE.P";clientGrid = ogm.getObjectGrid(ccc, gridName);ogSession = clientGrid.getSession();map = ogSession.getMap(clientGrid.getName() + MapType);map.setTimeToLive(TTL);

Here we have created a session for the specified object grid and created a map with a name defined by the client grid. MapType is a string that contains the definition of no time to live expiration with pessimistic locking as the starting default.

2) In our sample we have created the map type to be variable and defined by the user. In this sense the string MapType is changed throughout the code.

The user can click any of the buttons and change the map definition.

3) The following code shows how each button reacts to change the MapType string therefore changing the type of time to live for the map. The time to live has been set to 3600 seconds or one hour.

else if("LUTP".equals(operation)) {

MapType = ".LUT.P";response.getWriter().write("[LUT TTL with Pessimistic Locking

Map Enabled]");map = ogSession.getMap(clientGrid.getName() + MapType);

}

If the LUT TTL (Pessimistic) button is clicked, this function triggers and changes the MapType string to .LUT.P. Then the map is created using the map=session line and using a map name defined by the client grid, but the map name could be anything as long as it ends in .LUT.P.

Page 3: Time To Live Specifications

4) The following shows how to define all of the six map types talked about above where (A Map Name) is any map name.

map = ogSession.getMap((A Map Name).(TTL Type).(O or P)

• (A Map Name).NONE.PThe map has no time to live expiration with pessimistic locking

• (A Map Name).NONE.OThe map has no time to live expiration with optimistic locking

• (A Map Name).LUT.PThe map has Last Update Time, time to live expiration with pessimistic locking

• (A Map Name).LUT.OThe map has Last Update Time, time to live expiration with optimistic locking

• (A Map Name).LAT.PThe map has Last Access Time, time to live expiration with pessimistic locking

• (A Map Name).LAT.OThe map has Last Access time, time to live expiration with optimistic locking