Package com.splout.db.common.PortUtils

Examples of com.splout.db.common.PortUtils.PortLock


      throws EngineException {

    File dbFolder = dbFile.getParentFile();
    File mysqlFolder = new File(dbFolder, "mysql");

    PortLock portLock = PortUtils.getNextAvailablePort(EmbeddedMySQLConfig.DEFAULT_PORT);
    try {
      EmbeddedMySQLConfig mysqlConfig = new EmbeddedMySQLConfig(portLock.getPort(),
          EmbeddedMySQLConfig.DEFAULT_USER, EmbeddedMySQLConfig.DEFAULT_PASS, mysqlFolder, null);
      mySQL = new EmbeddedMySQL(mysqlConfig);
      // Trick: start mysql first on the empty dir, stop it, uncompress data, start it again
      // This is because mySQL creates some databases by default which doesn't create if "data" already exists
      // So we don't need to add them to the produced zip (1.6 MB less).
      mySQL.start(true);
      mySQL.stop();

      CompressorUtil.uncompress(dbFile, mysqlFolder);

      mySQL.start(false);

      initializeMySQL(mysqlConfig);
    } catch(IOException e) {
      throw new EngineException(e);
    } catch(InterruptedException e) {
      throw new EngineException(e);
    } catch(SQLException e) {
      throw new EngineException(e);
    } catch(ClassNotFoundException e) {
      throw new EngineException(e);
    } finally {
      portLock.release();
    }
  }
View Full Code Here


              new String[] { "ln", "-s", actualDataFile.getAbsolutePath(),
                  thisDataFile.getAbsolutePath() }).waitFor();
      FileUtils.copyFile(new File(redisExecutable), thisServer);
      thisServer.setExecutable(true);

      PortLock portLock = PortUtils.getNextAvailablePort(basePort);
      try {
        logger.info("Using port from port lock: " + portLock.getPort());
        redisServer = new RedisServer(thisServer, portLock.getPort());
        redisServer.start();
        jedis = new Jedis("localhost", portLock.getPort());
      } finally {
        portLock.release();
      }
    } catch(InterruptedException e) {
      throw new EngineException(e);
    } catch(IOException e) {
      throw new EngineException(e);
View Full Code Here

      final int threadId = i;
      pool[i] = new Thread() {
        @SuppressWarnings("unchecked")
        public void run() {
          setName("thread_" + threadId);
          PortLock portLock = PortUtils.getNextAvailablePort(EmbeddedMySQLConfig.DEFAULT_PORT);
          map.put(getName(), portLock);
        }
      };
      pool[i].start();
    }
   
    long sleptSoFar = 0;
    do {
      Thread.sleep(500);
      sleptSoFar += 500;
      if(sleptSoFar > 5000) {
        throw new RuntimeException("Waited too much");
      }
    } while(map.keySet().size() < N_THREADS);
   
    Set<Integer> distinctPorts = new HashSet<Integer>();
    for(Object entry: map.entrySet()) {
      PortLock pLock = (PortLock)((Map.Entry)entry).getValue();
      distinctPorts.add(pLock.getPort());
      pLock.release();
    }
   
    // Assert every thread locked on a different port
    assertEquals(distinctPorts.size(), map.keySet().size());
  }
View Full Code Here

    Path mysqlDb = new Path(local.getParent(), partition + "");

    LOG.info("Initializing SQL connection [" + partition + "]");
    try {
      PortLock portLock = PortUtils.getNextAvailablePort(EmbeddedMySQLConfig.DEFAULT_PORT);

      EmbeddedMySQL mySQL = null;
      EmbeddedMySQLConfig config = null;

      try {
        File mysqlDir = new File(mysqlDb.toString());
        LOG.info("Going to instantiate a MySQLD in: " + mysqlDir + ", port [" + portLock.getPort()
            + "] (partition: " + partition + ")");

        config = new EmbeddedMySQLConfig(portLock.getPort(), EmbeddedMySQLConfig.DEFAULT_USER,
            EmbeddedMySQLConfig.DEFAULT_PASS, mysqlDir, null);
        mySQL = new EmbeddedMySQL(config);
        mySQL.start(true);
      } catch(Exception e) {
        throw e;
      } finally {
        portLock.release();
      }

      mySQLs.put(partition, mySQL);

      // MySQL is successfully started at this point, or an Exception would have been thrown.
View Full Code Here

TOP

Related Classes of com.splout.db.common.PortUtils.PortLock

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.