asmuts      02/01/14 22:30:24

  Added:       src/java/org/apache/stratum/jcs/auxiliary/remote/group
                        RemoteGroupCache.java RemoteGroupCacheListener.java
  Log:
  special group functionality
  
  Revision  Changes    Path
  1.1                  
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/remote/group/RemoteGroupCache.java
  
  Index: RemoteGroupCache.java
  ===================================================================
  package org.apache.stratum.jcs.auxiliary.remote.group;
  
  import  java.io.*;
  import  java.util.*;
  
  import org.apache.stratum.jcs.engine.behavior.*;
  import org.apache.stratum.jcs.engine.control.*;
  import org.apache.stratum.jcs.engine.*;
  import org.apache.stratum.jcs.access.*;
  import org.apache.stratum.jcs.access.exception.*;
  import org.apache.stratum.jcs.engine.control.Cache;
  import org.apache.stratum.jcs.auxiliary.disk.*;
  import org.apache.stratum.jcs.auxiliary.remote.*;
  import org.apache.stratum.jcs.auxiliary.remote.behavior.*;
  import  org.apache.stratum.jcs.utils.reuse.*;
  
  import org.apache.stratum.jcs.utils.log.*;
  import org.apache.stratum.jcs.auxiliary.remote.RemoteCache;
  
  
  //////////////////////////////////////////////////////////////////
  public class RemoteGroupCache extends RemoteCache {
  
    ////////////////////////////////////////////////////////
    protected RemoteGroupCache(IRemoteCacheAttributes irca, IRemoteCacheService 
remote) {
      super( irca, remote );
      //p( "constructing remote group cache" );
    }
  
  }
  
  
  
  1.1                  
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/remote/group/RemoteGroupCacheListener.java
  
  Index: RemoteGroupCacheListener.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  
  package org.apache.stratum.jcs.auxiliary.remote.group;
  
  //////////////////////////////////
  import  java.io.*;
  import  java.rmi.*;
  import  java.rmi.registry.*;
  import  java.rmi.server.*;
  import  java.util.*;
  import  java.sql.*;
  
  /////////////////////////////////////
  import org.apache.stratum.jcs.engine.behavior.*;
  import org.apache.stratum.jcs.engine.control.*;
  import org.apache.stratum.jcs.engine.group.*;
  import org.apache.stratum.jcs.engine.*;
  import org.apache.stratum.jcs.access.*;
  import org.apache.stratum.jcs.engine.control.Cache;
  import org.apache.stratum.jcs.auxiliary.disk.*;
  import org.apache.stratum.jcs.auxiliary.remote.*;
  import org.apache.stratum.jcs.auxiliary.remote.behavior.*;
  
  // remove
  import org.apache.stratum.jcs.utils.log.*;
  
  ///////////////////////////////////////////////////////////////////////
  public class RemoteGroupCacheListener extends RemoteCacheListener implements 
IRemoteCacheListener, IRemoteCacheConstants, Serializable {
  
    ///////////////////////////////////////////
    protected RemoteGroupCacheListener ( IRemoteCacheAttributes irca ) {
      super( irca );
      p( "creating RemoteGroupCacheListener" );
    }
  
    /////////////////////////////////////////////
  
     ///////////////////////////////////////////////////////////////////////////
    // should store ina  hashmap based on store address
     public static IRemoteCacheListener getInstance( IRemoteCacheAttributes irca )  {
       //throws IOException, NotBoundException
        if (instance == null) {
          synchronized(RemoteGroupCacheListener.class) {
            if (instance == null) {
             instance = new RemoteGroupCacheListener( irca );
            }
          }
        }
        //instance.incrementClients();
        return instance;
     }
  
  
    /**
     * The remote cache can be configured to remove on remote put or to store
     * the element.  Removal saves space on the local cache.  If the local needs
     * the element it can go it.  The local copy will not be stale, and it need
     * not waste space and time.
     *
     * The group cache is in a more complicated situation.  If the group cache
     * removes upon remote put, the list of elements on the local cache will
     * be short.  The best thing to do is remove the local item so it isn't stale
     * and at the same time update the list.
     *
     * We don't want to invalidate the list since it is not easy to pass a HashSet
     * around while the program is modifying it.  The locking would be too slow and
     * it would be a great burden on all caches involved.
     *
     * I had to expose another method og teh GroupCache here.  It is not in the
     * the interface.  TODO: add the updateAttrnameSer to interface, maybe.
     */
    public void handlePut (ICacheElement cb) throws IOException {
  
      try {
  
        if ( cb.getKey() instanceof GroupAttrName) {
  
         if ( irca.getRemoveUponRemotePut() ) {
  
            if ( debugcmd ) {
              p( "PUTTING ELEMENT FROM REMOTE, (  invalidating ) " );
            }
  
            // remove the item
            handleRemove(cb.getCacheName(), cb.getKey());
  
            // add the key to the attrNameSet
            if ( debugcmd ) {
              p( "Adding to attrNameSet " );
            }
            getCacheManager();
            GroupCache cache = (GroupCache)cacheMgr.getCache(cb.getCacheName());
            if ( debugcmd ) {
              p( "cache = " + cache );
            }
            cache.updateGroupAttrNameSet( (GroupAttrName)cb.getKey(), 
cache.REMOTE_INVOKATION, false );
            if ( debugcmd ) {
              p( "Adding to attrNameSet " );
            }
  
         } else {
            if ( debugcmd ) {
              p( "PUTTING ELEMENT FROM REMOTE, ( updating ) " );
              p( "cb = " + cb );
            }
            if ( debugactivity ) {
              puts++;
              if ( puts % 100 == 0 ) {
                p( "puts = " + puts );
              }
            }
  
            getCacheManager();
            ICompositeCache cache = 
(ICompositeCache)cacheMgr.getCache(irca.getCacheName());
            cache.update( cb, false );
  
            /*
            ICompositeCache cache = 
(ICompositeCache)cacheMgr.getCache(irca.getCacheName());
            // copy the element to avoid the remote reference, may need to do a deep 
copy
            ICacheElement ce = new CacheElement( cb.getCacheName(), cb.getKey(), 
cb.getVal() );
            ce.setAttributes( cb.getAttributes().copy() );
            try {
              cache.update( ce, false );
            } catch( Exception e ) {
              // strange marshalling exception encountered
              log.error( e );
            }
            */
          }
  
        }  else {
          super.handlePut(cb);
        }
  
      } catch ( Exception e ) {
        log.error( e );
        // should probably throw ioe
        if (e instanceof IOException) {
          throw (IOException)e;
        }
      }
  
      return;
  }
      /*
      if ( debugcmd ) {
        p( "PUTTING ELEMENT FROM REMOTE" );
      }
  
      // could put this in the group cache.
      if (cb.getKey() instanceof GroupAttrName) {
        try {
          if ( debug ) {
            p( "removing gi for ga method" );
          }
          GroupAttrName gan = (GroupAttrName)cb.getKey();
          GroupId groupId = new GroupId(cb.getCacheName(), gan.groupId );
          //System.out.println( "removing gi for ga method" );
  
          // avoids overhead of removegan method where the attributeset is retrieved 
first
          GroupCache cache = (GroupCache)cacheMgr.getCache(irca.getCacheName());
          //cache.remove(new Integer(gan.hashCode()), cache.REMOTE_INVOKATION);
          cache.remove(gan, cache.REMOTE_INVOKATION);
  
          // other auxiliaries may update and not remove
          cache.remove(groupId, cache.REMOTE_INVOKATION);
  
          // too slow? can avoid lock  and go directly to super.remove
          //super.handleRemove(cb.getCacheName(), cb.getKey());
  
          //GroupCache cache = (GroupCache)cacheMgr.getCache(irca.getCacheName());
          //cache.remove(key, cache.REMOTE_INVOKATION, true);
  
          // since the removeGAN call removes form the attrlist
          // it must be called first or we loose 1 by saving 1 short
  
          // since we are treating a put as a remove we must invlidate the list
          // since it actually has 1 more element, otherwise the lsit would be 1 short
          // probably better just to add it
          //super.handleRemove(cb.getCacheName(), groupId);
  
          //super.handleRemove( cb );
  
       } catch ( Exception e ) {}
        return;
      } else {
        super.handlePut(cb);
      }
    }
  */
  
    ////////////////////////////////////////////////
    // override for new funcitonality
    // TODO: lazy init is too slow, find a better way
    protected void getCacheManager() {
      try {
        if ( cacheMgr == null ) {
          cacheMgr = (ICompositeCacheManager)GroupCacheManagerFactory.getInstance();
          if ( debugcmd ) {
            p( " groupcache cacheMgr = " + cacheMgr );
          }
        } else {
          if ( debugcmd ) {
            p( "already got groupcache cacheMgr = " + cacheMgr );
          }
        }
      } catch( Exception e ) {
        log.error( e );
      }
    }
  
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to