Esempio n. 1
0
  private void ConnectKnowledgeBaseBtnMouseClicked(
      java.awt.event.MouseEvent evt) { // GEN-FIRST:event_ConnectKnowledgeBaseBtnMouseClicked

    String sPrjFile = ProjectNameTF.getText().trim();
    String sLocationURI = sURI + "Location";

    Collection errors = new ArrayList();
    Date d1 = new Date();
    long l1 = d1.getTime();
    prj = Project.loadProjectFromFile(sPrjFile, errors);
    owlModel = (OWLModel) prj.getKnowledgeBase();

    kb = prj.getKnowledgeBase();
    URI uri = prj.getActiveRootURI();

    Collection colNumberOfInstance = kb.getInstances();
    lNumberOfInstance = colNumberOfInstance.size();

    Date d2 = new Date();
    long l2 = d2.getTime();
    lLoadedTime = (l2 - l1);

    theLogger.info("Connected to MySQL in " + lLoadedTime + " ms");
    theLogger.info("KB has " + lNumberOfInstance + " instances");

    LoggingAreaTA.append("Project has " + lNumberOfInstance + " in total\n");
    LoggingAreaTA.append("Project is loaded in " + lLoadedTime + " ms\n");
  } // GEN-LAST:event_ConnectKnowledgeBaseBtnMouseClicked
Esempio n. 2
0
  // function to do the join use case
  public static void share() throws Exception {
    HttpPost method = new HttpPost(url + "/share");
    String ipAddress = null;

    Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
    while (en.hasMoreElements()) {
      NetworkInterface ni = (NetworkInterface) en.nextElement();
      if (ni.getName().equals("eth0")) {
        Enumeration<InetAddress> en2 = ni.getInetAddresses();
        while (en2.hasMoreElements()) {
          InetAddress ip = (InetAddress) en2.nextElement();
          if (ip instanceof Inet4Address) {
            ipAddress = ip.getHostAddress();
            break;
          }
        }
        break;
      }
    }

    method.setEntity(new StringEntity(username + ';' + ipAddress, "UTF-8"));
    try {
      ResponseHandler<String> responseHandler = new BasicResponseHandler();
      connIp = client.execute(method, responseHandler);
    } catch (IOException e) {
      System.err.println("Fatal transport error: " + e.getMessage());
      e.printStackTrace();
    }

    // get present time
    date = new Date();
    long start = date.getTime();

    // Execute the vishwa share process
    Process p = Runtime.getRuntime().exec("java -jar vishwa/JVishwa.jar " + connIp);

    String ch = "alive";
    System.out.println("Type kill to unjoin from the grid");

    while (!ch.equals("kill")) {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      ch = in.readLine();
    }

    p.destroy();

    date = new Date();
    long end = date.getTime();
    long durationInt = end - start;

    String duration = String.valueOf(durationInt);
    method = new HttpPost(url + "/shareAck");
    method.setEntity(new StringEntity(username + ";" + duration, "UTF-8"));
    try {
      client.execute(method);
    } catch (IOException e) {
      System.err.println("Fatal transport error: " + e.getMessage());
      e.printStackTrace();
    }
  }
Esempio n. 3
0
  // function to do the compute use case
  public static void compute() throws Exception {
    HttpPost method = new HttpPost(url + "/compute");

    method.setEntity(new StringEntity(username, "UTF-8"));

    try {
      ResponseHandler<String> responseHandler = new BasicResponseHandler();
      connIp = client.execute(method, responseHandler);
    } catch (IOException e) {
      System.err.println("Fatal transport error: " + e.getMessage());
      e.printStackTrace();
    }

    System.out.println("Give the file name which has to be put in the grid for computation");

    // input of the file name to be computed
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String name = in.readLine();

    // get the absolute path of the current working directory
    File directory = new File(".");
    String pwd = directory.getAbsolutePath();

    // get present time
    date = new Date();
    long start = date.getTime();

    String cmd = "java -classpath " + pwd + "/vishwa/JVishwa.jar:. " + name + " " + connIp;
    System.out.println(cmd);

    // Execute the vishwa compute process
    Process p = Runtime.getRuntime().exec(cmd);

    // wait till the compute process is completed
    // check for the status code (0 for successful termination)
    int status = p.waitFor();

    if (status == 0) {
      System.out.println("Compute operation successful. Check the directory for results");
    }

    date = new Date();
    long end = date.getTime();
    long durationInt = end - start;

    String duration = String.valueOf(durationInt);
    method = new HttpPost(url + "/computeAck");
    method.setEntity(new StringEntity(username + ";" + duration, "UTF-8"));
    try {
      client.execute(method);
    } catch (IOException e) {
      System.err.println("Fatal transport error: " + e.getMessage());
      e.printStackTrace();
    }
  }
  public SetIfModifiedSince() throws Exception {

    serverSock = new ServerSocket(0);
    int port = serverSock.getLocalPort();

    Thread thr = new Thread(this);
    thr.start();

    Date date = new Date(new Date().getTime() - 1440000); // this time yesterday
    URL url;
    HttpURLConnection con;

    // url = new URL(args[0]);
    url = new URL("http://localhost:" + String.valueOf(port) + "/anything");
    con = (HttpURLConnection) url.openConnection();

    con.setIfModifiedSince(date.getTime());
    con.connect();
    int ret = con.getResponseCode();

    if (ret == 304) {
      System.out.println("Success!");
    } else {
      throw new RuntimeException(
          "Test failed! Http return code using setIfModified method is:"
              + ret
              + "\nNOTE:some web servers are not implemented according to RFC, thus a failed test does not necessarily indicate a bug in setIfModifiedSince method");
    }
  }
