use of es.bsc.compss.types.annotations.parameter.Stream in project compss by bsc-wdc.
the class COMPSsRuntimeImpl method processParameters.
/*
* ************************************************************************************************************
* PRIVATE HELPER METHODS
* ********************************************************************************************************
*/
private Parameter[] processParameters(int parameterCount, Object[] parameters) {
Parameter[] pars = new Parameter[parameterCount];
// Parameter parsing needed, object is not serializable
int i = 0;
for (int npar = 0; npar < parameterCount; ++npar) {
DataType type = (DataType) parameters[i + 1];
Direction direction = (Direction) parameters[i + 2];
Stream stream = (Stream) parameters[i + 3];
String prefix = (String) parameters[i + 4];
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(" Parameter " + (npar + 1) + " has type " + type.name());
}
switch(type) {
case FILE_T:
try {
String fileName = (String) parameters[i];
String originalName = new File(fileName).getName();
DataLocation location = createLocation((String) parameters[i]);
pars[npar] = new FileParameter(direction, stream, prefix, location, originalName);
} catch (Exception e) {
LOGGER.error(ERROR_FILE_NAME, e);
ErrorManager.fatal(ERROR_FILE_NAME, e);
}
break;
case PSCO_T:
case OBJECT_T:
pars[npar] = new ObjectParameter(direction, stream, prefix, parameters[i], oReg.newObjectParameter(parameters[i]));
break;
case EXTERNAL_OBJECT_T:
String id = (String) parameters[i];
pars[npar] = new ExternalObjectParameter(direction, stream, prefix, id, externalObjectHashcode(id));
break;
default:
/*
* Basic types (including String). The only possible direction is IN, warn otherwise
*/
if (direction != Direction.IN) {
LOGGER.warn(WARN_WRONG_DIRECTION + "Parameter " + npar + " is a basic type, therefore it must have IN direction");
}
pars[npar] = new BasicTypeParameter(type, Direction.IN, stream, prefix, parameters[i]);
break;
}
i += 5;
}
return pars;
}
use of es.bsc.compss.types.annotations.parameter.Stream in project compss by bsc-wdc.
the class GATWorker method parseApplicationParameters.
/**
* Parses the application parameters
*
* @param args
* arg[L]: boolean is the method executed on a certain instance arg[L]: integer amount of parameters of
* the method arg[L+]: parameters of the method For each parameter: type: 0-10 (file, boolean, char,
* string, byte, short, int, long, float, double, object) [substrings: amount of substrings (only used
* when the type is string)] value: value for the parameter or the file where it is contained (for
* objects and files) [Direction: R/W (only used when the type is object)]
*/
private static void parseApplicationParameters(String[] args) {
// Variables
if (GATWorker.hasTarget) {
// The target object of the last parameter before the return value (if any)
GATWorker.types = new Class[GATWorker.numParams - 1];
GATWorker.values = new Object[GATWorker.numParams - 1];
} else {
GATWorker.types = new Class[GATWorker.numParams];
GATWorker.values = new Object[GATWorker.numParams];
}
GATWorker.streams = new Stream[GATWorker.numParams];
GATWorker.prefixes = new String[GATWorker.numParams];
GATWorker.isFile = new boolean[GATWorker.numParams];
GATWorker.mustWrite = new boolean[GATWorker.numParams];
GATWorker.renamings = new String[GATWorker.numParams];
// Parse the parameter types and values
DataType[] dataTypesEnum = DataType.values();
Stream[] dataStream = Stream.values();
int argPosition = GATWorker.initialAppParamsPosition;
for (int i = 0; i < GATWorker.numParams; i++) {
// We need to use wrapper classes for basic types, reflection will unwrap automatically
int argType_index = Integer.parseInt(args[argPosition]);
if (argType_index >= dataTypesEnum.length) {
ErrorManager.error(WARN_UNSUPPORTED_TYPE + argType_index);
}
DataType argType = dataTypesEnum[argType_index];
argPosition++;
int argStream_index = Integer.parseInt(args[argPosition]);
if (argStream_index >= dataStream.length) {
ErrorManager.error(WARN_UNSUPPORTED_STREAM + argStream_index);
}
GATWorker.streams[i] = dataStream[argStream_index];
argPosition++;
String prefix = args[argPosition];
if (prefix == null || prefix.isEmpty()) {
prefix = Constants.PREFIX_EMTPY;
}
GATWorker.prefixes[i] = prefix;
argPosition++;
switch(argType) {
case FILE_T:
GATWorker.types[i] = String.class;
GATWorker.values[i] = args[argPosition++];
break;
case OBJECT_T:
GATWorker.renamings[i] = (String) args[argPosition++];
GATWorker.mustWrite[i] = ((String) args[argPosition++]).equals("W");
retrieveObject(renamings[i], i);
break;
case PSCO_T:
GATWorker.renamings[i] = (String) args[argPosition++];
GATWorker.mustWrite[i] = ((String) args[argPosition++]).equals("W");
retrievePSCO(renamings[i], i);
break;
case EXTERNAL_OBJECT_T:
GATWorker.types[i] = String.class;
GATWorker.values[i] = args[argPosition++];
break;
case BOOLEAN_T:
GATWorker.types[i] = boolean.class;
GATWorker.values[i] = new Boolean(args[argPosition++]);
break;
case CHAR_T:
GATWorker.types[i] = char.class;
GATWorker.values[i] = new Character(args[argPosition++].charAt(0));
break;
case STRING_T:
GATWorker.types[i] = String.class;
int numSubStrings = Integer.parseInt(args[argPosition++]);
String aux = "";
for (int j = 0; j < numSubStrings; j++) {
if (j != 0) {
aux += " ";
}
aux += args[argPosition++];
}
GATWorker.values[i] = aux;
break;
case BYTE_T:
GATWorker.types[i] = byte.class;
GATWorker.values[i] = new Byte(args[argPosition++]);
break;
case SHORT_T:
GATWorker.types[i] = short.class;
GATWorker.values[i] = new Short(args[argPosition++]);
break;
case INT_T:
GATWorker.types[i] = int.class;
GATWorker.values[i] = new Integer(args[argPosition++]);
break;
case LONG_T:
GATWorker.types[i] = long.class;
GATWorker.values[i] = new Long(args[argPosition++]);
break;
case FLOAT_T:
GATWorker.types[i] = float.class;
GATWorker.values[i] = new Float(args[argPosition++]);
break;
case DOUBLE_T:
GATWorker.types[i] = double.class;
GATWorker.values[i] = new Double(args[argPosition++]);
break;
default:
ErrorManager.error(WARN_UNSUPPORTED_TYPE + argType);
return;
}
GATWorker.isFile[i] = argType.equals(DataType.FILE_T);
}
// Retrieve return renaming if existing
if (GATWorker.hasReturn) {
// +1 = StreamType, +2 = prefix, +3 = value
GATWorker.retRenaming = args[argPosition + 3];
}
}
use of es.bsc.compss.types.annotations.parameter.Stream in project compss by bsc-wdc.
the class ITAppEditor method processParameterValue.
/**
* Process the parameter values of a method call
*
* @param paramIndex
* @param formalType
* @param annotType
* @param paramDirection
* @return
*/
private ParameterInformation processParameterValue(int paramIndex, Parameter par, Class<?> formalType) {
Type annotType = par.type();
Direction paramDirection = par.direction();
Stream paramStream = par.stream();
String paramPrefix = par.prefix();
StringBuilder infoToAppend = new StringBuilder("");
StringBuilder infoToPrepend = new StringBuilder("");
String type = "";
if (annotType.equals(Type.FILE)) {
// The File type needs to be specified explicitly, since its formal type is String
type = DATA_TYPES + ".FILE_T";
infoToAppend.append('$').append(paramIndex + 1).append(',');
infoToPrepend.insert(0, itSRVar + ADD_TASK_FILE + "$" + (paramIndex + 1) + ");");
} else if (annotType.equals(Type.STRING)) {
/*
* Mechanism to make a String be treated like a list of chars instead of like another object. Dependencies
* won't be watched for the string.
*/
type = DATA_TYPES + ".STRING_T";
infoToAppend.append('$').append(paramIndex + 1).append(',');
} else if (formalType.isPrimitive()) {
if (formalType.equals(boolean.class)) {
type = DATA_TYPES + ".BOOLEAN_T";
infoToAppend.append("new Boolean(").append("$").append(paramIndex + 1).append("),");
} else if (formalType.equals(char.class)) {
type = DATA_TYPES + ".CHAR_T";
infoToAppend.append("new Character(").append("$").append(paramIndex + 1).append("),");
} else if (formalType.equals(byte.class)) {
type = DATA_TYPES + ".BYTE_T";
infoToAppend.append("new Byte(").append("$").append(paramIndex + 1).append("),");
} else if (formalType.equals(short.class)) {
type = DATA_TYPES + ".SHORT_T";
infoToAppend.append("new Short(").append("$").append(paramIndex + 1).append("),");
} else if (formalType.equals(int.class)) {
type = DATA_TYPES + ".INT_T";
infoToAppend.append("new Integer(").append("$").append(paramIndex + 1).append("),");
} else if (formalType.equals(long.class)) {
type = DATA_TYPES + ".LONG_T";
infoToAppend.append("new Long(").append("$").append(paramIndex + 1).append("),");
} else if (formalType.equals(float.class)) {
type = DATA_TYPES + ".FLOAT_T";
infoToAppend.append("new Float(").append("$").append(paramIndex + 1).append("),");
} else if (formalType.equals(double.class)) {
type = DATA_TYPES + ".DOUBLE_T";
infoToAppend.append("new Double(").append("$").append(paramIndex + 1).append("),");
}
} else {
// Object or Self-Contained Object or Persistent SCO
type = CHECK_SCO_TYPE + "$" + (paramIndex + 1) + ")";
infoToAppend.append("$").append(paramIndex + 1).append(",");
}
ParameterInformation infoParam = new ParameterInformation(infoToAppend.toString(), infoToPrepend.toString(), type, paramDirection, paramStream, paramPrefix);
return infoParam;
}
use of es.bsc.compss.types.annotations.parameter.Stream in project compss by bsc-wdc.
the class ITFParser method checkParameterAnnotation.
/**
* Treats and display errors and warning related to the annotation of 1 parameter of a method/service
*
* @param m
* The method or service to be checked for warnings
* @param par
* The parameter to analyse
* @param i
* The position of the parameter (0 for the first parameter, 1 for the second, etc.)
* @param hasNonNative
* Indicates if the method has non-native annotations or not
*/
private static void checkParameterAnnotation(java.lang.reflect.Method m, Parameter par, int i, boolean hasNonNative) {
final String WARNING_LOCATION = "In parameter number " + (i + 1) + " of method '" + m.getName() + "' in interface '" + m.getDeclaringClass().toString().replace("interface ", "") + "'.";
Type annotType = par.type();
Direction annotDirection = par.direction();
Stream stream = par.stream();
boolean isOut = annotDirection.equals(Direction.OUT);
boolean isInOut = annotDirection.equals(Direction.INOUT);
/*
* Type checks
*/
if (annotType.equals(Type.STRING)) {
// Strings are immutable
if (isOut || isInOut) {
ErrorManager.warn("Can't specify a String with direction OUT/INOUT since they are immutable." + ErrorManager.NEWLINE + WARNING_LOCATION + ErrorManager.NEWLINE + "Using direction=IN instead.");
}
} else if (m.getParameterTypes()[i].isPrimitive()) {
// Primitive types are immutable (int, boolean, long, float, char, byte, short, double)
if (isOut || isInOut) {
String primType = m.getParameterTypes()[i].getName();
ErrorManager.warn("Can't specify a primitive type ('" + primType + "') with direction OUT/INOUT, " + "since they are always passed by value. " + ErrorManager.NEWLINE + WARNING_LOCATION + ErrorManager.NEWLINE + "Using direction=IN instead.");
}
} else if (annotType.equals(Type.OBJECT)) {
// Objects are not supported as OUT parameters
if (isOut) {
ErrorManager.warn("Can't specify an Object with direction OUT." + ErrorManager.NEWLINE + WARNING_LOCATION + ErrorManager.NEWLINE + "Using direction=INOUT instead.");
}
}
/*
* Non native tasks only support FILES as INOUT
*/
if (hasNonNative && !annotType.equals(Type.FILE) && (isOut || isInOut)) {
ErrorManager.error("Non-Native tasks only supports " + annotType.name() + " types in mode IN" + ErrorManager.NEWLINE + WARNING_LOCATION);
}
/*
* Stream checks
*/
if (!stream.equals(Stream.UNSPECIFIED)) {
// Stream parameters can only be files
if (!annotType.equals(Type.FILE)) {
ErrorManager.error("Can't specify an Stream with type different than File." + ErrorManager.NEWLINE + WARNING_LOCATION);
}
switch(stream) {
case STDIN:
if (isOut || isInOut) {
ErrorManager.error("Stream STDIN must have direction IN" + ErrorManager.NEWLINE + WARNING_LOCATION);
}
break;
case STDOUT:
if (!isOut && !isInOut) {
ErrorManager.error("Stream STDOUT must have direction OUT or INOUT" + ErrorManager.NEWLINE + WARNING_LOCATION);
}
break;
case STDERR:
if (!isOut && !isInOut) {
ErrorManager.error("Stream STDERR must have direction OUT or INOUT" + ErrorManager.NEWLINE + WARNING_LOCATION);
}
break;
case UNSPECIFIED:
// We never reach this point since the previous if protects this case
break;
}
}
}
use of es.bsc.compss.types.annotations.parameter.Stream in project compss by bsc-wdc.
the class GATWorker method logArguments.
/**
* Logs the parsed arguments
*/
private static void logArguments() {
// Print arguments information
System.out.println("");
System.out.println("[GAT WORKER] ------------------------------------");
System.out.println("[GAT WORKER] Parameters of execution:");
for (int j = 0; j < GATWorker.methodDefinition.length; ++j) {
System.out.println(" * Method Description " + j + ": " + GATWorker.methodDefinition[j]);
}
System.out.print(" * Parameter types:");
for (Class<?> c : GATWorker.types) {
System.out.print(" " + c.getName());
}
System.out.println("");
System.out.print(" * Parameter values:");
for (Object v : GATWorker.values) {
System.out.print(" " + v);
}
System.out.println("");
System.out.print(" * Parameter streams:");
for (Stream s : GATWorker.streams) {
System.out.print(" " + s.name());
}
System.out.println("");
if (GATWorker.hasReturn) {
System.out.println(" * Has return with renaming " + GATWorker.retRenaming);
} else {
System.out.println(" * Has NO return");
}
}
Aggregations