1 31 package org.objectweb.proactive.core.component.request; 32 33 import org.apache.log4j.Logger; 34 import org.objectweb.fractal.api.control.LifeCycleController; 35 import org.objectweb.proactive.core.UniqueID; 36 import org.objectweb.proactive.core.body.request.BlockingRequestQueueImpl; 37 import org.objectweb.proactive.core.body.request.Request; 38 import org.objectweb.proactive.core.body.request.RequestFilter; 39 40 41 63 public class ComponentRequestQueueImpl extends BlockingRequestQueueImpl implements ComponentRequestQueue { 64 protected static Logger logger = Logger.getLogger(ComponentRequestQueueImpl.class.getName()); 65 private boolean started = false; 66 private RequestFilter requestFilterOnComponentControllerClasses; 67 68 72 public ComponentRequestQueueImpl(UniqueID ownerID) { 73 super(ownerID); 74 requestFilterOnComponentControllerClasses = new RequestFilterOnComponentControllerClasses(); 75 } 76 77 public synchronized void start() { 78 started = true; 79 } 80 81 public synchronized void stop() { 82 started = false; 83 } 84 85 public synchronized boolean isStarted() { 86 return started; 87 } 88 89 public synchronized Request blockingRemoveOldest() { 90 Request req; 91 92 if (isStarted()) { 93 req = super.blockingRemoveOldest(); 94 } else { 95 req = super.blockingRemoveOldest(requestFilterOnComponentControllerClasses); 100 } 101 102 if (req instanceof ComponentRequest) { 104 if (req.getMethodCall().getReifiedMethod().getDeclaringClass().equals(LifeCycleController.class)) { 105 if (req.getMethodName().equals("startFc")) { 106 start(); 107 } else { 108 if (req.getMethodName().equals("stopFc")) { 109 stop(); 110 } 111 } 112 } 113 } 114 return req; 115 } 116 117 private class RequestFilterOnComponentControllerClasses implements RequestFilter, java.io.Serializable { 120 public RequestFilterOnComponentControllerClasses() { 121 } 122 123 public boolean acceptRequest(Request request) { 124 if (request instanceof ComponentRequest) { 125 return ((ComponentRequest) request).isControllerRequest(); 127 } else { 128 return false; 130 } 131 } 132 } 133 } | Popular Tags |