EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.scheduler.factory]

COVERAGE SUMMARY FOR SOURCE FILE [SchedulingFactory.java]

nameclass, %method, %block, %line, %
SchedulingFactory.java0%   (0/2)0%   (0/39)0%   (0/1208)0%   (0/240)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SchedulingFactory0%   (0/1)0%   (0/36)0%   (0/1164)0%   (0/229)
$SWITCH_TABLE$scheduler$configuration$LoadBalancingType (): int [] 0%   (0/1)0%   (0/34)0%   (0/1)
$SWITCH_TABLE$scheduler$configuration$PassiveResourceType (): int [] 0%   (0/1)0%   (0/27)0%   (0/1)
$SWITCH_TABLE$scheduler$configuration$PriorityClass (): int [] 0%   (0/1)0%   (0/55)0%   (0/1)
$SWITCH_TABLE$scheduler$configuration$PriorityDegradation (): int [] 0%   (0/1)0%   (0/27)0%   (0/1)
$SWITCH_TABLE$scheduler$configuration$ProcessSelection (): int [] 0%   (0/1)0%   (0/27)0%   (0/1)
$SWITCH_TABLE$scheduler$configuration$ResourceInstanceSelection (): int [] 0%   (0/1)0%   (0/27)0%   (0/1)
$SWITCH_TABLE$scheduler$configuration$RunQueueType (): int [] 0%   (0/1)0%   (0/27)0%   (0/1)
<static initializer> 0%   (0/1)0%   (0/8)0%   (0/1)
SchedulingFactory (SchedulerModel): void 0%   (0/1)0%   (0/36)0%   (0/9)
createActiveResource (ActiveResourceConfiguration): IActiveResource 0%   (0/1)0%   (0/39)0%   (0/8)
createInstanceSelector (ResourceInstanceSelection, SimActiveResource): IInsta... 0%   (0/1)0%   (0/24)0%   (0/5)
createLoadBalancer (LoadBalancing): ILoadBalancer 0%   (0/1)0%   (0/55)0%   (0/11)
createPassiveResource (PassiveResourceConfiguration): IPassiveResource 0%   (0/1)0%   (0/68)0%   (0/19)
createPreemptiveScheduler (SchedulerConfiguration, IActiveResource): IScheduler 0%   (0/1)0%   (0/32)0%   (0/8)
createPriorityManager (PriorityRange): PriorityManagerImpl 0%   (0/1)0%   (0/36)0%   (0/8)
createPriorityUpdadateStrategy (PriorityBoostConfiguration, IActiveProcess): ... 0%   (0/1)0%   (0/19)0%   (0/5)
createProcessQueue (PriorityConfiguration): IProcessQueue 0%   (0/1)0%   (0/20)0%   (0/5)
createProcessSelector (ProcessSelection): IProcessSelector 0%   (0/1)0%   (0/22)0%   (0/5)
createQueueingStrategy (QueueingConfiguration, IProcessQueue, SimActiveResour... 0%   (0/1)0%   (0/25)0%   (0/7)
createResourceFromExtension (String, String, String): IActiveResource 0%   (0/1)0%   (0/34)0%   (0/7)
createResourceInstance (int, IActiveResource): IResourceInstance 0%   (0/1)0%   (0/34)0%   (0/6)
createRunQueue (RunQueueType, IProcessQueue): IRunQueue 0%   (0/1)0%   (0/30)0%   (0/8)
createRunningProcess (ISchedulableProcess, ProcessConfiguration, ActiveResour... 0%   (0/1)0%   (0/97)0%   (0/30)
createScheduler (SchedulerConfiguration, IActiveResource): IScheduler 0%   (0/1)0%   (0/5)0%   (0/1)
createSimDelayResource (String, String): IActiveResource 0%   (0/1)0%   (0/22)0%   (0/4)
createSimFCFSResource (String, String): IActiveResource 0%   (0/1)0%   (0/23)0%   (0/4)
createSimProcessorSharingResource (String, String, int): IActiveResource 0%   (0/1)0%   (0/23)0%   (0/4)
createSimProcessorSharingResourceLinuxO1 (String, String, int): IActiveResource 0%   (0/1)0%   (0/23)0%   (0/4)
createSimProcessorSharingResourceWindows (String, String, int): IActiveResource 0%   (0/1)0%   (0/23)0%   (0/4)
createStaticPriorityBoost (StaticPriorityBoost): IPriorityBoost 0%   (0/1)0%   (0/44)0%   (0/14)
createTimeSlice (PreemptionConfiguration, ActiveProcess): ITimeSlice 0%   (0/1)0%   (0/18)0%   (0/6)
getManagerId (PriorityRange): String 0%   (0/1)0%   (0/33)0%   (0/3)
getPriority (PriorityClass, PriorityRange): IPriority 0%   (0/1)0%   (0/37)0%   (0/15)
getRegisteredSchedulerExtensions (): IExtension [] 0%   (0/1)0%   (0/15)0%   (0/6)
getSchedulerExtensionFactory (String): SchedulerExtensionFactory 0%   (0/1)0%   (0/76)0%   (0/15)
resetFactory (): void 0%   (0/1)0%   (0/19)0%   (0/7)
     
class SchedulingFactory$10%   (0/1)0%   (0/3)0%   (0/44)0%   (0/12)
SchedulingFactory$1 (SchedulingFactory, ActiveProcess): void 0%   (0/1)0%   (0/9)0%   (0/2)
casePriorityDependentTimeSliceConfiguration (PriorityDependentTimeSliceConfig... 0%   (0/1)0%   (0/19)0%   (0/6)
caseQuantumTimeSliceConfiguration (QuantumTimeSliceConfiguration): ITimeSlice 0%   (0/1)0%   (0/16)0%   (0/4)

1package de.uka.ipd.sdq.scheduler.factory;
2 
3import java.util.Hashtable;
4import java.util.Map;
5 
6import org.eclipse.core.runtime.CoreException;
7import org.eclipse.core.runtime.IConfigurationElement;
8import org.eclipse.core.runtime.IExtension;
9import org.eclipse.core.runtime.IExtensionPoint;
10import org.eclipse.core.runtime.IExtensionRegistry;
11import org.eclipse.core.runtime.Platform;
12 
13import scheduler.configuration.ActiveResourceConfiguration;
14import scheduler.configuration.DynamicPriorityBoostConfiguratioin;
15import scheduler.configuration.LoadBalancing;
16import scheduler.configuration.PassiveResourceConfiguration;
17import scheduler.configuration.PreemptionConfiguration;
18import scheduler.configuration.PreferredPriority;
19import scheduler.configuration.PreferredWaitingTime;
20import scheduler.configuration.PriorityBoostConfiguration;
21import scheduler.configuration.PriorityClass;
22import scheduler.configuration.PriorityConfiguration;
23import scheduler.configuration.PriorityDependentTimeSliceConfiguration;
24import scheduler.configuration.PriorityRange;
25import scheduler.configuration.ProcessConfiguration;
26import scheduler.configuration.ProcessSelection;
27import scheduler.configuration.QuantumTimeSliceConfiguration;
28import scheduler.configuration.QueueingConfiguration;
29import scheduler.configuration.SchedulerConfiguration;
30import scheduler.configuration.TimeSliceConfiguration;
31import scheduler.configuration.util.ConfigurationSwitch;
32import de.uka.ipd.sdq.scheduler.IActiveResource;
33import de.uka.ipd.sdq.scheduler.IPassiveResource;
34import de.uka.ipd.sdq.scheduler.IRunningProcess;
35import de.uka.ipd.sdq.scheduler.ISchedulableProcess;
36import de.uka.ipd.sdq.scheduler.ISchedulingFactory;
37import de.uka.ipd.sdq.scheduler.SchedulerModel;
38import de.uka.ipd.sdq.scheduler.loaddistribution.IInstanceSelector;
39import de.uka.ipd.sdq.scheduler.loaddistribution.ILoadBalancer;
40import de.uka.ipd.sdq.scheduler.loaddistribution.IProcessSelector;
41import de.uka.ipd.sdq.scheduler.loaddistribution.balancers.OneToIdleBalancer;
42import de.uka.ipd.sdq.scheduler.loaddistribution.balancers.ToThresholdBalancer;
43import de.uka.ipd.sdq.scheduler.loaddistribution.selectors.instance.IdleSelector;
44import de.uka.ipd.sdq.scheduler.loaddistribution.selectors.instance.RoundRobinSelector;
45import de.uka.ipd.sdq.scheduler.loaddistribution.selectors.process.NextRunnableProcessSelector;
46import de.uka.ipd.sdq.scheduler.loaddistribution.selectors.process.PreferIdealAndLastProcessSelector;
47import de.uka.ipd.sdq.scheduler.priority.IPriority;
48import de.uka.ipd.sdq.scheduler.priority.IPriorityBoost;
49import de.uka.ipd.sdq.scheduler.priority.IPriorityUpdateStrategy;
50import de.uka.ipd.sdq.scheduler.priority.impl.PriorityManagerImpl;
51import de.uka.ipd.sdq.scheduler.priority.update.DecayToBaseUpdate;
52import de.uka.ipd.sdq.scheduler.priority.update.SetToBaseUpdate;
53import de.uka.ipd.sdq.scheduler.priority.update.SleepAverageDependentUpdate;
54import de.uka.ipd.sdq.scheduler.processes.IActiveProcess;
55import de.uka.ipd.sdq.scheduler.processes.impl.ActiveProcess;
56import de.uka.ipd.sdq.scheduler.processes.impl.PreemptiveProcess;
57import de.uka.ipd.sdq.scheduler.processes.impl.ProcessWithPriority;
58import de.uka.ipd.sdq.scheduler.queueing.IProcessQueue;
59import de.uka.ipd.sdq.scheduler.queueing.IQueueingStrategy;
60import de.uka.ipd.sdq.scheduler.queueing.IRunQueue;
61import de.uka.ipd.sdq.scheduler.queueing.basicqueues.PriorityArray;
62import de.uka.ipd.sdq.scheduler.queueing.basicqueues.ProcessQueueImpl;
63import de.uka.ipd.sdq.scheduler.queueing.runqueues.ActiveExpiredRunQueue;
64import de.uka.ipd.sdq.scheduler.queueing.runqueues.SingleRunQueue;
65import de.uka.ipd.sdq.scheduler.resources.IResourceInstance;
66import de.uka.ipd.sdq.scheduler.resources.active.SimActiveResource;
67import de.uka.ipd.sdq.scheduler.resources.active.SimDelayResource;
68import de.uka.ipd.sdq.scheduler.resources.active.SimFCFSResource;
69import de.uka.ipd.sdq.scheduler.resources.active.SimProcessorSharingResource;
70import de.uka.ipd.sdq.scheduler.resources.active.SimResourceInstance;
71import de.uka.ipd.sdq.scheduler.resources.active.special.SimProcessorSharingResourceLinuxO1;
72import de.uka.ipd.sdq.scheduler.resources.active.special.SimProcessorSharingResourceWindows;
73import de.uka.ipd.sdq.scheduler.resources.passive.SimFairPassiveResource;
74import de.uka.ipd.sdq.scheduler.resources.passive.SimUnfairPassiveResource;
75import de.uka.ipd.sdq.scheduler.strategy.IScheduler;
76import de.uka.ipd.sdq.scheduler.strategy.impl.PreemptiveScheduler;
77import de.uka.ipd.sdq.scheduler.timeslice.ITimeSlice;
78import de.uka.ipd.sdq.scheduler.timeslice.impl.PriorityDependentTimeSlice;
79import de.uka.ipd.sdq.scheduler.timeslice.impl.QuantumTimeSlice;
80 
81/**
82 * Creates instances of active and passive resources with different scheduling
83 * strategies.
84 * 
85 * @author jens
86 * 
87 */
88public class SchedulingFactory implements ISchedulingFactory {
89    
90        private Map<String, IActiveResource> active_resource_map = new Hashtable<String, IActiveResource>();
91        private Map<String, IPassiveResource> passive_resource_map = new Hashtable<String, IPassiveResource>();
92        private Map<String, IResourceInstance> resource_instance_map = new Hashtable<String, IResourceInstance>();
93        private Map<String, IScheduler> scheduler_map = new Hashtable<String, IScheduler>();
94        private Map<String, ActiveProcess> process_map = new Hashtable<String, ActiveProcess>();
95        private Map<String, PriorityManagerImpl> manager_map = new Hashtable<String, PriorityManagerImpl>();
96 
97        private SchedulerModel model;
98        
99        public SchedulingFactory(SchedulerModel model) {
100            this.model = model;
101        }
102        
103        /*
104         * (non-Javadoc)
105         * 
106         * @see de.uka.ipd.sdq.scheduler.builder.ISchedulingFactory#createActiveResource(scheduler.configuration.ActiveResourceConfiguration)
107         */
108    public IActiveResource createActiveResource(ActiveResourceConfiguration configuration) {
109                SimActiveResource resource = (SimActiveResource) active_resource_map.get(configuration.getId());
110                if (resource == null) {
111            resource = new SimActiveResource(model, configuration.getReplicas(), configuration.getName(), configuration
112                    .getId());
113                                IScheduler scheduler = createScheduler(configuration.getSchedulerConfiguration(), resource);
114                                resource.setScheduler(scheduler);
115                        active_resource_map.put(configuration.getId(), resource);
116                }
117                return resource;
118        }
119        
120        public IActiveResource createResourceFromExtension(String extensionId, String resourceName, String resourceId)
121        {
122                IActiveResource resource = (IActiveResource) active_resource_map.get(resourceId);
123                if (resource == null) {
124                        SchedulerExtensionFactory factory = getSchedulerExtensionFactory(extensionId);
125                        assert factory != null;
126                        resource = factory.getExtensionScheduler(model, resourceName, resourceId);
127                        active_resource_map.put(resourceId, resource);
128                }
129                return resource;
130        }
131        
132        
133        public IActiveResource createSimFCFSResource(String resourceName, String resourceId)
134        {
135                IActiveResource resource = (IActiveResource) active_resource_map.get(resourceId);
136                resource = new SimFCFSResource(model, resourceName, resourceId, 1);
137                active_resource_map.put(resourceId, resource);
138                return resource;
139        }
140        
141        public IActiveResource createSimDelayResource(String resourceName, String resourceId)
142        {
143                IActiveResource resource = (IActiveResource) active_resource_map.get(resourceId);
144                resource = new SimDelayResource(model, resourceName, resourceId);
145                active_resource_map.put(resourceId, resource);
146                return resource;
147        }
148        
149        /*public IActiveResource createSimGinpexDiskResource(String resourceName, String resourceId, HDDParameterConfig hddParameterConfig)
150        {
151                IActiveResource resource = (IActiveResource) active_resource_map.get(resourceId);
152                resource = new SimGinpexDiskResource(resourceName, resourceId, hddParameterConfig);
153                active_resource_map.put(resourceId, resource);
154                return resource;
155        }*/
156        
157        public IActiveResource createSimProcessorSharingResource(String resourceName, String resourceId, int numberOfCores)
158        {
159                IActiveResource resource = (IActiveResource) active_resource_map.get(resourceId);
160                resource = new SimProcessorSharingResource(model, resourceName, resourceId, numberOfCores);
161                active_resource_map.put(resourceId, resource);
162                return resource;
163        }
164        
165        public IActiveResource createSimProcessorSharingResourceWindows(String resourceName, String resourceId, int numberOfCores)
166        {
167                IActiveResource resource = (IActiveResource) active_resource_map.get(resourceId);
168                resource = new SimProcessorSharingResourceWindows(model, resourceName, resourceId, numberOfCores);
169                active_resource_map.put(resourceId, resource);
170                return resource;
171        }
172        
173        public IActiveResource createSimProcessorSharingResourceLinuxO1(String resourceName, String resourceId, int numberOfCores)
174        {
175                IActiveResource resource = (IActiveResource) active_resource_map.get(resourceId);
176                resource = new SimProcessorSharingResourceLinuxO1(model, resourceName, resourceId, numberOfCores);
177                active_resource_map.put(resourceId, resource);
178                return resource;
179        }
180 
181    public IPassiveResource createPassiveResource(PassiveResourceConfiguration configuration) {
182                IPassiveResource resource = passive_resource_map.get(configuration
183                                .getId());
184                if (resource == null) {
185                        IPriorityBoost priority_boost = createStaticPriorityBoost(configuration
186                                        .getStaticPriorityBoostConfiguration());
187            SimActiveResource managing_resource = (SimActiveResource) createActiveResource(configuration
188                    .getManagingResource());
189 
190                        switch (configuration.getType()) {
191                        case FAIR:
192                                resource = new SimFairPassiveResource(model, configuration
193                                                .getCapacity(), configuration.getName(), configuration
194                                                .getId(), priority_boost, managing_resource);
195                                break;
196 
197                        case UNFAIR:
198                                resource = new SimUnfairPassiveResource(model, configuration
199                                                .getCapacity(), configuration.getName(), configuration
200                                                .getId(), priority_boost, managing_resource,
201                                                configuration.getAcquisitionDemand(),true);
202                                break;
203 
204                        default:
205                                break;
206                        }
207 
208                        passive_resource_map.put(configuration.getId(), resource);
209                }
210                return resource;
211        }
212        
213        
214        public IResourceInstance createResourceInstance(int index,
215                        IActiveResource containing_resource) {
216 
217                String id = containing_resource.getId() + index;
218 
219                IResourceInstance instance = resource_instance_map.get(id);
220                if (instance == null) {
221                        instance = new SimResourceInstance(model, index, containing_resource);
222                        resource_instance_map.put(id, instance);
223                }
224                return instance;
225        }
226 
227        /*
228         * (non-Javadoc)
229         * 
230         * @see de.uka.ipd.sdq.scheduler.builder.ISchedulingFactory#createRunningProcess(de.uka.ipd.sdq.scheduler.ISchedulableProcess,
231         *      scheduler.configuration.ProcessConfiguration,
232         *      scheduler.configuration.ActiveResourceConfiguration)
233         */
234    public IRunningProcess createRunningProcess(ISchedulableProcess process,
235            ProcessConfiguration configuration, ActiveResourceConfiguration resourceConfiguration) {
236                String id = process.getId() + resourceConfiguration.getId();
237 
238                ActiveProcess active_process = process_map.get(id);
239 
240                if (active_process == null) {
241                        if (resourceConfiguration.getReplicas() > 0) {
242 
243                                if (resourceConfiguration.getSchedulerConfiguration()
244                                                .getPriorityConfiguration() != null) {
245                                        IPriority prio = getPriority(configuration.getPriority(),
246                                                        resourceConfiguration.getSchedulerConfiguration()
247                                                                        .getPriorityConfiguration().getRange());
248                                        active_process = new ProcessWithPriority(model, process, prio);
249                                        IPriorityUpdateStrategy updateStrategy = createPriorityUpdadateStrategy(
250                                                        resourceConfiguration.getSchedulerConfiguration()
251                                                                        .getPriorityConfiguration()
252                                                                        .getBoostConfiguration(), active_process);
253                                        ((ProcessWithPriority) active_process)
254                                                        .setPriorityUpdateStrategy(updateStrategy);
255                                }
256                                if (resourceConfiguration.getSchedulerConfiguration()
257                                                .getPreemptionConfiguration() != null) {
258                                        if (active_process == null)
259                                                active_process = new PreemptiveProcess(model, process);
260                                        ITimeSlice timeslice = createTimeSlice(
261                                                        resourceConfiguration.getSchedulerConfiguration()
262                                                                        .getPreemptionConfiguration(),
263                                                        active_process);
264                                        timeslice.fullReset();
265                                        ((PreemptiveProcess) active_process)
266                                                        .setTimeSlice(timeslice);
267                                } else {
268                                        active_process = new ActiveProcess(model, process);
269                                }
270                                process_map.put(id, active_process);
271                        }
272                }
273 
274                return active_process;
275        }
276 
277    private IPriorityUpdateStrategy createPriorityUpdadateStrategy(
278            PriorityBoostConfiguration boostConfiguration, IActiveProcess process) {
279                if (boostConfiguration instanceof DynamicPriorityBoostConfiguratioin) {
280                        DynamicPriorityBoostConfiguratioin dynamic = (DynamicPriorityBoostConfiguratioin) boostConfiguration;
281                        return new SleepAverageDependentUpdate(model, process, dynamic
282                                        .getMaxSleepAverage(), dynamic.getMaxBonus());
283                }
284                return null;
285        }
286 
287        private IPriority getPriority(PriorityClass priority, PriorityRange range) {
288                PriorityManagerImpl manager = createPriorityManager(range);
289                IPriority prio = manager.getDefaultPriority();
290                switch (priority) {
291                case LOWEST:
292                        prio = manager.getLowestPriority();
293                        break;
294                case LOW:
295                        prio = manager.getLowPriority();
296                        break;
297                case AVERAGE:
298                        prio = manager.getAveragePriority();
299                        break;
300                case HIGH:
301                        prio = manager.getHighPriority();
302                        break;
303                case HIGHEST:
304                        prio = manager.getHighestPriority();
305                        break;
306                default:
307                        prio = manager.getDefaultPriority();
308                        break;
309                }
310                return prio;
311        }
312 
313        private ITimeSlice createTimeSlice(
314                        PreemptionConfiguration preemptionConfiguration,
315                        final ActiveProcess process) {
316 
317                ConfigurationSwitch<ITimeSlice> timesliceSwitch = new ConfigurationSwitch<ITimeSlice>() {
318                        
319                        @Override
320                        public ITimeSlice caseQuantumTimeSliceConfiguration(
321                                        QuantumTimeSliceConfiguration configuration) {
322                                double timeslice = configuration.getTimeslice();
323                                int quanta = configuration.getQuanta();
324                                int min_quanta = configuration.getMinQuanta();
325                                return new QuantumTimeSlice(timeslice,quanta,min_quanta);
326                        }
327                        
328                        @Override
329                        public ITimeSlice casePriorityDependentTimeSliceConfiguration(
330                                        PriorityDependentTimeSliceConfiguration configuration) {
331                                double timeslice = configuration.getTimeslice();
332                                double min_timeslice = configuration.getMinTimeslice();
333                                double min_time_to_be_scheduled = configuration.getMinTimeToBeScheduled();
334                                return new PriorityDependentTimeSlice(
335                                                (ProcessWithPriority) process, timeslice,
336                                                min_timeslice, min_time_to_be_scheduled);
337                        }
338                };
339 
340                if (preemptionConfiguration != null) {
341                        TimeSliceConfiguration timesliceConf = preemptionConfiguration
342                                        .getTimesliceConfiguration();
343                        return timesliceSwitch.doSwitch(timesliceConf);
344                }
345                return null;
346        }
347 
348    private IScheduler createScheduler(SchedulerConfiguration configuration, IActiveResource scheduled_resource) {
349                return createPreemptiveScheduler(configuration,scheduled_resource);
350        }
351 
352    private IScheduler createPreemptiveScheduler(SchedulerConfiguration configuration,
353            IActiveResource scheduled_resource) {
354                IProcessQueue process_queue_prototype = createProcessQueue(configuration
355                                .getPriorityConfiguration());
356        IQueueingStrategy queueing_strategy = createQueueingStrategy(configuration.getQueueingConfiguration(),
357                process_queue_prototype, (SimActiveResource) scheduled_resource);
358                boolean in_front_after_waiting = configuration.isInFrontAfterWaiting();
359                double scheduling_interval = configuration.getInterval();
360                return new PreemptiveScheduler(model, (SimActiveResource) scheduled_resource,
361                                queueing_strategy, in_front_after_waiting, scheduling_interval, configuration.getStarvationBoost());
362        }
363 
364        private IProcessQueue createProcessQueue(PriorityConfiguration configuration) {
365                if (configuration == null) {
366                        return new ProcessQueueImpl(model);
367                }
368                PriorityManagerImpl manager = createPriorityManager(configuration
369                                .getRange());
370                return new PriorityArray(model, manager);
371        }
372 
373        private PriorityManagerImpl createPriorityManager(PriorityRange range) {
374                String id = getManagerId(range);
375                PriorityManagerImpl manager = manager_map.get(id);
376                if (manager == null) {
377                        manager = new PriorityManagerImpl(range.getHighest(), range
378                                        .getHigh(), range.getAverage(), range.getLow(), range
379                                        .getLowest(), range.getDefault());
380                        manager_map.put(id, manager);
381                }
382                return manager;
383        }
384 
385        private String getManagerId(PriorityRange range) {
386                return range.getHighest() + "_" + range.getHigh() + "_"
387                                + range.getAverage() + "_" + range.getLow() + "_"
388                                + range.getLowest() + "_" + range.getDefault();
389        }
390 
391    private IQueueingStrategy createQueueingStrategy(QueueingConfiguration configuration,
392            IProcessQueue process_queue_prototype, SimActiveResource resource) {
393                IRunQueue runqueue_prototype = createRunQueue(configuration
394                                .getRunqueueType(), process_queue_prototype);
395                IInstanceSelector instance_selector = createInstanceSelector(
396                                configuration.getInitialInstanceSelection(), resource);
397 
398                QueueingConfigurationSwitch qSwitch = new QueueingConfigurationSwitch(
399                                runqueue_prototype, instance_selector, this, resource);
400                return qSwitch.doSwitch(configuration);
401        }
402 
403        private IInstanceSelector createInstanceSelector(
404                        scheduler.configuration.ResourceInstanceSelection initialInstanceSelection,
405                        SimActiveResource resource) {
406                switch (initialInstanceSelection) {
407                case PREFER_IDLE:
408                        return new IdleSelector(resource);
409                case ROUND_ROBIN:
410                        return new RoundRobinSelector(resource);
411                default:
412                        assert false : "Unknown InstanceSelector!";
413                        break;
414                }
415                return null;
416        }
417 
418        private IRunQueue createRunQueue(scheduler.configuration.RunQueueType type,
419                        IProcessQueue process_queue_prototype) {
420                IRunQueue runqueue = null;
421                switch (type) {
422                case SINGLE:
423                        runqueue = new SingleRunQueue(process_queue_prototype);
424                        break;
425                case ACTIVE_AND_EXPIRED:
426                        runqueue = new ActiveExpiredRunQueue(model, process_queue_prototype);
427                        break;
428                default:
429                        assert false : "Unknown RunqueueType";
430                        break;
431                }
432                return runqueue;
433        }
434 
435        private IPriorityBoost createStaticPriorityBoost(
436                        scheduler.configuration.StaticPriorityBoost configuration) {
437                IPriorityBoost boost = null;
438                if (configuration != null) {
439                        IPriorityUpdateStrategy update_strategy = null;
440                        switch (configuration.getDegradation()) {
441                        case RESET:
442                                update_strategy = new SetToBaseUpdate(1);
443                                break;
444                        case SLOW_DECAY:
445                                update_strategy = new DecayToBaseUpdate();
446                                break;
447                        default:
448                                assert false : "Undefinded Priority Update Configuration.";
449                                break;
450                        }
451                        boost = new de.uka.ipd.sdq.scheduler.priority.boost.StaticPriorityBoost(
452                                        update_strategy, configuration.getBonus(),
453                                        (int) configuration.getTimePenalty(),
454                                        configuration.isResetTimeslice());
455                }
456                return boost;
457        }
458 
459        public IProcessSelector createProcessSelector(
460                        ProcessSelection processSelection) {
461                switch (processSelection) {
462                case NEXT_RUNNABLE:
463                        return new NextRunnableProcessSelector();
464                case PREFER_IDEAL_AND_LAST:
465                        return new PreferIdealAndLastProcessSelector();
466                default:
467                        assert false : "Unknown ProcessSelection";
468                        break;
469                }
470                return null;
471        }
472 
473        public ILoadBalancer createLoadBalancer(LoadBalancing load_balancing) {
474                double balance_interval = load_balancing.getBalancingInterval();
475                double threshold = load_balancing.getThreshold();
476                boolean prio_increasing = load_balancing.getPreferredPriority() == PreferredPriority.HIGHER;
477                boolean queue_ascending = load_balancing.getPreferredWaitingTime() == PreferredWaitingTime.SHORT;
478 
479                switch (load_balancing.getBalancingType()) {
480                case ANY_TO_THRESHOLD:
481                        return new ToThresholdBalancer(model, balance_interval, 
482                                        prio_increasing, queue_ascending, (int)threshold);
483                case IDLE_TO_THRESHOLD:
484//                        return new IdleToThresholdBalancer(balance_interval,
485//                                        global_balance, prio_increasing, queue_ascending,
486//                                        max_iterations, threshold);
487                case IDLE_TO_ONE:
488                        return new OneToIdleBalancer(balance_interval, 
489                                        prio_increasing, queue_ascending);
490                default:
491                        assert false : "Unknown LoadBalancing Type.";
492                        break;
493                }
494                return null;
495        }
496 
497        public void resetFactory() {
498                this.active_resource_map.clear();
499                this.manager_map.clear();
500                this.passive_resource_map.clear();
501                this.process_map.clear();
502                this.resource_instance_map.clear();
503                this.scheduler_map.clear();
504        }
505        
506        private static final String SchedulerExtensionPointId = "de.uka.ipd.sdq.scheduler";
507        private static final String SchedulerExtensionPointAttribute_Class = "class";
508        
509        private static IExtension[] getRegisteredSchedulerExtensions() {
510                IExtensionRegistry registry = Platform.getExtensionRegistry();
511                IExtensionPoint extensionPoint = registry.getExtensionPoint(SchedulerExtensionPointId);
512                if (extensionPoint == null) {
513                        // No extension point found!
514                        return null;
515                }
516                IExtension[] extensions = extensionPoint.getExtensions();
517                return extensions;
518        }
519        
520        private static SchedulerExtensionFactory getSchedulerExtensionFactory(String extensionId) {
521                IExtension[] registeredExtensions = getRegisteredSchedulerExtensions();
522                assert (registeredExtensions != null) : "No scheduler extensions available!";
523                for (int i = 0; i < registeredExtensions.length; i++) {
524                        IExtension registeredExtension = registeredExtensions[i];
525                        IConfigurationElement[] elements = registeredExtension.getConfigurationElements();
526                        if (registeredExtension.getUniqueIdentifier().equals(extensionId)) {
527                                for (int j = 0; j < elements.length; j++) {
528                                        IConfigurationElement element = elements[j];
529                                        Object o = null;
530                                        try {
531                                                o = element.createExecutableExtension(SchedulerExtensionPointAttribute_Class);
532                                        } catch (CoreException e) {
533                                        }
534                                        if ((o!= null) && (o instanceof SchedulerExtensionFactory)) {
535                                                return (SchedulerExtensionFactory)o;
536                                        }
537                                }
538                        }        
539                }
540                assert false : "No scheduler extension for ID " + extensionId + " available!";
541                return null;
542        }
543        
544}

[all classes][de.uka.ipd.sdq.scheduler.factory]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov