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