All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.parallelj.launching.remote.RemoteProgram Maven / Gradle / Ivy

Go to download

ParallelJ is a Java framework for parallel computing. It provides flow modeling and execution. This projet covers the launching of a ParallelJ program purpose. It allows to launch easily the programs, and access them remotely.

The newest version!
/*
 *     ParallelJ, framework for parallel computing
 *
 *     Copyright (C) 2010, 2011, 2012 Atos Worldline or third-party contributors as
 *     indicated by the @author tags or express copyright attribution
 *     statements applied by the authors.
 *
 *     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.
 *
 *     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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */
package org.parallelj.launching.remote;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.parallelj.Programs;
import org.parallelj.Programs.ProcessHelper;
import org.parallelj.internal.kernel.KProcess;
import org.parallelj.internal.kernel.KProgram;
import org.parallelj.internal.reflect.ProcessHelperImpl;
import org.parallelj.internal.reflect.ProgramAdapter.Adapter;
import org.parallelj.launching.LaunchingMessageKind;
import org.parallelj.launching.inout.Argument;
import org.parallelj.launching.inout.ArgumentComparator;
import org.parallelj.launching.inout.IProgramInputOutputs;
import org.parallelj.launching.inout.Output;

public class RemoteProgram {
	private Class adapterClass;
	
	private List arguments = new ArrayList();
	private List output = new ArrayList();
	
	public RemoteProgram(final Class adapterClass) {
		this.adapterClass = adapterClass;
		
		// Instanciate an instance of Program to get its arguments and output..
		try {
			Object obj = adapterClass.newInstance();
			ProcessHelper p = Programs.as(obj);
			this.arguments = ((IProgramInputOutputs) ((KProgram) ((KProcess) ((ProcessHelperImpl) p)
					.getProcess()).getProgram())).getArguments();
			this.output = ((IProgramInputOutputs) ((KProgram) ((KProcess) ((ProcessHelperImpl) p)
					.getProcess()).getProgram())).getOutputs();
			
			// Sorts Arguments
			Collections.sort(this.arguments, new ArgumentComparator());
		} catch (Exception e) {
			LaunchingMessageKind.ELAUNCH0002.format(e);
		}
	}

	public Class getAdapterClass() {
		return this.adapterClass;
	}

	public List getArguments() {
		return this.arguments;
	}

	public List getOutput() {
		return this.output;
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy