KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * JBoss, the OpenSource J2EE webOS
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */

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 JavaDoc;
13 import javax.naming.NamingException JavaDoc;
14 import java.util.Properties JavaDoc;
15
16 /**
17  * Simple client which looks up a TreeCache via JNDI and invokes a bunch of methods on it
18  * @author Bela Ban
19  * @version $Id: Client.java,v 1.1.8.2 2005/04/06 21:07:03 starksm Exp $
20  */

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