Search This Blog

Monday 20 December 2010

Querying Coherence Cache from JRuby

To complete the Coherence/JRuby demos this final demo shows how we can query the cache using filters to show the data we are interested in. From this demo you can see our cache has the oracle data dictionary view ALL_DB_OBJECTS data which was loaded from an 11.2.0.2 RDBMS. The output will make that obvious.

JRuby script is as follows - coh-extend-client-query.rb
require 'java'
require 'C:/jdev/scripting/demos/jruby/extendclient-coherence/extenddemo.jar'
require 'C:/jdev/coherence/36/coherence/lib/coherence.jar'

include_class "pas.au.coherence.extend.server.AllDBObject"
import com.tangosol.net.CacheFactory
import com.tangosol.net.NamedCache
import java.util.Date
import java.lang.System
import java.math.BigDecimal
import java.util.Set

puts "***********************************************"
puts "Coherence 3.6 Extend Client Example from JRUBY"
puts "***********************************************"

print "Started at ", Date.new.toString, "\n"

begin

  # setup required properties to connect to proxy server as extend client
  System.setProperty("tangosol.pof.enabled", "true")
  System.setProperty("tangosol.pof.config", "extend-pof-config.xml")
  System.setProperty("tangosol.coherence.cacheconfig", "client-cache-config.xml")
  System.setProperty("proxy.host", "papicell-au2.au.oracle.com")

  # get named cache alldbobjs
  alldbobjs = CacheFactory.getCache("alldbobjs")

  #retrieve size of cache
  print "\nCache [alldbobjs] size  = " + alldbobjs.size().to_s + "\n\n"
  
  #retrieve all SCOTT schema entries
  filter = com.tangosol.util.filter.EqualsFilter.new("getOwner", "SCOTT")
  scottObjects = alldbobjs.entrySet(filter)
  
  #iterate through SCOTT's objects 
  print "\nTotal of " + scottObjects.size().to_s + " cache entries found \n"

  print "Is scottObjects empty : ", scottObjects.empty?, "\n"
  puts
  
  iterator = scottObjects.iterator()
  while iterator.hasNext()
    entry = iterator.next()
    print "Key : [" + entry.getKey().to_s + "] "
    print "Value : [Owner=" + entry.getValue().getOwner() + 
          ", objectName=" + entry.getValue().getObjectName() +
          ", objectType=" + entry.getValue().getObjectType() + "]"
    puts
  end
  
rescue 
  print "\n** Error occured **\n"
 print "Failed to access Coherence Cluster from proxy server -> \n", $!, "\n\n"
  
end

puts
print "Ended at ", Date.new.toString, "\n"

The output when run shows the SCOTT schema objects being queried from the cache


C:\jdev\scripting\demos\jruby\extendclient-coherence>vi coh-extend-client-query.rb


C:\jdev\scripting\demos\jruby\extendclient-coherence>jrb coh-extend-client-query.rb
***********************************************
Coherence 3.6 Extend Client Example from JRUBY
***********************************************
Started at Mon Dec 20 07:36:52 EST 2010
2010-12-20 07:36:52.752/0.869 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Loaded operational configuration from "jar:file:/C:
/jdev/coherence/36/coherence/lib/coherence.jar!/tangosol-coherence.xml"
2010-12-20 07:36:52.756/0.873 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Loaded operational overrides from "jar:file:/C:/jde
v/coherence/36/coherence/lib/coherence.jar!/tangosol-coherence-override-dev.xml"
2010-12-20 07:36:52.756/0.873 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Optional configuration override "/tangosol-coherence-
override.xml" is not specified
2010-12-20 07:36:52.759/0.876 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Optional configuration override "/custom-mbeans.xml"
is not specified


Oracle Coherence Version 3.6.0.0 Build 17229
 Grid Edition: Development mode
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.


2010-12-20 07:36:52.945/1.062 Oracle Coherence GE 3.6.0.0 (thread=main, member=n/a): Loaded cache configuration from "jar:file:/C:/jd
ev/scripting/demos/jruby/extendclient-coherence/extenddemo.jar!/client-cache-config.xml"
2010-12-20 07:36:53.107/1.224 Oracle Coherence GE 3.6.0.0 (thread=RemoteCache:TcpInitiator, member=n/a): Loaded POF configuration fro
m "jar:file:/C:/jdev/scripting/demos/jruby/extendclient-coherence/extenddemo.jar!/extend-pof-config.xml"
2010-12-20 07:36:53.111/1.228 Oracle Coherence GE 3.6.0.0 (thread=RemoteCache:TcpInitiator, member=n/a): Loaded included POF configur
ation from "jar:file:/C:/jdev/coherence/36/coherence/lib/coherence.jar!/coherence-pof-config.xml"
2010-12-20 07:36:53.214/1.331 Oracle Coherence GE 3.6.0.0 (thread=RemoteCache:TcpInitiator, member=n/a): Started: TcpInitiator{Name=Rem
oteCache:TcpInitiator, State=(SERVICE_STARTED), ThreadCount=0, Codec=Codec(Format=POF), PingInterval=0, PingTimeout=0, RequestTimeout=0, Con
nectTimeout=0, SocketProvider=SystemSocketProvider, RemoteAddresses=[papicell-au2.au.oracle.com/10.187.80.136:9099]}
2010-12-20 07:36:53.218/1.335 Oracle Coherence GE 3.6.0.0 (thread=main, member=n/a): Opening Socket connection to 10.187.80.136:9099
2010-12-20 07:36:53.220/1.337 Oracle Coherence GE 3.6.0.0 (thread=main, member=n/a): Connected to 10.187.80.136:9099


Cache [alldbobjs] size  = 99927




Total of 55 cache entries found
Is scottObjects empty : false


Key : [82967] Value : [Owner=SCOTT, objectName=TEST_STRING, objectType=TABLE]
Key : [126758] Value : [Owner=SCOTT, objectName=Host2, objectType=JAVA CLASS]
Key : [128400] Value : [Owner=SCOTT, objectName=DISPLAYPROPERTIES, objectType=FUNCTION]
Key : [173453] Value : [Owner=SCOTT, objectName=SYS_LOB0000173452C00002$$, objectType=LOB]
Key : [128399] Value : [Owner=SCOTT, objectName=CheckProperties, objectType=JAVA CLASS]
Key : [85457] Value : [Owner=SCOTT, objectName=JUNKPR, objectType=PROCEDURE]
Key : [150089] Value : [Owner=SCOTT, objectName=HELLOWORLDPKG, objectType=PACKAGE]
Key : [155471] Value : [Owner=SCOTT, objectName=CELCIUSTOFAHRENHEIT, objectType=FUNCTION]
Key : [91848] Value : [Owner=SCOTT, objectName=SYS_C0019928, objectType=INDEX]
Key : [82964] Value : [Owner=SCOTT, objectName=TEST_TYP, objectType=TYPE]
Key : [150088] Value : [Owner=SCOTT, objectName=pas/au/jsp/DemoJSP, objectType=JAVA CLASS]
Key : [82966] Value : [Owner=SCOTT, objectName=TEST_PROC1, objectType=PROCEDURE]
Key : [91846] Value : [Owner=SCOTT, objectName=SYS_LOB0000091845C00002$$, objectType=LOB]
Key : [73200] Value : [Owner=SCOTT, objectName=PK_DEPT, objectType=INDEX]
Key : [91849] Value : [Owner=SCOTT, objectName=xp_cmdshell, objectType=JAVA CLASS]
Key : [91855] Value : [Owner=SCOTT, objectName=xp_cmdshell, objectType=JAVA SOURCE]
Key : [126760] Value : [Owner=SCOTT, objectName=HOST_API, objectType=PACKAGE BODY]
Key : [173456] Value : [Owner=SCOTT, objectName=FORMMODEL_INS_TRG, objectType=TRIGGER]
Key : [73199] Value : [Owner=SCOTT, objectName=DEPT, objectType=TABLE]
Key : [155571] Value : [Owner=SCOTT, objectName=SAYHELLONAME, objectType=FUNCTION]
Key : [169925] Value : [Owner=SCOTT, objectName=DEPT_LIST_TABLE, objectType=TYPE]
Key : [173144] Value : [Owner=SCOTT, objectName=CUSTOMER, objectType=TABLE]
Key : [91850] Value : [Owner=SCOTT, objectName=DOIT, objectType=PROCEDURE]
Key : [160445] Value : [Owner=SCOTT, objectName=runhttprequest, objectType=JAVA SOURCE]
Key : [169926] Value : [Owner=SCOTT, objectName=WS_PACKAGE, objectType=PACKAGE]
Key : [73204] Value : [Owner=SCOTT, objectName=SALGRADE, objectType=TABLE]
Key : [160648] Value : [Owner=SCOTT, objectName=SYS_C0046421, objectType=INDEX]
Key : [140715] Value : [Owner=SCOTT, objectName=DRIVERVERSION, objectType=PROCEDURE]
Key : [160446] Value : [Owner=SCOTT, objectName=RunHttpRequest, objectType=JAVA CLASS]
Key : [173455] Value : [Owner=SCOTT, objectName=FORMMODEL_PK, objectType=INDEX]
Key : [73202] Value : [Owner=SCOTT, objectName=PK_EMP, objectType=INDEX]
Key : [169927] Value : [Owner=SCOTT, objectName=WS_PACKAGE, objectType=PACKAGE BODY]
Key : [173452] Value : [Owner=SCOTT, objectName=FORMMODEL, objectType=TABLE]
Key : [79037] Value : [Owner=SCOTT, objectName=XML_PACKAGE, objectType=PACKAGE]
Key : [91845] Value : [Owner=SCOTT, objectName=CREATE$JAVA$LOB$TABLE, objectType=TABLE]
Key : [160890] Value : [Owner=SCOTT, objectName=MYTEST3, objectType=TABLE]
Key : [160647] Value : [Owner=SCOTT, objectName=CAL, objectType=TABLE]
Key : [155581] Value : [Owner=SCOTT, objectName=SAYHELLONAME_SYS, objectType=FUNCTION]
Key : [79038] Value : [Owner=SCOTT, objectName=XML_PACKAGE, objectType=PACKAGE BODY]
Key : [169924] Value : [Owner=SCOTT, objectName=DEPT_TYPE, objectType=TYPE]
Key : [85455] Value : [Owner=SCOTT, objectName=Junk, objectType=JAVA SOURCE]
Key : [155472] Value : [Owner=SCOTT, objectName=CELCIUSTOFAHRENHEIT1, objectType=FUNCTION]
Key : [155473] Value : [Owner=SCOTT, objectName=CELCIUSTOFAHRENHEIT2, objectType=FUNCTION]
Key : [173457] Value : [Owner=SCOTT, objectName=FORMMODEL_UPD_TRG, objectType=TRIGGER]
Key : [180988] Value : [Owner=SCOTT, objectName=ALL_DB_OBJECTS, objectType=TABLE]
Key : [160447] Value : [Owner=SCOTT, objectName=FN_RUN_HTTP_REQUEST, objectType=FUNCTION]
Key : [150090] Value : [Owner=SCOTT, objectName=HELLOWORLDPKG, objectType=PACKAGE BODY]
Key : [91851] Value : [Owner=SCOTT, objectName=JAVA$OPTIONS, objectType=TABLE]
Key : [173458] Value : [Owner=SCOTT, objectName=FORMMODEL_ID_SEQ, objectType=SEQUENCE]
Key : [85456] Value : [Owner=SCOTT, objectName=Junk, objectType=JAVA CLASS]
Key : [162619] Value : [Owner=SCOTT, objectName=TMP_JD_TEST, objectType=TABLE]
Key : [126759] Value : [Owner=SCOTT, objectName=HOST_API, objectType=PACKAGE]
Key : [73201] Value : [Owner=SCOTT, objectName=EMP, objectType=TABLE]
Key : [73203] Value : [Owner=SCOTT, objectName=BONUS, objectType=TABLE]
Key : [126757] Value : [Owner=SCOTT, objectName=HOST2, objectType=JAVA SOURCE]


Ended at Mon Dec 20 07:36:54 EST 2010

Thursday 16 December 2010

Access Coherence Cache from JRuby as an Extend client

In my previous example below I wanted to quickly join a coherence cluster from JRuby and basically did it the easiest way possible by simply becoming a member in the cluster.

Access Coherence Cache from JRuby/Jython scripts

In the example below we will we use JRuby as a Coherence*Extend client using POF (Portable Object Format) and we do this for the following reasons.

1. Being a console application we want to connect/disconnect many times a day and even though we are a storage disabled member it results in overhead which an extend client avoids.
2. Being an extend client we are storage disabled by default.
3. Using POF has many advantages ranging from performance benefits to language independence, although in this example we are using it from a Java enabled client.

So our JRuby code is now as follows.
require 'java'
require 'C:/jdev/scripting/demos/jruby/extendclient-coherence/extenddemo.jar'
require 'C:/jdev/coherence/36/coherence/lib/coherence.jar'

include_class "pas.au.coherence.extend.server.AllDBObject"
import com.tangosol.net.CacheFactory
import com.tangosol.net.NamedCache
import java.util.Date
import java.lang.System
import java.math.BigDecimal

puts "***********************************************"
puts "Coherence 3.6 Extend Client Example from JRUBY"
puts "***********************************************"

print "Started at ", Date.new.toString, "\n"

begin

  # setup required properties to connect to proxy server as extend client
  System.setProperty("tangosol.coherence.cacheconfig", "client-cache-config.xml")
  System.setProperty("tangosol.pof.enabled", "true")
  System.setProperty("tangosol.pof.config", "extend-pof-config.xml")
  System.setProperty("proxy.host", "papicell-au2.au.oracle.com")

  # get named cache alldbobjs
  alldbobjs = CacheFactory.getCache("alldbobjs")

  #retrieve size of cache
  print "\nCache [alldbobjs] size  = " + alldbobjs.size().to_s + "\n\n"

  #retrieve one record
  objectid = BigDecimal.new(54)

  objectrecord = AllDBObject.new
  objectrecord = alldbobjs.get(objectid)

  puts "Record 54 = " + objectrecord.to_s
  puts

rescue
  print "\n** Error occured **\n"
        print "Failed to access Coherence Cluster from proxy server ", $!, "\n\n"

end

print "Ended at ", Date.new.toString, "\n"
From the code we have done the following.

1. Used a client cache config file to connect as an extend client, basically connect to an extend proxy which is a cluster member.

2. We provide a client JAR file which contains our domain objects and config files that being extenddemo.jar

3. The client cache config is defined as follows.
<!DOCTYPE cache-config SYSTEM "cache-config.dtd">

<cache-config>
  <caching-scheme-mapping>
    <cache-mapping>
      <cache-name>alldbobjs</cache-name>
      <scheme-name>remote</scheme-name>
    </cache-mapping>
  </caching-scheme-mapping>
  <caching-schemes>
    <remote-cache-scheme>
      <scheme-name>remote</scheme-name>
      <initiator-config>
        <tcp-initiator>
          <remote-addresses>
            <socket-address>
              <address system-property="proxy.host">
  papicell-au2.au.oracle.com
       </address>
              <port system-property="proxy.port">
                9099
              </port>
              <reusable>true</reusable>
            </socket-address>
          </remote-addresses>
        </tcp-initiator>
      </initiator-config>
    </remote-cache-scheme>
  </caching-schemes>
</cache-config>

So when we run this we get output as follows.

C:\jdev\scripting\demos\jruby\extendclient-coherence>jrb coh-extend-client.rb
***********************************************
Coherence 3.6 Extend Client Example from JRUBY
***********************************************
Started at Thu Dec 16 14:08:06 EST 2010
2010-12-16 14:08:06.114/1.033 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Loaded operational configuration from "jar:file:/C:
/jdev/coherence/36/coherence/lib/coherence.jar!/tangosol-coherence.xml"
2010-12-16 14:08:06.118/1.037 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Loaded operational overrides from "jar:file:/C:/jde
v/coherence/36/coherence/lib/coherence.jar!/tangosol-coherence-override-dev.xml"
2010-12-16 14:08:06.118/1.037 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Optional configuration override "/tangosol-coherence-
override.xml" is not specified
2010-12-16 14:08:06.121/1.040 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Optional configuration override "/custom-mbeans.xml"
is not specified


Oracle Coherence Version 3.6.0.0 Build 17229
 Grid Edition: Development mode
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.


2010-12-16 14:08:06.304/1.223 Oracle Coherence GE 3.6.0.0 (thread=main, member=n/a): Loaded cache configuration from "jar:file:/C:/jd
ev/scripting/demos/jruby/extendclient-coherence/extenddemo.jar!/client-cache-config.xml"
2010-12-16 14:08:06.472/1.391 Oracle Coherence GE 3.6.0.0 (thread=RemoteCache:TcpInitiator, member=n/a): Loaded POF configuration fro
m "jar:file:/C:/jdev/scripting/demos/jruby/extendclient-coherence/extenddemo.jar!/extend-pof-config.xml"
2010-12-16 14:08:06.475/1.394 Oracle Coherence GE 3.6.0.0 (thread=RemoteCache:TcpInitiator, member=n/a): Loaded included POF configur
ation from "jar:file:/C:/jdev/coherence/36/coherence/lib/coherence.jar!/coherence-pof-config.xml"
2010-12-16 14:08:06.567/1.486 Oracle Coherence GE 3.6.0.0 (thread=RemoteCache:TcpInitiator, member=n/a): Started: TcpInitiator{Name=Rem
oteCache:TcpInitiator, State=(SERVICE_STARTED), ThreadCount=0, Codec=Codec(Format=POF), PingInterval=0, PingTimeout=0, RequestTimeout=0, Con
nectTimeout=0, SocketProvider=SystemSocketProvider, RemoteAddresses=[papicell-au2.au.oracle.com/10.187.80.136:9099]}
2010-12-16 14:08:06.572/1.491 Oracle Coherence GE 3.6.0.0 (thread=main, member=n/a): Opening Socket connection to 10.187.80.136:9099
2010-12-16 14:08:06.580/1.499 Oracle Coherence GE 3.6.0.0 (thread=main, member=n/a): Connected to 10.187.80.136:9099


Cache [alldbobjs] size  = 99927


Record 54 = AllDbObject - owner: SYS ,objectName: I_CDEF2 ,subObjectName: null ,objectId: 54 ,dataObjectId: 54 ,objectType: INDEX ,created:
2009-08-15 ,lastDDLTime: 2009-08-15 ,timestamp: 2009-08-15:00:16:51 ,status: VALID ,temporrary: N ,generated: N ,secondary: N ,namespace: 4
,editionName: null


Ended at Thu Dec 16 14:08:06 EST 2010

Monday 6 December 2010

Access Coherence Cache from JRuby/Jython scripts

The following example show how to use JRuby or Jython to access Coherence caches. Although this is basic and simply using the cache config file out of coherence.jar it gives you enough to see how simple it is to join the cluster as member and access coherence.jar from these 2 scripting languages.

I could of easily used groovy here as well but decided to stick with jruby and jython for now. Also the script members that join the cluster are storage disabled meaning that they must connect to node which is storage enabled to add data to the cache.

For this demo I have the following installed.
  • Coherence 3.6
  • JDK 1.6
  • JRuby 1.5.6
  • Jython 2.5.1
PRE STEPS

1. Start a cache server as follows. We do this to ensure we have a storage enabled node. The cache config file being used is the one inside coherence.jar. 

C:\jdev\coherence\36\coherence\bin>cache-server.cmd

In the example below jy = jython and jrb = jruby executables.

JRUBY

1. Create a ruby script as follows.
require 'java'
require 'C:/jdev/coherence/36/coherence/lib/coherence.jar'

import com.tangosol.net.CacheFactory
import com.tangosol.net.NamedCache
import java.util.Date
import java.lang.System

puts "*********************************"
puts "Coherence 3.6 Example from JRUBY"
puts "*********************************"

print "Started at ", Date.new.toString, "\n"

begin

  # ensure we are storage disabled
  System.setProperty("tangosol.coherence.distributed.localstorage", "false")
  
  CacheFactory.ensureCluster

  # get named cache
  testcache = CacheFactory.getCache("Test")

  # add data to cache
  testcache.put("1", "pas apicella")

  # retrive data from cache
  puts "Cache entry 1 = " + testcache.get("1")
  
rescue 
 print "Failed to access Coherence Cluster ", $!, "\n"
 
ensure 
  CacheFactory.shutdown
  
end

print "Ended at ", Date.new.toString, "\n"

2. Run it as follows ensuring your reference coherence.jar correctly

> jrb coherence.rb

Output as follows


C:\jdev\scripting\demos\jruby>jrb coherence.rb
*********************************
Coherence 3.6 Example from JRUBY
*********************************
Started at Mon Dec 06 11:38:09 EST 2010
2010-12-06 11:38:09.939/0.855 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Loaded operational configuration from "jar:file:/C:
/jdev/coherence/36/coherence/lib/coherence.jar!/tangosol-coherence.xml"
2010-12-06 11:38:09.942/0.858 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Loaded operational overrides from "jar:file:/C:/jde
v/coherence/36/coherence/lib/coherence.jar!/tangosol-coherence-override-dev.xml"
2010-12-06 11:38:09.943/0.859 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Optional configuration override "/tangosol-coherence-
override.xml" is not specified
2010-12-06 11:38:09.946/0.862 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Optional configuration override "/custom-mbeans.xml"
is not specified


Oracle Coherence Version 3.6.0.0 Build 17229
 Grid Edition: Development mode
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.


2010-12-06 11:38:10.474/1.390 Oracle Coherence GE 3.6.0.0 (thread=main, member=n/a): TCMP bound to /10.187.114.243:8090 using SystemSoc
ketProvider
2010-12-06 11:38:11.683/2.600 Oracle Coherence GE 3.6.0.0 (thread=Cluster, member=n/a): This Member(Id=2, Timestamp=2010-12-06 11:38:
11.675, Address=10.187.114.243:8090, MachineId=50163, Location=machine:paslap-au,process:3824, Role=JrubyMain, Edition=Grid Edition, Mode=De
velopment, CpuCount=4, SocketCount=4) joined cluster "cluster:0xC4DB" with senior Member(Id=1, Timestamp=2010-12-06 11:37:53.952, Address=10
.187.114.243:8088, MachineId=50163, Location=machine:paslap-au,process:1280, Role=CoherenceServer, Edition=Grid Edition, Mode=Development, C
puCount=4, SocketCount=4)
2010-12-06 11:38:11.693/2.609 Oracle Coherence GE 3.6.0.0 (thread=Cluster, member=n/a): Member 1 joined Service Cluster with senior mem
ber 1
2010-12-06 11:38:11.693/2.609 Oracle Coherence GE 3.6.0.0 (thread=Cluster, member=n/a): Member 1 joined Service Management with senior
member 1
2010-12-06 11:38:11.693/2.609 Oracle Coherence GE 3.6.0.0 (thread=Cluster, member=n/a): Member 1 joined Service DistributedCache with s
enior member 1
2010-12-06 11:38:11.693/2.609 Oracle Coherence GE 3.6.0.0 (thread=Cluster, member=n/a): Member 1 joined Service ReplicatedCache with se
nior member 1
2010-12-06 11:38:11.693/2.609 Oracle Coherence GE 3.6.0.0 (thread=Cluster, member=n/a): Member 1 joined Service OptimisticCache with se
nior member 1
2010-12-06 11:38:11.693/2.609 Oracle Coherence GE 3.6.0.0 (thread=Cluster, member=n/a): Member 1 joined Service InvocationService with
senior member 1
2010-12-06 11:38:11.697/2.613 Oracle Coherence GE 3.6.0.0 (thread=main, member=n/a): Started cluster Name=cluster:0xC4DB


Group{Address=224.3.6.0, Port=36000, TTL=4}


MasterMemberSet
  (
  ThisMember=Member(Id=2, Timestamp=2010-12-06 11:38:11.675, Address=10.187.114.243:8090, MachineId=50163, Location=machine:paslap-au,proces
s:3824, Role=JrubyMain)
  OldestMember=Member(Id=1, Timestamp=2010-12-06 11:37:53.952, Address=10.187.114.243:8088, MachineId=50163, Location=machine:paslap-au,proc
ess:1280, Role=CoherenceServer)
  ActualMemberSet=MemberSet(Size=2, BitSetCount=2
    Member(Id=1, Timestamp=2010-12-06 11:37:53.952, Address=10.187.114.243:8088, MachineId=50163, Location=machine:paslap-au,process:1280, R
ole=CoherenceServer)
    Member(Id=2, Timestamp=2010-12-06 11:38:11.675, Address=10.187.114.243:8090, MachineId=50163, Location=machine:paslap-au,process:3824, R
ole=JrubyMain)
    )
  RecycleMillis=1200000
  RecycleSet=MemberSet(Size=0, BitSetCount=0
    )
  )


TcpRing{Connections=[1]}
IpMonitor{AddressListSize=0}


2010-12-06 11:38:11.727/2.643 Oracle Coherence GE 3.6.0.0 (thread=Invocation:Management, member=2): Service Management joined the clust
er with senior service member 1
2010-12-06 11:38:11.788/2.704 Oracle Coherence GE 3.6.0.0 (thread=main, member=2): Loaded cache configuration from "jar:file:/C:/jdev
/coherence/36/coherence/lib/coherence.jar!/coherence-cache-config.xml"
2010-12-06 11:38:12.017/2.933 Oracle Coherence GE 3.6.0.0 (thread=DistributedCache, member=2): Service DistributedCache joined the clus
ter with senior service member 1
Cache entry 1 = pas apicella
2010-12-06 11:38:12.124/3.040 Oracle Coherence GE 3.6.0.0 (thread=Invocation:Management, member=2): Service Management left the cluster


2010-12-06 11:38:12.129/3.045 Oracle Coherence GE 3.6.0.0 (thread=DistributedCache, member=2): Service DistributedCache left the cluste
r
2010-12-06 11:38:12.222/3.138 Oracle Coherence GE 3.6.0.0 (thread=Cluster, member=2): Service Cluster left the cluster
Ended at Mon Dec 06 11:38:12 EST 2010


C:\jdev\scripting\demos\jruby>


JYTHON

1. Create a jython script as follows
from com.tangosol.net import CacheFactory, NamedCache
from java.util import Date
from java.lang import System as javasystem

print "*********************************"
print "Coherence 3.6 Example from JYTHON"
print "*********************************"

print "Started at " + Date().toString()

try:

 javasystem.setProperty("tangosol.coherence.distributed.localstorage", "false")
  
 CacheFactory.ensureCluster()
 
 # get named cache
 testcache = CacheFactory.getCache("Test")
 
 # add data to cache
 testcache.put("1", "pas apicella")

 # retrive data from cache
 print "Cache entry 1 = " + testcache.get("1")

except:
    print "Unexpected error:", sys.exc_info()[0]
    raise
    
finally:
    CacheFactory.shutdown()
    
print "Ended at " + Date().toString()
    
    
2. Add coherence.jar to the classpath as shown below.

> set CLASSPATH=C:\jdev\coherence\36\coherence\lib\coherence.jar

3. Run it as follows ensuring your reference coherence.jar correctly

> jy coherence.py

Output as follows


C:\jdev\scripting\demos\jython>jy coherence.py
*********************************
Coherence 3.6 Example from JYTHON
*********************************
Started at Mon Dec 06 11:41:08 EST 2010
2010-12-06 11:41:08.838/1.916 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Loaded operational configuration from "jar:file:/C:
/jdev/coherence/36/coherence/lib/coherence.jar!/tangosol-coherence.xml"
2010-12-06 11:41:08.844/1.922 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Loaded operational overrides from "jar:file:/C:/jde
v/coherence/36/coherence/lib/coherence.jar!/tangosol-coherence-override-dev.xml"
2010-12-06 11:41:08.845/1.923 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Optional configuration override "/tangosol-coherence-
override.xml" is not specified
2010-12-06 11:41:08.851/1.929 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Optional configuration override "/custom-mbeans.xml"
is not specified


Oracle Coherence Version 3.6.0.0 Build 17229
 Grid Edition: Development mode
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.


2010-12-06 11:41:10.012/3.090 Oracle Coherence GE 3.6.0.0 (thread=main, member=n/a): TCMP bound to /10.187.114.243:8090 using SystemSoc
ketProvider
2010-12-06 11:41:11.191/4.269 Oracle Coherence GE 3.6.0.0 (thread=Cluster, member=n/a): This Member(Id=3, Timestamp=2010-12-06 11:41:
11.172, Address=10.187.114.243:8090, MachineId=50163, Location=machine:paslap-au,process:6172, Role=PythonUtilJython, Edition=Grid Edition,
Mode=Development, CpuCount=4, SocketCount=4) joined cluster "cluster:0xC4DB" with senior Member(Id=1, Timestamp=2010-12-06 11:37:53.952, Add
ress=10.187.114.243:8088, MachineId=50163, Location=machine:paslap-au,process:1280, Role=CoherenceServer, Edition=Grid Edition, Mode=Develop
ment, CpuCount=4, SocketCount=4)
2010-12-06 11:41:11.207/4.285 Oracle Coherence GE 3.6.0.0 (thread=Cluster, member=n/a): Member 1 joined Service Cluster with senior mem
ber 1
2010-12-06 11:41:11.207/4.285 Oracle Coherence GE 3.6.0.0 (thread=Cluster, member=n/a): Member 1 joined Service Management with senior
member 1
2010-12-06 11:41:11.207/4.285 Oracle Coherence GE 3.6.0.0 (thread=Cluster, member=n/a): Member 1 joined Service DistributedCache with s
enior member 1
2010-12-06 11:41:11.207/4.285 Oracle Coherence GE 3.6.0.0 (thread=Cluster, member=n/a): Member 1 joined Service ReplicatedCache with se
nior member 1
2010-12-06 11:41:11.207/4.285 Oracle Coherence GE 3.6.0.0 (thread=Cluster, member=n/a): Member 1 joined Service OptimisticCache with se
nior member 1
2010-12-06 11:41:11.207/4.285 Oracle Coherence GE 3.6.0.0 (thread=Cluster, member=n/a): Member 1 joined Service InvocationService with
senior member 1
2010-12-06 11:41:11.210/4.288 Oracle Coherence GE 3.6.0.0 (thread=main, member=n/a): Started cluster Name=cluster:0xC4DB


Group{Address=224.3.6.0, Port=36000, TTL=4}


MasterMemberSet
  (
  ThisMember=Member(Id=3, Timestamp=2010-12-06 11:41:11.172, Address=10.187.114.243:8090, MachineId=50163, Location=machine:paslap-au,proces
s:6172, Role=PythonUtilJython)
  OldestMember=Member(Id=1, Timestamp=2010-12-06 11:37:53.952, Address=10.187.114.243:8088, MachineId=50163, Location=machine:paslap-au,proc
ess:1280, Role=CoherenceServer)
  ActualMemberSet=MemberSet(Size=2, BitSetCount=2
    Member(Id=1, Timestamp=2010-12-06 11:37:53.952, Address=10.187.114.243:8088, MachineId=50163, Location=machine:paslap-au,process:1280, R
ole=CoherenceServer)
    Member(Id=3, Timestamp=2010-12-06 11:41:11.172, Address=10.187.114.243:8090, MachineId=50163, Location=machine:paslap-au,process:6172, R
ole=PythonUtilJython)
    )
  RecycleMillis=1200000
  RecycleSet=MemberSet(Size=0, BitSetCount=0
    )
  )


TcpRing{Connections=[1]}
IpMonitor{AddressListSize=0}


2010-12-06 11:41:11.243/4.321 Oracle Coherence GE 3.6.0.0 (thread=Invocation:Management, member=3): Service Management joined the clust
er with senior service member 1
2010-12-06 11:41:11.300/4.378 Oracle Coherence GE 3.6.0.0 (thread=main, member=3): Loaded cache configuration from "jar:file:/C:/jdev
/coherence/36/coherence/lib/coherence.jar!/coherence-cache-config.xml"
2010-12-06 11:41:11.438/4.516 Oracle Coherence GE 3.6.0.0 (thread=DistributedCache, member=3): Service DistributedCache joined the clus
ter with senior service member 1
Cache entry 1 = pas apicella
2010-12-06 11:41:11.484/4.562 Oracle Coherence GE 3.6.0.0 (thread=Invocation:Management, member=3): Service Management left the cluster


2010-12-06 11:41:11.488/4.566 Oracle Coherence GE 3.6.0.0 (thread=DistributedCache, member=3): Service DistributedCache left the cluste
r
2010-12-06 11:41:11.580/4.658 Oracle Coherence GE 3.6.0.0 (thread=Cluster, member=3): Service Cluster left the cluster
Ended at Mon Dec 06 11:41:11 EST 2010


C:\jdev\scripting\demos\jython>

Tuesday 23 November 2010

Create a Simple Google Chrome Extension Within JDeveloper 11g

After having a quick look at the chrome extension tutorial I realized  all I really need to create extensions was to use basic web techologies like HTML, CSS, JavaScript etc. Finally a chance to use the JavaScript editor with JDeveloper 11g , so here are the steps to build a demo from a JDeveloper project and eventually load the  extension within Google Chrome itself.

Note: JDeveloper 11g provides a JavaScript debugger making it a good choice to develop JavaScript from and also provides JavaScript insight which makes it productive at the same time.

1. New empty project called "HelloApples"
2. Right click on the project and select "New -> Web Tier -> HTML - JSON File"
3. Name the file "manifest.json"
4. Add contents as follows

{
  "name": "Apples First Extension",
  "version": "1.0",
  "description": "The first extension that I made.",
  "browser_action": {
    "default_icon": "icon.png",
    "popup": "popup.html"
  }
}

5. Right click on the project and select "New -> Web Tier -> HTML -> HTML Page"
6. Name the page "popup.html" and replace the file contents as follows.
<style> 
body {
  min-width:357px;
  overflow-x:hidden;
}
</style>

<SCRIPT LANGUAGE="JavaScript">
var now = new Date();

var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

function fourdigits(number) {
 return (number < 1000) ? number + 1900 : number;
        }
today =  days[now.getDay()] + ", " +
         months[now.getMonth()] + " " +
         date + ", " +
         (fourdigits(now.getYear())) ;

document.write("Hello apples todays date is " + today);
</script>
7. Add the icon.png to the project , the one we use here is from the google demo below.

  http://code.google.com/chrome/extensions/getstarted.html

8. Your project would look as follows within JDeveloper. You will see a WEB-INF folder which
is there due to the fact the project has previously been run in the integrated WLS to test the popup.html



9. In Google Chrome bring up the extensions management page by clicking the wrench icon on the right hand side and choosing "Tools > Extensions". (On Mac, use Window > Extensions.)
10. If Developer mode has a + by it, click the + to add developer information to the page.
11. Click the Load unpacked extension button. A file dialog appears.
12. In the file dialog, navigate to your extension's folder within your JDeveloper project
and click OK.

eg:

C:\jdev\jdevprod\11113\jdeveloper\jdev\mywork\ChromeExtensionDemo\HelloApples\public_html

If all went well you should see your extension in the Google Chrome toolbar and when clicked it should show you todays date.

Wednesday 17 November 2010

How to configure your own cache factory to access multiple caches?

I needed to be able to load multiple cache configurations files within the same JVM for different applications. I found that to do this I simply create my own Cache Factory and supply my own cache config file. Of course you are in the same cluster as that member but this allows you to load different configuration files as shown below.

1. Create two cache config files as follows.

Cache Config 1 - cache-config1.xml
<?xml version="1.0"?>
<!DOCTYPE cache-config SYSTEM "cache-config.dtd">

<cache-config>

  <caching-scheme-mapping>
    <cache-mapping>
      <cache-name>config1</cache-name>
      <scheme-name>distributed</scheme-name>
    </cache-mapping>
  </caching-scheme-mapping>

  <caching-schemes>
    <distributed-scheme>
      <scheme-name>distributed</scheme-name>
      <service-name>DistributedCacheConfig1</service-name>
      <backing-map-scheme>
        <local-scheme>
          <high-units>10m</high-units>
        </local-scheme>
      </backing-map-scheme>
      <autostart>true</autostart>
    </distributed-scheme>
  </caching-schemes>

</cache-config> 

Cache Config 2 - cache-config2.xml
<?xml version="1.0"?>
<!DOCTYPE cache-config SYSTEM "cache-config.dtd">

<cache-config>

  <caching-scheme-mapping>
    <cache-mapping>
      <cache-name>config2</cache-name>
      <scheme-name>distributed</scheme-name>
    </cache-mapping>
  </caching-scheme-mapping>

  <caching-schemes>
    <distributed-scheme>
      <scheme-name>distributed</scheme-name>
      <service-name>DistributedCacheConfig2</service-name>
      <backing-map-scheme>
        <local-scheme>
          <high-units>10m</high-units>
        </local-scheme>
      </backing-map-scheme>
      <autostart>true</autostart>
    </distributed-scheme>
  </caching-schemes>

</cache-config>

2. Create a test class as follows.
package pas.au.coheremce.demo;

import com.tangosol.net.ConfigurableCacheFactory;
import com.tangosol.net.DefaultConfigurableCacheFactory;
import com.tangosol.net.NamedCache;
import com.tangosol.net.DefaultConfigurableCacheFactory.CacheInfo;

public class CacheFactoryDemo
{
  private ClassLoader loader = null;
  
  public CacheFactoryDemo()
  {
    loader  = getClass().getClassLoader();
  }

  public void run ()
  {
    // access cache config cache-config1.xml
    accessCacheConfig("cache-config1.xml", "config1");
    
    // access cache config cache-config2.xml
    accessCacheConfig("cache-config2.xml", "config2");
  }
  
  private void accessCacheConfig(String configName, String cacheName)
  {
    ConfigurableCacheFactory factory = 
      new DefaultConfigurableCacheFactory(configName);
    
    NamedCache namedCache = factory.ensureCache(cacheName, loader);  
    
    // display scheme mapping to verify we are using the correct cache config file
    DefaultConfigurableCacheFactory dccf = (DefaultConfigurableCacheFactory) factory;
    CacheInfo info = dccf.findSchemeMapping(cacheName);
    System.out.println(String.valueOf(dccf.resolveScheme(info)));
  }
  
  public static void main(String[] args)
  {
    CacheFactoryDemo test = new CacheFactoryDemo();
    test.run();
    System.out.println("all done..");
  }
}

3. When run the output below shows how this works.In the code we display the scheme mapping to verify we have set this up correctly.

Access cache-config1.xml and the output is as follows
Oracle Coherence Version 3.6.0.0 Build 17229
 Grid Edition: Development mode
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

2010-11-17 12:57:53.461/0.473 Oracle Coherence GE 3.6.0.0 <Info> (thread=main, member=n/a): Loaded cache configuration from "file:/C:/jdev/jdevprod/11113/jdeveloper/jdev/mywork/CoherenceLoadCustomCacheConfig/Demo/classes/cache-config1.xml"
2010-11-17 12:57:53.821/0.833 Oracle Coherence GE 3.6.0.0 <D4> (thread=main, member=n/a): TCMP bound to /10.187.114.243:8088 using SystemSocketProvider
2010-11-17 12:57:57.215/4.227 Oracle Coherence GE 3.6.0.0 <Info> (thread=Cluster, member=n/a): Created a new cluster "cluster:0xC4DB" with Member(Id=1, Timestamp=2010-11-17 12:57:53.846, Address=10.187.114.243:8088, MachineId=50163, Location=machine:paslap-au,process:6608, Role=PasAuCoheremceCacheFactoryDemo, Edition=Grid Edition, Mode=Development, CpuCount=4, SocketCount=4) UID=0x0ABB72F30000012C578D6836C3F31F98
2010-11-17 12:57:57.224/4.236 Oracle Coherence GE 3.6.0.0 <Info> (thread=main, member=n/a): Started cluster Name=cluster:0xC4DB

...

2010-11-17 12:57:57.440/4.452 Oracle Coherence GE 3.6.0.0 <D5> (thread=DistributedCache:DistributedCacheConfig1, member=1): Service DistributedCacheConfig1 joined the cluster with senior service member 1
<distributed-scheme>
  <scheme-name>distributed</scheme-name>
  <service-name>DistributedCacheConfig1</service-name>
  <backing-map-scheme>
    <local-scheme>
      <high-units>10m</high-units>
    </local-scheme>
  </backing-map-scheme>
  <autostart>true</autostart>
</distributed-scheme>

Access cache-config2.xml and the output from that is as follows
2010-11-17 12:57:57.504/4.516 Oracle Coherence GE 3.6.0.0 <Info> (thread=main, member=1): Loaded cache configuration from "file:/C:/jdev/jdevprod/11113/jdeveloper/jdev/mywork/CoherenceLoadCustomCacheConfig/Demo/classes/cache-config2.xml"
2010-11-17 12:57:57.508/4.520 Oracle Coherence GE 3.6.0.0 <D5> (thread=DistributedCache:DistributedCacheConfig2, member=1): Service DistributedCacheConfig2 joined the cluster with senior service member 1
<distributed-scheme>
  <scheme-name>distributed</scheme-name>
  <service-name>DistributedCacheConfig2</service-name>
  <backing-map-scheme>
    <local-scheme>
      <high-units>10m</high-units>
    </local-scheme>
  </backing-map-scheme>
  <autostart>true</autostart>
</distributed-scheme>  

More information on  this can be found in the javadoc as follows:

http://download.oracle.com/otn_hosted_doc/coherence/330/com/tangosol/net/DefaultConfigurableCacheFactory.html

Friday 12 November 2010

JDeveloper 11g - Using Coherence Resource Adapater (RA) Within Weblogic 11g

The following demo is an example on how to use the Coherence RA within Weblogic 11g (10.3.3). In this example we are using Coherence 3.6 and this setup is based on having the RA as a stand alone application which my web based application developed in JDeveloper 11g (11.1.1.3) would then use.

Steps for Setup in WLS 11g (10.3.3)

1. Place coherence.jar into $DOM_HOME/lib directory as shown below.

[oracle@wayne-p2 lib]$ pwd
/home/oracle/product/11gR3/user_projects/domains/cohtx-dom/lib
[oracle@wayne-p2 lib]$ ls -la
total 5324
drwxr-x---   2 oracle oinstall    4096 Nov 10 13:17 .
drwxr-x---  13 oracle oinstall    4096 Nov 10 08:38 ..
-rw-r-----   1 oracle oinstall 5409133 Nov 10 13:17 coherence.jar
-rw-r-----   1 oracle oinstall     702 Nov  7 13:29 readme.txt
[oracle@wayne-p2 lib]$

2. Deploy $COH_HOME/lib/coherence-transaction.rar (Coherence 3.6) to the WLS 10.3.3. Accept all the defaults here during deployment BUT ensure you target it to the managed server you wish to use.



For information on how to use the Coherence RA you just deployed use the documentation
link below.

http://download.oracle.com/docs/cd/E15357_01/coh.360/e15723/api_transactionslocks.htm#BEIEBGAH
Using the Coherence Resource Adapter

Steps for Application Side (JDeveloper 11g - 11.1.1.3)

In the steps below we just highlight what is needed from the JDeveloper project itself, rather then full steps on what to create. This demo was built using Struts/JSP.

