
org.mobicents.media.server.scheduler.PriorityQueueScheduler Maven / Gradle / Ivy
The newest version!
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.mobicents.media.server.scheduler;
import java.lang.InterruptedException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.LockSupport;
import org.mobicents.media.server.concurrent.ConcurrentCyclicFIFO;
import org.apache.log4j.Logger;
/**
* Implements scheduler with multi-level priority queue.
*
* This scheduler implementation follows to uniprocessor model with "super" thread.
* The "super" thread includes IO bound thread and one or more CPU bound threads
* with equal priorities.
*
* The actual priority is assigned to task instead of process and can be
* changed dynamically at runtime using the initial priority level, feedback
* and other parameters.
*
*
* @author Oifa Yulian
*/
public class PriorityQueueScheduler {
//SS7 QUEUES
public static final Integer RECEIVER_QUEUE=0;
public static final Integer SENDER_QUEUE=1;
//MANAGEMENT QUEUE FOR CONTROL PROCESSING
public static final Integer MANAGEMENT_QUEUE=2;
//UDP MANAGER QUEUE FOR POOLING CHANNELS
public static final Integer UDP_MANAGER_QUEUE=3;
//CORE QUEUES
public static final Integer INPUT_QUEUE=4;
public static final Integer MIXER_MIX_QUEUE=5;
public static final Integer OUTPUT_QUEUE=6;
//HEARTBEAT QUEUE
public static final Integer HEARTBEAT_QUEUE=-1;
//The clock for time measurement
private Clock clock;
//priority queue
protected OrderedTaskQueue[] taskQueues = new OrderedTaskQueue[7];
protected OrderedTaskQueue[] heartBeatQueue = new OrderedTaskQueue[5];
//CPU bound threads
private CoreThread coreThread;
private CriticalThread criticalThread;
//flag indicating state of the scheduler
private boolean isActive;
private Logger logger = Logger.getLogger(PriorityQueueScheduler.class) ;
private ConcurrentCyclicFIFO waitingTasks=new ConcurrentCyclicFIFO();
private ConcurrentCyclicFIFO criticalTasks=new ConcurrentCyclicFIFO();
private WorkerThread[] workerThreads;
private CriticalWorkerThread[] criticalWorkerThreads;
/**
* Creates new instance of scheduler.
*/
public PriorityQueueScheduler(Clock clock) {
this.clock = clock;
for(int i=0;i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy