?? 分布式對話服務器的管理(4).txt
字號:
作者:運氣
email: webmaster@chinaspx.com
日期:7/4/2001 1:42:32 PM
首先,對話服務器將獲得Mnemosyne對象的一個實例,該實例被綁定到對話服務器的本地IP上。
protected void bindMnemosyne()
{
file://得到Mnemosyne
Mnemosyne Mnemosyne = null;
try
{
Mnemosyne = MnemosyneFactory.getMnemosyne();
}
catch(RemoteException remoteException)
{
System.out.println("Internal error:");
System.out.println("Can't create a Mnemosyne");
System.exit(1);
}
// 把Mnemosyne綁定到MnemosyneImpl
try
{
String rmiURL = "//" + _localIP + "/MnemosyneImpl";
Naming.rebind(rmiURL, Mnemosyne);
}
catch(ArrayIndexOutOfBoundsException ArrayIndexOutOfBoundsException)
{
throw new IllegalArgumentException("LocalIP is invalid");
}
catch(MalformedURLException malformedURLException)
{
throw new IllegalArgumentException("LocalIP is invalid");
}
catch(RemoteException remoteException)
{
System.out.println("Internal error:");
System.out.println("Can't rebind a Mnemosyne to MnemosyneImpl");
System.exit(1);
}
}
通過把本地Mnemosyne上一系列代表RMI名字符號的URL賦予遠程對話服務器,就能引發同步操作,這些URL存貯在一個被稱作rmiURL的字符串數組中。在SessionServer的符號中,URL是作為參數從命令行命令中獲得的,但它可以來自其他渠道:
protected void synchronizeMnemosyne()
{
file://獲得本地Mnemosyne
Mnemosyne localMnemosyne = null;
try
{
localMnemosyne = (Mnemosyne) Naming.lookup(_localIP);
}
catch(Exception exception)
{
System.out.println("Internal error:");
System.out.println("Can't lookup local MnemosyneImpl");
System.exit(1);
}
file://獲得同步用的遠程Mnemosynes
Vector remoteMnemosynes = new Vector();
// _rmiURLS對象是代表需要進行同步的遠程服務器的字符串數組
for(int index = 1;index < _rmiURLS.length;index++)
{
try
{
remoteMnemosynes.add(Naming.lookup(_rmiURLS[index]));
}
catch(Exception exception)
{
}
}
file:// 同步
try
{
if(remoteMnemosynes.size() > 1)
localMnemosyne.synchronize(remoteMnemosynes);
}
catch(Exception exception)
{
System.out.println("Internal error:");
System.out.println("Can't synchronize local MnemosyneImpl");
System.exit(1);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -