Saturday Feb 07, 2015

OSB 11g Result Cache setup in 5min

This is the short write-up to help those who want to kick-start the OSB result caching. I've omitted all the details so one can get to start and test the feature pretty quickly.

Before proceed, port numbers that Coherence uses should be assigned. Here I assume that managed server "osb_m1", "osb_m2" is on physically different servers, and each have listen address and ports as osb_m1:9090, osb_m2:9092 respectively. 

1. edit Coherence override file

Locate osb-coherence-override.xml under $OSB_HOME/config/osb/coherence and edit file as below.

<!DOCTYPE coherence SYSTEM "coherence.dtd">

<coherence>

<cluster-config>

<unicast-listener>

<well-known-addresses>

                <socket-address id="1">

                    <address system-property="OSB.coherence.wka1">osb_m1</address>

                    <port system-property="OSB.coherence.wka1.port">9090</port>

                </socket-address>

                <socket-address id="2">

                    <address system-property="OSB.coherence.wka1">osb_m2</address>

                    <port system-property="OSB.coherence.wka1.port">9092</port>

                </socket-address>

</well-known-addresses>

</unicast-listener>

</cluster-config>

</coherence>

Each managed servers will use this single file. 

2. Edit setDomainEnv.sh of each managed server to include following settings.

-Dtangosol.coherence.distributed.localstorage=false -DOSB.coherence.localhost=<osb_m1  or osb_m2> -DOSB.coherence.localport=<9090  or 9092>

3. Create Coherence server startup script.

Download the script here.

 Now start Coherence server and OSB server. You can see if it's correctly set-up by seeing the log like below from Coherence. 

------------ 

  ActualMemberSet=MemberSet(Size=2

    Member(Id=1, Timestamp=2015-02-07 18:43:49.363, Address=127.0.0.1:7890, MachineId=60314, Location=site:,machine:localhost,process:23918, Role=OSB-node)

    Member(Id=2, Timestamp=2015-02-07 19:37:44.98, Address=127.0.0.1:7892, MachineId=60314, Location=site:,machine:localhost,process:25937, Role=CoherenceServer)

    )

------------ 

To see whether is properly working, go to invocation trace. 

cache-originated above indicates that result is served from Coherence cache.

Hope this helps.

Wednesday Jan 30, 2013

Accessing Coherence from OSB Pipeline

I recently got an request from customer that they want to invalidate the data in OSB ResultCache. As there is no way that we can create Key to invalidate the data, best way we can take is using filter. Here is the snippet of the code. 

 extern "C" void invalidate(char* key) {

    try {

        String::View vsCacheName = "/osb/service/ResultCache";

        NamedCache::Handle hCache = CacheFactory::getCache(vsCacheName);

        ValueExtractor::Handle hExtractor = KeyExtractor::create(ReflectionExtractor::create("getToken"));

        Filter::View vEqualsFilter = EqualsFilter::create(hExtractor, String::create(key));

        hCache->invokeAll(vEqualsFilter, ConditionalRemove::create(AlwaysFilter::getInstance(),true));

    } catch (const std::exception& e) {

        std::cerr << "error: " << e.what() << std::endl;

    }

}

One issue here is that we cannot specify which result of BusinessService should be invalidated. If two BusinessServices happen to have same token, This will remove both of them which sometimes is not desirable. Also, Index is not in place, so if size of cache is huge, we would expect the performance issue.Currently, I'm not aware of any way to make Key class. I tried making it by myself, but somehow, the one I make and generated by OSB is different.so I ended up making my own ResultCache logic to achieve this purpose.

--

public class ResultCacheHelper {
 private static String CACHE_NAME = "dist-test";
 
 public static void put(String key, org.apache.xmlbeans.XmlObject value) throws IOException {
 NamedCache cache = CacheFactory.getCache(CACHE_NAME);
 cache.put(key, serialize(value));
 CacheFactory.log("Cache Key : " + key + " is put in Cache!:" + serialize(value).toString());
 }
 
 public static org.apache.xmlbeans.XmlObject get(String key) throws IOException, ClassNotFoundException, XmlException {
 XmlObject result;
 NamedCache cache = CacheFactory.getCache(CACHE_NAME);
 
 byte[] bytes = (byte[]) cache.get(key);
 if(bytes == null) {
 String xmlNull = "<cache xmlns=\"http://com.oracle.demoapp.ws/\">null</cache>";
 result = org.apache.xmlbeans.XmlObject.Factory.parse(xmlNull);
 CacheFactory.log("Cache Key : " + key + " is not found in Cache!");
 } else  {
 result = (org.apache.xmlbeans.XmlObject)deserialize(bytes, Thread.currentThread().getContextClassLoader());
 CacheFactory.log("Cache Key : " + key + " is found in Cache!:"+result.toString());
 }
 
 return result;
 }
 
 protected static Object deserialize(byte[] bytes, final ClassLoader cl)
 throws IOException, ClassNotFoundException {
 ObjectInputStream ois = null;
 try {
 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
 ois = new ObjectInputStream(bais) {
 protected Class<?> resolveClass(ObjectStreamClass desc)
 throws IOException, ClassNotFoundException {
 return Class.forName(desc.getName(), false, cl);
 }
 };
 return ois.readObject();
 } finally {
 if (ois != null)
 ois.close();
 }
 }
 protected static byte[] serialize(Object object) throws IOException {
 ObjectOutputStream oos = null;
 try {
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 oos = new ObjectOutputStream(baos);
 oos.writeObject(object);
 return baos.toByteArray();
 } finally {
 if (oos != null)
 oos.close();
 }
 }
}

--


Now I can just simply invalidate the cache

        String::View deleteKey = key;

        String::View vsCacheName = "dist-test";

        NamedCache::Handle hCache = CacheFactory::getCache(vsCacheName);

        hCache->remove(deleteKey);

 I believe that OSB invalidation feature will be added in near future. 

About

Solution & Technology Architect, Asia Pacific

Search

Archives
« August 2015
SunMonTueWedThuFriSat
      
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
     
Today