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

📄 topregionalrc.java

📁 中間件開發详细说明:清华大学J2EE教程讲义(ppt)-Tsinghua University J2EE tutorial lectures (ppt) [上载源码成为会员下载此源码] [成为VIP会
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * 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 */package gridsim.datagrid.index;import java.util.*;import eduni.simjava.*;import gridsim.datagrid.*;import gridsim.net.Link;import gridsim.*;import gridsim.datagrid.filter.Filter;/** * This class acts as a centralized RC or a root RC in a hierarchical model. * It is responsible for generating a unique ID for each file name. * Hence, the full name of the file will be "filename+uniqueID" * when you use {@link gridsim.datagrid.DataGridUser#getFullFilename(String)} * * @author  Uros Cibej and Anthony Sulistio * @since   GridSim Toolkit 4.0 * @see gridsim.datagrid.index.RegionalRC */public class TopRegionalRC extends AbstractRC{    private Hashtable catalogueHash_;   // storing replicas    private Hashtable attrHash_;        // storing file attributes    private int lastUniqueID;           //  generate a uniqueID    /** Default name for this RC entity, which is "GridSim_TopRC".     *  NOTE: This default name is useful when a user forgets to tell the     * {@link gridsim.datagrid.DataGridUser} or     * {@link gridsim.datagrid.DataGridResource} entity about the RC id.     */    public static final String DEFAULT_NAME = "GridSim_TopRC";    /**     * Creates a new Replica Catalogue (RC) entity.     * @param name  this entity name     * @param link  the link that this GridSim entity will use to     *              communicate with other GridSim or Network entities.     * @throws Exception    This happens when one of the input parameters is     *                      invalid.     */    public TopRegionalRC(String name, Link link) throws Exception    {        super(name, link);        init();    }    /**     * Creates a new Replica Catalogue (RC) entity with a default name.     * @param link  the link that this GridSim entity will use to     *              communicate with other GridSim or Network entities.     * @throws Exception    This happens when the network link is null     */    public TopRegionalRC(Link link) throws Exception    {        super(TopRegionalRC.DEFAULT_NAME, link);        init();    }    /** Initialization of all atttributes */    private void init()    {        catalogueHash_ = new Hashtable();        attrHash_ = new Hashtable();        lastUniqueID = 0;    }    //-------MAIN METHOD FOR HANDLING REQUESTS/EVENTS--------------    /**     * Processes an incoming request that uses a user-defined tag. This method     * is useful for creating a new RC entity.     * @param ev  a Sim_event object (or an incoming event or request)     * @return <tt>true</tt> if successful, <tt>false</tt> otherwise     */    protected boolean processOtherEvent(Sim_event ev)    {        boolean result = true;        switch ( ev.get_tag() )        {            //-----------REPLICA MANAGER REQUESTS--------            case DataGridTags.CTLG_ADD_MASTER:                processAddMaster(ev);                break;            case DataGridTags.CTLG_DELETE_MASTER:                processDeleteMaster(ev);                break;            case DataGridTags.CTLG_ADD_REPLICA:                processAddReplica(ev);                break;            case DataGridTags.CTLG_DELETE_REPLICA:                processDeleteReplica(ev);                break;            //-------USER REQUESTS---------------            case DataGridTags.CTLG_GET_FILE_ATTR:                processFileAttrRequest(ev);                break;            case DataGridTags.CTLG_GET_REPLICA:                processGetReplica(ev);                break;            case DataGridTags.CTLG_GET_REPLICA_LIST:                processGetReplicaList(ev);                break;            case DataGridTags.CTLG_FILTER:                processFilterFiles(ev);                break;            default:                System.out.println(super.get_name() +                    ".processOtherEvent(): Warning - unknown tag = "+ev.get_tag());                result = false;                break;        }        return result;    }    //  -----------------PROCESS REPLICA MANAGER REQUESTS------------    /**     * Manages the request for adding a replica to the catalogue. It receives an     * event with the name of the file and the <code>resID</code> where this     * file is located.     * <br>     * If the catalogue already contains an entry for this file name (i.e.     * the master file is already registered) than adds the <code>resID</code>     * to the list of resources with that file.     * <br>     * If there is no entry in the catalogue for this file name, then     * returns an error to the resource.     *     * @param ev    a Sim_event object     */    private void processAddReplica(Sim_event ev)    {        if (ev == null) {            return;        }        Object[] obj = (Object[]) ev.get_data();        if (obj == null)        {            System.out.println(super.get_name() +                    ".processAddReplica(): replica is null");            return;        }        String name = (String) obj[0];      // get file name        Integer resID = (Integer) obj[1];   // get resource id        int result = DataGridTags.CTLG_ADD_REPLICA_SUCCESSFUL;        try        {            /*****  // DEBUG            System.out.println(super.get_name() +                ".processAddReplica(): top RC for " + name);            *****/            // if this replica name is a new entry            ArrayList list = (ArrayList) catalogueHash_.get(name);            if (list == null)            {                /*****  // DEBUG                System.out.println(super.get_name() +                    ".processAddReplica(): empty list --> new catalogue for " +                    name);                *****/                list = new ArrayList();   // create a new list                list.add(resID);          // put resource ID into this list                catalogueHash_.put(name, list);     // add into catalogue            }            else            {                list.add(resID);                /*****  // DEBUG                System.out.println(super.get_name() +                    ".processAddReplica(): adds into the list for " + name);                *****/            }        }        catch (Exception e) {            result = DataGridTags.CTLG_ADD_REPLICA_ERROR;        }        /*****  // DEBUG        System.out.println(super.get_name() +                ".processAddReplica(): sends the result back to " +                GridSim.getEntityName((Integer) obj[1]));        *****/        sendMessage(name, DataGridTags.CTLG_ADD_REPLICA_RESULT,                    result, resID.intValue() );    }    /**     * Manages the request for deleting a replica from the Replica Catalogue.     * If there is no entry for the filename in the catalogue, then return     * an error.     * Otherwise, delete the entry from the catalogue and send a message to     * the lower level catalogue/or to the resource.     *     * @param ev    a Sim_event object     */    private void processDeleteReplica(Sim_event ev)    {        if (ev == null) {            return;        }        Object[] obj = (Object[]) ev.get_data();        if (obj == null)        {            System.out.println(super.get_name() +                    ".processDeleteReplica(): no object is found");            return;        }        String name = (String) obj[0];      // get file name        Integer resID = (Integer) obj[1];   // get resource id        int msg = DataGridTags.CTLG_DELETE_REPLICA_SUCCESSFUL;        try        {            int event = DataGridTags.CTLG_DELETE_REPLICA;            ArrayList list = (ArrayList) catalogueHash_.get(name);            if (list != null && list.size() > 1) {                 if (list.remove(resID) == false) {                    msg = DataGridTags.CTLG_DELETE_REPLICA_ERROR_DOESNT_EXIST;                }            }            else{                msg = DataGridTags.CTLG_DELETE_REPLICA_ERROR_DOESNT_EXIST;            }        }        catch (Exception e) {            msg = DataGridTags.CTLG_DELETE_REPLICA_ERROR;        }        sendMessage(name, DataGridTags.CTLG_DELETE_REPLICA_RESULT, msg,                    resID.intValue() );    }    /**     * Registers a master file into the Replica Catalogue.     * The method is similar to {@link #processAddReplica(Sim_event)}.     * However, in this method, this file is known as     * "name+uniqueID", e.g. test4 (name is "test" and uniqueID is "4").     *     * @param ev    a Sim_event object     */    private void processAddMaster(Sim_event ev)    {        if (ev == null) {            return;        }        int result = -1;        Object[] data = (Object[]) ev.get_data();        if (data == null)        {            System.out.println(super.get_name() +                    ".processAddMaster(): master file name is null");            return;        }        String filename = (String) data[0];             // file name        FileAttribute attr = (FileAttribute) data[1];   // file attribute        Integer resourceID = (Integer) data[2];                 // resource ID        int uniqueID = -1;        try        {            uniqueID = createUniqueID(filename); // create a unique file ID            result = DataGridTags.CTLG_ADD_MASTER_SUCCESSFUL;            // put the master file attribute into the catalogue            ArrayList list = new ArrayList();            list.add(resourceID);            catalogueHash_.put(filename + uniqueID, list);            attrHash_.put(filename + uniqueID, attr);            /*****  // DEBUG            System.out.println(super.get_name() +                ".processAddMaster(): " + filename + " --> id = " + uniqueID);            *****/        }        catch (Exception e) {            result = DataGridTags.CTLG_ADD_MASTER_ERROR;        }        // sends the result back to sender        data = new Object[3];        data[0] = filename;        data[1] = new Integer(uniqueID);        data[2] = new Integer(result);

⌨️ 快捷键说明

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