⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regionalgis.java

📁 中間件開發详细说明:清华大学J2EE教程讲义(ppt)-Tsinghua University J2EE tutorial lectures (ppt) [上载源码成为会员下载此源码] [成为VIP会
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @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()) );            /******   // Debug info            System.out.println(super.get_name()+".getListFromOtherRegional(): "                    + "query to " + GridSim.getEntityName( obj.intValue() )                    + ", tag = " + eventTag);            ******/        }        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();        }        /******   // DEBUG info        System.out.println(super.get_name()+".sendListToSender(): send list = "            + list + ", tag = " + tag + " to "+GridSim.getEntityName(senderID));        System.out.println();        ******/        // 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)    {        /*****   // Debug info        Integer id = (Integer) ev.get_data();        System.out.println(super.get_name() + ".processResourceList():" +            " request from " + GridSim.getEntityName(id.intValue()) +            " for list = " + resList_ + " tag = " + ev.get_tag());        *******/        boolean result = sendListToSender(ev, resList_);        if (result == false)        {            System.out.println(super.get_name() +                ".processResourceList(): Warning - unable to send a list " +                "of resource IDs to sender.");        }    }    /**     * Process an incoming request 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 processResourceARList(Sim_event ev)    {        boolean result = sendListToSender(ev, arList_);        if (result == false)        {            System.out.println(super.get_name() +                ".processResourceARList(): Warning - unable to send a list " +                "of resource IDs to sender.");        }    }    /**     * Registers other information to {@link gridsim.GridInformationService} or     * system GIS.<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.     * @pre $none     * @post $none     */    protected void registerOtherEntity() {        // empty    }    /**     * Informs the registered entities regarding to the end of a simulation.<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.     * @pre $none     * @post $none     */    protected void processEndSimulation()    {        resList_.clear();        arList_.clear();        if (regionalList_ != null) {            regionalList_.clear();        }        if (globalResList_ != null) {            globalResList_.clear();        }        if (globalResARList_ != null) {            globalResARList_.clear();        }        if (userList_ != null) {            userList_.clear();        }        if (userARList_ != null) {            userARList_.clear();        }    }} // end class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -