コード例 #1
0
ファイル: FSWatch.java プロジェクト: micheee/DeepFS
  /**
   * Creates a WatchService and registers the given directory.
   *
   * @param dir root of file hierarchy to monitor
   * @param recursive whether to watch recursively
   * @param v call back reference to produce FSML output on events
   * @throws IOException in case of failure
   */
  public FSWatch(final Path dir, final boolean recursive, final FSMLVisitor v) throws IOException {
    this.watcher = FileSystems.getDefault().newWatchService();
    this.keys = new HashMap<WatchKey, Path>();
    this.recursive = recursive;
    this.fsml = v;

    if (recursive) {
      System.err.format("%s Scanning %s ...\n", NAME, dir);
      registerAll(dir);
      System.err.println(NAME + " Done.");
    } else {
      register(dir);
    }

    // enable trace after initial registration
    this.trace = true;

    session = new ClientSession(Conf.DBHOST, Conf.DBPORT, Conf.DBUSER, Conf.DBPASS);
    try {
      String r = session.execute("open " + Conf.DBNAME);
      System.err.print(NAME + " " + r + session.info());
    } catch (BaseXException e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
ファイル: ServerMemTest.java プロジェクト: fpapai/basex
 @Override
 public void run() {
   try {
     // Perform query
     session.execute("xquery " + QUERY);
     session.close();
   } catch (final Exception ex) {
     ex.printStackTrace();
   }
 }
コード例 #3
0
ファイル: ClientSession.java プロジェクト: JosuaKrause/basex
  /**
   * Executes a command and sends the result to the specified output stream.
   *
   * @param cmd server command
   * @param arg argument
   * @param os target output stream
   * @return string
   * @throws IOException I/O exception
   */
  protected String exec(final ServerCmd cmd, final String arg, final OutputStream os)
      throws IOException {

    final OutputStream o = os == null ? new ArrayOutput() : os;
    sout.write(cmd.code);
    send(arg);
    sout.flush();
    final BufferInput bi = new BufferInput(sin);
    ClientSession.receive(bi, o);
    if (!ClientSession.ok(bi)) throw new BaseXException(bi.readString());
    return o.toString();
  }
コード例 #4
0
 /**
  * Runs the stress test.
  *
  * @param clients number of clients
  * @param runs number of runs per client
  * @throws Exception exception
  */
 private void run(final int clients, final int runs) throws Exception {
   // run server instance
   server = createServer();
   // create test database
   try (final ClientSession cs = createClient()) {
     cs.execute("create db test <test/>");
     // run clients
     final Client[] cl = new Client[clients];
     for (int i = 0; i < clients; ++i) cl[i] = new Client(runs, i % 2 == 0);
     for (final Client c : cl) c.start();
     for (final Client c : cl) c.join();
     // drop database and stop server
     cs.execute("drop db test");
   }
   stopServer(server);
 }
コード例 #5
0
 @Override
 public void run() {
   try {
     // Perform some queries
     for (int i = 0; i < runs; ++i) {
       final String qu =
           read
               ? "count(db:open('test'))"
               : "db:add('test', <a/>, 'test.xml', map { 'intparse': true() })";
       session.execute("xquery " + qu);
     }
     session.close();
   } catch (final Exception ex) {
     ex.printStackTrace();
   }
 }
コード例 #6
0
 /**
  * Constructor.
  *
  * @param runs number of runs
  * @param read read flag
  * @throws Exception exception
  */
 Client(final int runs, final boolean read) throws Exception {
   this.runs = runs;
   this.read = read;
   session = createClient();
   session.execute("set autoflush false");
 }