Esempio n. 5
0
 /**
  * Returns the time that the file denoted by this abstract pathname was last modified.
  *
  * @return A <code>long</code> value representing the time the file was last modified, measured in
  *     system-dependent way.
  */
 public long lastModified() {
   try {
     Date date = ftpClient.lastModified(getPath());
     return date.getTime();
   } catch (IOException e) {
     return 0;
   } catch (FTPException e) {
     return 0;
   }
 }
Esempio n. 6
0
 public static long getDateHeader(String stringValue) throws ParseException {
   for (SimpleDateFormat dateHeaderFormat : dateHeaderFormats) {
     try {
       Date date = dateHeaderFormat.parse(stringValue);
       return date.getTime();
     } catch (
         Exception
             e) { // used to be ParseException, but NumberFormatException may be thrown as well
       // Ignore and try next
     }
   }
   throw new ParseException(stringValue, 0);
 }
  /**
   * Waits until either the State attribute of this MBean equals the specified <VAR>state</VAR>
   * parameter, or the specified <VAR>timeout</VAR> has elapsed. The method <CODE>waitState</CODE>
   * returns with a boolean value indicating whether the specified <VAR>state</VAR> parameter equals
   * the value of this MBean's State attribute at the time the method terminates.
   *
   * <p>Two special cases for the <VAR>timeout</VAR> parameter value are:
   *
   * <UL>
   *   <LI>if <VAR>timeout</VAR> is negative then <CODE>waitState</CODE> returns immediately (i.e.
   *       does not wait at all),
   *   <LI>if <VAR>timeout</VAR> equals zero then <CODE>waitState</CODE> waits until the value of
   *       this MBean's State attribute is the same as the <VAR>state</VAR> parameter (i.e. will
   *       wait indefinitely if this condition is never met).
   * </UL>
   *
   * @param state The value of this MBean's State attribute to wait for. <VAR>state</VAR> can be one
   *     of: <CODE>DiscoveryResponder.OFFLINE</CODE>, <CODE>DiscoveryResponder.ONLINE</CODE>, <CODE>
   *     DiscoveryResponder.STARTING</CODE>, <CODE>DiscoveryResponder.STOPPING</CODE>.
   * @param timeout The maximum time to wait for, in milliseconds, if positive. Infinite time out if
   *     0, or no waiting at all if negative.
   * @return <code>true</code> if the value of this MBean's State attribute is the same as the
   *     <VAR>state</VAR> parameter; <code>false</code> otherwise.
   */
  public boolean waitState(int state, long timeout) {
    if (logger.finerOn()) {
      logger.finer(
          "waitState",
          state + "(0on,1off,2st) TO=" + timeout + " ; current state = " + getStateString());
    }
    // ------------
    // Test timeout
    // ------------
    if (timeout < 0) {
      return (this.state == state);
    }

    boolean done = (this.state == state);
    Date currentDate;
    long currentTimeOut = -1;

    // -----------------
    // Date start
    // -----------------
    Date endDate = new Date((new Date()).getTime() + timeout);
    while (!done) {
      // -----------------
      // Find out timeout
      // ----------------
      if (timeout != 0) {
        currentTimeOut = endDate.getTime() - (new Date()).getTime();
        if (currentTimeOut <= 0) {
          done = true;
          break;
        }
      }

      try {
        synchronized (this) {
          if (timeout == 0) {
            if (logger.finerOn()) {
              logger.finer("waitState", "Start waiting infinite, current state = " + this.state);
            }
            done = (this.state == state);
            while (!done) {
              done = (this.state == state);
              try {
                wait(1000);
              } catch (Exception e) {
              }
            }
          } else {
            if (logger.finerOn()) {
              logger.finer(
                  "waitState",
                  "Start waiting " + currentTimeOut + " current state = " + this.state);
            }
            wait(currentTimeOut);
          }
        }
        done = (this.state == state);
      } catch (InterruptedException e) {
        done = (this.state == state);
      }
    }
    if (logger.finerOn()) {
      logger.finer("waitState", "End, TO=" + currentTimeOut);
    }
    return (this.state == state);
  }
Esempio n. 8
0
 /**
  * Returns a long containing the NTP value for a given Java Date.
  *
  * @param d Date to set
  * @return long
  */
 public static long getNtpTime(Date d) throws SdpParseException {
   if (d == null) return -1;
   return ((d.getTime() / 1000) + SdpConstants.NTP_CONST);
 }