This is a simple example that demonstrates the use of a cache writer to validate modifications to a region.
A cache writer is added to a region as the region is created. Before an event (e.g., create a new entry, update an existing entry) occurs on that region, the cache writer has the appropriate handler method invoked, e.g.,
beforeCreate() for creating a new entry. This method invocation can affect the operation on the region: if it throws
CacheWriterException the operation is aborted.
In this example, a cache writer is installed that vets all of the creation events for the region for proper formatting of Social Security numbers. A number of entries are created in the region. The cache writer vets the supplied key for valid formatting. In other applications, the event could either be persisted to some other data store (i.e., write-ahead) or a notification about the activity could be sent via some other mechanism.
This example assumes you have installed Java and Geode.
geode-examples/writer directory, build the example and run unit tests.
$ ../gradlew build
Next start a locator, start a server, and create a region.
$ gfsh run --file=scripts/start.gfsh
Run the example to add a cache listener, put entries into the region, and capture the events.
$ ../gradlew run
Shut down the system.
$ gfsh run --file=scripts/stop.gfsh
Hii ni mfano rahisi ambayo inaonyesha matumizi ya cache mwandishi kuthibitisha marekebisho kwa mkoa. cache mwandishi ni aliongeza kwa mkoa kama mkoa ni kuundwa. Kabla ya tukio (kwa mfano, kuunda kuingia mpya, kusasisha kuingia zilizopo) hutokea katika eneo hilo, cache mwandishi ina sahihi handler mbinu kuitwa, kwa mfano, kabla ya kuunda () kwa ajili ya kujenga kuingia mpya. Hii mbinu wito inaweza kuathiri operesheni juu ya mkoa: kama ni throws CacheWriterException operesheni ni aborted. Katika mfano huu, cache mwandishi ni imewekwa kwamba vets wote wa matukio ya uundaji kwa ajili ya mkoa kwa ajili ya muundo sahihi wa namba za usalama wa kijamii. Idadi ya entries ni kuundwa katika mkoa. cache mwandishi vets muhimu zinazotolewa kwa ajili ya umbizo halali. Katika maombi mengine, tukio inaweza ama kuwa persisted kwa baadhi ya hifadhi nyingine ya data (yaani, kuandika mbele) au taarifa kuhusu shughuli inaweza kutumwa kupitia baadhi ya utaratibu mwingine. Mfano huu inachukua umewekwa Java na Geode. Geode-Examples na Wanasayansi wa Uandishi wa Kiwango cha Juu (GERD) wanafanya kazi kwa kutumia mfululizo wa vipimo vya kipekee vya kipekee. "Kama ""kuanzisha"" eneo, unaweza kuanzisha eneo la eneo, kuanzisha eneo la eneo, na kuanzisha eneo la eneo." Gfsh run -file=scripts_start.gfsh Run mfano kuongeza cache msikilizaji, kuweka entries katika mkoa, na kukamata matukio. $ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Gfsh: ""File=script=stop."""