![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 16, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #include <WNS/queuingsystem/MM1Step2.hpp> 00029 00030 using namespace wns::queuingsystem; 00031 00032 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00033 SimpleMM1Step2, 00034 wns::simulator::ISimulationModel, 00035 "openwns.queuingsystem.SimpleMM1Step2", 00036 wns::PyConfigViewCreator); 00037 00038 SimpleMM1Step2::SimpleMM1Step2(const wns::pyconfig::View& config) : 00039 logger_(config.get("logger")) 00040 { 00041 wns::pyconfig::View disConfig = config.get("jobInterArrivalTimeDistribution"); 00042 std::string disName = disConfig.get<std::string>("__plugin__"); 00043 jobInterarrivalTime_ = 00044 wns::distribution::DistributionFactory::creator(disName)->create(disConfig); 00045 00046 disConfig = config.get("jobProcessingTimeDistribution"); 00047 disName = disConfig.get<std::string>("__plugin__"); 00048 jobProcessingTime_ = 00049 wns::distribution::DistributionFactory::creator(disName)->create(disConfig); 00050 } 00051 00052 void 00053 SimpleMM1Step2::doStartup() 00054 { 00055 MESSAGE_SINGLE(NORMAL, logger_, "MM1Step2 started, generating first job\n" << *this); 00056 00057 generateNewJob(); 00058 } 00059 00060 void 00061 SimpleMM1Step2::doShutdown() 00062 { 00063 00064 } 00065 00066 // begin example "wns.queuingsystem.mm1step2.generateNewJob.example" 00067 void 00068 SimpleMM1Step2::generateNewJob() 00069 { 00070 // Create a new job 00071 Job job = Job(); 00072 00073 // Insert the new job at the end of the queue 00074 queue_.push_back(job); 00075 00076 wns::simulator::Time delayToNextJob = (*jobInterarrivalTime_)(); 00077 00078 MESSAGE_SINGLE(NORMAL, logger_, "Generated new job, next job in " << delayToNextJob << "s\n" << *this); 00079 00080 // The job is the only job in the system. There is no job that is currently 00081 // being served -> the server is free and can process the next job 00082 if (queue_.size() == 1) 00083 { 00084 processNextJob(); 00085 } 00086 00087 wns::simulator::getEventScheduler()->scheduleDelay( 00088 boost::bind(&SimpleMM1Step2::generateNewJob, this), 00089 delayToNextJob); 00090 00091 } 00092 // end example 00093 00094 // begin example "wns.queuingsystem.mm1step2.onJobProcessed.example" 00095 void 00096 SimpleMM1Step2::onJobProcessed() 00097 { 00098 Job finished = queue_.front(); 00099 00100 queue_.pop_front(); 00101 00102 MESSAGE_SINGLE(NORMAL, logger_, "Finished a job\n" << *this); 00103 MESSAGE_BEGIN(NORMAL, logger_, m, "Sojourn Time of last job "); 00104 m << wns::simulator::getEventScheduler()->getTime() - finished.getCreationTime(); 00105 MESSAGE_END(); 00106 00107 // if there are still jobs, serve them 00108 if (!queue_.empty()) 00109 { 00110 processNextJob(); 00111 } 00112 } 00113 // end example 00114 00115 void 00116 SimpleMM1Step2::processNextJob() 00117 { 00118 wns::simulator::Time processingTime = (*jobProcessingTime_)(); 00119 00120 wns::simulator::getEventScheduler()->scheduleDelay( 00121 boost::bind(&SimpleMM1Step2::onJobProcessed, this), 00122 processingTime); 00123 MESSAGE_SINGLE(NORMAL, logger_, "Processing next job, processing time: " << processingTime << "s\n" << *this); 00124 } 00125 00126 std::string 00127 SimpleMM1Step2::doToString() const 00128 { 00129 std::stringstream ss; 00130 ss << "Jobs in system: " << queue_.size(); 00131 return ss.str(); 00132 }
1.5.5