use of es.bsc.compss.types.annotations.parameter.Direction in project compss by bsc-wdc.
the class StreamRegistry method newRandomAccessFile.
// RandomAccessFile
public RandomAccessFile newRandomAccessFile(File file, String mode) throws FileNotFoundException {
Direction direction;
if (mode.length() == 1) {
// mode == "r"
direction = Direction.IN;
} else {
// mode == "rw?"
direction = Direction.INOUT;
}
StreamList list = obtainList(file, direction);
RandomAccessFile raf = new RandomAccessFile(list.getRenaming(), mode);
list.addStream(raf);
try {
list.addFD(raf.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 RandomAccessFile for file " + file + lineSep + e.getMessage());
}
return raf;
}
use of es.bsc.compss.types.annotations.parameter.Direction in project compss by bsc-wdc.
the class StreamRegistry method newPrintWriter.
public PrintWriter newPrintWriter(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException {
Direction direction = Direction.OUT;
StreamList list = obtainList(file, direction);
PrintWriter pw = new PrintWriter(list.getRenaming(), csn);
list.addStream(pw);
return pw;
}
use of es.bsc.compss.types.annotations.parameter.Direction in project compss by bsc-wdc.
the class StreamRegistry method newPrintWriter.
// PrintWriter
public PrintWriter newPrintWriter(File file) throws FileNotFoundException {
Direction direction = Direction.OUT;
StreamList list = obtainList(file, direction);
PrintWriter pw = new PrintWriter(list.getRenaming());
list.addStream(pw);
return pw;
}
use of es.bsc.compss.types.annotations.parameter.Direction 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.Direction in project compss by bsc-wdc.
the class StreamRegistry method newFileWriter.
// FileWriter
public FileWriter newFileWriter(File file, boolean append) throws IOException {
Direction direction = append ? Direction.INOUT : Direction.OUT;
StreamList list = obtainList(file, direction);
FileWriter fw = new FileWriter(list.getRenaming(), append);
list.addStream(fw);
return fw;
}
Aggregations