<commit_before>/*
 * ################################################################
 *
 * ProActive: The Java(TM) library for Parallel, Distributed,
 *            Concurrent computing with Security and Mobility
 *
 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
 * Contact: <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 *  Initial developer(s):               The ProActive Team
 *                        http://www.inria.fr/oasis/ProActive/contacts.html
 *  Contributor(s):
 *
 * ################################################################
 */
package org.objectweb.proactive.core.body.request;

import org.apache.log4j.Logger;

import org.objectweb.proactive.Body;
import org.objectweb.proactive.core.UniqueID;
import org.objectweb.proactive.core.body.UniversalBody;
import org.objectweb.proactive.core.body.ft.exception.ProtocolErrorException;
import org.objectweb.proactive.core.body.ft.protocols.FTManager;
import org.objectweb.proactive.core.body.reply.Reply;
import org.objectweb.proactive.core.exceptions.NonFunctionalException;
import org.objectweb.proactive.core.mop.MethodCall;
import org.objectweb.proactive.ext.security.ProActiveSecurityManager;
import org.objectweb.proactive.ext.security.exceptions.RenegotiateSessionException;

import java.io.IOException;


/**
 * This class defines a particular request that is subject to <i>wait-by-necessity</i>
 * mecanism. It only contains the Id of the awaited sender. When this awaited sender
 * eventually send a request, the corresponding awaited request is updated, and then
 * behaves as a normal ProActive request.
 * If an active object tries to serve an awaited request that is not yet updated, it's
 * activity is suspended until the awaited request is updated.
 * This request can be considered as a "future of request".
 * (@see org.objectweb.proactive.core.body.future.Future)
 * @author cdelbe
 * @since ProActive 2.2
 */
public class AwaitedRequest implements Request, java.io.Serializable {

    /** Logger */
    public static Logger logger = Logger.getLogger(AwaitedRequest.class.getName());

    // awaited sender
    private UniqueID awaitedSender;

    // wrapped Request
    private Request wrappedRequest;
    private boolean isArrived;

    /**
     * Create a new awaited request.
     * @param awaitedSender the id of the awaited sender.
     */
    public AwaitedRequest(UniqueID awaitedSender) {
        this.awaitedSender = awaitedSender;
        this.isArrived = false;
    }

    /**
     * Update this awaited request with a received request from the awaited sender.
     * @param r the received request.
     */
    public synchronized void setAwaitedRequest(Request r) {
        //System.err.println("[AWAITED] Request is updated by " + this.awaitedSender);
        //if(!(r.getSourceBodyID().equals(this.awaitedSender))){
        //    logger.error(" **ERROR** : update request is not from the awaited sender !");
        //}
        this.wrappedRequest = r;
        this.isArrived = true;
        notifyAll();
    }

    /**
     * Return the id of the awaited sender
     * @return the id of the awaited sender
     */
    public UniqueID getAwaitedSender() {
        return this.awaitedSender;
    }

    /**
     * Serve the request. This method is subject to wait-by-necessity mechanism.
     * @return the reply resulting from the service of this request.
     */
    public Reply serve(Body targetBody) throws ServeException {
        waitForRequest();
        return wrappedRequest.serve(targetBody);
    }

