User Manual, Developers Guide and API Documentation

MM1Step1.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 // begin example "wns.queuingsystem.mm1step1.cpp.example"
00028 #include <WNS/queuingsystem/MM1Step1.hpp>
00029 
00030 using namespace wns::queuingsystem;
00031 
00032 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00033     SimpleMM1Step1,
00034     wns::simulator::ISimulationModel,
00035     "openwns.queuingsystem.SimpleMM1Step1",
00036     wns::PyConfigViewCreator);
00037 
00038 SimpleMM1Step1::SimpleMM1Step1(const wns::pyconfig::View& config) :
00039     jobsInSystem_(0),
00040     logger_(config.get("logger"))
00041 {
00042     wns::pyconfig::View disConfig = config.get("jobInterArrivalTimeDistribution");
00043     std::string disName = disConfig.get<std::string>("__plugin__");
00044     jobInterarrivalTime_ = 
00045         wns::distribution::DistributionFactory::creator(disName)->create(disConfig);
00046 
00047     disConfig = config.get("jobProcessingTimeDistribution");
00048     disName = disConfig.get<std::string>("__plugin__");
00049     jobProcessingTime_ = 
00050         wns::distribution::DistributionFactory::creator(disName)->create(disConfig);
00051 }
00052 
00053 void
00054 SimpleMM1Step1::doStartup()
00055 {
00056     MESSAGE_SINGLE(NORMAL, logger_, "MM1Step1 started, generating first job\n" << *this);
00057 
00058     generateNewJob();
00059 }
00060 
00061 void
00062 SimpleMM1Step1::doShutdown()
00063 {
00064 
00065 }
00066 
00067 void
00068 SimpleMM1Step1::generateNewJob()
00069 {
00070     ++jobsInSystem_;
00071 
00072     wns::simulator::Time delayToNextJob = (*jobInterarrivalTime_)();
00073 
00074     MESSAGE_SINGLE(NORMAL, logger_, "Generated new job, next job in " << delayToNextJob << "s\n" << *this);
00075 
00076     // The job is the only job in the system. There is no job that is currently
00077     // being served -> the server is free and can process the next job
00078     if (jobsInSystem_ == 1)
00079     {
00080         processNextJob();
00081     }
00082 
00083     wns::simulator::getEventScheduler()->scheduleDelay(
00084         boost::bind(&SimpleMM1Step1::generateNewJob, this),
00085         delayToNextJob);
00086 
00087 }
00088 
00089 void
00090 SimpleMM1Step1::onJobProcessed()
00091 {
00092     --jobsInSystem_;
00093     MESSAGE_SINGLE(NORMAL, logger_, "Finished a job\n" << *this);
00094     // if there are still jobs, serve them
00095     if (jobsInSystem_ > 0)
00096     {
00097         processNextJob();
00098     }
00099 }
00100 
00101 void
00102 SimpleMM1Step1::processNextJob()
00103 {
00104     wns::simulator::Time processingTime = (*jobProcessingTime_)();
00105 
00106     wns::simulator::getEventScheduler()->scheduleDelay(
00107         boost::bind(&SimpleMM1Step1::onJobProcessed, this),
00108         processingTime);
00109     MESSAGE_SINGLE(NORMAL, logger_, "Processing next job, processing time: " << processingTime << "s\n" << *this);
00110 }
00111 
00112 std::string
00113 SimpleMM1Step1::doToString() const
00114 {
00115     std::stringstream ss;
00116     ss << "Jobs in system: " << jobsInSystem_;
00117     return ss.str();
00118 }
00119 // end example
00120 

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