📄 regionalgiswithfailure.java
字号:
".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 // 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_--; // 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 * @post $none */ protected void processGlobalResourceARList(Sim_event ev) { LinkedList regionalList = null; // regional GIS list int eventTag = AbstractGIS.GIS_INQUIRY_RESOURCE_AR_LIST; boolean result = false; // for a first time request, it needs to call the system GIS first, // then asks each regional GIS for its resource IDs. if (globalResARList_ == null) { // get regional GIS list from system GIS first regionalList = requestFromSystemGIS(); // ask a resource list from each regional GIS result = getListFromOtherRegional(regionalList, eventTag); if (result == true) { globalResARList_ = new ArrayList(); // storing global AR numAR_ = regionalList.size() - 1; // excluding GIS itself // then store the user ID Integer id = (Integer) ev.get_data(); userARList_ = new ArrayList(); userARList_.add(id); return; // then exit } } // cache the request and store the user ID if it is already sent if (numAR_ > 0 && userARList_ != null && userARList_.size() > 0) { Integer id = (Integer) ev.get_data(); userARList_.add(id); return; // then exit } result = sendListToSender(ev, globalResARList_); if (result == false) { System.out.println(super.get_name() + ".processGlobalResourceARList(): Warning - can't send a " + "resource AR list to sender."); } } /** * Process an incoming request from users about getting a list of resource * IDs, that are registered in other regional GIS entities. * * @param ev a Sim_event object (or an incoming event or request) * @pre ev != null * @post $none */ protected void processGlobalResourceList(Sim_event ev) { /*** NOTE: possible cases are - if there is only 1 local GIS and no other regional GISes - if there is only 1 user queries for this - if there are 2 or more users query at different time ****/ LinkedList regionalList = null; // regional GIS list int eventTag = AbstractGIS.GIS_INQUIRY_RESOURCE_LIST; boolean result = false; // for a first time request, it needs to call the system GIS first, // then asks each regional GIS for its resource IDs. if (globalResList_ == null) { // get regional GIS list from system GIS first regionalList = requestFromSystemGIS(); // ask a resource list from each regional GIS result = getListFromOtherRegional(regionalList, eventTag); if (result == true) { globalResList_ = new ArrayList(); // storing global resources numRes_ = regionalList.size() - 1; // excluding itself // then store the user ID Integer id = (Integer) ev.get_data(); userList_ = new ArrayList(); userList_.add(id); return; // then exit } } // cache the request and store the user ID if it is already sent if (numRes_ > 0 && userList_ != null && userList_.size() > 0) { Integer id = (Integer) ev.get_data(); userList_.add(id); return; // then exit } // send the result back to sender, where the list could be empty result = sendListToSender(ev, globalResList_); if (result == false) { System.out.println(super.get_name() + ".processGlobalResourceList(): Warning - can't send a " + "resource list to sender."); } } /** * Get a list of IDs specified in the eventTag from other regional GIS * @param regionalList a list of regional GIS IDs * @param eventTag an event tag or type of request * @return <tt>true</tt> if successful, <tt>false</tt> otherwise * @pre regionalList != null * @post $none */ protected boolean getListFromOtherRegional(List regionalList, int eventTag) { // check for input first if (regionalList == null || regionalList.size() == 0) { return false; } // a loop to ask each regional GIS for its resource IDs Iterator it = regionalList.iterator(); while ( it.hasNext() ) { Integer obj = (Integer) it.next(); // can not send to itself if (obj.equals(myID_) == true) { continue; } // send a request to a regional GIS super.send( super.output, 0.0, eventTag, new IO_data(myID_, Link.DEFAULT_MTU, obj.intValue()) ); } return true; } /** * Asks from {@link gridsim.GridInformationService} or system GIS about * a list of regional GIS entity ID. * @return a list of regional GIS entity ID * @pre $none * @post $none */ protected LinkedList requestFromSystemGIS() { // get the regional GIS list from local cache if (regionalList_ != null) { return regionalList_; } else { regionalList_ = new LinkedList(); } // for the first time, ask the regional GIS list from system GIS int eventTag = GridSimTags.REQUEST_REGIONAL_GIS; boolean result = requestFromSystemGIS(eventTag, regionalList_); return regionalList_; } /** * Asks from {@link gridsim.GridInformationService} or system GIS about * a specific event or request. * * @param eventTag an event tag or type of request * @param list a list storing the results * @return <tt>true</tt> if successful, <tt>false</tt> otherwise * @pre list != null * @post $none */ protected boolean requestFromSystemGIS(int eventTag, List list) { boolean result = false; if (list == null) { return result; } // send a request to system GIS for a list of other regional GIS super.send( super.output, 0.0, eventTag, new IO_data(myID_, Link.DEFAULT_MTU, super.systemGIS_) ); // waiting for a response from system GIS Sim_type_p tag = new Sim_type_p(eventTag); // only look for this type of ack Sim_event ev = new Sim_event(); super.sim_get_next(tag, ev); try { List tempList = (List) ev.get_data(); list.addAll(tempList); result = true; } catch (Exception e) { result = false; System.out.println(super.get_name() + ".requestFromSystemGIS(): Exception error."); } return result; } /** * Sends a given list to sender * @param ev a Sim_event object * @param list a list to be sent to * @return <tt>true</tt> if successful, <tt>false</tt> otherwise */ private boolean sendListToSender(Sim_event ev, List list) { if (ev == null) { return false; } boolean result = false; Object obj = ev.get_data(); if (obj instanceof Integer) { Integer id = (Integer) obj; result = sendListToSender(id.intValue(), ev.get_tag(), list); } return result; } /** * Sends a list to sender * @param senderID the sender ID * @param tag an event tag * @param list a list to be sent to * @return <tt>true</tt> if successful, <tt>false</tt> otherwise * @pre senderID != -1 * @post $none */ protected boolean sendListToSender(int senderID, int tag, List list) { if (senderID < 0) { return false; } int length = 0; if (list == null || list.size() == 0) { length = 1; } else { length = list.size(); } // Send the event or message super.send( super.output, 0.0, tag, new IO_data(list, Link.DEFAULT_MTU*length, senderID) ); return true; } /** * Process an incoming request 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 processResourceList(Sim_event ev) { /*// REMOVE !!! System.out.println("---"); for (int i = 0; i < resList_.size(); i++) System.out.println(super.get_name()+ ": resList_.get(" + i + "): " + GridSim.getEntityName(((Integer) resList_.get(i)).intValue())); System.out.println("---");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -