Oracle Coherence Chinese tutorial 25: Map management action triggers

Source: Internet
Author: User

MapManagementAction Trigger

Map triggers the supplemental standardOracle Coherencethe ability to provide a highly customizable cache management system. For example, map triggers can prevent illegal transactions, perform complex security authorizations or complex business rules, provide transparent event logs and audits, and collect statistical data modifications. Other possible uses of triggers include restricting actions, hitting a cache, and issuing the time when the application is redeployed.

For example, suppose you have code that is associated withNamedcachework, items inserted into the map before you want to change the behavior or content of an entry. In addition to the map trigger, you do not need to modify the existing code to make this change.

Map triggers can also be part of the upgrade process. In addition to the map trigger prompt the insert is transferred to another from a cache.

Oracle Coherencethe map trigger in the cache is a bit like a trigger that might be applied to a database. is the corresponding mapping entry that is running a response that has pending changes (or deletions)Maptriggerthe functional agent represented by the interface. Non-processed changes are represented by theMaptrigger.entryinterface. This interface inherits from theInvocablemap.entryinterface, so it provides the method to retrieve, update, and delete values in the underlying map.

OfMaptriggerThe interface contains a process method that is used to validate, reject, or modify pending changes in the map. This approach is called commitment to change the underlying map content prior to action. This method can be used to evaluate the existing and new value changes to be passed and produce the following results:

Overwrite requirements change with different values

Undo a pending change the original value reset

Delete the entry from the underlying map

by throwing aruntimeexceptionreject Pending Changes

Do nothing and allow pending change commitments

Maptriggerfunctionality is typically added as part of the application startup process. That can be added programmaticallyMaptrigger APIor use the consistent cache as described in-config.xmlthe class factory mechanism in the configuration file, which can be configured. In this case,Maptriggerduring registration the firstCachefactory.getcache(... ) to invoke the appropriate cache. Example25-1Assumptions ofCreatemaptriggermethod returns aNew Maptriggerlistener (New Mycustomtrigger ());:

Example 25-1 example maptriggerlistener configuration

<distributed-scheme>

...

<listener>

<class-scheme>

<class-factory-name>package. Myfactory</class-factory-name>

<method-name>createTriggerListener</method-name>

<init-params>

<init-param>

<param-type>string</param-type>

<param-value>{cache-name}</param-value>

</init-param>

</init-params>

</class-scheme>

</listener>

</distributed-scheme>

Oracle CoherenceIn addition to themaptrigger.entry Maptriggerinterface, which provides aFiltertriggerand theMaptriggerlistenerclass. Filtertriggeris a universalMaptrigger, implemented, performs a predefined action if the associated filter pending change is rejected. TheFiltertriggeryou can reject pending operations, ignore changes, restore the original values of the entries, or delete the entries themselves from the underlying map.

Maptriggerlistenerthat is used to register with the correspondingNamedcacheof theMaptriggerThe Special PurposeMaplistenerthe implementation. Example25-2,Maptriggerlistenerwith the people of the named cache is used to registerPersonmaptrigger.

Cases25-2àmaptriggerlistenerRegisterMaptriggerthe named cache

Namedcache person = Cachefactory.getcache ("people");

Maptrigger trigger = new Personmaptrigger ();

Person.addmaplistener (new Maptriggerlistener (trigger));


These APIs reside in the com.tangosol.util package. For more information on These APIs, see Javadoc page maptrigger , Maptrigger.entry , filtertrigger , maptriggerlistener .

25.1aExample of a MAP trigger

The code in the example 25-3 describes the map trigger, which can be called. In the example 25-3 , the personmaptrigger class, which is placed in the map before the modification entry is implemented. In this case, the name property of the last person object is converted to uppercase characters. Entry, and then return to the object.

Example 25-3 a maptrigger class

...

public class Personmaptrigger implements Maptrigger

{

Public Personmaptrigger ()

{

}

public void process (Maptrigger.entry Entry)

{

Person person = (person) entry.getvalue ();

String sName = Person.getlastname ();

String Snameuc = Sname.touppercase ();

if (!snameuc.equals (sName))

{

Person.setlastname (SNAMEUC);

System.out.println ("Changed Last name of [" + SName + "] to [" + person.getlastname () + "]");

Entry.setvalue (person);

}

}

----Hashcode () and Equals () must be implemented

public boolean equals (Object O)

{

return o! = null && o.getclass () = = This.getclass ();

}

public int hashcode ()

{

Return GetClass (). GetName (). Hashcode ();

}

}

Example 25-4 maptrigger , called by the Personmaptrigger . The new maptriggerlistener personmaptrigger Pass the People namedcache .

Example 25-4 calls a Maptrigger and passes to the named cache

...

public class MyFactory

{

/**

* Instantiate a maptriggerlistener for a given namedcache

*/

public static Maptriggerlistener Createtriggerlistener (String scachename)

{

Maptrigger Trigger;

if ("People". Equals (Scachename))

{

Trigger = new Personmaptrigger ();

}

Else

{

Throw IllegalArgumentException ("Unknown cache name" + scachename);

}

System.out.println ("Creating Maptrigger for Cache" + scachename);

return new Maptriggerlistener (trigger);

}

public static void Main (string[] args)

{

Namedcache cache = Cachefactory.getcache ("people");

Cache.addmaplistener (Createtriggerlistener ("people"));

SYSTEM.OUT.PRINTLN ("Installed Maptrigger into cache people");

}

}

Oracle Coherence Chinese tutorial 25: Map management action triggers

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.