?? transaction.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 + -