📄 mobileplacemanager.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -