mobileplacemanager.java
来自「一个agent 工具包,可以开发移动设备应用,考虑了安全措施」· Java 代码 · 共 95 行
JAVA
95 行
package SOMA.mobilePlace;
import SOMA.naming.*;
import SOMA.Environment;
import SOMA.agent.AgentWorker;
import java.util.*;
import java.io.*;
/** Gestore dei place mobili di un dominio.
*
* @author Livio Profiri
*/
public class MobilePlaceManager implements Serializable
{
transient Environment env;
Hashtable mobilePlacePositions = new Hashtable();
Hashtable waitingAgents = new Hashtable();
public final static PlaceID DISCONNECTED = new PlaceID( "", "" )
{
public String toString()
{
return "DISCONNECTED";
}
public boolean equals(Object obj)
{
return this == obj;
}
};
/** Costruttore.
* @param env L'environment del place.
*/
public MobilePlaceManager( Environment env )
{
this.env = env;
env.dir.addItem( "mpm", new MobilePlaceManagerExplorerItem( this ) );
}
public PlaceID getPosition( PlaceID mobilePlaceID )
{
return (PlaceID)mobilePlacePositions.get( mobilePlaceID );
}
public PlaceID putPosition( PlaceID mobilePlaceID, PlaceID position )
{
return (PlaceID)mobilePlacePositions.put( mobilePlaceID, position );
}
public PlaceID removePosition( PlaceID mobilePlaceID )
{
waitingAgents.remove( mobilePlaceID );
return (PlaceID)mobilePlacePositions.remove( mobilePlaceID );
}
public void printStatus( PrintStream out )
{
printMobilePlacePositions( out );
printWaitingAgents( out );
}
public void printMobilePlacePositions( PrintStream out )
{
out.println( "Mobile places positions: " );
Iterator i = mobilePlacePositions.entrySet().iterator();
for( int j = 1; i.hasNext(); j++ )
{
Map.Entry e = (Map.Entry)i.next();
out.println( " " + j + ") " + e.getKey() + " --> " + e.getValue() );
}
out.println();
}
/** Restituisce true se gli agenti destinati a destination devono attendere qui. */
public boolean checkWaitCondition( PlaceID destination )
{
return destination instanceof MobilePlaceID
&& env.placeID.equals( destination.getHome() )
&& getPosition( destination ) == DISCONNECTED;
}
/** Aggiunge un agente alla liste degli agenti che attendono un place mobile.*/
public void addWaitingAgent( AgentID agentID, PlaceID destination )
{
// Prendo il Set di agenti che aspettano
Set agentIDSet = (Set)waitingAgents.get( destination );
if( agentIDSet == null ) //Se non c'
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?