Пример #1
0
 protected void stopSlave(String name) throws InterruptedException {
   ServerRunner sr = slaveRunners.get(name);
   if (sr == null) {
     throw new RuntimeException("Slave does not exist!");
   } else {
     sr.stop();
   }
 }
Пример #2
0
 protected void startMaster() throws Exception {
   master = new TPCMaster(NUMSLAVES, new KVCache(1, 4));
   SocketServer clientSocketServer = new SocketServer(hostname, CLIENTPORT);
   clientSocketServer.addHandler(new TPCClientHandler(master));
   masterClientRunner = new ServerRunner(clientSocketServer, "masterClient");
   masterClientRunner.start();
   SocketServer slaveSocketServer = new SocketServer(hostname, SLAVEPORT);
   slaveSocketServer.addHandler(new TPCRegistrationHandler(master));
   masterSlaveRunner = new ServerRunner(slaveSocketServer, "masterSlave");
   masterSlaveRunner.start();
   Thread.sleep(100);
 }
Пример #3
0
  @After
  public void tearDown() throws InterruptedException {
    masterClientRunner.stop();
    masterSlaveRunner.stop();

    for (ServerRunner slaveRunner : slaveRunners.values()) {
      slaveRunner.stop();
    }

    client = null;
    master = null;
    slaveRunners = null;
  }
Пример #4
0
  protected void startSlave(long slaveID) throws Exception {
    String name = new Long(slaveID).toString();
    ServerRunner sr = slaveRunners.get(slaveID);
    if (sr != null) {
      sr.start();
      return;
    }

    SocketServer ss = new SocketServer(InetAddress.getLocalHost().getHostAddress(), 0);
    KVServer slaveKvs = new KVServer(100, 10);
    String logPath = "bin/log." + slaveID + "@" + ss.getHostname();
    TPCLog log = new TPCLog(logPath, slaveKvs);
    TPCMasterHandler handler = new TPCMasterHandler(slaveID, slaveKvs, log);
    ss.addHandler(handler);
    ServerRunner slaveRunner = new ServerRunner(ss, name);
    slaveRunner.start();
    slaveRunners.put(name, slaveRunner);

    handler.registerWithMaster(InetAddress.getLocalHost().getHostAddress(), ss);
  }