org/objectweb/proactive/calcium/proactive/ActiveObjectSkernel.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.calcium.proactive;
00032 
00033 import java.io.Serializable;
00034 
00035 import org.objectweb.proactive.Body;
00036 import org.objectweb.proactive.RunActive;
00037 import org.objectweb.proactive.Service;
00038 import org.objectweb.proactive.calcium.Skernel;
00039 import org.objectweb.proactive.calcium.Task;
00040 import org.objectweb.proactive.core.body.request.Request;
00041 import org.objectweb.proactive.core.body.request.RequestFilter;
00042 
00043 public class ActiveObjectSkernel<T> extends Skernel implements RunActive, Serializable {
00044 
00045         public ActiveObjectSkernel(){
00046         }
00047 
00048         public ActiveObjectSkernel(Skernel skernel){
00049                 super();
00050                 
00051                 while(skernel.getReadyQueueLength() >0){
00052                         this.putTask(skernel.getReadyTask(0));
00053                 }
00054         }
00055 
00056         //Producer-Consumer
00057         public void runActivity(Body body) {
00058                 Service service = new Service(body);
00059                 
00060                 while(true){
00061                         String allowedMethodNames="getStats|putTask|getReadyQueueLength|hasResults|isFinished|isPaniqued|getStatsGlobal";
00062                         
00063                         if(getReadyQueueLength() > 0 ) allowedMethodNames +="getReadyTask|";
00064                         if(hasResults()) allowedMethodNames += "getResult|";
00065                         
00066                         service.blockingServeOldest( new RequestFilterOnAllowedMethods(allowedMethodNames));
00067                 }
00068         }
00069         
00070         @SuppressWarnings("unchecked")
00071         public Task<?> getReadyTask(){
00072                 Task<?> task= super.getReadyTask(0);
00073                 if(task==null){    //ProActive doesn't handle null
00074                         task= new Task<T>();
00075                         task.setDummy();
00076                         return task;   //return dummy task
00077                 }
00078                 return task;
00079         }
00080         
00081         protected class RequestFilterOnAllowedMethods implements RequestFilter,
00082         java.io.Serializable {
00083         private String allowedMethodNames;
00084 
00085         public RequestFilterOnAllowedMethods(String allowedMethodNames) {
00086             this.allowedMethodNames = allowedMethodNames;
00087         }
00088 
00089         public boolean acceptRequest(Request request) {
00090             return allowedMethodNames.indexOf(request.getMethodName())>=0;
00091         }
00092     }
00093 }

Generated on Mon Jan 22 15:16:05 2007 for ProActive by  doxygen 1.5.1