Java Code Examples for java.lang.Thread#start()

The following examples show how to use java.lang.Thread#start() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Standby.java    From RDFS with Apache License 2.0 6 votes vote down vote up
/**
 * Instantiates ingest thread for the given edits file type
 * 
 * @param type (EDITS, EDITS_NEW)
 */
private void instantiateIngest(IngestFile type)
    throws IOException {
  File edits;
  InjectionHandler.processEvent(InjectionEvent.STANDBY_INSTANTIATE_INGEST);
  synchronized (ingestStateLock) {
    assertState(StandbyIngestState.NOT_INGESTING);
    edits = getIngestFile(type);
    // if the file does not exist, 
    // do not change the state
    if (!edits.exists()
        || InjectionHandler
            .falseCondition(InjectionEvent.STANDBY_EDITS_NOT_EXISTS, type)) {
      return;
    }
    setCurrentIngestFile(edits);
    ingest = new Ingest(this, fsnamesys, confg, edits);
    ingestThread = new Thread(ingest);
    ingestThread.start(); 
    currentIngestState = type == IngestFile.EDITS
        ? StandbyIngestState.INGESTING_EDITS
        : StandbyIngestState.INGESTING_EDITS_NEW;
  } 
  LOG.info("Standby: Instantiated ingest for edits file: " + edits.getName());
}
 
Example 2
Source File: MoveFactory.java    From eb-java-scorekeep with Apache License 2.0 4 votes vote down vote up
public Move newMove(String sessionId, String gameId, String userId, String moveText) throws SessionNotFoundException, GameNotFoundException, StateNotFoundException, RulesException {
  String moveId = Identifiers.random();
  String stateId = Identifiers.random();
  Move move = new Move().setId(moveId)
                        .setSession(sessionId)
                        .setGame(gameId)
                        .setUser(userId)
                        .setMove(moveText);
  String newStateText = "";
  // load game state
  Game game = gameController.getGame(sessionId, gameId);
  List<String> states = game.getStates();
  State oldState = stateController.getState(sessionId, gameId, states.get(states.size() - 1));
  Set<String> oldTurn = oldState.getTurn();
  // check turn 
  // if ( oldTurn.contains(userId) {}
  // load game rules
  //   rules = rulesFactory.getRules(rulesId)
  // apply move
  //   String stateText = rules.move(oldState, move)
  Set<String> newTurn = game.getUsers();
  if (newTurn.size() != 1) {
    newTurn.remove(userId);
  }
  String rulesName = game.getRules();
  if ( !rulesName.matches("[a-zA-Z]{1,16}") ) {
    throw new RulesException(rulesName);
  }
  try {
    Class<?> rules = Class.forName("scorekeep." + rulesName);
    Method moveMethod = rules.getMethod("move", String.class, String.class);
    newStateText = (String) moveMethod.invoke(null, oldState.getState(), moveText);
  } catch ( ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new RulesException(rulesName); }
  // save new game state
  State newState = new State(stateId, sessionId, gameId, newStateText, newTurn);
  // send notification on game end
  if ( newStateText.startsWith("A") || newStateText.startsWith("B")) {
    Thread comm = new Thread() {
      public void run() {
        Sns.sendNotification("Scorekeep game completed", "Winner: " + userId);
      }
    };
    comm.start();
  }
  // register state and move id to game
  gameController.setGameMove(sessionId, gameId, moveId);
  gameController.setGameState(sessionId, gameId, stateId);
  moveModel.saveMove(move);
  stateModel.saveState(newState);
  return move;
}
 
Example 3
Source File: SS.java    From journaldev with MIT License 4 votes vote down vote up
public ConnectionHandler1(Socket socket) {
    this.socket = socket;
 
    Thread t = new Thread(this);
    t.start();
}