📄 datagriduser.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 */package gridsim.datagrid;import eduni.simjava.*;import gridsim.datagrid.index.*;import gridsim.*;import gridsim.net.Link;import gridsim.datagrid.filter.*;import java.util.*;/** * A class for representing a user in a Data Grid environment * @author Uros Cibej and Anthony Sulistio * @since GridSim Toolkit 4.0 */public class DataGridUser extends GridUser { private String rcName_; // replica catalogue name private int rcID_; // replica catalogue ID private Integer myID_; // this entity ID /** * Creates a new DataGrid user.<br> * NOTE: When using this constructor, do not forget to set * the regional GIS name and the Replica Catalogue name for this entity. * @param name the user name * @param link a network link to connect this user to a network * @throws Exception happens if one of the inputs is empty or null * @see gridsim.GridUser#setRegionalGIS(String) * @see gridsim.GridUser#setRegionalGIS(AbstractGIS) * @see gridsim.datagrid.DataGridUser#setReplicaCatalogue(String) * @see gridsim.datagrid.DataGridUser#setReplicaCatalogue(AbstractRC) */ public DataGridUser(String name, Link link) throws Exception { super(name, link); init(); } /** * Creates a new DataGrid user.<br> * NOTE: When using this constructor, do not forget to set * the Replica Catalogue name for this entity. * @param name the user name * @param link a network link to connect this user to a network * @param regionalGIS a Regional GIS name * @throws Exception happens if one of the inputs is empty or null * @see gridsim.datagrid.DataGridUser#setReplicaCatalogue(String) * @see gridsim.datagrid.DataGridUser#setReplicaCatalogue(AbstractRC) */ public DataGridUser(String name, Link link, String regionalGIS) throws Exception { super(name, link, regionalGIS); init(); } /** Initializes all the variables */ private void init() { rcName_ = null; rcID_ = -1; myID_ = new Integer( super.get_id() ); } /** * Creates a new DataGrid user * @param name the user name * @param link a network link to connect this user to a network * @param rcName a Replica Catalogue name * @param regionalGIS a Regional GIS name * @throws Exception happens if one of the inputs is empty or null */ public DataGridUser(String name, Link link, String rcName, String regionalGIS) throws Exception { super(name, link, regionalGIS); rcID_ = GridSim.getEntityId(rcName); if (rcName == null || rcID_ == -1) { throw new Exception(name + ": Error - invalid RC name"); } rcName_ = rcName; myID_ = new Integer( super.get_id() ); } /** * Sets a Replica Catalogue name for this user * (the old name will be overwritten). * @param rcName a Replica Catalogue name * @return <tt>true</tt> if successful, <tt>false</tt> otherwise */ public boolean setReplicaCatalogue(String rcName) { int id = GridSim.getEntityId(rcName); if (rcName == null || id == -1) { return false; } rcName_ = rcName; rcID_ = id; return true; } /** * Sets a Replica Catalogue name for this user * (the old name will be overwritten). * @param rc a Replica Catalogue object * @return <tt>true</tt> if successful, <tt>false</tt> otherwise */ public boolean setReplicaCatalogue(AbstractRC rc) { if (rc == null) { return false; } return setReplicaCatalogue( rc.get_name() ); } /** * Checks whether a Replica Catalogue entity has been allocated to * this user or not * @return <tt>true</tt> if the entity has been set, * <tt>false</tt> otherwise */ private boolean checkRC() { // if no RC entity exists boolean result = true; if (rcID_ == -1) { // use the default RC name rcID_ = GridSim.getEntityId(TopRegionalRC.DEFAULT_NAME); rcName_ = TopRegionalRC.DEFAULT_NAME; // If the default RC entity doesn't exist if (rcID_ == -1) { result = false; rcName_ = null; // change the RC name to null System.out.println(super.get_name() + ": Error - no TopRegionalRC entity exists."); } } return result; } /** * Gets a Replica Catalogue name * @return a Replica Catalogue name or <tt>null</tt> if it does not exist */ public String getReplicaCatalogueName() { checkRC(); return rcName_; } /** * Gets a Replica Catalogue id * @return a Replica Catalogue id or <tt>-1</tt> if it does not exist */ public int getReplicaCatalogueID() { checkRC(); return rcID_; } /** * Gets a list of local Replica Catalogue (RC) IDs from a regional * GIS entity * @return a list of local RC IDs in <tt>Integer</tt> object * or <tt>null</tt> if RCs do not exist. */ public Object[] getLocalRCList() { return super.getList(DataGridTags.INQUIRY_LOCAL_RC_LIST); } /** * Gets a list of global Replica Catalogue (RC) IDs. * Global RC means a RC that is registered to other * regional GIS entities. * @return a list of global RC IDs in <tt>Integer</tt> object * or <tt>null</tt> if RCs do not exist. */ public Object[] getGlobalRCList() { return super.getList(DataGridTags.INQUIRY_GLOBAL_RC_LIST); } /** * Gets the first resource ID that has the given logical file name (lfn). * <br>NOTE: The rest of resource IDs are ignored. If you want to know * all the resource IDs, then * use {@link #getReplicaLocationList(String)} method instead. * In addition, this method only contacts the given/chosen RC entity, not * all RCs. * @param lfn a logical file name * @return a resource ID or <tt>-1</tt> if not found */ public int getReplicaLocation(String lfn) { if (lfn == null) { return -1; } int resourceID = -1; int eventTag = DataGridTags.CTLG_GET_REPLICA; // set tag name // consult with the RC first int rcID = getReplicaCatalogueID(); if (rcID == -1) { return -1; } // sends a request to this RC sendEvent(eventTag, lfn, rcID); // waiting for a response from the RC Sim_type_p tag = new Sim_type_p(DataGridTags.CTLG_REPLICA_DELIVERY); // only look for this type of ack Sim_event ev = new Sim_event(); super.sim_get_next(tag, ev); try { Object[] data = (Object[]) ev.get_data(); // get the data Integer resID = (Integer) data[1]; // get the resource ID if (resID != null) { resourceID = resID.intValue(); } } catch (Exception e) { resourceID = -1; System.out.println(super.get_name() + ".getReplicaLocation(): Exception"); } return resourceID; } /** * Gets a list of resource IDs that store the given logical file name (lfn). * <br>NOTE: This method only contacts the given/chosen RC entity, not * all RCs. * @param lfn a logical file name * @return a list of resource IDs or <tt>null</tt> if not found */ public List getReplicaLocationList(String lfn) { int rcID = getReplicaCatalogueID(); return getReplicaLocationList(lfn, rcID); } /** * Gets a list of resource IDs that store the given logical file name (lfn). * <br>NOTE: This method only contacts the given/chosen RC entity, not * all RCs. * @param lfn a logical file name * @param rcID a RC entity ID * @return a list of resource IDs or <tt>null</tt> if not found */ public List getReplicaLocationList(String lfn, int rcID) { if (lfn == null || rcID == -1) { return null; } // send the event to the RC entity int eventTag = DataGridTags.CTLG_GET_REPLICA_LIST; sendEvent(eventTag, lfn, rcID); // waiting for a response from the RC Sim_type_p tag =new Sim_type_p(DataGridTags.CTLG_REPLICA_LIST_DELIVERY); // only look for this type of ack Sim_event ev = new Sim_event(); super.sim_get_next(tag, ev); List resList = null; // a list of resource IDs storing lfn try { Object[] data = (Object[]) ev.get_data(); // get the data resList = (List) data[1]; // get the resource list } catch (Exception e) { resList = null; System.out.println(super.get_name() + ".getReplicaLocationList(): Exception."); } return resList; } /** * Gets an attribute file for a given logical file name (lfn) * @param lfn a logical file name * @return a FileAttribute object or <tt>null</tt> if not found */ public FileAttribute getFileAttribute(String lfn) { // check first int rcID = getReplicaCatalogueID(); if (rcID == -1 || lfn == null) { return null; } int eventTag = DataGridTags.CTLG_GET_FILE_ATTR; FileAttribute fAttr = null; // sends a request to this RC sendEvent(eventTag, lfn, rcID); // waiting for a response from the RC Sim_type_p tag = new Sim_type_p(DataGridTags.CTLG_FILE_ATTR_DELIVERY); // only look for this type of ack Sim_event ev = new Sim_event(); super.sim_get_next(tag, ev); try { fAttr = (FileAttribute) ev.get_data(); } catch (Exception e) { fAttr = null; System.out.println(super.get_name()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -