KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > tests > misc > Client


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 JavaDoc;
7 import javax.naming.NamingException JavaDoc;
8 import java.util.Properties JavaDoc;
9
10 /**
11  * Simple client which looks up a TreeCache via JNDI and invokes a bunch of methods on it
12  * @author Bela Ban
13  * @version $Id: Client.java,v 1.1.1.1 2005/03/31 10:15:10 belaban Exp $
14  */

15 public class Client {
16    public static void main(String JavaDoc[] args) {
17       try {
18          new Client().start(args);
19       }
20       catch(NamingException JavaDoc e) {
21          e.printStackTrace();
22       }
23       catch(CacheException e) {
24          e.printStackTrace();
25       }
26    }
27
28    private void start(String JavaDoc[] args) throws NamingException JavaDoc, CacheException {
29       TreeCacheMBean cache;
30       String JavaDoc jndi_name=args.length > 0? args[0] : "MyCache";
31       Properties JavaDoc props=new Properties JavaDoc();
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 JavaDoc ctx=new InitialContext JavaDoc(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