📄 gridresourcewithfailure.java
字号:
// Checks the status of a Gridlet case GridSimTags.GRIDLET_STATUS: processGridletStatus(ev); break; // Ping packet case GridSimTags.INFOPKT_SUBMIT: processPingRequest(ev); break; case GridSimTags.GRIDRESOURCE_FAILURE: processFailure(ev); break; case GridSimTags.GRIDRESOURCE_RECOVERY: // Do nothing, as we have done it in the "if" statement break; // Get the total number of machines of this resource case GridSimTags.RESOURCE_NUM_MACHINES: src_id = ((Integer) ev.get_data()).intValue(); int numMachines = resource_.getNumMachines(); super.send(super.output, 0.0, ev.get_tag(), new IO_data(new Integer(numMachines), SIZE, src_id)); break; case GridSimTags.GRIDRESOURCE_FAILURE_INFO: // Do nothing, as we have done it in the "if" statement break; // other unknown tags are processed by this method default: processOtherEvent(ev); break; } }// if (getResourceFailed() == false) else { // If we receive an event while the resource is out of order, // we have to send the event back. // Otherwise the sender of that event would get stuck. Object obj = ev.get_data(); if (obj instanceof Gridlet) { Gridlet gl = (Gridlet) ev.get_data(); try { gl.setGridletStatus(Gridlet.FAILED_RESOURCE_UNAVAILABLE); gl.setResourceParameter(super.get_id(), resource_.getCostPerSec()); }catch(Exception e) {} /***********/ if (record_ == true) { System.out.println(super.get_name() + ": receives an event from " + GridSim.getEntityName(gl.getUserID()) + " while resource is failed, so not processed. Event tag: " + ev.get_tag() + ". Returning GRIDLET_RETURN to sender."); } /***********/ super.send(super.output, 0, GridSimTags.GRIDLET_RETURN, new IO_data(gl,gl.getGridletOutputSize(),gl.getUserID()) ); }// if (obj instanceof Gridlet) else if (ev.get_tag() == GridSimTags.RESOURCE_CHARACTERISTICS) { // Resource characteristics inquiry // We do this because the RegionalGISWithFailure entity needs it src_id = ((Integer) ev.get_data()).intValue(); super.send(super.output, 0.0, ev.get_tag(), new IO_data(resource_, resource_.getByteSize(), src_id)); } } } /** * Process the event for an User who wants to know the status of a Gridlet. * This GridResourceWithFailure will then send the status back to the User. * @param ev a Sim_event object * @pre ev != null * @post $none */ private void processGridletStatus(Sim_event ev) { int gridletId = 0; int userId = 0; int status = -1; try { // if a sender using gridletXXX() methods int data[] = (int[]) ev.get_data(); gridletId = data[0]; userId = data[1]; status = policy_.gridletStatus(gridletId, userId); } // if a sender using normal send() methods catch (ClassCastException c) { try { Gridlet gl = (Gridlet) ev.get_data(); gridletId = gl.getGridletID(); userId = gl.getUserID(); status = policy_.gridletStatus(gridletId, userId); } catch (Exception e) { System.out.println(super.get_name() + ": Error in processing GridSimTags.GRIDLET_STATUS"); System.out.println( e.getMessage() ); return; } } catch (Exception e) { System.out.println(super.get_name() + ": Error in processing GridSimTags.GRIDLET_STATUS"); System.out.println( e.getMessage() ); return; } int[] array = new int[2]; array[0] = gridletId; array[1] = status; int tag = GridSimTags.GRIDLET_STATUS; super.send( super.output, GridSimTags.SCHEDULE_NOW, tag, new IO_data(array, SIZE, userId) ); } /** * Processes a Gridlet based on the event type * @param ev a Sim_event object * @param type event type * @pre ev != null * @pre type > 0 * @post $none */ private void processGridlet(Sim_event ev, int type) { int gridletId = 0; int userId = 0; try { // if a sender using gridletXXX() methods int data[] = (int[]) ev.get_data(); gridletId = data[0]; userId = data[1]; } // if a sender using normal send() methods catch (ClassCastException c) { try { Gridlet gl = (Gridlet) ev.get_data(); gridletId = gl.getGridletID(); userId = gl.getUserID(); } catch (Exception e) { System.out.println(super.get_name() + ": Error in processing Gridlet"); System.out.println( e.getMessage() ); return; } } catch (Exception e) { System.out.println(super.get_name() + ": Error in processing a Gridlet."); System.out.println( e.getMessage() ); return; } // begins executing .... switch (type) { case GridSimTags.GRIDLET_CANCEL: policy_.gridletCancel(gridletId, userId); break; case GridSimTags.GRIDLET_PAUSE: policy_.gridletPause(gridletId, userId, false); break; case GridSimTags.GRIDLET_PAUSE_ACK: policy_.gridletPause(gridletId, userId, true); break; case GridSimTags.GRIDLET_RESUME: policy_.gridletResume(gridletId, userId, false); break; case GridSimTags.GRIDLET_RESUME_ACK: policy_.gridletResume(gridletId, userId, true); break; default: break; } } /** * Process the event for an User who wants to know the move of a Gridlet. * @param ev a Sim_event object * @param type event tag * @pre ev != null * @pre type > 0 * @post $none */ private void processGridletMove(Sim_event ev, int type) { boolean ack = false; if (type == GridSimTags.GRIDLET_MOVE_ACK) { ack = true; } try { // if a sender using gridletMove() methods int data[] = (int[]) ev.get_data(); int gridletId = data[0]; int userId = data[1]; int destId = data[2]; policy_.gridletMove(gridletId, userId, destId, ack); } catch (Exception e) { System.out.println(super.get_name()+": Error in moving a Gridlet."); System.out.println( e.getMessage() ); } } /** * Processes a Gridlet submission * @param ev a Sim_event object * @param ack an acknowledgement * @pre ev != null * @post $none */ private void processGridletSubmit(Sim_event ev, boolean ack) { try { // gets the Gridlet object Gridlet gl = (Gridlet) ev.get_data(); // checks whether this Gridlet has finished or not if (gl.isFinished() == true) { String name = GridSim.getEntityName( gl.getUserID() ); System.out.println(super.get_name() + ": Warning - Gridlet #" + gl.getGridletID() + " owned by " + name + " is already completed/finished."); System.out.println("Therefore, it is not being executed again"); System.out.println(); // NOTE: If a Gridlet has finished, then it won't be processed. // So, if ack is required, this method sends back a result. // If ack is not required, this method don't send back a result. // Hence, this might cause GridSim to be hanged since waiting // for this Gridlet back. if (ack == true) { int[] array = new int[2]; array[0] = gl.getGridletID(); array[1] = GridSimTags.FALSE; // unique tag = operation tag int tag = GridSimTags.GRIDLET_SUBMIT_ACK; super.send(super.output, GridSimTags.SCHEDULE_NOW, tag, new IO_data(array, SIZE, gl.getUserID()) ); } super.send(super.output, 0, GridSimTags.GRIDLET_RETURN, new IO_data(gl,gl.getGridletOutputSize(),gl.getUserID()) ); return; } // process this Gridlet to this GridResourceWithFailure gl.setResourceParameter(super.get_id(), resource_.getCostPerSec()); policy_.gridletSubmit(gl, ack); } catch (ClassCastException c) { System.out.println(super.get_name() + ".processGridletSubmit(): " + "ClassCastException error."); System.out.println( c.getMessage() ); } catch (Exception e) { System.out.println(super.get_name() + ".processGridletSubmit(): " + "Exception error."); System.out.println( e.getMessage() ); } } /** * Processes a ping request. * @param ev a Sim_event object * @pre ev != null * @post $none */ private void processPingRequest(Sim_event ev) { InfoPacket pkt = (InfoPacket) ev.get_data(); pkt.setTag(GridSimTags.INFOPKT_RETURN); pkt.setDestID(pkt.getSrcID()); // sends back to the sender super.send(super.output, 0.0, GridSimTags.INFOPKT_RETURN, new IO_data(pkt, pkt.getSize(), pkt.getSrcID())); } //////////////////////////////////////////// /** * Processes a polling request. * @param ev a Sim_event object * @pre ev != null * @post $none */ private void processPolling(Sim_event ev) { // The resource WILL ALWAYS give a response to the polling requests, // even when all the machines of the resource are out of order. // When all the machines are out of order, // the resource will wait for a period of time before answering // the polling request. AvailabilityInfo resAv = (AvailabilityInfo) ev.get_data(); /*******
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -