[jboss-cvs] JBossCache/src/org/jboss/cache/marshall ...

Manik Surtani manik at jboss.org
Mon Apr 2 20:43:52 EDT 2007


  User: msurtani
  Date: 07/04/02 20:43:52

  Modified:    src/org/jboss/cache/marshall   AbstractMarshaller.java
                        CacheMarshaller200.java
  Log:
  JBCACHE-876
  
  Revision  Changes    Path
  1.7       +24 -25    JBossCache/src/org/jboss/cache/marshall/AbstractMarshaller.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AbstractMarshaller.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/marshall/AbstractMarshaller.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- AbstractMarshaller.java	12 Mar 2007 18:13:47 -0000	1.6
  +++ AbstractMarshaller.java	3 Apr 2007 00:43:52 -0000	1.7
  @@ -37,7 +37,7 @@
      /**
       * Map<GlobalTransaction, Fqn> for prepared tx that have not committed
       */
  -   private Map<GlobalTransaction, String> transactions = new ConcurrentHashMap<GlobalTransaction, String>(16);
  +   private Map<GlobalTransaction, Fqn> transactions = new ConcurrentHashMap<GlobalTransaction, Fqn>(16);
   
      protected void init(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling)
      {
  @@ -80,7 +80,7 @@
       *
       * @param call
       */
  -   protected String extractFqnFromMethodCall(MethodCall call)
  +   protected Fqn extractFqnFromMethodCall(MethodCall call)
      {
         MethodCall c0 = (MethodCall) call.getArgs()[0];
         return extractFqn(c0);
  @@ -91,7 +91,7 @@
       *
       * @param call
       */
  -   protected String extractFqnFromListOfMethodCall(MethodCall call)
  +   protected Fqn extractFqnFromListOfMethodCall(MethodCall call)
      {
         Object[] args = call.getArgs();
         // We simply pick the first one and assume everyone will need to operate under the same region!
  @@ -99,14 +99,14 @@
         return extractFqn(c0);
      }
   
  -   protected String extractFqn(MethodCall methodCall)
  +   protected Fqn extractFqn(MethodCall methodCall)
      {
         if (methodCall == null)
         {
            throw new NullPointerException("method call is null");
         }
   
  -      String fqnStr = null;
  +      Fqn fqn = null;
         Object[] args = methodCall.getArgs();
         switch (methodCall.getMethodId())
         {
  @@ -114,7 +114,7 @@
            case MethodDeclarations.prepareMethod_id:
               // Prepare method has a list of modifications. We will just take the first one and extract.
               List modifications = (List) args[1];
  -            fqnStr = extractFqn((MethodCall) modifications.get(0));
  +            fqn = extractFqn((MethodCall) modifications.get(0));
   
               // the last arg of a prepare call is the one-phase flag
               boolean one_phase_commit = (Boolean) args[args.length - 1];
  @@ -123,13 +123,13 @@
               // we can find it when the commit/rollback comes through
               if (!one_phase_commit)
               {
  -               transactions.put((GlobalTransaction) args[0], fqnStr);
  +               transactions.put((GlobalTransaction) args[0], fqn);
               }
               break;
            case MethodDeclarations.rollbackMethod_id:
            case MethodDeclarations.commitMethod_id:
               // We stored the fqn in the transactions map during the prepare phase
  -            fqnStr = transactions.remove(args[0]);
  +            fqn = transactions.remove(args[0]);
               break;
            case MethodDeclarations.getPartialStateMethod_id:
            case MethodDeclarations.dataGravitationMethod_id:
  @@ -140,12 +140,10 @@
            case MethodDeclarations.getKeysMethodLocal_id:
            case MethodDeclarations.getKeyValueMethodLocal_id:
            case MethodDeclarations.existsMethod_id:
  -            Fqn fqn = (Fqn) args[0];
  -            fqnStr = fqn.toString();
  +            fqn = (Fqn) args[0];
               break;
            case MethodDeclarations.dataGravitationCleanupMethod_id:
  -            Fqn fqn1 = (Fqn) args[1];
  -            fqnStr = fqn1.toString();
  +            fqn = (Fqn) args[1];
               break;
            case MethodDeclarations.remoteAnnounceBuddyPoolNameMethod_id:
            case MethodDeclarations.remoteAssignToBuddyGroupMethod_id:
  @@ -154,13 +152,12 @@
            case MethodDeclarations.replicateMethod_id:
            case MethodDeclarations.clusteredGetMethod_id:
               // possible when we have a replication queue.
  -            fqnStr = extractFqn((MethodCall) args[0]);
  +            fqn = extractFqn((MethodCall) args[0]);
               break;
            default:
               if (MethodDeclarations.isCrudMethod(methodCall.getMethodId()))
               {
  -               Fqn fqn2 = (Fqn) args[1];
  -               fqnStr = fqn2.toString();
  +               fqn = (Fqn) args[1];
               }
               else
               {
  @@ -172,27 +169,29 @@
   
         if (log.isTraceEnabled())
         {
  -         log.trace("extract(): received " + methodCall + "extracted fqn: " + fqnStr);
  +         log.trace("extract(): received " + methodCall + "extracted fqn: " + fqn);
         }
   
  -      return fqnStr;
  +      return fqn;
      }
   
      /**
  -    * Retrieves the {@link Region} from the {@link RegionManager} after taking into account that this may be a Buddy Backup FQN
  +    * Retrieves the {@link Region} from the {@link RegionManager} after taking into account that this may be a Buddy Backup Fqn.
  +    * If the fqn passed in is null, the region has been deactivated or if a region cannot be found, this method returns a null.
       *
  -    * @param fqnString
  -    * @return
  +    * @param fqn of the region to locate
  +    * @return a region
       */
  -   protected Region getRegion(String fqnString)
  +   protected Region getRegion(Fqn fqn)
      {
  -      Fqn fqn = Fqn.fromString(fqnString);
  -
  +      if (fqn == null) return null;
         if (BuddyManager.isBackupFqn(fqn))
         {
            // Strip out the buddy group portion
  -         fqn = fqn.getSubFqn(2, fqn.size());
  +         fqn = BuddyManager.getActualFqn(fqn);
         }
  -      return regionManager.getRegion(fqn, false);
  +      Region r = regionManager.getRegion(fqn, Region.Type.MARSHALLING, false);
  +      return r;
  +      //return r != null && r.isActive() ? r : null;
      }
   }
  
  
  
  1.11      +25 -31    JBossCache/src/org/jboss/cache/marshall/CacheMarshaller200.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheMarshaller200.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/marshall/CacheMarshaller200.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -b -r1.10 -r1.11
  --- CacheMarshaller200.java	7 Feb 2007 22:06:54 -0000	1.10
  +++ CacheMarshaller200.java	3 Apr 2007 00:43:52 -0000	1.11
  @@ -72,7 +72,7 @@
      protected static final InactiveRegionException IRE = new InactiveRegionException("Cannot unmarshall to an inactive region");
   
      // this is pretty nasty, and may need more thought.
  -   protected final ThreadLocal<String> regionForCall = new ThreadLocal<String>();
  +   protected final ThreadLocal<Fqn> regionForCall = new ThreadLocal<Fqn>();
   
      public CacheMarshaller200(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling)
      {
  @@ -100,18 +100,18 @@
      {
         if (useRegionBasedMarshalling)
         {
  -         String fqnAsString;
  +         Fqn region;
            if (o == null)
            {
               // if the return value we're trying to marshall is null we're easy ...
  -            fqnAsString = null;
  +            region = null;
            }
            else if (isReturnValue(o))
            {
               // we are marshalling a return value from a method call.
               // let's see if an incoming unmarshalling call for this exists, in the same thread stack and had registered
               // a Fqn region.
  -            fqnAsString = regionForCall.get();
  +            region = regionForCall.get();
   
               // otherwise, we need to marshall the retval.
            }
  @@ -120,10 +120,10 @@
               // this is an outgoing method call.
               // we first marshall the Fqn as a String
               MethodCall call = (MethodCall) o;
  -            fqnAsString = extractFqnAsString(call);
  +            region = extractFqnRegion(call);
            }
  -         if (log.isTraceEnabled()) log.trace("Region based call.  Using region " + fqnAsString);
  -         objectToObjectStream(o, out, fqnAsString);
  +         if (log.isTraceEnabled()) log.trace("Region based call.  Using region " + region);
  +         objectToObjectStream(o, out, region);
         }
         else
         {
  @@ -149,18 +149,13 @@
         }
      }
   
  -   public void objectToObjectStream(Object obj, ObjectOutputStream out, Fqn region) throws Exception
  -   {
  -      objectToObjectStream(obj, out, region.toString());
  -   }
  -
  -   protected void objectToObjectStream(Object o, ObjectOutputStream out, String region) throws Exception
  +   public void objectToObjectStream(Object o, ObjectOutputStream out, Fqn region) throws Exception
      {
         if (log.isTraceEnabled()) log.trace("Marshalling object " + o);
         Map<Object, Integer> refMap = new HashMap<Object, Integer>();
         if (useRegionBasedMarshalling) // got to check again in case this meth is called directly
         {
  -         log.trace("Writing region " +region+ " to stream");
  +         log.trace("Writing region " + region + " to stream");
            marshallObject(region, out, refMap);
         }
         marshallObject(o, out, refMap);
  @@ -170,7 +165,7 @@
      {
         Map<Integer, Object> refMap = new HashMap<Integer, Object>();
         Object o = unmarshallObject(in, refMap);
  -      String regionString = null;
  +      Fqn regionFqn = null;
         if (o == null)
         {
            // a null region.  Could happen.  Use std marshalling.
  @@ -178,17 +173,17 @@
         }
         else
         {
  -         regionString = (String) o;
  +         regionFqn = (Fqn) o;
         }
   
  -      if (log.isTraceEnabled()) log.trace("Unmarshalled regionString " + regionString + " from stream");
  +      if (log.isTraceEnabled()) log.trace("Unmarshalled regionFqn " + regionFqn + " from stream");
   
         Region region = null;
         Object retValue;
   
  -      if (regionString != null)
  +      if (regionFqn != null)
         {
  -         region = findRegion(regionString);
  +         region = findRegion(regionFqn);
         }
         if (region == null)
         {
  @@ -199,17 +194,15 @@
            retValue = unmarshallObject(in, region.getClassLoader(), refMap);
   
            // only set this if this is an incoming method call and not a return value.
  -         if (!isReturnValue(retValue)) regionForCall.set(regionString);
  +         if (!isReturnValue(retValue)) regionForCall.set(regionFqn);
         }
         if (log.isTraceEnabled()) log.trace("Unmarshalled object " + retValue);
         return retValue;
      }
   
  -   private Region findRegion(String fqn) throws InactiveRegionException
  +   private Region findRegion(Fqn fqn) throws InactiveRegionException
      {
  -      Region region;
  -      // obtain a region from MarshRegionManager, if not, will use default.
  -      region = fqn == null ? null : getRegion(fqn);
  +      Region region = getRegion(fqn);
   
         if (region != null)
         {
  @@ -231,28 +224,29 @@
         return region;
      }
   
  -   private String extractFqnAsString(MethodCall call) throws Exception
  +   private Fqn extractFqnRegion(MethodCall call) throws Exception
      {
  -      String fqnAsString;
  +      Fqn fqn;
         if (call.getMethod().equals(MethodDeclarations.replicateMethod))
         {
  -         fqnAsString = extractFqnFromMethodCall(call);
  +         fqn = extractFqnFromMethodCall(call);
         }
         else if (call.getMethod().equals(MethodDeclarations.replicateAllMethod))
         {
  -         fqnAsString = extractFqnFromListOfMethodCall(call);
  +         fqn = extractFqnFromListOfMethodCall(call);
         }
         else if (call.getMethod().equals(RpcTreeCache.dispatchRpcCallMethod))
         {
            MethodCall call2 = (MethodCall) call.getArgs()[1];
  -         fqnAsString = extractFqn(call2);
  +         fqn = extractFqn(call2);
         }
         else
         {
  -         fqnAsString = extractFqn(call);
  +         fqn = extractFqn(call);
         }
   
  -      return fqnAsString;
  +      Region r = getRegion(fqn);
  +      return r == null ? null : r.getFqn();
      }
   
      // --------- Marshalling methods
  
  
  



More information about the jboss-cvs-commits mailing list