    /*
     * Wait for a request from the awaited sender.
     */
    private synchronized void waitForRequest() {
        while (!isArrived) {
            try {
                if (logger.isDebugEnabled()) {
                    logger.debug("Waiting for a request from " +
                        this.awaitedSender);
                }
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    //// WRAPPED METHODS
    public MethodCall getMethodCall() {
        return wrappedRequest.getMethodCall();
    }

    public Object getParameter(int index) {
        return wrappedRequest.getParameter(index);
    }

    public UniversalBody getSender() {
        return wrappedRequest.getSender();
    }

    public boolean hasBeenForwarded() {
        return wrappedRequest.hasBeenForwarded();
    }

    public void resetSendCounter() {
        throw new ProtocolErrorException(
            "An active object is trying to send an awaited request");
    }

    public void notifyReception(UniversalBody bodyReceiver)
        throws IOException {
        wrappedRequest.notifyReception(bodyReceiver);
    }

    public int send(UniversalBody destinationBody)
        throws IOException, RenegotiateSessionException {
        throw new ProtocolErrorException(
            "An active object is trying to send an awaited request");
    }

    public String getMethodName() {
        if (!this.isArrived) {
            return "Awaited Request from " + this.awaitedSender;
        } else {
            return wrappedRequest.getMethodName();
        }
    }

    public UniqueID getSourceBodyID() {
        return this.awaitedSender;
    }

    public long getTimeStamp() {
        return wrappedRequest.getTimeStamp();
    }

    public boolean isOneWay() {
        return wrappedRequest.isOneWay();
    }

    public long getSequenceNumber() {
        return wrappedRequest.getSequenceNumber();
    }

    public void setMessageInfo(char[] mi) {
        wrappedRequest.setMessageInfo(mi);
    }

    public char[] getMessageInfo() {
        return null;
    }

    public void setIgnoreIt() {
        wrappedRequest.setIgnoreIt();
    }

    public boolean ignoreIt() {<commit_msg>Adding specific IC2D code<commit_after>/*
 * ################################################################
 *
 * ProActive: The Java(TM) library for Parallel, Distributed,
 *            Concurrent computing with Security and Mobility
 *
 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
 * Contact: <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 *  Initial developer(s):               The ProActive Team
 *                        http://www.inria.fr/oasis/ProActive/contacts.html
 *  Contributor(s):
 *
 * ################################################################
 */
package org.objectweb.proactive.core.body.request;

import org.apache.log4j.Logger;

import org.objectweb.proactive.Body;
import org.objectweb.proactive.core.UniqueID;
import org.objectweb.proactive.core.body.UniversalBody;
import org.objectweb.proactive.core.body.ft.exception.ProtocolErrorException;
import org.objectweb.proactive.core.body.ft.protocols.FTManager;
import org.objectweb.proactive.core.body.reply.Reply;
import org.objectweb.proactive.core.exceptions.NonFunctionalException;
import org.objectweb.proactive.core.mop.MethodCall;
import org.objectweb.proactive.ext.security.ProActiveSecurityManager;
import org.objectweb.proactive.ext.security.exceptions.RenegotiateSessionException;

import java.io.IOException;


/**
 * This class defines a particular request that is subject to <i>wait-by-necessity</i>
 * mecanism. It only contains the Id of the awaited sender. When this awaited sender
 * eventually send a request, the corresponding awaited request is updated, and then
 * behaves as a normal ProActive request.
 * If an active object tries to serve an awaited request that is not yet updated, it's
 * activity is suspended until the awaited request is updated.
 * This request can be considered as a "future of request".
 * (@see org.objectweb.proactive.core.body.future.Future)
 * @author cdelbe
 * @since ProActive 2.2
 */
public class AwaitedRequest implements Request, java.io.Serializable {

    /** Logger */
    public static Logger logger = Logger.getLogger(AwaitedRequest.class.getName());

    // awaited sender
    private UniqueID awaitedSender;

    // wrapped Request
    private Request wrappedRequest;
    private boolean isArrived;

    /**
     * Create a new awaited request.
     * @param awaitedSender the id of the awaited sender.
     */
    public AwaitedRequest(UniqueID awaitedSender) {
        this.awaitedSender = awaitedSender;
        this.isArrived = false;
    }

    /**
     * Update this awaited request with a received request from the awaited sender.
     * @param r the received request.
     */
    public synchronized void setAwaitedRequest(Request r) {
        //System.err.println("[AWAITED] Request is updated by " + this.awaitedSender);
        //if(!(r.getSourceBodyID().equals(this.awaitedSender))){
        //    logger.error(" **ERROR** : update request is not from the awaited sender !");
        //}
        this.wrappedRequest = r;
        this.isArrived = true;
        notifyAll();
    }

    /**
     * Return the id of the awaited sender
     * @return the id of the awaited sender
     */
    public UniqueID getAwaitedSender() {
        return this.awaitedSender;
    }

    /**
     * Serve the request. This method is subject to wait-by-necessity mechanism.
     * @return the reply resulting from the service of this request.
     */
    public Reply serve(Body targetBody) throws ServeException {
        waitForRequest();
        return wrappedRequest.serve(targetBody);
    }

    /*
     * Wait for a request from the awaited sender.
     */
    private synchronized void waitForRequest() {
        while (!isArrived) {
            try {
                if (logger.isDebugEnabled()) {
                    logger.debug("Waiting for a request from " +
                        this.awaitedSender);
                }
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    //// WRAPPED METHODS
    public MethodCall getMethodCall() {
        return wrappedRequest.getMethodCall();
    }

    public Object getParameter(int index) {
        return wrappedRequest.getParameter(index);
    }

    public UniversalBody getSender() {
        return wrappedRequest.getSender();
    }

    public boolean hasBeenForwarded() {
        return wrappedRequest.hasBeenForwarded();
    }

    public void resetSendCounter() {
        throw new ProtocolErrorException(
            "An active object is trying to send an awaited request");
    }

    public void notifyReception(UniversalBody bodyReceiver)
        throws IOException {
        wrappedRequest.notifyReception(bodyReceiver);
    }

    public int send(UniversalBody destinationBody)
        throws IOException, RenegotiateSessionException {
        throw new ProtocolErrorException(
            "An active object is trying to send an awaited request");
    }

    public String getMethodName() {
        if (!this.isArrived) {
            return "Awaited Request from " + this.awaitedSender;
        } else {
            return wrappedRequest.getMethodName();
        }
    }

    public UniqueID getSourceBodyID() {
        return this.awaitedSender;
    }

    public long getTimeStamp() {
        return wrappedRequest.getTimeStamp();
    }

    public boolean isOneWay() {
        return wrappedRequest.isOneWay();
    }

    public long getSequenceNumber() {
    	if (!this.isArrived) {
           return 0;
        } else {
            return wrappedRequest.getSequenceNumber();
        }
    }

    public void setMessageInfo(char[] mi) {
        wrappedRequest.setMessageInfo(mi);
    }

    public char[] getMessageInfo() {
        return null;
    }

    public void setIgnoreIt() {
        wrappedRequest.setIgnoreIt();
    }

    public boolean ignoreIt() {
{'fraction_non_alphanumeric': 0.10295468462951622, 'fraction_numerical': 0.004286589099816289, 'mean_word_length': 2.7629608294930876, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5563424', 'n_tokens_mistral': 3529, 'n_tokens_neox': 3332, 'n_words': 1078}