1. In the web.xml create a resource reference as shown below.
<resource-ref>
    <res-ref-name>eis/CoherenceTxCF</res-ref-name>
    <res-type>com.tangosol.coherence.transaction.ConnectionFactory
    </res-type>
    <res-auth>Container</res-auth>
  </resource-ref>

2. Create a weblogic.xml file as follows. You add a new one to a web project using "File -> New -> General -> Deployment Descriptors -> Weblogic Deployment Descriptor"
<resource-ref>
<?xml version = '1.0' encoding = 'windows-1252'?>
<weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd"
                  xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">
    <resource-description>
      <res-ref-name>
        eis/CoherenceTxCF
      </res-ref-name>
      <jndi-name>
        tangosol.coherenceTx
      </jndi-name>
    </resource-description>
    <resource-description>
      <res-ref-name>
        eis/CoherenceTxCCICF
      </res-ref-name>
      <jndi-name>
        tangosol.coherenceTxCCI
      </jndi-name>
    </resource-description>
</weblogic-web-app>

Note: The JNDI resource description "tangosol.coherenceTx" is defined in the Coherence RA we deployed earlier. This maps back to our web.xml JNDI reference "eis/CoherenceTxCF".

3.The cache config file is included in the web project and so must be loaded at application startup. To do this we use a empty servlet and define this in the init() method as shown below.
package support.au.coherence.demo;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.*;
import javax.servlet.http.*;

public class CacheSetupServlet
  extends HttpServlet
{
  private static final String CONTENT_TYPE = "text/html; charset=windows-1252";

  public void init(ServletConfig config) throws ServletException
  {
    // servlet only required to ensure this application using our cache config
    System.setProperty("tangosol.coherence.cacheconfig", 
                       "coherence-tx-cache-config.xml");
    System.out.println("** CacheSetupServlet.init() called **");
    super.init(config);
  }
}  

Note: coherence-tx-cache-config.xml is defined as follows
<?xml version="1.0"?>

<!DOCTYPE cache-config SYSTEM "cache-config.dtd">

<cache-config>

  <caching-scheme-mapping>
    <cache-mapping>
      <cache-name>tx-*</cache-name>
      <scheme-name>transactional</scheme-name>
    </cache-mapping>
  </caching-scheme-mapping>

  <caching-schemes>
    <transactional-scheme>
      <scheme-name>transactional</scheme-name>
      <service-name>TestTxnService</service-name>
      <request-timeout>30000</request-timeout>
      <autostart>true</autostart>
    </transactional-scheme>

  </caching-schemes>

</cache-config>

4. In order for this HTTP Servlet to start up at application start up we define an entry in web.xml as follows.
<servlet>
    <servlet-name>CacheSetupServlet</servlet-name>
    <servlet-class>support.au.coherence.demo.CacheSetupServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet> 

5. Now we are ready to dpeloy our application which we can do from JDeveloper itself by creating a WAR deployment profile. A successful deployment is shown as follows

[09:08:54 AM] ----  Deployment started.  ----
[09:08:54 AM] Target platform is  (Weblogic 10.3).
[09:08:58 AM] Retrieving existing application information
[09:08:58 AM] Running dependency analysis...
[09:08:58 AM] Building...
[09:09:02 AM] Deploying profile...
[09:09:02 AM] Wrote Web Application Module to C:\jdev\jdevprod\11113\jdeveloper\jdev\mywork\CoherenceRAWebApplication\Demo\deploy\cohra-web.war
[09:09:02 AM] Redeploying Application...
[09:09:04 AM] [Deployer:149191]Operation 'deploy' on application 'cohra-web' is initializing on 'apple'
[09:09:05 AM] [Deployer:149192]Operation 'deploy' on application 'cohra-web' is in progress on 'apple'
[09:09:06 AM] [Deployer:149194]Operation 'deploy' on application 'cohra-web' has succeeded on 'apple'
[09:09:06 AM] Application Redeployed Successfully.
[09:09:06 AM] The following URL context root(s) were defined and can be used as a starting point to test your application:
[09:09:06 AM] http://10.187.81.36:7003/cohra-web
[09:09:06 AM] Elapsed time for deployment:  12 seconds
[09:09:06 AM] ----  Deployment finished.  ----

The Struts action which does the work here is as follows.

package support.au.coherence.demo;


import com.tangosol.coherence.transaction.Connection;
import com.tangosol.coherence.transaction.ConnectionFactory;

import com.tangosol.coherence.transaction.OptimisticNamedCache;

import java.io.IOException;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


public class TestCohRAAction extends Action
{
  private final String DEPT_TX_CACHE = "tx-dept";
  private final String EMP_TX_CACHE = "tx-emp";
  private final String TX_SERVICE = "TestTxnService";
  
  /**This is the main action called from the Struts framework.
   * @param mapping The ActionMapping used to select this instance.
   * @param form The optional ActionForm bean for this request.
   * @param request The HTTP Request we are processing.
   * @param response The HTTP Response we are processing.
   */
  public ActionForward execute(ActionMapping mapping, ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response)
    throws IOException, ServletException
  {
    InitialContext initCtx = null;
    ConnectionFactory factory = null;
    Connection coherenceTxConn = null;
    
    try
    {
      initCtx = getInititalContext();
      factory = (ConnectionFactory) 
          initCtx.lookup("java:comp/env/eis/CoherenceTxCF");
      
      coherenceTxConn = factory.createConnection(TX_SERVICE);
      coherenceTxConn.setAutoCommit(false);
      
      OptimisticNamedCache dept = coherenceTxConn.getNamedCache(DEPT_TX_CACHE);
      OptimisticNamedCache emp  = coherenceTxConn.getNamedCache(EMP_TX_CACHE);
      
      // Empty both caches we want to esnure no data exists prior to the run
      // as inserts will fail if they already exist
      dept.clear();
      emp.clear();
      
      dept.insert("10", "ACCOUNTING");
      emp.insert("1", "dept 10 : PAS");
      emp.insert("2", "dept 10 : LUCIA");
      emp.insert("3", "dept 10 : SIENA");
      emp.insert("4", "dept 10 : LUCAS");
      
      coherenceTxConn.commit();
      
      System.out.println(String.format("Size of dept cache = %s", dept.size()));
      System.out.println(String.format("Size of emp cache = %s", emp.size()));
      
      request.setAttribute
        ("deptcache", 
         String.format("Size of dept cache = %s", dept.size()));

      request.setAttribute
        ("empcache", 
         String.format("Size of emp cache is %s", emp.size()));
    }
    catch (Exception ex)
    {
      ex.printStackTrace();
      coherenceTxConn.rollback();
    }
    finally 
    {
      if (coherenceTxConn != null)
      {
        coherenceTxConn.close();
      }
    }
    
    return mapping.findForward( "success");
  }
  
  private InitialContext getInititalContext () throws NamingException
  {
    return new InitialContext();
  }
} 

The resulting view page simply displays the cache sizes as part of the transaction once committed as shown below.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
  <title>Coherence RA Web Application</title>
</head>
<body>
<h2>Coherence RA Web Application</h2>

${deptcache}
${empcache}
<p />
<hr />
<b>Oracle Support Services</b>

</body>
</html>

The JDeveloper project would look something like this.

Thursday 11 November 2010

Referencing Coherence from Web Applications (WAR) in WLS 11g

I am constantly providing coherence.jar in the WEB-INF/lib of my web based (WAR) applications in WLS 11g. So obviously it made more sense to deploy coherence.jar as library and then reference it but WLS 11g does not allow web based applications to reference shared library JAR files as per the link below.

http://download.oracle.com/docs/cd/E13222_01/wls/docs92/programming/libraries.html#wp1071062

"You cannot reference any other type of shared J2EE library (EJB, Enterprise application, or plain JAR file) from the weblogic.xml deployment descriptor file of a Web Application."

Here is what i did to get this to work.

1. Create a shared library coherence.jar for version 3.6 as shown below. I targeted this to the managed servers I was using.



2. In my WAR file create a META-INF/MANIFEST.MF with content as follows.

Extension-List: cohlib
cohlib-Extension-Name: coherence
cohlib-Specification-Version: 3.6.0.0
cohlib-Implementation-Version: 3.6.0.0

3. The JDeveloper 11g project would look something like this, as you can clearly see there is no coherence.jar in WEB-INF\lib folder with this setup.


I found this setup as follows enabling me to use JAR files as libraries from WAR / Web Based Applications.

http://download.oracle.com/docs/cd/E13222_01/wls/docs92/programming/libraries.html#wp1064645

Monday 8 November 2010

Age Expiry Local Cache With Coherence

The local cache supports automatic expiration of entries based on the age of the value, as configured by the expiry-delay tag. The following example will show how to expire cache entries after the configured time as per expiry-delay, regardless of how many times the entry is updated, hence overriding the default behavior.

1. Create a java class as follows.
package support.au.coherence.examples;

import com.tangosol.net.cache.CacheLoader;
import com.tangosol.net.cache.LocalCache;
import com.tangosol.util.SafeHashMap;

public class AgeExpiryLocalCache extends LocalCache
{
  public AgeExpiryLocalCache()
  {
    super();
  }

  public AgeExpiryLocalCache(int cUnits)
  {
    super(cUnits);
  }

  public AgeExpiryLocalCache(int cUnits, int cExpiryMillis)
  {
    super(cUnits, cExpiryMillis);
  }

  public AgeExpiryLocalCache
  (int cUnits, int cExpiryMillis, CacheLoader loader)
  {
    super(cUnits, cExpiryMillis, loader);
  }

  protected SafeHashMap.Entry instantiateEntry()
  {
    return new Entry();
  }

  /**
   * Entry extension that will not reset expiry when entry
   * value is updated.
   */
  public class Entry extends LocalCache.Entry
  {
    public Entry()
    {
      super();
    }

    protected void scheduleExpiry()
    {
      // only set the expiry if it has not been set yet
      if (getExpiryMillis() > 0)
      {
        return;
      }
  
      super.scheduleExpiry();
    }
  }
}

2. Setup you cache config file to use this custom Local Cache as shown below.



 
   
     age-cache
     age-scheme
   
 
 
  
    age-scheme
      
        
           60s         
           
             support.au.coherence.examples.AgeExpiryLocalCache
           
        
      
      true
  
 


So in this example cache entries will expire 60 seconds after they are first inserted regardless of how often it is updated.

Tuesday 2 November 2010

Connecting to WLS 11g MBeanServer using jconsole on a windows client

Viewing the MBeans available in WLS 11g from the client side with jconsole is done as follows. The key here is to create the necessary client side JAR file required to access WLS 11g using JMX. In this example we are using JDK 1.6.

Note: The steps for JDK 1.5 are NOT identical to these.

1. First create a wlfullclient.jar with steps as follows on the WLS server. This will give you what you need on the client side to connect to WLS MBean Server.

- Change directories to the server/lib directory.

cd WL_HOME/server/lib

- Use the following command to create wlfullclient.jar in the server/lib directory:

java -jar wljarbuilder.jar

2. Now add/provide wlfullclient.jar to the classpath for jconsole on the client side as follows.

jconsole -J-Djava.class.path=wlfullclient.jar;C:\jdev\jdk\jdk1.6.0_21\lib\jconsole.jar -J-Djmx.remote.protocol.provider.pkgs=weblogic.management.remote

3. Jconsole should display requesting you to provide the remote server you wish to connect to. In this example I am simply going to connect to the RUNTIME MBean Sever with connect details as follows for the "Remote Process" field. Also I have to add a username/password for the WLS 11g server in order to connect.

service:jmx:iiop://wayne-p2.au.oracle.com:7003/jndi/weblogic.management.mbeanservers.runtime


4. Press the connect button and now you can easily see which MBeans you wish to view.


For more information on the MBeans in WLS 11g refer to this URL.

http://download.oracle.com/docs/cd/E14571_01/apirefs.1111/e13951/core/index.html

Friday 29 October 2010

Using Apache Velocity From JDeveloper 11g

I needed to support various output formats (console, HTML, SQL) for a Java console application I was creating and so saw Apache Velocity as a good fit for this. Here are some quick steps to get this setup in JDeveloper 11g.

1. Add the velocity JAR files to your project classpath as shown below.


2. Create a velocity.properties file as follows. In this example the templates files will be read from the file system , you can read them from the classpath if you wish. You will see that from this example below the velocity template files are in the SRC directory of the project so I can edit them from the IDE itself.

resource.loader = file
file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader
file.resource.loader.path = C:/jdev/jdevprod/11113/jdeveloper/jdev/mywork/VelocityDemo/Demo/src/templates
file.resource.loader.cache = true

3. In the directory "C:/jdev/jdevprod/11113/jdeveloper/jdev/mywork/VelocityDemo/Demo/src/templates" create a helloworld.vm template file as follows

Hello $name!  Welcome to Velocity!

4. Now create a java class as follows
package support.au.demos.velocity;

import java.io.StringWriter;

import java.net.URL;

import java.util.Properties;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;


public class HelloWorld
{
  public HelloWorld()
  {
  }
  
  public static void main(String[] args) throws Exception
  {
    /*  first, get and initialize an engine  */
    VelocityEngine ve = new VelocityEngine();

    Properties props = new Properties();
    
    URL url = ClassLoader.getSystemResource("velocity.properties");
    props.load(url.openStream());
    
    ve.init(props);
    /*  next, get the Template  */
    Template t = ve.getTemplate( "helloworld.vm" );
    /*  create a context and add data */
    VelocityContext context = new VelocityContext();
    context.put("name", "World");
    /* now render the template into a StringWriter */
    StringWriter writer = new StringWriter();
    t.merge( context, writer );
    /* show the World */
    System.out.println( writer.toString() ); 
  }
}

5. Your project would look something like this


6. Run HelloWorld to verify the output as shown below.

Hello World!  Welcome to Velocity!

Friday 22 October 2010

Generic MBean client for FMW JVM's (Coherence, WLS etc)

Having done some work with MBeans in OC4J 10.1.3.x I decided with the help of steve to create a query tool which allowed you to view the properties/attributes of any MBean from the command line. The JMX API makes it easy to write a generic tool so in the end I can query any JVM with an MBean Server using the tool. In short this is what I did using spring to ensure it was easy to setup with XML and of course run with ANT. Whats good about this is I can just query the MBeans I want to see rather then all of them. Early days but it does what I need it to do at this stage. Different output methods is what I want to do next, currently it just goes to standard out / console.

Step 1 - Define a connection Interface
package oracle.support.rda.server;

import java.util.Hashtable;

import javax.management.MBeanServerConnection;
import javax.management.remote.JMXServiceURL;

public interface ServerConnection 
{
  public void doConnection(String url) throws Exception;
  public void doConnection(JMXServiceURL jmxServiceURL, Hashtable env) throws Exception;
  public MBeanServerConnection getConnection();
  public boolean isConnected();
  public void close ();
}

Step 2 - Create an abstract class which implements the interface , pretty much does everything you need to connect to a MBean Server.
package oracle.support.rda.server;

import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;


public abstract class ServerConnectionBase implements ServerConnection
{
  private JMXConnector jmxCon = null;
  private Logger logger = Logger.getLogger(this.getClass().getName());
  
  public ServerConnectionBase()
  {
  }

  public void doConnection(String url) throws Exception
  {
    logger.log(Level.INFO, "JMX Service URL = " + url);
    JMXServiceURL serviceURL = new JMXServiceURL(url);

    jmxCon = JMXConnectorFactory.connect(serviceURL);
  }

  public void doConnection(JMXServiceURL jmxServiceURL, Hashtable env) throws Exception
  {
    logger.log(Level.INFO, "Service URL Path = " + jmxServiceURL.getURLPath());
    jmxCon = JMXConnectorFactory.connect(jmxServiceURL, env);    
  }
  
  public MBeanServerConnection getConnection()
  {
    MBeanServerConnection mbs = null;

    if (jmxCon != null) 
    {
        try 
        {
            mbs = jmxCon.getMBeanServerConnection();
        } 
        catch (Throwable t) 
        {
            logger.log(Level.SEVERE,
                      "** FMW-RDA [ServerConnectionBase.getConnection] : Unable to retrieve MBeanServerConnection");
        }
    }

    return mbs;
  }

  public boolean isConnected()
  {
    boolean ret = false;
    if (jmxCon == null) 
    {
        return false;
    } 
    else 
    {
        try 
        {
            jmxCon.getConnectionId();
            return true;
        } 
        catch (Throwable t) 
        {
            // no need to do anything here
        }
    }

    return ret;
  }

  public void close()
  {
    if (jmxCon != null) 
    {
        try 
        {
            jmxCon.close();
            jmxCon = null;
        } 
        catch (Throwable t) 
        {
        }
    }
  }

}

Step 3 -Finally a class which connects to a WLS 11g instance
package oracle.support.rda.server.connections.wls;

import java.net.URL;

import java.util.Hashtable;
import java.util.Properties;
import java.util.logging.Logger;

import javax.management.remote.JMXConnectorFactory;

import javax.management.remote.JMXServiceURL;

import javax.naming.Context;

import oracle.support.rda.server.ServerConnectionBase;
import oracle.support.rda.server.connections.coherence.CohJMXConnection;

public class WLSJMXConnection extends ServerConnectionBase
{
  private static WLSJMXConnection instance = null;
  private Logger logger = Logger.getLogger(this.getClass().getName());
  private String serviceURL = null;
  
  static
  {
    try
    {
      instance = new WLSJMXConnection();
    }
    catch (Exception e)
    {
      throw new RuntimeException(e.getMessage(), e);
    }
  }
  
  private WLSJMXConnection() throws Exception
  {
    JMXServiceURL jmxServiceURL = null;
    Hashtable h = new Hashtable();
    
    if (instance == null)
    {
      Properties props = new Properties();
      
      URL url = ClassLoader.getSystemResource("server.properties");
      props.load(url.openStream());

      h.put(Context.SECURITY_PRINCIPAL, props.getProperty("wls.username"));
      h.put(Context.SECURITY_CREDENTIALS, props.getProperty("wls.password"));
      h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
         "weblogic.management.remote");
      h.put("jmx.remote.x.request.waiting.timeout", new Long(10000));

      serviceURL = (String) props.getProperty("serviceurl");
      
      jmxServiceURL = 
        new JMXServiceURL(serviceURL);
      
    }
    
    super.doConnection(jmxServiceURL, h);
  }

  public static WLSJMXConnection getInstance() throws Exception
  { 
    return instance;
  }

  public String getServiceURL()
  {
    return serviceURL;
  }
}

So we would then use this connection in a spring XML file as follows using a Factory Class which defines the connections we wish to use. At the time of this post I had an OC4J 10.1.3.x, WLS 10.3.x and Coherence connection implementation classes which extend ServerConnectionBase.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

  <bean id="serverConnection" 
        class="oracle.support.rda.server.ConnectionFactory" 
        factory-method="getWLSConnection" 
        singleton="true">
  </bean> 

Step 4 - Define an interface which allows us to invoke queries against the MBeans and view there attributes

package oracle.support.rda.spring.queries;

import javax.management.MBeanServerConnection;

import oracle.support.rda.spring.exception.RDAQueryException;

public interface RDAQuery 
{
    public Object invoke(MBeanServerConnection mbs) throws RDAQueryException;
    public void setMBeanName(String mbeanName);
}

Step 5 - Define a implementation class for the query interface. The abstract class has been left out here but that's what does all the work of viewing the MBean attributes etc..
package oracle.support.rda.spring.queries;

import java.util.logging.Logger;

import javax.management.MBeanServerConnection;

import oracle.support.rda.spring.exception.RDAQueryException;

public class GenericQuery extends RDAQueryBase
{
  Logger logger = Logger.getLogger(this.getClass().getName());
  
  @Override
  public Object invoke(MBeanServerConnection mbs) throws RDAQueryException 
  {
      logger.info("Generic Query called");
      return super.invoke(mbs);
  }
}


Step 6 - Define the MBeans I wish to query as shown in the example below.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

  <bean id="serverConnection" 
        class="oracle.support.rda.server.ConnectionFactory" 
        factory-method="getWLSConnection" 
        singleton="true">
  </bean>
  
  <bean id="machineQuery" class="oracle.support.rda.spring.queries.GenericQuery">
    <property name="MBeanName">
      <value>com.bea:Name=machine1,Type=Machine</value>
    </property>
  </bean>

  <bean id="nodeMgrQuery" class="oracle.support.rda.spring.queries.GenericQuery">
    <property name="MBeanName">
      <value>com.bea:Name=machine1,Type=NodeManager,Machine=machine1</value>
    </property>
  </bean>
  
  <bean id="appleJVMQuery" class="oracle.support.rda.spring.queries.GenericQuery">
    <property name="MBeanName">
      <value>
        com.bea:ServerRuntime=apple,Name=apple,Type=JVMRuntime      
      </value>
    </property>
    <!--
    The following properties will not be displayed, giving you
    control over what information you show.
    -->
    <property name="nukedAttributes">
      <list>
        <value>ThreadStackDump</value>  
      </list>
    </property>
  </bean>
  
  <bean id="jdbcResourceQuery" class="oracle.support.rda.spring.queries.GenericQuery">
    <property name="MBeanName">
      <value>
        com.bea:Name=jdbc/scottDS,Type=JDBCSystemResource    
      </value>
    </property>
  </bean>

  <bean id="jdbcPropertiesQuery" class="oracle.support.rda.spring.queries.GenericQuery">
    <property name="MBeanName">
      <value>
        com.bea:Name=user,Type=weblogic.j2ee.descriptor.wl.JDBCPropertyBean,Parent=[pastest_dom]/JDBCSystemResources[jdbc/scottDS],Path=JDBCResource[jdbc/scottDS]/JDBCDriverParams/Properties/Properties[user]  
      </value>
    </property>
  </bean>

  <!--  
    This defines the Invoker object, which gets passed 
    a reference to the ServerConnection AND the list of queries
   -->
  <bean id="queryInvoker" class="oracle.support.rda.spring.invoker.QueryInvoker">
    <property name="serverConnection" ref="serverConnection"/>
    <property name="rdaQueries">
      <list>
        <ref bean="machineQuery"/>
        <ref bean="nodeMgrQuery"/>
        <ref bean="appleJVMQuery"/>
        <ref bean="jdbcResourceQuery"/>
        <ref bean="jdbcPropertiesQuery"/>
      </list>
    </property>
  </bean>    

  <!--  
   Bean used to list of MBeans available for use
   -->
  <bean id="showMBeans" class="oracle.support.rda.spring.invoker.MBeanViewer">
    <property name="serverConnection" ref="serverConnection"/>
  </bean> 
  
</beans> 

I provided the ability to remove properties you really don't wish to view for the MBean itself. The name nukedAttributes came from steve.

The queryInvoker bean is what actually invokes the queries themselves which takes a List of query beans themselves and uses the MBean Server Connection we defined at the start. That class is as follows

package oracle.support.rda.spring.invoker;
package oracle.support.rda.spring.invoker;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import oracle.support.rda.server.ServerConnection;
import oracle.support.rda.spring.exception.RDAQueryException;
import oracle.support.rda.spring.queries.RDAQuery;

@SuppressWarnings("unchecked")
public class QueryInvoker {

    private final Logger logger = Logger.getLogger(this.getClass().getName());
    private ServerConnection serverConnection;
    private List<RDAQuery> rdaQueries = new ArrayList<RDAQuery>();
    
    /**
     * @param rdaQueries the rdaQueries to set
     */
    public void setRdaQueries(List rdaQueries) 
    {
      System.out.println(rdaQueries.toString());
      this.rdaQueries = rdaQueries;
    }

    /**
     * @param mbeanServerConnection the mbeanServerConnection to set
     */
    public void setServerConnection(ServerConnection serverConnection) 
    {
      this.serverConnection = serverConnection;
    }

    public QueryInvoker() 
    {
      // TODO Auto-generated constructor stub
      logger.setLevel(Level.ALL);
    }
    
    public int getQueryCount() 
    {
      return rdaQueries.size();
    }
    
    public void run() 
    {
      for(RDAQuery query: rdaQueries) 
      {
          
        try 
        {
            System.out.println(query.invoke(serverConnection.getConnection()));    
        } 
        catch (RDAQueryException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
      }
    }
       
}

Output of this running is as follows against OC4J 10.1.3.x in an OPMN managed environment.

C:\jdev\ant-demos\11gFMW\fmw-rda>ant run-rda
Buildfile: build.xml

init:
    [mkdir] Created dir: C:\jdev\ant-demos\11gFMW\fmw-rda\dist
    [mkdir] Created dir: C:\jdev\ant-demos\11gFMW\fmw-rda\classes

compile:
    [javac] Compiling 17 source files to C:\jdev\ant-demos\11gFMW\fmw-rda\classes
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
     [copy] Copying 1 file to C:\jdev\ant-demos\11gFMW\fmw-rda\classes

package:
      [jar] Building jar: C:\jdev\ant-demos\11gFMW\fmw-rda\dist\fmwrda.jar

run-rda:
     [java] 17/10/2010 8:17:48 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
     [java] INFO: Loading XML bean definitions from class path resource [query-beans.xml]
     [java] 17/10/2010 8:17:49 PM oracle.support.rda.server.ServerConnectionBase doConnection
     [java] INFO: Service URL Path = /opmn://beast.au.oracle.com:6003/home
     [java] [oracle.support.rda.spring.queries.GenericQuery@6401d98a, oracle.support.rda.spring.queries.GenericQuery@35712651]
     [java] Queries: 2
     [java] 17/10/2010 8:17:54 PM oracle.support.rda.spring.queries.GenericQuery invoke
     [java] INFO: Generic Query called
     [java]
     [java] [MBean: oc4j:j2eeType=ThreadPool,name=http,J2EEServer=standalone]
     [java] 17/10/2010 8:17:55 PM oracle.support.rda.spring.queries.GenericQuery invoke
     [java] INFO: Generic Query called
     [java]
     [java] *** Attributes ***
     [java]                             (int) minPoolSize                   : 0
     [java]                            (long) poolSize                      : 11
     [java]             ([Ljava.lang.String;) executingThreadNames          : com.evermind.util.ReleasableResourcePooledExecutor$MyWorker@93
c4f1=Thread[JMSServer[beast.au.oracle.com:12601],5,HTTPThreadGroup], com.evermind.util.ReleasableResourcePooledExecutor$MyWorker@1e2299d=Thr
ead[RMIClientConnectionThread-HTTPThreadGroup-10,5,HTTPThreadGroup], com.evermind.util.ReleasableResourcePooledExecutor$MyWorker@d844a9=Thre
ad[RMIServer [/0.0.0.0:12401] count:1,5,HTTPThreadGroup], com.evermind.util.ReleasableResourcePooledExecutor$MyWorker@aa3e6e=Thread[RMIServe
rConnectionThread-7,5,HTTPThreadGroup], com.evermind.util.ReleasableResourcePooledExecutor$MyWorker@56cf01=Thread[RMICallHandler-41,5,HTTPTh
readGroup], com.evermind.util.ReleasableResourcePooledExecutor$MyWorker@83e5f1=Thread[RMIServer [/0.0.0.0:12701] count:1,5,HTTPThreadGroup],
 com.evermind.util.ReleasableResourcePooledExecutor$MyWorker@3de6df=Thread[RMIClientConnectionThread-HTTPThreadGroup-8,5,HTTPThreadGroup], c
om.evermind.util.ReleasableResourcePooledExecutor$MyWorker@12cc81d=Thread[RMIServerConnectionThread-39,5,HTTPThreadGroup], com.evermind.util
.ReleasableResourcePooledExecutor$MyWorker@e834e4=Thread[RMIClientConnectionThread-RMICallHandler-21,5,HTTPThreadGroup], com.evermind.util.R
eleasableResourcePooledExecutor$MyWorker@1a04c26=Thread[RMIClientConnectionThread-RMICallHandler-4,5,HTTPThreadGroup], com.evermind.util.Rel
easableResourcePooledExecutor$MyWorker@ca22a=Thread[RMIServerConnectionThread-9,5,HTTPThreadGroup],
     [java]                (java.lang.String) name                          : http
     [java]                             (int) queueCapacity                 : 0
     [java]                (java.lang.String) objectName                    : oc4j:j2eeType=ThreadPool,name=http,J2EEServer=standalone
     [java]                             (int) maxPoolSize                   : 1024
     [java]                         (boolean) stateManageable               : false
     [java]                            (long) keepAliveTime                 : 600000
     [java]                         (boolean) eventProvider                 : false
     [java]     (javax.management.ObjectName) ObjectName                    : oc4j:j2eeType=ThreadPool,name=http,J2EEServer=standalone
     [java]                             (int) queueSize                     : 0
     [java]                         (boolean) statisticsProvider            : false
     [java]                         (boolean) debug                         : false
     [java]
     [java]
     [java] [MBean: oc4j:j2eeType=J2EEServer,name=standalone]
     [java]
     [java] *** Attributes ***
     [java]  ([Ljavax.management.ObjectName;) DeployedObjects               : [Ljavax.management.ObjectName;@30e34726
     [java]                (java.lang.String) serverBuildDate               : 090727
     [java]  ([Ljavax.management.ObjectName;) J2eeWebSites                  : [Ljavax.management.ObjectName;@1b980630
     [java]  ([Ljavax.management.ObjectName;) Resources                     : [Ljavax.management.ObjectName;@1b45e2d5
     [java]  ([Loracle.oc4j.admin.management.shared.SharedLibrary;) sharedLibraries               : [Loracle.oc4j.admin.management.shared.Sh
aredLibrary;@581de498
     [java]                             (int) state                         : 1
     [java]                         (boolean) dmsOn                         : true
     [java]             ([Ljava.lang.String;) deployedObjects               : oc4j:j2eeType=EJBModule,name="admin_ejb",J2EEApplication=syste
m,J2EEServer=standalone, oc4j:j2eeType=EJBModule,name="jmsrouter_ejb",J2EEApplication=default,J2EEServer=standalone, oc4j:j2eeType=EJBModule
,name="SessionEJB",J2EEApplication=SessionEJB,J2EEServer=standalone, oc4j:j2eeType=WebModule,name=web,J2EEApplication=mapviewer,J2EEServer=s
tandalone, oc4j:j2eeType=WebModule,name=WebServices,J2EEApplication=WSRocks,J2EEServer=standalone, oc4j:j2eeType=WebModule,name=petercrap,J2
EEApplication=petercrap,J2EEServer=standalone, oc4j:j2eeType=WebModule,name=wsil-ias,J2EEApplication=WSIL-App,J2EEServer=standalone, oc4j:j2
eeType=WebModule,name=webapp1,J2EEApplication=testhtml,J2EEServer=standalone, oc4j:j2eeType=WebModule,name=sunilcrap,J2EEApplication=sunilcr
ap,J2EEServer=standalone, oc4j:j2eeType=WebModule,name=WebServices,J2EEApplication=AdrianTest-Project1-WS,J2EEServer=standalone, oc4j:j2eeTy
pe=WebModule,name=javasso-web,J2EEApplication=javasso,J2EEServer=standalone, oc4j:j2eeType=WebModule,name=JMXSoapAdapter-web,J2EEApplication
=system,J2EEServer=standalone, oc4j:j2eeType=WebModule,name=webapp,J2EEApplication=datatags,J2EEServer=standalone, oc4j:j2eeType=WebModule,n
ame=dms,J2EEApplication=system,J2EEServer=standalone, oc4j:j2eeType=WebModule,name=defaultWebApp,J2EEApplication=default,J2EEServer=standalo
ne, oc4j:j2eeType=WebModule,name=SupportWar,J2EEApplication=Support,J2EEServer=standalone, oc4j:j2eeType=WebModule,name=jmsrouter_web,J2EEAp
plication=default,J2EEServer=standalone, oc4j:j2eeType=WebModule,name=webapp1,J2EEApplication=secDemo,J2EEServer=standalone, oc4j:j2eeType=W
ebModule,name=ascontrol,J2EEApplication=ascontrol,J2EEServer=standalone, oc4j:j2eeType=ResourceAdapterModule,name=simpleOemsRA,J2EEApplicati
on=default,J2EEServer=standalone, oc4j:j2eeType=ResourceAdapterModule,name=OracleASjms,J2EEApplication=default,J2EEServer=standalone, oc4j:j
2eeType=J2EEApplication,name=system,J2EEServer=standalone, oc4j:j2eeType=J2EEApplication,name=WSIL-App,J2EEServer=standalone, oc4j:j2eeType=
J2EEApplication,name=petercrap,J2EEServer=standalone, oc4j:j2eeType=J2EEApplication,name=default,J2EEServer=standalone, oc4j:j2eeType=J2EEAp
plication,name=mapviewer,J2EEServer=standalone, oc4j:j2eeType=J2EEApplication,name=Support,J2EEServer=standalone, oc4j:j2eeType=J2EEApplicat
ion,name=secDemo,J2EEServer=standalone, oc4j:j2eeType=J2EEApplication,name=javasso,J2EEServer=standalone, oc4j:j2eeType=J2EEApplication,name
=WSRocks,J2EEServer=standalone, oc4j:j2eeType=J2EEApplication,name=datatags,J2EEServer=standalone, oc4j:j2eeType=J2EEApplication,name=sunilc
rap,J2EEServer=standalone, oc4j:j2eeType=J2EEApplication,name=AdrianTest-Project1-WS,J2EEServer=standalone, oc4j:j2eeType=J2EEApplication,na
me=testhtml,J2EEServer=standalone, oc4j:j2eeType=J2EEApplication,name=SessionEJB,J2EEServer=standalone, oc4j:j2eeType=J2EEApplication,name=a
scontrol,J2EEServer=standalone,
     [java]     (javax.management.ObjectName) ObjectName                    : oc4j:j2eeType=J2EEServer,name=standalone
     [java]             ([Ljava.lang.String;) j2eeWebSites                  : oc4j:j2eeType=J2EEWebSite,name=default-web-site,J2EEServer=sta
ndalone,
     [java]                (java.lang.String) serverVendor                  : Oracle Corp.
     [java]                (java.lang.String) serverVersion                 : 10.1.3.5.0
     [java]                         (boolean) statisticsProvider            : false
     [java]                            (long) startTime                     : 1286851282887
     [java]                (java.lang.String) instanceName                  : home
     [java]                (java.lang.String) defaultRoutingId              : g_rt_id
     [java]  ([Ljavax.management.ObjectName;) JavaVMs                       : [Ljavax.management.ObjectName;@edc86eb
     [java]  ([Loracle.oc4j.admin.management.shared.InstalledLibrary;) installedLibraries            : [Loracle.oc4j.admin.management.shared
.InstalledLibrary;@6f7918f0
     [java]                (java.lang.String) oracleHome                    : /home/u01/app/oracle/product/1013AS_blue
     [java]                (java.lang.String) objectName                    : oc4j:j2eeType=J2EEServer,name=standalone
     [java]             ([Ljava.lang.String;) resources                     : oc4j:j2eeType=JDBCResource,name="jdev-connection-pool-scott-11
gr2",J2EEApplication=sunilcrap,J2EEServer=standalone, oc4j:j2eeType=JDBCResource,name="jdev-connection-pool-scott-11gr1",J2EEApplication=pet
ercrap,J2EEServer=standalone, oc4j:j2eeType=JDBCResource,name="jdev-connection-pool-scott-11gr1",J2EEApplication=AdrianTest-Project1-WS,J2EE
Server=standalone, oc4j:j2eeType=JDBCResource,name="jdev-connection-pool-scott-11gr2",J2EEApplication=petercrap,J2EEServer=standalone, oc4j:
j2eeType=JDBCResource,name="jdev-connection-pool-srs-10g",J2EEApplication=sunilcrap,J2EEServer=standalone, oc4j:j2eeType=JDBCResource,name="
jdev-connection-pool-coherence-11gr2",J2EEApplication=sunilcrap,J2EEServer=standalone, oc4j:j2eeType=JDBCResource,name="jdev-connection-pool
-scott-11gr2",J2EEApplication=AdrianTest-Project1-WS,J2EEServer=standalone, oc4j:j2eeType=JDBCResource,name="jdev-connection-pool-scott-11gr
1",J2EEApplication=sunilcrap,J2EEServer=standalone, oc4j:j2eeType=JDBCResource,name="Example OCI Connection Pool",J2EEApplication=default,J2
EEServer=standalone, oc4j:j2eeType=JDBCResource,name="jdev-connection-pool-pas-11gr2",J2EEApplication=sunilcrap,J2EEServer=standalone, oc4j:
j2eeType=JDBCResource,name="jdev-connection-pool-srs-10g",J2EEApplication=AdrianTest-Project1-WS,J2EEServer=standalone, oc4j:j2eeType=JDBCRe
source,name="jdev-connection-pool-srs-10g",J2EEApplication=petercrap,J2EEServer=standalone, oc4j:j2eeType=JDBCResource,name="oemsdbPool",J2E
EApplication=default,J2EEServer=standalone, oc4j:j2eeType=JDBCResource,name="jdev-connection-pool-scott-10g",J2EEApplication=sunilcrap,J2EES
erver=standalone, oc4j:j2eeType=JDBCResource,name="jdev-connection-pool-pas-11gr2",J2EEApplication=petercrap,J2EEServer=standalone, oc4j:j2e
eType=JDBCResource,name="jdev-connection-pool-pas-11gr2",J2EEApplication=AdrianTest-Project1-WS,J2EEServer=standalone, oc4j:j2eeType=JDBCRes
ource,name="jdev-connection-pool-scott-10g",J2EEApplication=AdrianTest-Project1-WS,J2EEServer=standalone, oc4j:j2eeType=JDBCResource,name="s
cottPool",J2EEApplication=default,J2EEServer=standalone, oc4j:j2eeType=JDBCResource,name="jdev-connection-pool-scott-10g",J2EEApplication=pe
tercrap,J2EEServer=standalone, oc4j:j2eeType=JNDIResource,name="AdrianTest-Project1-WS",J2EEServer=standalone,applicationName=AdrianTest-Pro
ject1-WS, oc4j:j2eeType=JNDIResource,name="ascontrol",J2EEServer=standalone,applicationName=ascontrol, oc4j:j2eeType=JNDIResource,name="pete
rcrap",J2EEServer=standalone,applicationName=petercrap, oc4j:j2eeType=JNDIResource,name="javasso",J2EEServer=standalone,applicationName=java
sso, oc4j:j2eeType=JNDIResource,name="sunilcrap",J2EEServer=standalone,applicationName=sunilcrap, oc4j:j2eeType=JNDIResource,name="Support",
J2EEServer=standalone,applicationName=Support, oc4j:j2eeType=JNDIResource,name="datatags",J2EEServer=standalone,applicationName=datatags, oc
4j:j2eeType=JNDIResource,name="WSRocks",J2EEServer=standalone,applicationName=WSRocks, oc4j:j2eeType=JNDIResource,name="WSIL-App",J2EEServer
=standalone,applicationName=WSIL-App, oc4j:j2eeType=JNDIResource,name="secDemo",J2EEServer=standalone,applicationName=secDemo, oc4j:j2eeType
=JNDIResource,name="default",J2EEServer=standalone,applicationName=default, oc4j:j2eeType=JNDIResource,name="testhtml",J2EEServer=standalone
,applicationName=testhtml, oc4j:j2eeType=JNDIResource,name="mapviewer",J2EEServer=standalone,applicationName=mapviewer, oc4j:j2eeType=JNDIRe
source,name="SessionEJB",J2EEServer=standalone,applicationName=SessionEJB, oc4j:j2eeType=JTAResource,name="oc4j-tm",J2EEServer=standalone, o
c4j:j2eeType=JMSResource,name="JMS",J2EEServer=standalone, oc4j:j2eeType=JMSAdministratorResource,name="JMSAdministrator",J2EEServer=standal
one, oc4j:j2eeType=JCAResource,name=JCAResource,ResourceAdapter=OJMS RA,ResourceAdapterModule=simpleOemsRA,J2EEApplication=default,J2EEServe
r=standalone, oc4j:j2eeType=JCAResource,name=JCAResource,ResourceAdapter=OracleASjms,ResourceAdapterModule=OracleASjms,J2EEApplication=defau
lt,J2EEServer=standalone,
     [java]                         (boolean) stateManageable               : true
     [java]     (javax.management.ObjectName) defaultApplication            : oc4j:j2eeType=J2EEApplication,name=default,J2EEServer=standalo
ne
     [java]             ([Ljava.lang.String;) javaVMs                       : oc4j:j2eeType=JVM,name=single,J2EEServer=standalone,
     [java]                (java.lang.String) node                          : beast.au.oracle.com
     [java]                         (boolean) eventProvider                 : true
     [java]

BUILD SUCCESSFUL
Total time: 15 seconds
C:\jdev\ant-demos\11gFMW\fmw-rda>

If you wanted to create queries against a Coherence Server your query-beans.xml file would look like this. The idea here is to specifically query only the MBeans your interested in so you could easily tailor it to meet your needs such as monitoring a JDBC connection pool. The bean with id "showMBean" is used to view all available MBeans you can use.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

  <!--  This creates a a basic ServerConnection object using no username/password -->
  <bean id="serverConnection"
        class="oracle.support.rda.coherence.ConnectionFactory"
        factory-method="getCoherenceConnection"
        singleton="true">
  </bean>
 
  <!--  This section defines the set of Queries to execute, add/remove easily!-->
  <bean id="clusterQuery" class="oracle.support.rda.spring.queries.GenericQuery">
    <property name="MBeanName">
      <value>Coherence:type=Cluster</value>
    </property>
    <!--
    The following properties will not be displayed, giving you
    control over what information you show.
    -->
    <property name="nukedAttributes">
      <list>
        <value>MembersDeparted</value> 
      </list>
    </property>
  </bean>

  <bean id="managementQuery" class="oracle.support.rda.spring.queries.GenericQuery">
    <property name="MBeanName">
      <value>Coherence:type=Management</value>
    </property>
  </bean>

  <bean id="reporterQuery" class="oracle.support.rda.spring.queries.GenericQuery">
    <property name="MBeanName">
      <value>Coherence:type=Reporter</value>
    </property>
  </bean>

  <bean id="runtimeQuery1" class="oracle.support.rda.spring.queries.GenericQuery">
    <property name="MBeanName">
      <value>Coherence:type=Platform,Domain=java.lang,subType=Runtime,nodeId=1</value>
    </property>
    <property name="nukedAttributes">
      <list>
        <value>SystemProperties</value> 
      </list>
    </property>   
  </bean>
 
  <!-- 
    This defines the Invoker object, which gets passed
    a reference to the ServerConnection AND the list of queries
   -->
  <bean id="queryInvoker" class="oracle.support.rda.spring.invoker.QueryInvoker">
    <property name="serverConnection" ref="serverConnection"/>
    <property name="rdaQueries">
      <list>
        <ref bean="clusterQuery"/>
        <ref bean="managementQuery"/>
        <ref bean="reporterQuery"/>
        <ref bean="runtimeQuery1"/>
      </list>
    </property>
  </bean>  

  <!-- 
   Bean used to list of MBeans available for use
   -->
  <bean id="showMBeans" class="oracle.support.rda.spring.invoker.MBeanViewer">
    <property name="serverConnection" ref="serverConnection"/>
  </bean>
 
</beans>