Package se.sics.cooja.MoteType

Examples of se.sics.cooja.MoteType.MoteTypeCreationException


    // CHECK JNI CLASS AVAILABILITY
    String libString = CoreComm.getAvailableClassName();
    if (libString == null) {
      logger.fatal("No more libraries can be loaded!");
      throw new MoteTypeCreationException("Maximum number of mote types already exist");
    }

    // GENERATE NEW FILE
    BufferedWriter destFile = null;
    BufferedReader sourceFile = null;
View Full Code Here


        if (templateFileReader != null)
          templateFileReader.close();
      } catch (Exception e2) {
      }

      throw (MoteTypeCreationException) new MoteTypeCreationException(
          "Could not generate corecomm source file: " + className + ".java")
          .initCause(e);
    }

    File genFile = new File("se/sics/cooja/corecomm/" + destFilename);
    if (genFile.exists())
      return;

    throw (MoteTypeCreationException) new MoteTypeCreationException(
        "Could not generate corecomm source file: " + className + ".java");
  }
View Full Code Here

      if (classFile.exists())
        return;

    } catch (IOException e) {
      MoteTypeCreationException exception = (MoteTypeCreationException) new MoteTypeCreationException(
          "Could not compile corecomm source file: " + className + ".java")
          .initCause(e);
      exception.setCompilationOutput(compilationOutput);
      throw exception;
    } catch (InterruptedException e) {
      MoteTypeCreationException exception = (MoteTypeCreationException) new MoteTypeCreationException(
          "Could not compile corecomm source file: " + className + ".java")
          .initCause(e);
      exception.setCompilationOutput(compilationOutput);
      throw exception;
    }

    MoteTypeCreationException exception = new MoteTypeCreationException(
        "Could not compile corecomm source file: " + className + ".java");
    exception.setCompilationOutput(compilationOutput);
    throw exception;
  }
View Full Code Here

          .toURL() }, CoreComm.class.getClassLoader());
      loadedClass = urlClassLoader.loadClass("se.sics.cooja.corecomm."
          + className);

    } catch (MalformedURLException e) {
      throw (MoteTypeCreationException) new MoteTypeCreationException(
          "Could not load corecomm class file: " + className + ".class")
          .initCause(e);
    } catch (ClassNotFoundException e) {
      throw (MoteTypeCreationException) new MoteTypeCreationException(
          "Could not load corecomm class file: " + className + ".class")
          .initCause(e);
    }
    if (loadedClass == null)
      throw (MoteTypeCreationException) new MoteTypeCreationException(
          "Could not load corecomm class file: " + className + ".class");

    return loadedClass;
  }
View Full Code Here

      coreCommFiles.add(libFile);
      fileCounter++;

      return newCoreComm;
    } catch (Exception e) {
      throw (MoteTypeCreationException) new MoteTypeCreationException(
          "Error when creating corecomm instance: " + className).initCause(e);
    }
  }
