use of es.bsc.compss.types.annotations.parameter.Direction 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.Direction 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.Direction in project compss by bsc-wdc.
the class StreamRegistry method newPrintStream.
public PrintStream newPrintStream(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException {
Direction direction = Direction.OUT;
StreamList list = obtainList(file, direction);
PrintStream ps = new PrintStream(list.getRenaming(), csn);
list.addStream(ps);
return ps;
}
use of es.bsc.compss.types.annotations.parameter.Direction in project compss by bsc-wdc.
the class StreamRegistry method newFileInputStream.
// FileInputStream
public FileInputStream newFileInputStream(File file) throws FileNotFoundException {
Direction direction = Direction.IN;
StreamList list = obtainList(file, direction);
/*
* Create the stream on the renaming of the obtained list for the file, then add it to the list The possible
* exception is thrown for the application to handle it
*/
FileInputStream fis = new FileInputStream(list.getRenaming());
list.addStream(fis);
try {
list.addFD(fis.getFD());
} catch (IOException e) {
// We must go up as a FileNotFoundException, since it is the one that the application deals with
throw new FileNotFoundException("Loader - Error creating FileInputStream for file " + file + lineSep + e.getMessage());
}
return fis;
}
use of es.bsc.compss.types.annotations.parameter.Direction in project compss by bsc-wdc.
the class StreamRegistry method newPrintStream.
// PrintStream
public PrintStream newPrintStream(File file) throws FileNotFoundException {
Direction direction = Direction.OUT;
StreamList list = obtainList(file, direction);
PrintStream ps = new PrintStream(list.getRenaming());
list.addStream(ps);
return ps;
}
Aggregations