📄 regionalgis.java
字号:
/* * Title: GridSim Toolkit * Description: GridSim (Grid Simulation) Toolkit for Modeling and Simulation * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * * $Id: RegionalGIS.java,v 1.8 2006/01/17 01:30:24 anthony Exp $ */package gridsim.index;import java.util.*;import eduni.simjava.*;import gridsim.*;import gridsim.net.Link;/** * RegionalGIS is a simple regional GridInformationService (GIS) entity that * performs basic functionalities, such as storing a list of local resources, * and asking other regional GIS entities for resources. * <p> * If you want to implement other complex functionalities, you need to extend * this class and to override {@link #processOtherEvent(Sim_event)} * and/or {@link #registerOtherEntity()} method. * * @author Anthony Sulistio * @since GridSim Toolkit 3.2 * @invariant $none */public class RegionalGIS extends AbstractGIS{ /** This entity ID in <tt>Integer</tt> object. */ protected Integer myID_; private ArrayList resList_; // all resources within this region private ArrayList arList_; // AR resources only within this region private ArrayList globalResList_; // all resources outside this region private ArrayList globalResARList_; // AR resources only outside this region private LinkedList regionalList_; // list of regional GIS, incl. myself private ArrayList userList_; // list of users querying for global res private ArrayList userARList_; // list of users querying for global AR res private int numRes_; // counting for num of GIS entities for res request private int numAR_; // counting for num of GIS entities for res AR request /** * Creates a new regional GIS entity * @param name this regional GIS name * @param link a network link to this entity * @throws Exception This happens when creating this entity before * initializing GridSim package or this entity name is * <tt>null</tt> or empty * @pre name != null * @pre link != null * @post $none */ public RegionalGIS(String name, Link link) throws Exception { super(name, link); init(); } /** * Initialises all attributes * @pre $none * @post $none */ private void init() { myID_ = new Integer( super.get_id() ); resList_ = new ArrayList(); arList_ = new ArrayList(); regionalList_ = null; globalResList_ = null; globalResARList_ = null; userList_ = null; userARList_ = null; numAR_ = -1; numRes_ = -1; } /** * Stores the incoming registration ID into the given list. <br> * NOTE: <tt>ev.get_data()</tt> should contain an <tt>Integer</tt> object. * * @param ev a new Sim_event object or incoming registration request * @param list a list storing the registration IDs * @return <tt>true</tt> if successful, <tt>false</tt> otherwise * @pre ev != null * @pre list != null * @post $none */ protected boolean storeRegistrationID(Sim_event ev, List list) { boolean result = false; if (ev == null || list == null) { return result; } Object obj = ev.get_data(); if (obj instanceof Integer) { Integer id = (Integer) obj; list.add(id); result = true; } return result; } /** * Process a registration request from a resource entity * supporting Advanced Reservation to this regional * GIS entity. <br> * NOTE: <tt>ev.get_data()</tt> should contain an <tt>Integer</tt> object * representing the resource ID. * * @param ev a Sim_event object (or a registration request) * @pre ev != null * @post $none */ protected void processRegisterResourceAR(Sim_event ev) { boolean result1 = storeRegistrationID(ev, arList_); boolean result2 = storeRegistrationID(ev, resList_); if (result1 == false || result2 == false) { System.out.println(super.get_name() + ".processRegisterResourceAR(): Warning - can't register " + "a resource ID."); } } /** * Process a registration request from a resource entity to this regional * GIS entity. <br> * NOTE: <tt>ev.get_data()</tt> should contain an <tt>Integer</tt> object * representing the resource ID. * * @param ev a Sim_event object (or a registration request) * @pre ev != null * @post $none */ protected void processRegisterResource(Sim_event ev) { boolean result = storeRegistrationID(ev, resList_); if (result == false) { System.out.println(super.get_name() + ".processRegisterResource(): Warning - can't register " + "a resource ID."); } } /** * Process an incoming request that uses a user-defined tag. <br> * NOTE: This method can be overridden by its subclasses, provided * that they call this method first. This is required, just in case * this method is not empty. * * @param ev a Sim_event object (or an incoming event or request) * @pre ev != null * @post $none */ protected void processOtherEvent(Sim_event ev) { // empty } /** * Process an incoming request from other GIS entities about getting * a list of resource IDs, that are registered to this regional GIS entity. * * @param ev a Sim_event object (or an incoming event or request) * @pre ev != null * @post $none */ protected void processGISResourceList(Sim_event ev) { if (ev == null || ev.get_data() == null) { return; } Integer id = (Integer) ev.get_data(); int tag = AbstractGIS.GIS_INQUIRY_RESOURCE_RESULT; /***** // Debug info System.out.println(super.get_name() + ".processGISResourceList():" + " request from " + GridSim.getEntityName(id.intValue()) + " for list = " + resList_ + " tag = " + ev.get_tag()); *****/ boolean result = sendListToSender(id.intValue(), tag, resList_); if (result == false) { System.out.println(super.get_name() + ".processGISResourceList(): Warning - unable to send a list " + "of resource IDs to sender."); } } /** * Process an incoming request from other GIS entities about getting * a list of resource IDs supporting Advanced Reservation, * that are registered to this regional GIS entity. * * @param ev a Sim_event object (or an incoming event or request) * @pre ev != null * @post $none */ protected void processGISResourceARList(Sim_event ev) { if (ev == null || ev.get_data() == null) { return; } Integer id = (Integer) ev.get_data(); int tag = AbstractGIS.GIS_INQUIRY_RESOURCE_AR_RESULT; /***** // Debug info System.out.println(super.get_name() + ".processGISResourceARList():" + " request from " + GridSim.getEntityName(id.intValue()) + " for list = " + resList_ + " tag = " + ev.get_tag()); *****/ boolean result = sendListToSender(id.intValue(), tag, arList_); if (result == false) { System.out.println(super.get_name() + ".processGISResourceARList(): Warning - unable to send a " + "list of resource IDs to sender."); } } /** * Process an incoming delivery from other GIS entities about their * resource list supporting Advanced Reservation. <br> * NOTE: ev.get_data() should contain <tt>List</tt> containing resource IDs * (in <tt>Integer</tt> object). * * @param ev a Sim_event object (or an incoming event or request) * @pre ev != null * @post $none */ protected void processGISResourceARResult(Sim_event ev) { try { List list = (List) ev.get_data(); // get the data globalResARList_.addAll(list); // add the result into a list numAR_--; // decrement the counter for GIS entity /***** // Debug info System.out.println(); System.out.println(super.get_name() + " ... AR result tag = " + ev.get_tag() + " counter = " + numAR_); System.out.println(super.get_name() + " ... AR list = " + globalResARList_); *****/ // send back the result to user(s) if (numAR_ == 0) { numAR_ = -1; sendBackResult(globalResARList_, AbstractGIS.INQUIRY_GLOBAL_RESOURCE_AR_LIST, userARList_); } } catch (Exception e) { System.out.println(super.get_name() + ": Error - expected to send List object in ev.get_data()"); } } /** * Process an incoming delivery from other GIS entities about their * resource list. <br> * NOTE: ev.get_data() should contain <tt>List</tt> containing resource IDs * (in <tt>Integer</tt> object). * * @param ev a Sim_event object (or an incoming event or request) * @pre ev != null * @post $none */ protected void processGISResourceResult(Sim_event ev) { try { List list = (List) ev.get_data(); globalResList_.addAll(list); numRes_--; /***** // Debug info System.out.println(); System.out.println(super.get_name() + " ... EMPTY tag = " + ev.get_tag() + " counter = " + numRes_); System.out.println(super.get_name()+" ... list = "+globalResList_); *****/ // send back the result to user(s) if (numRes_ == 0) { numRes_ = -1; sendBackResult(globalResList_, AbstractGIS.INQUIRY_GLOBAL_RESOURCE_LIST, userList_); } } catch (Exception e) { System.out.println(super.get_name() + ": Error - expected to send List object in ev.get_data()"); } } /** * Sends the result back to sender * @param list a List object containing resource IDs * @param tag a return tag name * @param userList a list of user IDs * * @pre userList != null * @post $none */ private void sendBackResult(List list, int tag, ArrayList userList) { if (userList == null) { return; } // send back the result to each user in the list Iterator it = userList.iterator(); while ( it.hasNext() ) { Integer id = (Integer) it.next(); sendListToSender(id.intValue(), tag, list); } userList.clear(); // then clear up the list } /** * Process an incoming request about getting a list of regional GIS IDs * (including this entity ID), that are registered to the * {@link gridsim.GridInformationService} or system GIS. * * @param ev a Sim_event object (or an incoming event or request) * @pre ev != null * @post $none */ protected void processInquiryRegionalGIS(Sim_event ev) { // get regional GIS list from system GIS LinkedList regionalList = requestFromSystemGIS(); // then send the list to sender boolean result = sendListToSender(ev, regionalList); if (result == false) { System.out.println(super.get_name() + ".processInquiryRegionalGIS(): Warning - unable to send a " + "list of regional GIS IDs to sender."); } } /** * Process an incoming request about getting a list of resource IDs * supporting Advanced Reservation that are registered in other regional * GIS entities. * * @param ev a Sim_event object (or an incoming event or request) * @pre ev != null
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -