<commit_before>/*
 * ################################################################
 *
 * ProActive: The Java(TM) library for Parallel, Distributed,
 *            Concurrent computing with Security and Mobility
 *
 * Copyright (C) 1997-2007 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 General Public License
 * as published by the Free Software Foundation; either version
 * 2 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU 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://proactive.inria.fr/team_members.htm
 *  Contributor(s):
 *
 * ################################################################
 */
package org.objectweb.proactive.extra.scheduler.resourcemanager;

import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;

import org.apache.log4j.Logger;
import org.objectweb.proactive.ActiveObjectCreationException;
import org.objectweb.proactive.Body;
import org.objectweb.proactive.InitActive;
import org.objectweb.proactive.RunActive;
import org.objectweb.proactive.Service;
import org.objectweb.proactive.api.ProActiveObject;
import org.objectweb.proactive.api.ProFuture;
import org.objectweb.proactive.core.node.Node;
import org.objectweb.proactive.core.node.NodeException;
import org.objectweb.proactive.core.util.log.Loggers;
import org.objectweb.proactive.core.util.log.ProActiveLogger;
import org.objectweb.proactive.core.util.wrapper.BooleanWrapper;
import org.objectweb.proactive.core.util.wrapper.IntWrapper;
import org.objectweb.proactive.core.util.wrapper.StringWrapper;
import org.objectweb.proactive.extra.infrastructuremanager.common.IMConstants;
import org.objectweb.proactive.extra.infrastructuremanager.exception.IMException;
import org.objectweb.proactive.extra.infrastructuremanager.frontend.IMConnection;
import org.objectweb.proactive.extra.infrastructuremanager.frontend.IMMonitoring;
import org.objectweb.proactive.extra.infrastructuremanager.frontend.IMUser;
import org.objectweb.proactive.extra.infrastructuremanager.frontend.NodeSet;
import org.objectweb.proactive.extra.scheduler.common.scripting.Script;
import org.objectweb.proactive.extra.scheduler.common.scripting.ScriptHandler;
import org.objectweb.proactive.extra.scheduler.common.scripting.ScriptLoader;
import org.objectweb.proactive.extra.scheduler.common.scripting.ScriptResult;
import org.objectweb.proactive.extra.scheduler.common.scripting.SelectionScript;


/**
 * The Infrastructure Manager Proxy provides an interface with the
 * Infrastructure Manager. It combines the IMMonitoring and IMUser interface,
 * and adds the Post Scripting management.
 *
 *
 * @author ProActive Team
 * @version 1.0, Jun 15, 2007
 * @since ProActive 3.2
 */
public class InfrastructureManagerProxy implements InitActive, RunActive,
    IMConstants {
    private static final long VERIF_TIMEOUT = 10000;
    private static Logger logger = ProActiveLogger.getLogger(Loggers.SCHEDULER);
    private IMMonitoring monitoring;
    private IMUser user;
    private HashMap<Node, ScriptResult<?>> nodes;
    private boolean running = true;

    /** ProActive no Args constructor **/
    public InfrastructureManagerProxy() {
    } //proactive no arg constructor

    /** IMProxy constructor.
     *
     * @param monitoring the Monitoring interface
     * @param user the User interface
     */
    public InfrastructureManagerProxy(IMMonitoring monitoring, IMUser user) {
        this.monitoring = monitoring;
        this.user = user;
    }

    /**
     * Get a IMProxy by its URI (example : "rmi://localhost:1099/" ).
     *
     *
     * @param uriIM
     * @return
     * @throws ActiveObjectCreationException
     * @throws IOException
     * @throws NodeException
     */
    public static InfrastructureManagerProxy getProxy(URI uriIM)
        throws ActiveObjectCreationException, IOException, NodeException {
        try {
            IMUser user = IMConnection.connectAsUser(uriIM.toString() +
                    NAME_ACTIVE_OBJECT_IMUSER);
            IMMonitoring monitor = IMConnection.connectAsMonitor(uriIM.toString() +
                    NAME_ACTIVE_OBJECT_IMMONITORING);
            return (InfrastructureManagerProxy) ProActiveObject.newActive(InfrastructureManagerProxy.class.getCanonicalName(),
                new Object[] { monitor, user });
        } catch (IMException e) {
            throw new ActiveObjectCreationException(e);
        }
    }

    public StringWrapper echo() {
        return new StringWrapper("User Interface says " + user.echo() +
            " and Monitoring Interface says " + monitoring.echo());
    }

    // FREE NODES *********************************************
    /**
     * Simply free a Node<commit_msg>Fixed connection Bug with Infrastructure Manager<commit_after>/*
 * ################################################################
 *
 * ProActive: The Java(TM) library for Parallel, Distributed,
 *            Concurrent computing with Security and Mobility
 *
 * Copyright (C) 1997-2007 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 General Public License
 * as published by the Free Software Foundation; either version
 * 2 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU 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://proactive.inria.fr/team_members.htm
 *  Contributor(s):
 *
 * ################################################################
 */
package org.objectweb.proactive.extra.scheduler.resourcemanager;

import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;

import org.apache.log4j.Logger;
import org.objectweb.proactive.ActiveObjectCreationException;
import org.objectweb.proactive.Body;
import org.objectweb.proactive.InitActive;
import org.objectweb.proactive.RunActive;
import org.objectweb.proactive.Service;
import org.objectweb.proactive.api.ProActiveObject;
import org.objectweb.proactive.api.ProFuture;
import org.objectweb.proactive.core.node.Node;
import org.objectweb.proactive.core.node.NodeException;
import org.objectweb.proactive.core.util.log.Loggers;
import org.objectweb.proactive.core.util.log.ProActiveLogger;
import org.objectweb.proactive.core.util.wrapper.BooleanWrapper;
import org.objectweb.proactive.core.util.wrapper.IntWrapper;
import org.objectweb.proactive.core.util.wrapper.StringWrapper;
import org.objectweb.proactive.extra.infrastructuremanager.common.IMConstants;
import org.objectweb.proactive.extra.infrastructuremanager.exception.IMException;
import org.objectweb.proactive.extra.infrastructuremanager.frontend.IMConnection;
import org.objectweb.proactive.extra.infrastructuremanager.frontend.IMMonitoring;
import org.objectweb.proactive.extra.infrastructuremanager.frontend.IMUser;
import org.objectweb.proactive.extra.infrastructuremanager.frontend.NodeSet;
import org.objectweb.proactive.extra.scheduler.common.scripting.Script;
import org.objectweb.proactive.extra.scheduler.common.scripting.ScriptHandler;
import org.objectweb.proactive.extra.scheduler.common.scripting.ScriptLoader;
import org.objectweb.proactive.extra.scheduler.common.scripting.ScriptResult;
import org.objectweb.proactive.extra.scheduler.common.scripting.SelectionScript;


/**
 * The Infrastructure Manager Proxy provides an interface with the
 * Infrastructure Manager. It combines the IMMonitoring and IMUser interface,
 * and adds the Post Scripting management.
 *
 *
 * @author ProActive Team
 * @version 1.0, Jun 15, 2007
 * @since ProActive 3.2
 */
public class InfrastructureManagerProxy implements InitActive, RunActive,
    IMConstants {
    private static final long VERIF_TIMEOUT = 10000;
    private static Logger logger = ProActiveLogger.getLogger(Loggers.SCHEDULER);
    private IMMonitoring monitoring;
    private IMUser user;
    private HashMap<Node, ScriptResult<?>> nodes;
    private boolean running = true;

    /** ProActive no Args constructor **/
    public InfrastructureManagerProxy() {
    } //proactive no arg constructor

    /** IMProxy constructor.
     *
     * @param monitoring the Monitoring interface
     * @param user the User interface
     */
    public InfrastructureManagerProxy(IMMonitoring monitoring, IMUser user) {
        this.monitoring = monitoring;
        this.user = user;
    }

    /**
     * Get a IMProxy by its URI (example : "rmi://localhost:1099/" ).
     *
     *
     * @param uriIM
     * @return
     * @throws ActiveObjectCreationException
     * @throws IOException
     * @throws NodeException
     */
    public static InfrastructureManagerProxy getProxy(URI uriIM)
        throws ActiveObjectCreationException, IOException, NodeException {
        try {
            String url = uriIM.toString();
            if (!url.endsWith("/")) {
                url += "/";
            }
            IMUser user = IMConnection.connectAsUser(url +
                    NAME_ACTIVE_OBJECT_IMUSER);
            IMMonitoring monitor = IMConnection.connectAsMonitor(url +
                    NAME_ACTIVE_OBJECT_IMMONITORING);
            return (InfrastructureManagerProxy) ProActiveObject.newActive(InfrastructureManagerProxy.class.getCanonicalName(),
                new Object[] { monitor, user });
        } catch (IMException e) {
            throw new ActiveObjectCreationException(e);
        }
    }

    public StringWrapper echo() {
        return new StringWrapper("User Interface says " + user.echo() +
            " and Monitoring Interface says " + monitoring.echo());
    }

    // FREE NODES *********************************************
    /**
     * Simply free a Node
{'fraction_non_alphanumeric': 0.11614573700758277, 'fraction_numerical': 0.007952653967079712, 'mean_word_length': 3.8088039128501556, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5330676', 'n_tokens_mistral': 2950, 'n_tokens_neox': 2807, 'n_words': 750}