00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
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         
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){    
00074                         task= new Task<T>();
00075                         task.setDummy();
00076                         return 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 }