Search in sources :

Example 1 with Request

use of org.objectweb.proactive.core.body.request.Request in project scheduling by ow2-proactive.

the class AOSynchronization method waitForNewRequests.

/**
 * Wait for a new request in the request queue, until a request is found or until a timeout based on the pending wait request queue
 * @param service active object service
 * @return composite object containing the request and the waited time
 * @throws InterruptedException if the thread is interrupted while waiting for request
 */
private List<NewRequestWithWaitTime> waitForNewRequests(Service service) throws InterruptedException {
    // we cannot wait more then min(pending_wait_requests_timeouts)
    long maximumTimeToWaitForNewRequests = computeMinimumTimeout();
    List<NewRequestWithWaitTime> newRequests = new ArrayList<>();
    logger.trace("Waiting for new requests with timeout = " + maximumTimeToWaitForNewRequests + " ms");
    long waitStart = System.currentTimeMillis();
    do {
        Request request = service.blockingRemoveOldest(maximumTimeToWaitForNewRequests);
        long timeSpentWaiting = System.currentTimeMillis() - waitStart;
        logger.trace("Time spent waiting for new request: " + timeSpentWaiting + " ms");
        newRequests.add(new NewRequestWithWaitTime(request, timeSpentWaiting));
    } while (service.hasRequestToServe());
    return newRequests;
}
Also used : Request(org.objectweb.proactive.core.body.request.Request)

Example 2 with Request

use of org.objectweb.proactive.core.body.request.Request in project scheduling by ow2-proactive.

the class RMCore method runActivity.

/**
 * RunActivity periodically send "alive" event to listeners
 */
public void runActivity(Body body) {
    Service service = new Service(body);
    // recalculating nodes number only once per policy period
    while (body.isActive()) {
        Request request = null;
        try {
            request = service.blockingRemoveOldest(PAResourceManagerProperties.RM_ALIVE_EVENT_FREQUENCY.getValueAsLong());
            if (request != null) {
                try {
                    try {
                        caller = checkMethodCallPermission(request.getMethodName(), request.getSourceBodyID());
                        service.serve(request);
                    } catch (SecurityException ex) {
                        logger.warn("Cannot serve request: " + request, ex);
                        service.serve(new ThrowExceptionRequest(request, ex));
                    }
                } catch (Throwable e) {
                    logger.error("Cannot serve request: " + request, e);
                }
            }
        } catch (InterruptedException e) {
            logger.warn("runActivity interrupted", e);
        }
    }
}
Also used : Request(org.objectweb.proactive.core.body.request.Request) ImmediateService(org.objectweb.proactive.annotation.ImmediateService) Service(org.objectweb.proactive.Service) NodesHouseKeepingService(org.ow2.proactive.resourcemanager.housekeeping.NodesHouseKeepingService)

Example 3 with Request

use of org.objectweb.proactive.core.body.request.Request in project scheduling by ow2-proactive.

the class RMCore method checkPermissionAndGetClientIsSuccessful.

protected Client checkPermissionAndGetClientIsSuccessful() {
    final Request currentRequest = PAActiveObject.getContext().getCurrentRequest();
    String methodName = currentRequest.getMethodName();
    return checkMethodCallPermission(methodName, currentRequest.getSourceBodyID());
}
Also used : Request(org.objectweb.proactive.core.body.request.Request)

Example 4 with Request

use of org.objectweb.proactive.core.body.request.Request in project scheduling by ow2-proactive.

the class AOSynchronization method runActivity.

@Override
public void runActivity(Body body) {
    Service service = new Service(body);
    while (body.isActive()) {
        try {
            List<NewRequestWithWaitTime> requestsWithWaitTime = waitForNewRequests(service);
            for (NewRequestWithWaitTime requestWithWaitTime : requestsWithWaitTime) {
                Request request = requestWithWaitTime.getNewRequest();
                if (request != null && request.getMethodName().equals("freeze")) {
                    service.serve(request);
                    service.blockingServeOldest("resume");
                } else if (request != null && request.getMethodName().startsWith("waitUntilThen") && !testWaitFunction(service, request)) {
                    // If the predicate is not met, delay the wait method execution
                    TimedOutRequest timedOutRequest = new TimedOutRequest(request, extractWaitRequestTimeoutParameter(request));
                    logger.trace("New pending wait request : " + timedOutRequest);
                    waitUntilQueue.add(new TimedOutRequest(request, extractWaitRequestTimeoutParameter(request)));
                } else if (request != null) {
                    service.serve(request);
                }
            }
            unblockWaitMethods(service, computeMaxTimeSpentWaiting(requestsWithWaitTime));
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
}
Also used : Request(org.objectweb.proactive.core.body.request.Request) Service(org.objectweb.proactive.Service) ImmediateService(org.objectweb.proactive.annotation.ImmediateService)

Aggregations

Request (org.objectweb.proactive.core.body.request.Request)4 Service (org.objectweb.proactive.Service)2 ImmediateService (org.objectweb.proactive.annotation.ImmediateService)2 NodesHouseKeepingService (org.ow2.proactive.resourcemanager.housekeeping.NodesHouseKeepingService)1