User Manual, Developers Guide and API Documentation

MM1Step3.cpp

Go to the documentation of this file.
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/MM1Step3.hpp>
00029 
00030 using namespace wns::queuingsystem;
00031 
00032 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00033     SimpleMM1Step3,
00034     wns::simulator::ISimulationModel,
00035     "openwns.queuingsystem.SimpleMM1Step3",
00036     wns::PyConfigViewCreator);
00037 
00038 SimpleMM1Step3::SimpleMM1Step3(const wns::pyconfig::View& config) :
00039     config_(config),
00040     logger_(config.get("logger")),
00041     // For now we use an expty Context Collector Collection
00042     cpc_(),
00043     // The name of the measurement source. Must match the one configured
00044     // in the global Probe Bus Registry
00045     sojournTime_(cpc_, "SojournTime")
00046 {
00047     wns::pyconfig::View disConfig = config.get("jobInterArrivalTimeDistribution");
00048     std::string disName = disConfig.get<std::string>("__plugin__");
00049     jobInterarrivalTime_ = 
00050         wns::distribution::DistributionFactory::creator(disName)->create(disConfig);
00051 
00052     disConfig = config.get("jobProcessingTimeDistribution");
00053     disName = disConfig.get<std::string>("__plugin__");
00054     jobProcessingTime_ = 
00055         wns::distribution::DistributionFactory::creator(disName)->create(disConfig);
00056 }
00057 
00058 // begin example "wns.queuingsystem.mm1step3.doStartup.example"
00059 void
00060 SimpleMM1Step3::doStartup()
00061 {
00062     MESSAGE_SINGLE(NORMAL, logger_, "MM1Step3 started, generating first job\n" << *this);
00063 
00064     generateNewJob();
00065 }
00066 // end example
00067 
00068 void
00069 SimpleMM1Step3::doShutdown()
00070 {
00071 }
00072 
00073 void
00074 SimpleMM1Step3::generateNewJob()
00075 {
00076     // Create a new job
00077     Job job = Job();
00078 
00079     queue_.push_back(job);
00080 
00081     wns::simulator::Time delayToNextJob = (*jobInterarrivalTime_)();
00082 
00083     MESSAGE_SINGLE(NORMAL, logger_, "Generated new job, next job in " << delayToNextJob << "s\n" << *this);
00084 
00085     // The job is the only job in the system. There is no job that is currently
00086     // being served -> the server is free and can process the next job
00087     if (queue_.size() == 1)
00088     {
00089         processNextJob();
00090     }
00091 
00092     wns::simulator::getEventScheduler()->scheduleDelay(
00093         boost::bind(&SimpleMM1Step3::generateNewJob, this),
00094         delayToNextJob);
00095 
00096 }
00097 
00098 void
00099 SimpleMM1Step3::onJobProcessed()
00100 {
00101     Job finished = queue_.front();
00102 
00103     queue_.pop_front();
00104 
00105     // Calculate the Jobs sojourn time
00106     wns::simulator::Time  now;
00107     wns::simulator::Time  sojournTime;
00108     now = wns::simulator::getEventScheduler()->getTime();
00109     sojournTime = now - finished.getCreationTime();
00110 
00111     // Give some debug output
00112     MESSAGE_SINGLE(NORMAL, logger_, "Finished a job\n" << *this);
00113     MESSAGE_BEGIN(NORMAL, logger_, m, "Sojourn Time of last job ");
00114     m << sojournTime;
00115     MESSAGE_END();
00116 
00117     // Forward the measurement to the Probe Bus
00118     sojournTime_.put(sojournTime);
00119 
00120     // if there are still jobs, serve them
00121     if (!queue_.empty())
00122     {
00123         processNextJob();
00124     }
00125 }
00126 
00127 void
00128 SimpleMM1Step3::processNextJob()
00129 {
00130     wns::simulator::Time processingTime = (*jobProcessingTime_)();
00131 
00132     wns::simulator::getEventScheduler()->scheduleDelay(
00133         boost::bind(&SimpleMM1Step3::onJobProcessed, this),
00134         processingTime);
00135     MESSAGE_SINGLE(NORMAL, logger_, "Processing next job, processing time: " << processingTime << "s\n" << *this);
00136 }
00137 
00138 std::string
00139 SimpleMM1Step3::doToString() const
00140 {
00141     std::stringstream ss;
00142     ss << "Jobs in system: " << queue_.size();
00143     return ss.str();
00144 }

Generated on Fri May 25 03:31:52 2012 for openWNS by  doxygen 1.5.5