Search in sources :

Example 6 with Direction

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;
}
Also used : RandomAccessFile(java.io.RandomAccessFile) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Direction(es.bsc.compss.types.annotations.parameter.Direction)

Example 7 with Direction

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;
}
Also used : Direction(es.bsc.compss.types.annotations.parameter.Direction) PrintWriter(java.io.PrintWriter)

Example 8 with Direction

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;
}
Also used : Direction(es.bsc.compss.types.annotations.parameter.Direction) PrintWriter(java.io.PrintWriter)

Example 9 with Direction

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;
        }
    }
}
Also used : Type(es.bsc.compss.types.annotations.parameter.Type) Stream(es.bsc.compss.types.annotations.parameter.Stream) Direction(es.bsc.compss.types.annotations.parameter.Direction)

Example 10 with Direction

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;
}
Also used : FileWriter(java.io.FileWriter) Direction(es.bsc.compss.types.annotations.parameter.Direction)

Aggregations

Direction (es.bsc.compss.types.annotations.parameter.Direction)12 IOException (java.io.IOException)4 Stream (es.bsc.compss.types.annotations.parameter.Stream)3 FileNotFoundException (java.io.FileNotFoundException)3 PrintStream (java.io.PrintStream)3 DataType (es.bsc.compss.types.annotations.parameter.DataType)2 Type (es.bsc.compss.types.annotations.parameter.Type)2 PrintWriter (java.io.PrintWriter)2 DataLocation (es.bsc.compss.types.data.location.DataLocation)1 BasicTypeParameter (es.bsc.compss.types.parameter.BasicTypeParameter)1 ExternalObjectParameter (es.bsc.compss.types.parameter.ExternalObjectParameter)1 FileParameter (es.bsc.compss.types.parameter.FileParameter)1 ObjectParameter (es.bsc.compss.types.parameter.ObjectParameter)1 Parameter (es.bsc.compss.types.parameter.Parameter)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 FilterInputStream (java.io.FilterInputStream)1