View Full Code Here

        if (outputFile.exists()) {
          compilationOutput.addMessage("Error when deleting old " + outputFile.getName(), MessageList.ERROR);
          if (onFailure != null) {
            onFailure.actionPerformed(null);
          }
          throw new MoteTypeCreationException("Error when deleting old " + outputFile.getName());
        }
      }

      Thread readInput = new Thread(new Runnable() {
        public void run() {
          try {
            String readLine;
            while ((readLine = processNormal.readLine()) != null) {
              if (compilationOutput != null) {
                compilationOutput.addMessage(readLine, MessageList.NORMAL);
              }
            }
          } catch (IOException e) {
            logger.warn("Error while reading from process");
          }
        }
      }, "read input stream thread");

      Thread readError = new Thread(new Runnable() {
        public void run() {
          try {
            String readLine;
            while ((readLine = processError.readLine()) != null) {
              if (compilationOutput != null) {
                compilationOutput.addMessage(readLine, MessageList.ERROR);
              }
            }
          } catch (IOException e) {
            logger.warn("Error while reading from process");
          }
        }
      }, "read error stream thread");

      final MoteTypeCreationException syncException = new MoteTypeCreationException("");
      Thread handleCompilationResultThread = new Thread(new Runnable() {
        public void run() {

          /* Wait for compilation to end */
          try {
            compileProcess.waitFor();
          } catch (Exception e) {
            compilationOutput.addMessage(e.getMessage(), MessageList.ERROR);
            syncException.setCompilationOutput(new MessageList());
            syncException.fillInStackTrace();
            return;
          }

          /* Check return value */
          if (compileProcess.exitValue() != 0) {
            compilationOutput.addMessage("Process returned error code " + compileProcess.exitValue(), MessageList.ERROR);
            if (onFailure != null) {
              onFailure.actionPerformed(null);
            }
            syncException.setCompilationOutput(new MessageList());
            syncException.fillInStackTrace();
            return;
          }

          if (outputFile == null) {
            /* No firmware to generate: OK */
            if (onSuccess != null) {
              onSuccess.actionPerformed(null);
            }
            return;
          }

          if (!outputFile.exists()) {
            compilationOutput.addMessage("No firmware file: " + outputFile, MessageList.ERROR);
            if (onFailure != null) {
              onFailure.actionPerformed(null);
            }
            syncException.setCompilationOutput(new MessageList());
            syncException.fillInStackTrace();
            return;
          }

          compilationOutput.addMessage("", MessageList.NORMAL);
          compilationOutput.addMessage("Compilation succeded", MessageList.NORMAL);
          if (onSuccess != null) {
            onSuccess.actionPerformed(null);
          }
        }
      }, "handle compilation results");

      readInput.start();
      readError.start();
      handleCompilationResultThread.start();

      if (synchronous) {
        try {
          handleCompilationResultThread.join();
        } catch (Exception e) {
          /* Make sure process has exited */
          compileProcess.destroy();

          String msg = e.getMessage();
          if (e instanceof InterruptedException) {
            msg = "Aborted by user";
          }
          throw (MoteTypeCreationException) new MoteTypeCreationException(
              "Compilation error: " + msg).initCause(e);
        }

        /* Detect error manually */
        if (syncException.hasCompilationOutput()) {
          throw (MoteTypeCreationException) new MoteTypeCreationException(
          "Bad return value").initCause(syncException);
        }
      }
    } catch (IOException ex) {
      if (onFailure != null) {
        onFailure.actionPerformed(null);
      }
      throw (MoteTypeCreationException) new MoteTypeCreationException(
          "Compilation error: " + ex.getMessage()).initCause(ex);
    }

    return compileProcess;
  }
View Full Code Here

          templateFileReader.close();
        }
      } catch (Exception e2) {
      }

      throw (MoteTypeCreationException) new MoteTypeCreationException(
          "Could not generate corecomm source file: " + className + ".java")
          .initCause(e);
    }

    File genFile = new File("se/sics/cooja/corecomm/" + destFilename);
    if (genFile.exists()) {
      return;
    }

    throw new MoteTypeCreationException(
        "Could not generate corecomm source file: " + className + ".java");
  }
View Full Code Here

      if (classFile.exists()) {
        return;
      }

    } catch (IOException e) {
      MoteTypeCreationException exception = (MoteTypeCreationException) new MoteTypeCreationException(
          "Could not compile corecomm source file: " + className + ".java")
          .initCause(e);
      exception.setCompilationOutput(compilationOutput);
      throw exception;
    } catch (InterruptedException e) {
      MoteTypeCreationException exception = (MoteTypeCreationException) new MoteTypeCreationException(
          "Could not compile corecomm source file: " + className + ".java")
          .initCause(e);
      exception.setCompilationOutput(compilationOutput);
      throw exception;
    }

    MoteTypeCreationException exception = new MoteTypeCreationException(
        "Could not compile corecomm source file: " + className + ".java");
    exception.setCompilationOutput(compilationOutput);
    throw exception;
  }
View Full Code Here

          CoreComm.class.getClassLoader());
      loadedClass = urlClassLoader.loadClass("se.sics.cooja.corecomm."
          + className);

    } catch (MalformedURLException e) {
      throw (MoteTypeCreationException) new MoteTypeCreationException(
          "Could not load corecomm class file: " + className + ".class")
          .initCause(e);
    } catch (ClassNotFoundException e) {
      throw (MoteTypeCreationException) new MoteTypeCreationException(
          "Could not load corecomm class file: " + className + ".class")
          .initCause(e);
    }
    if (loadedClass == null) {
      throw new MoteTypeCreationException(
          "Could not load corecomm class file: " + className + ".class");
    }

    return loadedClass;
  }
View Full Code Here

      coreCommFiles.add(libFile);
      fileCounter++;

      return newCoreComm;
    } catch (Exception e) {
      throw (MoteTypeCreationException) new MoteTypeCreationException(
          "Error when creating corecomm instance: " + className).initCause(e);
    }
  }
View Full Code Here

TOP

Related Classes of se.sics.cooja.MoteType.MoteTypeCreationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.