⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transaction.java

📁 一宗队列算法
💻 JAVA
字号:
//Source file: E:/工作和学习/工作/硕士论文工作/程序/数据库缓存管理/20040304/src/MemCachePak/Transaction.java

/* tangtang */

package MemCachePak;


public class Transaction
{
   private String[] ref;
   private int size;
   private int cost;
   private String BeginPoint;
   private boolean SourceOrMedia = true;
   public MemCacheInterface theMemCacheInterface;

   public Transaction()
   {
   }

   /**
   @roseuid 41771061005D
   */
   public String ExecuteH(HitComInterface HitComp)
   {
     //循环1 从cache中查找和访问URL匹配的缓存对象
     String SourceFileName = ref[0];
     String CacheFileName = ref[1];
     int MinHP = Configuration.MAX;
     String cachefilename = null;
     WebObj head = theMemCacheInterface.SearchObj(SourceFileName);
     //循环2 将所有此对象的版本与输入的对象进行匹配分析
     while(head!=null)
     {
       int HP=HitComp.HitCom(ref,head.GetObjRef());
      if(HP==1)
      {
        MinHP = HP;
        cachefilename = head.GetCachedFileName();
        head.AddUsedCount();
        head.SetLastUsedTime();
        break;
      }
       else if(MinHP>HP)
           {
             if(HP!=0)
             {
               MinHP = HP;
               cachefilename = head.GetCachedFileName();
             }
           }
       head = head.NextObjEdition;
     }
     //如果有匹配的对象,并且符合高层策略,则返回对象信息
     if (MinHP==1)
     {
       return cachefilename;
     }
       else if(MinHP==Configuration.MAX)
            {
              return "UNHIT";
            }
            else if(MinHP>0&&MinHP<Configuration.MAX)
            {
              /*if(HpLimit==1)
              {
                return "UNHIT";
              }
              else
              {
              WebDelayInterface WI = new WebDelayInterface();
              StationLoadInterface SI = new StationLoadInterface();
              WI.Set(150);
              SI.Set(8);
              CapabilityStatistic CS = new CapabilityStatistic();
              int delay,load,delayLimit,loadLimit;
              delay = WI.Get();
              load = SI.Get();
              delayLimit = CS.GetWebDelaySta();
              loadLimit = CS.GetStationLoadSta();
                 if(delay<=delayLimit&&load<=loadLimit&&MinHP<=HpLimit)
                 {
                   return "*"+cachefilename;//*代表此时返回的web对象需要经过适配模块的处理
                 }
                 else if(MinHP<=HpLimit)
                      {
                         return cachefilename;//此时有参数超出门限,执行部分匹配,直接为用户返回这个web对象
                      }
                      else return "UNHIT";
              }*/

              //如果HpLimit是1,此时就是普通的匹配算法;当它大于1时就是我们的自适应平衡匹配算法
              //也可以调节Mcost来调整部分匹配的力度,它越大部分匹配就越容易
              if(Configuration.HpLimit==1)//必须精确匹配
              {
                if(MinHP>Configuration.Mcost)
                {
                  return "UNHIT";//版本之间的相关度很小,直接到原始服务器利用原始对象进行适配
                }
                else
                {
                  //将执行版本间转换
                  head = theMemCacheInterface.GetCachedObj(SourceFileName,cachefilename);
                  head.AddMediaUsedCount();
                  head.SetLastMediaUsedTime();
                  return "*"+cachefilename;//*代表此时返回的web对象需要经过适配模块的处理,
                                           //版本之间的相关度大,返回中间版本进行适配

                }
              }
              else if(MinHP<=Configuration.HpLimit)//可以实行部分匹配
              {
                WebDelayInterface WI = new WebDelayInterface();
                StationLoadInterface SI = new StationLoadInterface();
                //在这里调整网络负载和服务器负载
                WI.Set(150);
                SI.Set(20);
                CapabilityStatistic CS = new CapabilityStatistic();
                int delay,load,delayLimit,loadLimit;
                delay = WI.Get();
                load = SI.Get();
                delayLimit = CS.GetWebDelaySta();
                loadLimit = CS.GetStationLoadSta();
                if(delay<=delayLimit&&load<=loadLimit)
                {
                  if(MinHP>Configuration.Mcost)
                  {
                    return "UNHIT";
                  }
                  else
                  {
                    //将执行版本间转换
                    head = theMemCacheInterface.GetCachedObj(SourceFileName,cachefilename);
                    head.AddMediaUsedCount();
                    head.SetLastMediaUsedTime();
                    return "*"+cachefilename;//*代表此时返回的web对象需要经过适配模块的处理
                  }
                }
                else
                  {
                    head = theMemCacheInterface.GetCachedObj(SourceFileName,cachefilename);
                    head.AddUsedCount();
                    head.SetLastUsedTime();
                    return "#"+cachefilename;//此时有参数超出门限,执行部分匹配,直接为用户返回这个web对象
                  }
              }
              else return "UNHIT";
            }
            else return "UNHIT";
   }

   /**
   @roseuid 41771458032C
   */
   public boolean ExecuteI(ReplaceComInterface ReplaceCom)
   {
     if(SourceOrMedia)
     {
       boolean result = ReplaceCom.InsertNewObj(ref,size,cost);
       while(theMemCacheInterface.GetCacheSize()>=Configuration.MAX_SIZE)
       {
          ReplaceCom.ReplaceCache();
       }
       return result;
     }
     else
     {
       boolean result = ReplaceCom.InsertNewObj(ref,size,cost,BeginPoint,SourceOrMedia);
       while(theMemCacheInterface.GetCacheSize()>=Configuration.MAX_SIZE)
       {
          ReplaceCom.ReplaceCache();
       }
       return result;
     }
   }

   /**
   @roseuid 417714AF035B
   */
   public boolean ExecuteP(PreAdpInterface PreAdp)
   {
     return true;
   }

   /**
   @roseuid 417CDA700334
   */
   public Transaction(MemCacheInterface Cache)
   {
     theMemCacheInterface = Cache;
   }

   /**
   @roseuid 417CDB75023A
   */
   public boolean Set(String[] RefArray, int FileSize, int SavedCost)
   {
     ref = RefArray;
     size = FileSize;
     cost = SavedCost;
     return true;
   }

   /**
   @roseuid 417F5F800242
   */
   public boolean Set(String[] InputObjRefArray)
   {
     ref = InputObjRefArray;
     return true;
   }

   /**
   @roseuid 419813D90222
   */
   public boolean Set(String[] RefArray, int FileSize, int SavedCost, String BeginPt, boolean IsSource)
   {
     ref = RefArray;
     size = FileSize;
     cost = SavedCost;
     BeginPoint = BeginPt;
     SourceOrMedia = IsSource;
     return true;
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -