DiameterWorker.java

Go to the documentation of this file.
00001 /*
00002  * $Id: DiameterWorker.java 2 2006-11-14 22:37:20Z vingarzan $
00003  *
00004  * Copyright (C) 2004-2006 FhG Fokus
00005  *
00006  * This file is part of Open IMS Core - an open source IMS CSCFs & HSS
00007  * implementation
00008  *
00009  * Open IMS Core is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * For a license to use the Open IMS Core software under conditions
00015  * other than those described here, or to purchase support for this
00016  * software, please contact Fraunhofer FOKUS by e-mail at the following
00017  * addresses:
00018  *     info@open-ims.org
00019  *
00020  * Open IMS Core is distributed in the hope that it will be useful,
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  * GNU General Public License for more details.
00024  *
00025  * You should have received a copy of the GNU General Public License
00026  * along with this program; if not, write to the Free Software
00027  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028  *
00029  */
00030 
00031 package de.fhg.fokus.diameter.DiameterPeer;
00032 
00033 
00034 import java.util.concurrent.ArrayBlockingQueue;
00035 import java.util.Vector;
00036 
00037 import org.apache.log4j.Logger;
00038 
00039 import de.fhg.fokus.diameter.DiameterPeer.data.DiameterTask;
00040 
00047 public class DiameterWorker extends Thread {
00048     
00050     private static final Logger LOGGER = Logger.getLogger(DiameterWorker.class);
00051 
00052     int id;
00053     private boolean running;
00054     private ArrayBlockingQueue<DiameterTask> queueTasks;
00055     
00056     
00063     public DiameterWorker(int id, ArrayBlockingQueue<DiameterTask> tasks) {
00064         this.id = id;
00065         this.running = true;
00066         this.queueTasks = tasks;
00067         this.start();
00068     }
00069 
00070 
00071 
00077     public void run() {
00078         DiameterTask task;
00079         int i, size;
00080         EventListener e;
00081         Vector listeners;
00082         
00083         while(running){
00084             task=null;
00085             try {
00086                 task = (DiameterTask) queueTasks.take();
00087             } catch (InterruptedException e1) { }
00088         
00089             if (task==null||task.peer==null||task.msg==null) {
00090                 //LOGGER.debug("["+id+"]ety "+queueTasks.size());
00091                 continue;
00092             }
00093             //LOGGER.debug("["+id+"]got "+queueTasks.size());
00094             //LOGGER.debug("processing");
00095             listeners = task.peer.diameterPeer.eventListeners;
00096 //          if (listeners.size()>0) ((EventListener) listeners.get(0)).recvMessage(task.peer.FQDN,task.msg);
00097             size = listeners.size();
00098             for(i=0;i<size;i++){
00099                 e = (EventListener) listeners.get(i); 
00100                 e.recvMessage(task.peer.FQDN,task.msg);
00101             }
00102         }
00103         //LOGGER.debug("["+id+"]end "+queueTasks.size());
00104     }
00105 
00106     
00110     public void shutdown()
00111     {
00112         this.running = false;
00113         
00114         // poison the queue (now it just wakes the worker)
00115         try {
00116             this.queueTasks.put(new DiameterTask(null,null));
00117         } catch (InterruptedException e) {
00118             e.printStackTrace();
00119         }
00120     }
00121 }

Generated on Thu Oct 23 04:07:36 2008 for Open IMS Core JavaDiameterPeer by  doxygen 1.5.2