1 package org.jboss.cache.tests.misc; 2 3 import org.jboss.cache.CacheException; 4 import org.jboss.cache.TreeCacheMBean; 5 6 import javax.naming.InitialContext ; 7 import javax.naming.NamingException ; 8 import java.util.Properties ; 9 10 15 public class Client { 16 public static void main(String [] args) { 17 try { 18 new Client().start(args); 19 } 20 catch(NamingException e) { 21 e.printStackTrace(); 22 } 23 catch(CacheException e) { 24 e.printStackTrace(); 25 } 26 } 27 28 private void start(String [] args) throws NamingException , CacheException { 29 TreeCacheMBean cache; 30 String jndi_name=args.length > 0? args[0] : "MyCache"; 31 Properties props=new Properties (); 32 props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); 33 props.setProperty("java.naming.provider.url", "jnp://localhost:1099"); 34 props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming"); 35 InitialContext ctx=new InitialContext (props); 36 cache=(TreeCacheMBean)ctx.lookup(jndi_name); 37 cache.put("a/b/c", null); 38 System.out.println("Cache: " + cache.printDetails()); 39 System.out.println("cache mode: " + cache.getCacheMode()); 40 int numLocks, numNodes, numAttrs; 41 42 numLocks=cache.getNumberOfLocksHeld(); 43 numNodes=cache.getNumberOfNodes(); 44 numAttrs=cache.getNumberOfAttributes(); 45 System.out.println("Nodes: " + numNodes + ", locks: " + numLocks + ", attributes: " + numAttrs); 46 } 47 } 48 | Popular Tags |