Search in sources :

Example 1 with Direction

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;
}
Also used : DataLocation(es.bsc.compss.types.data.location.DataLocation) Direction(es.bsc.compss.types.annotations.parameter.Direction) IOException(java.io.IOException) BasicTypeParameter(es.bsc.compss.types.parameter.BasicTypeParameter) ExternalObjectParameter(es.bsc.compss.types.parameter.ExternalObjectParameter) ExternalObjectParameter(es.bsc.compss.types.parameter.ExternalObjectParameter) ObjectParameter(es.bsc.compss.types.parameter.ObjectParameter) ExternalObjectParameter(es.bsc.compss.types.parameter.ExternalObjectParameter) ObjectParameter(es.bsc.compss.types.parameter.ObjectParameter) FileParameter(es.bsc.compss.types.parameter.FileParameter) Parameter(es.bsc.compss.types.parameter.Parameter) BasicTypeParameter(es.bsc.compss.types.parameter.BasicTypeParameter) DataType(es.bsc.compss.types.annotations.parameter.DataType) Stream(es.bsc.compss.types.annotations.parameter.Stream) InputStream(java.io.InputStream) FileParameter(es.bsc.compss.types.parameter.FileParameter) File(java.io.File)

Example 2 with Direction

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

Example 3 with Direction

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

Example 4 with Direction

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

Example 5 with Direction

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;
}
Also used : PrintStream(java.io.PrintStream) 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