[jboss-user] [JBossCache] - who can help me? something about treecache.

neddy do-not-reply at jboss.com
Mon Jan 15 21:45:08 EST 2007


I want to use the Jboss's TreeCache to manage my object,but something problem:
	
	I have an interface class CacheEngin.java
	
	code:
		/*
	 * Copyright (c) Rafael Steil
	 * All rights reserved.
	 *
	 * Redistribution and use in source and binary forms,
	 * with or without modification, are permitted provided
	 * that the following conditions are met:
	 *
	 * 1) Redistributions of source code must retain the above
	 * copyright notice, this list of conditions and the
	 * following  disclaimer.
	 * 2)  Redistributions in binary form must reproduce the
	 * above copyright notice, this list of conditions and
	 * the following disclaimer in the documentation and/or
	 * other materials provided with the distribution.
	 * 3) Neither the name of "Rafael Steil" nor
	 * the names of its contributors may be used to endorse
	 * or promote products derived from this software without
	 * specific prior written permission.
	 *
	 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
	 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
	 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
	 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
	 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
	 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
	 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
	 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
	 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
	 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
	 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
	 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
	 * IN CONTRACT, STRICT LIABILITY, OR TORT
	 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
	 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
	 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
	 *
	 * Created on Jan 13, 2005 5:58:36 PM
	 * The JForum Project
	 * http://www.jforum.net
	 */
package com.eplugger.plugin.cache.engine;

import java.util.Collection;

/**
 * @author Rafael Steil
 * @version $Id: CacheEngine.java,v 1.1 2006/10/21 08:27:56 lyw Exp $
 */
public interface CacheEngine {
  public static final String DUMMY_FQN = "";
  public static final String NOTIFICATION = "notification";
  public static final String defaultFqn = "/default";

  /**
   * Inits the cache engine.
   */
  public void init();

  /**
   * Stops the cache engine
   */
  public void stop();

  /**
   * Adds a new object to the cache.
   * The fqn will be set as the value of {@link #DUMMY_FQN}
   *
   * @param key The key to associate with the object.
   * @param value The object to cache
   */
  public void add(String key, Object value);

  /**
   *
   * Adds a new object to the cache.
   *
   * @param fqn The fully qualified name of the cache.
   * @param key The key to associate with the object
   * @param value The object to cache
   */
  public void add(String fqn, String key, Object value);

  /**
   * Gets some object from the cache.
   *
   * @param fqn The fully qualified name associated with the key
   * @param key The key to get
   * @return The cached object, or null if no entry was found
   */
  public Object get(String fqn, String key);

  /**
   * Gets some object from the cache.
   *
   * @param key The fqn tree to get
   * @return The cached object, or null if no entry was found
   */
  public Object get(String fqn);

  /**
   * Gets all values from some given FQN.
   *
   * @param fqn
   * @return
   */
  public Collection getValues(String fqn);

  /**
   * Removes an entry from the cache.
   *
   * @param fqn The fully qualified name associated with the key
   * @param key The key to remove
   */
  public void remove(String fqn, String key);

  /**
   * Removes a complete note from the cache
   * @param key The fqn to remove
   */
  public void remove(String fqn);

  /**
   * Removes a default cache
   * @param key The fqn to remove
   */
  public void remove();

  /**
   * Removes a complete note from the cache
   * @param key The fqn to remove
   */
  public int size(String fqn);

  /**
   * Removes a default cache
   * @param key The fqn to remove
   */
  public int size();

}


I use TreeCache at a Class JBossTreeCacheEngine.jave
Code:

package com.eplugger.plugin.cache.engine;

import java.util.Collection;

import java.util.Map;
import org.jboss.cache.CacheException;
import java.util.HashMap;
import org.jboss.cache.Fqn;
import org.jboss.cache.TransactionManagerLookup;
import org.jboss.cache.TreeCache;
import junit.framework.TestCase;
import org.jboss.cache.lock.IsolationLevel;

/**
 * Title: 
 * Description: 
 * Copyright: Copyright (c) 2007
 * Company: 
 * @author not attributable
 * @version 1.0
 */

public class JBossTreeCacheEngine
    extends TestCase
    implements CacheEngine {
  public JBossTreeCacheEngine() {
  }

  TreeCache cache = null;
  Exception ex=null;
  protected void setUp() throws Exception {
     super.setUp();
     cache=new TreeCache();
     cache.setCacheMode(TreeCache.LOCAL);
     cache.setClusterProperties("treecache.xml");
     cache.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
     cache.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
     cache.createService();
     cache.startService();
     ex=null;
  }

  protected void tearDown() throws Exception {
     super.tearDown();
     if(cache != null) {
        cache.stopService();
        cache.destroyService();
        cache=null;
     }
     if(ex != null)
        throw ex;
  }

  public void init() {
    try {
     this.setUp();
    }
    catch (Exception ex) {
      System.out.print("################jboss treecache unInit###########");
      ex.printStackTrace();
    }
  }

  public void stop() {
    try {
      this.tearDown();
    }
    catch (Exception ex) {
      System.out.print("################jboss treecache unstop###########");
      ex.printStackTrace();
    }

  }

  public void add(String key, Object value) {
    try {
      this.add(defaultFqn, key, value);
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  public void add(String fqn, String key, Object value) {
    try {
      this.cache.put(Fqn.fromString(fqn), key, value);
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }

  }

  public Object get(String fqn, String key) {
    try {
      return cache.get(Fqn.fromString(fqn), key);
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
    return null;
  }

  public Object get(String key) {
    try {
      return cache.get(Fqn.fromString(defaultFqn), key);
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
    return null;
  }

  public Collection getValues(String fqn) {
    return cache._getData(Fqn.fromString(fqn)).values();
  }

  public void remove(String fqn, String key) {
    try {
      cache.remove(Fqn.fromString(fqn), key);
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  public void remove(String fqn) {

    try {
      this.cache.remove(Fqn.fromString(fqn));
    }
    catch (CacheException ex) {
      ex.printStackTrace();
    }
  }

  public void remove() {
    try {
      this.cache.remove(defaultFqn);
    }
    catch (CacheException ex) {
      ex.printStackTrace();
    }
  }

  public int size(String fqn) {
    Map map = (Map) cache._getData(Fqn.fromString(fqn));
    if (map == null) {
      return 0;
    }
    return map.size();

  }

  public int size() {
    return this.size(defaultFqn);
  }

}

the treecache.xml:

<?xml version="1.0" encoding="UTF-8" ?>


<!-- ==================================================================== -->
<!-- Defines TreeCache configuration -->
<!-- ==================================================================== -->

jboss:service=Naming
jboss:service=TransactionManager
<!-- Configure the TransactionManager -->
org.jboss.cache.DummyTransactionManagerLookup
<!--
Node locking scheme :
PESSIMISTIC (default)
OPTIMISTIC
-->
PESSIMISTIC
<!--
Node locking isolation level :
SERIALIZABLE
REPEATABLE_READ (default)
READ_COMMITTED
READ_UNCOMMITTED
NONE
(ignored if NodeLockingScheme is OPTIMISTIC)
-->
REPEATABLE_READ
<!-- Valid modes are LOCAL
REPL_ASYNC
REPL_SYNC
INVALIDATION_ASYNC
INVALIDATION_SYNC
-->
LOCAL
<!-- Whether each interceptor should have an mbean
registered to capture and display its statistics. -->
true
<!-- Name of cluster. Needs to be the same for all clusters, in order
to find each other -->
JBoss-Cache-Cluster


<!-- UDP: if you have a multihomed machine,
set the bind_addr attribute to the appropriate NIC IP address
-->
<!-- UDP: On Windows machines, because of the media sense feature
being broken with multicast (even after disabling media sense)
set the loopback attribute to true
-->
<UDP mcast_addr="228.1.2.3" mcast_port="45566" ip_ttl="64" ip_mcast="true"
mcast_send_buf_size="150000" mcast_recv_buf_size="80000" ucast_send_buf_size="150000"
ucast_recv_buf_size="80000" loopback="false" />
<PING timeout="2000" num_initial_members="3" up_thread="false" down_thread="false" />
<MERGE2 min_interval="10000" max_interval="20000" />
<FD shun="true" up_thread="true" down_thread="true" />
<VERIFY_SUSPECT timeout="1500" up_thread="false" down_thread="false" />
<pbcast.NAKACK gc_lag="50" max_xmit_size="8192" retransmit_timeout="600,1200,2400,4800" up_thread="false" down_thread="false" />
<UNICAST timeout="600,1200,2400" window_size="100" min_threshold="10" down_thread="false" />
<pbcast.STABLE desired_avg_gossip="20000" up_thread="false" down_thread="false" />
<FRAG frag_size="8192" down_thread="false" up_thread="false" />
<pbcast.GMS join_timeout="5000" join_retry_timeout="2000" shun="true" print_local_addr="true" />
<pbcast.STATE_TRANSFER up_thread="false" down_thread="false" />



<!-- Buddy Replication config -->


<!-- Enables buddy replication. This is the ONLY-->
true
<!-- These are the default values anyway -->
org.jboss.cache.buddyreplication.NextMemberBuddyLocator
<!-- numBuddies is the number of backup nodes each each node will *try* to select a buddy on a different physical host. If it will fall back to colocated nodes. -->

numBuddies = 1
ignoreColocatedBuddies = true

<!--
A way to specify a preferred replication group. the same pool name (falling back to other buddies if not available).
This allows backup buddies are picked, so for example, nodes may be hinted topick buddies or power supply for added fault tolerance.
 -->
myBuddyPoolReplicationGroup
<!-- Communication timeout for inter-buddy group from groups, defaults to 1000. -->
2000
<!-- Whether data is removed from old owners when-->
true
<!-- Whether backup nodes can respond to data gravitation defaults to true. -->
true
<!-- Whether all cache misses result in a data gravitation enable data gravitation on a per-invocation-->
 false



<!-- The max amount of time (in milliseconds) we wait until the
initial state (ie. the contents of the cache) are retrieved from
existing members in a clustered environment
-->
5000
<!-- Number of milliseconds to wait until all responses for a
synchronous call have been received.
-->
10000
<!-- Max number of milliseconds to wait for a lock acquisition -->
15000
<!-- Name of the eviction policy class. -->
org.jboss.cache.eviction.LRUPolicy
<!-- Specific eviction policy configurations. This is LRU -->


5
<!-- Cache wide default -->

5000
1000
<!-- Maximum time an object is kept in cache regardless of idle time -->
120


5000
1000


5
4



<!-- New 1.3.x cache loader config block -->


<!-- if passivation is true, only the first cache loader is used; the rest are ignored -->
false
/a/b, /allTempObjects, /some/specific/fqn
false
<!-- we can now have multiple cache loaders, which get chained -->

org.jboss.cache.loader.FileCacheLoader
<!-- same as the old CacheLoaderConfig attribute -->

location=c:\\tmp\\myFileStore

<!-- whether the cache loader writes are asynchronous -->
false
<!-- only one cache loader in the chain may set fetchPersistentState to true.
An exception is thrown if more than one cache loader sets this to true. -->
true
<!-- determines whether this cache loader ignores writes - defaults to false. -->
false
<!-- if set to true, purges the contents of this cache loader when the cache starts up.
Defaults to false. -->
false




 <!-- Configure Marshalling -->
true
true


 


but	when I run this object Throw an Exception at the Tomcat4.1 control like under:

*********************** ClearCache 2007-01-16 09:29:48
java.lang.RuntimeException: java.lang.NoSuchMethodError: org.jboss.cache.marshall.JBCMethodCall.getArgs()[Ljava/lang/Object;
        at org.jboss.cache.TreeCache.invokeMethod(TreeCache.java:5526)
        at org.jboss.cache.TreeCache.remove(TreeCache.java:3700)
        at org.jboss.cache.TreeCache.remove(TreeCache.java:3688)
        at com.eplugger.plugin.cache.engine.JBossTreeCacheEngine.remove(JBossTreeCacheEngine.java:139)
        at com.eplugger.plugin.cache.ChannelCacheManager.clearCache(ChannelCacheManager.java:518)
        at com.eplugger.plugin.cache.ChannelCacheThread.run(ChannelCacheThread.java:37)
        at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.NoSuchMethodError: org.jboss.cache.marshall.JBCMethodCall.getArgs()[Ljava/lang/Object;
        at org.jboss.cache.interceptors.CacheMgmtInterceptor.invoke(CacheMgmtInterceptor.java:123)
        at org.jboss.cache.TreeCache.invokeMethod(TreeCache.java:5520)
        ... 6 more


who can tell me what is wrong? and how can I do ? or what can I do? I use JDK 1.4.2_06 and mysql 4.1.3 and tomcat4.1      
        

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4002074#4002074

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4002074



More information about the jboss-user mailing list