📄 topregionalrc.java
字号:
super.send(super.output, 0, DataGridTags.CTLG_ADD_MASTER_RESULT, new IO_data(data, DataGridTags.PKT_SIZE, resourceID.intValue()) ); } /** * Deletes a master file from the catalogue. A method very * similar to the {@link #processDeleteReplica(Sim_event)}. The * difference is that the master file is never deleted if there are more * than one entry in the catalogue, i.e. replicas of this file still exist. * Before the master file can be deleted all the replicas need to be deleted * first. * * @param ev a Sim_event object */ private void processDeleteMaster(Sim_event ev) { if (ev == null) { return; } Object[] obj = (Object[]) ev.get_data(); if (obj == null) { System.out.println(super.get_name() + ".processDeleteMaster(): master file name is null"); return; } String name = (String) obj[0]; // get file name Integer resID = (Integer) obj[1]; // get resource id int msg = DataGridTags.CTLG_DELETE_MASTER_SUCCESSFUL; try { ArrayList list = (ArrayList) catalogueHash_.get(name); if (list.size() != 1) { msg = DataGridTags.CTLG_DELETE_MASTER_REPLICAS_EXIST; } else if (list.remove(resID) == false) { msg = DataGridTags.CTLG_DELETE_MASTER_DOESNT_EXIST; } else { catalogueHash_.remove(name); // remove from the catalogue attrHash_.remove(name); } } catch (Exception e) { msg = DataGridTags.CTLG_DELETE_MASTER_ERROR; } sendMessage(name, DataGridTags.CTLG_DELETE_MASTER_RESULT, msg, resID.intValue() ); } //-----------------PROCESS USER REQUESTS------------------------------- /** * Processes the request for a file attribute. If the Replica Catalogue * contains the {@link gridsim.datagrid.FileAttribute} of the file * then it is sent to the requester. * * @param ev a Sim_event object */ private void processFileAttrRequest(Sim_event ev) { if (ev == null) { return; } int requesterID = -1; int size = 0; FileAttribute attr = null; try { Object[] obj = (Object[]) ev.get_data(); if (obj == null) { return; } String name = (String) obj[0]; // get file name Integer senderID = (Integer) obj[1]; // get sender id requesterID = senderID.intValue(); // get the file attribute of a given filename attr = (FileAttribute) attrHash_.get(name); if (attr != null) { size = attr.getAttributeSize(); } else { size = DataGridTags.PKT_SIZE; attr = null; } } catch (Exception e) { attr = null; size = DataGridTags.PKT_SIZE; } // send back to requester if (requesterID != -1) { super.send(super.output, 0, DataGridTags.CTLG_FILE_ATTR_DELIVERY, new IO_data(attr, size, requesterID) ); } } /** * Processes a request for filtering the files. A user sends a * {@link gridsim.datagrid.filter.Filter} to the Replica Catalogue. * Only the top level Replica Catalogue runs the filter accross the list * of all {@link gridsim.datagrid.FileAttribute} * All the attributes that are filtered out are sent back to the requester. * * @param ev a Sim_event object */ private void processFilterFiles(Sim_event ev) { if (ev == null) { return; } Object[] data = (Object[]) ev.get_data(); if (data == null) { return; } Filter f = (Filter) data[0]; int destination = ((Integer) data[1]).intValue(); ArrayList list = new ArrayList(); int size = 0; Enumeration attributes = attrHash_.elements(); while ( attributes.hasMoreElements() ) { FileAttribute attrTemp = (FileAttribute) attributes.nextElement(); if (f.match(attrTemp) == true) { list.add(attrTemp); // add this attribute into the list size += attrTemp.getAttributeSize(); } } // sends back the result to the sender super.send(super.output, 0, DataGridTags.CTLG_FILTER_DELIVERY, new IO_data(list, size, destination) ); } /** * Processes the request for a file location. If the catalogue contains the * file name, the first location of that file is returned back to the user. * If there is no enty for the file name in the catalogue and this is not * the top Replica Catalogue, the request is forwarded to the higher level * catalogue. * * @param ev a Sim_event object */ private void processGetReplica(Sim_event ev) { if (ev == null) { return; } Object[] data = (Object[]) ev.get_data(); if (data == null) { return; } String filename = (String) data[0]; // get file name Integer sender = (Integer) data[1]; // get sender id // creates an object that contains the required information Object[] dataTemp = new Object[3]; dataTemp[0] = filename; ArrayList list = (ArrayList) catalogueHash_.get(filename); if (list != null) { dataTemp[1] = (Integer) list.get(0); } else { dataTemp[1] = new Integer(-1); } // sends back the result to sender super.send(super.output, 0, DataGridTags.CTLG_REPLICA_DELIVERY, new IO_data(dataTemp, DataGridTags.PKT_SIZE, sender.intValue()) ); } /** * Sends the list of file replica locations that are registered to this RC. * @param ev a Sim_event object */ private void processGetLocalReplicaList(Sim_event ev) { if (ev == null) { return; } Object[] data = (Object[]) ev.get_data(); if (data == null) { return; } String filename = (String) data[0]; // get file name Integer sender = (Integer) data[1]; // get sender id // creates an object that contains the required information Object[] dataTemp = new Object[2]; dataTemp[0] = filename; dataTemp[1] = (ArrayList) catalogueHash_.get(filename); // sends back the result to sender super.send(super.output, 0, DataGridTags.CTLG_REPLICA_LIST_DELIVERY, new IO_data(dataTemp, DataGridTags.PKT_SIZE, sender.intValue()) ); } /** * Sends a list of resource IDs for the location of replicas * @param ev a Sim_event object */ private void processGetReplicaList(Sim_event ev) { processGetLocalReplicaList(ev); } // -----------------ADDITIONAL METHODS------------ /** * Creates a unique ID of a file. This method is used only on the top level * Replica Catalogue, since it is resposible for generating uniqued IDs. * * @return a unique ID */ private int createUniqueID(String currentFileName) { lastUniqueID++; //test if the new id would create a clash ArrayList list = (ArrayList) catalogueHash_.get(currentFileName+lastUniqueID); while(list!=null){ //if it creates a clash, try using a greater ID lastUniqueID++; list = (ArrayList) catalogueHash_.get(currentFileName+lastUniqueID); } return lastUniqueID; } /** * Sends a message as a result of adding or deleting a file. <br> * <b>Example: </b>the file of the operation is <i>file12 </i>, the event to * be sent is <i>CTLG_DELETE_REPLICA_RESULT </i> and the message to be sent * is <i>CTLG_DELETE_SUCCESFUL </i>. * * @param fileName the name of the file * @param event the event to be sent * @param msg the message to be sent * @param dest the destination of the message */ private void sendMessage(String fileName, int event, int msg, int dest) { Object pack[] = new Object[2]; pack[0] = fileName; pack[1] = new Integer(msg); super.send(super.output, GridSimTags.SCHEDULE_NOW, event, new IO_data(pack, DataGridTags.PKT_SIZE, dest)); } /** * Registers other information to a GIS entity -- THIS METHOD IS EMPTY */ protected void registerOtherEntity() { // empty ... } /** * Performs last activities before the end of a simulation -- THIS * METHOD IS EMPTY */ protected void processEndSimulation() { // empty ... } /** * Register a file which is already stored in a resource <b>before</b> the * start of simulation. <br> * NOTE: A unique id of this file IS NOT available * * @param fAttr a FileAttribute object * @param sourceID the entity ID that stores this file * @return <tt>true</tt> if successful, <tt>false</tt> otherwise */ public boolean registerOriginalFile(FileAttribute fAttr, int sourceID) { if (fAttr == null || sourceID == -1) { return false; } ArrayList list = (ArrayList) catalogueHash_.get( fAttr.getName() ); if (list != null) { list.add( new Integer(sourceID) ); } else { list = new ArrayList(); list.add( new Integer(sourceID) ); catalogueHash_.put(fAttr.getName(), list); attrHash_.put(fAttr.getName(), fAttr); } return true; }} // end class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -