// attempts to remove the player with the specified id form the lobby public boolean removePlayerById(Player p1) { if (this.status == LobbyStatus.STARTED) { // lobby is already started, so we don't want to touch it Log.warning("Lobby(" + this.id + ") Cannot remove player from lobby: is already started."); return false; } // we need an iterator over the players Iterator<Player> iter = this.players.listIterator(); while (iter.hasNext()) { Player p2 = iter.next(); if (p1.getId() == p2.getId()) { // if the IDs are the same, remove the player form the lobby iter.remove(); Log.info("Lobby(" + this.id + "): Removed " + p2 + " from Lobby."); if (this.status == LobbyStatus.READY) { // lobby was ready (however, the gameStart()-message is // still on it's way somewhere), so it is WAITING now this.status = LobbyStatus.WAITING; Log.info("Lobby(" + this.id + "): Lobby is now waiting for players again."); return true; } } } return false; }
private void tabbedPaneStateChanged( javax.swing.event.ChangeEvent evt) { // GEN-FIRST:event_tabbedPaneStateChanged // Add your handling code here: try { AbstractPage newPage = (AbstractPage) tabbedPane.getSelectedComponent(); Log.print( "AdminFrame.stateChanged: currentPage: " + (currentPage == null ? "null" : currentPage.getClass().getName())); // ignore if we aren't changing tabs // presumably, we failed to change tabs and are now resetting // also ignore first time -- we do at window opening if (currentPage == newPage || currentPage == null) { return; } // Log.print("AdminFrame.stateChanged: newPage: " + newPage.getClass().getName()); // tab doesn't get focus before switch, so we need to check here that // this tab switch is acceptable // Also, initial tab setting could happen before window is visible, // so we do the initial call in the WindowOpening event if (currentPage.exitPageCheck()) { // open the page openNewPage(newPage); } else { // page did not permit exit (e.g., failed save check) tabbedPane.setSelectedComponent(currentPage); } } catch (Throwable t) { Log.quit(t); } } // GEN-LAST:event_tabbedPaneStateChanged
/** * Create a <code>ManagedTable</code> instance and add it to the static ArrayList of instances. * * @param name the table name of this instance */ private ManagedTable(String name) { this.tableName = name; tableList.add(this); tableNumber = tableList.size() - 1; Log.print(this.toString()); if (tableNumber > 127) { Log.quit("Too many managed tables"); } }
// manages acknowledgements of Players (provided the lobby is in the correct // state and Player is member of the lobby) // when this was the last player who acknowledged the lobby has nothing to // do anymore. Therefore, its status is set to DONE, so that the // LobbyManager knows that its safe to delete the lobby public boolean gameStartAckFromPlayer(Player p1) { boolean retVal = false; boolean allAcknowledged = true; // if the lobby is not in the started phase, the game hasn't started yet // therefore, it makes no sense for a player to claim a successful start // of the game if (this.status != LobbyStatus.STARTED) { if (this.containsPlayerByIdCheck(p1)) { Log.warning( "Lobby(" + this.id + "): Player " + p1 + " acknowledged start of game, even though it hasn\'t" + " started yet."); } return false; } // iterate through all players which are member of this lobby for (Player p2 : this.players) { // if the IDs are identical if (p1.getId() == p2.getId()) { // we register the acknowledge p2.acknowledged(); Log.info( "Lobby(" + this.id + "): Player " + p2 + " successfully acknowledged start of the game."); // and indicate a successful acknowledgement retVal = true; // HOWEVER we are not done yet because of our small side-task: // we need to check all other players in the lobby whether they // also have already acknowledged their successful game-start } else if (p2.hasAcknowledged() == false) { allAcknowledged = false; } } if (allAcknowledged) { Log.info( "Lobby(" + this.id + "): All players have acknowledged." + " This lobby\'s job is done."); this.status = LobbyStatus.DONE; } return retVal; }
@Override public void run() { running = true; done = false; Log.println("WAV Source START"); if (audioStream == null) try { initWav(); } catch (UnsupportedAudioFileException e1) { Log.errorDialog("ERROR", "Unsupported File Format\n" + e1.getMessage()); e1.printStackTrace(Log.getWriter()); running = false; } catch (IOException e1) { Log.errorDialog("ERROR", "There was a problem opening the wav file\n" + e1.getMessage()); e1.printStackTrace(Log.getWriter()); running = false; } while (running) { // Log.println("wav running"); if (audioStream != null) { int nBytesRead = 0; if (circularBuffer.getCapacity() > readBuffer.length) { try { nBytesRead = audioStream.read(readBuffer, 0, readBuffer.length); bytesRead = bytesRead + nBytesRead; framesProcessed = framesProcessed + nBytesRead / frameSize; // Check we have not stopped mid read if (audioStream == null) running = false; else if (!(audioStream.available() > 0)) running = false; } catch (IOException e) { Log.errorDialog("ERROR", "Failed to read from file " + fileName); e.printStackTrace(Log.getWriter()); } } else { try { Thread.sleep(1); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Log.println("No room in Buffer"); } for (int i = 0; i < nBytesRead; i += 2) { // circularBuffer.add(readBuffer[i]); circularBuffer.add(readBuffer[i], readBuffer[i + 1]); } } } framesProcessed = totalFrames; cleanup(); // This might cause the decoder to miss the end of a file (testing inconclusive) but // it also ensure the file is close and stops an error if run again very quickly running = false; try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } Log.println("WAV Source EXIT"); }
private void initWav() throws UnsupportedAudioFileException, IOException { readBuffer = new byte[DEFAULT_READ_BUFFER_SIZE]; // circularBuffer = new CircularByteBuffer(67200*3); Log.println("Wavefile: " + fileName); File soundFile = null; soundFile = new File(fileName); audioStream = AudioSystem.getAudioInputStream(soundFile); audioFormat = audioStream.getFormat(); Config.wavSampleRate = (int) audioFormat.getSampleRate(); Log.println("Format: " + audioFormat); totalFrames = audioStream.getFrameLength(); frameSize = audioFormat.getFrameSize(); Log.println("Length (frames): " + totalFrames); bytesRead = 0; framesProcessed = 0; }
public void cleanup() { try { if (audioStream != null) audioStream.close(); audioStream = null; // This will prevent us from trying one last read from the file and generating an // exception } catch (IOException e) { e.printStackTrace(Log.getWriter()); } // Give the decoder time to finish - not sure this makes any difference though?? if (circularBuffer.size() > 0) { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(Log.getWriter()); } } done = true; }
/** * Performs this action`s penalty on a selected player. * * @param data The current data to work on. * @param player The player to penalise. * @param side The side the player is playing on (0:left, 1:right). * @param number The player`s number, beginning with 0! */ @Override public void performOn(AdvancedData data, PlayerInfo player, int side, int number) { player.penalty = PlayerInfo.PENALTY_SPL_PLAYING_WITH_HANDS; data.whenPenalized[side][number] = data.getTime(); Log.state( data, "Playing with Hands " + Rules.league.teamColorName[data.team[side].teamColor] + " " + (number + 1)); }
/** Write the message with attributes and set the result. */ @Override public void run() throws IOException { MessageWriter writer = scon.startMessage(T_BINDER_UPDATE); writer.writeAttribute(A_PAGE_ID, pageId); if (isToRemovePage) { writer.writeAttribute(A_REMOVE, "YES"); } addStandardAttributes(writer); writer.endElement(); writer.close(); Log.print("(TaskBinderUpdate.run) page=" + pageId + " isToRemovePage=" + isToRemovePage); Element reply = scon.receiveMessage(); String ok = reply.getNodeName(); if (!T_OK.equals(ok) && !T_FAIL.equals(ok)) { Log.quit("BatchBoundary unexpected message type: " + ok); } }
private static int chooseQAChildrenForCoder(ServerTask task, int percent, int usersId) throws SQLException, IOException { Statement st = task.getStatement(); ResultSet rs = st.executeQuery( "select count(*)" + " from child C" + " inner join batch B using (batch_id)" + " left join batchuser BU using (batch_id)" + " left join childcoded CC" + " on C.child_id=CC.child_id and CC.round=0" + " where B.volume_id=" + task.getLockVolumeId() + " and B.status='QA'" + " and BU.coder_id=" + usersId + " and CC.child_id is null"); rs.next(); int availableCount = rs.getInt(1); rs.close(); int selectCount = (availableCount * percent + 99) / 100; int count = st.executeUpdate( "insert into childcoded (child_id, status)" + " select C.child_id, 'QA'" + " from child C" + " inner join batch B using (batch_id)" + " left join batchuser BU using (batch_id)" + " left join childcoded CC" + " on C.child_id=CC.child_id and CC.round=0" + " where B.volume_id=" + task.getLockVolumeId() + " and B.status='QA'" + " and CC.child_id is null" + " and BU.coder_id=" + usersId + " order by rand()" + " limit " + selectCount); Log.print( "chooseQAChildrenForCoder: volume=" + task.getLockVolumeId() + " count=" + count + " usersId=" + usersId); return count; }
/** * Performs this action`s penalty on a selected player. * * @param data The current data to work on. * @param player The player to penalise. * @param side The side the player is playing on (0:left, 1:right). * @param number The player`s number, beginning with 0! */ @Override public void performOn(AdvancedData data, PlayerInfo player, int side, int number) { player.penalty = PlayerInfo.PENALTY_HL_ILLEGAL_DEFENSE; handleRepeatedPenalty(data, player, side, number); data.whenPenalized[side][number] = data.getTime(); Log.state( data, "Illegal Defense " + Rules.league.teamColorName[data.team[side].teamColor] + " " + (number + 1)); }
/** * Remove a log file from disk and report any errors. * * @param f * @throws IOException */ public static void remove(String f) throws IOException { try { // if (!Config.logFileDirectory.equalsIgnoreCase("")) { // f = Config.logFileDirectory + File.separator + f; // //System.err.println("Loading: "+log); // } File file = new File(f); if (file.exists()) if (file.delete()) { Log.println(file.getName() + " is deleted!"); } else { Log.println("Delete operation failed for: " + file.getName()); throw new IOException( "Could not delete file " + file.getName() + " Check the file system and remove it manually."); } } catch (Exception ex) { JOptionPane.showMessageDialog( MainWindow.frame, ex.toString(), "Error Deleting File", JOptionPane.ERROR_MESSAGE); } }
@Override public void actionPerformed(ActionEvent e) { boolean refreshTabs = false; if (e.getSource() == btnGetT0) { MainWindow.updateManager.updateT0(sat); updateTimeSeries(); } if (e.getSource() == btnCancel) { this.dispose(); } if (e.getSource() == btnSave) { try { try { sat.telemetryDownlinkFreqkHz = Integer.parseInt(telemetryDownlinkFreqkHz.getText()); sat.minFreqBoundkHz = Integer.parseInt(minFreqBoundkHz.getText()); sat.maxFreqBoundkHz = Integer.parseInt(maxFreqBoundkHz.getText()); } catch (NumberFormatException ex) { throw new Exception("The Frequency fields must contain a valid number"); } if (sat.rssiLookUpTableFileName != rssiLookUpTableFileName.getText()) { sat.rssiLookUpTableFileName = rssiLookUpTableFileName.getText(); refreshTabs = true; } if (sat.ihuTempLookUpTableFileName != ihuTempLookUpTableFileName.getText()) { sat.ihuTempLookUpTableFileName = ihuTempLookUpTableFileName.getText(); refreshTabs = true; } if (sat.ihuVBattLookUpTableFileName != ihuVBattLookUpTableFileName.getText()) { sat.ihuVBattLookUpTableFileName = ihuVBattLookUpTableFileName.getText(); refreshTabs = true; } if (sat.BATTERY_CURRENT_ZERO != Double.parseDouble(BATTERY_CURRENT_ZERO.getText())) { sat.BATTERY_CURRENT_ZERO = Double.parseDouble(BATTERY_CURRENT_ZERO.getText()); refreshTabs = true; } if (sat.useIHUVBatt != useIHUVBatt.isSelected()) { sat.useIHUVBatt = useIHUVBatt.isSelected(); refreshTabs = true; } sat.track = track.isSelected(); if (refreshTabs) MainWindow.refreshTabs(false); sat.save(); this.dispose(); } catch (Exception Ex) { Log.errorDialog("Invalid Paramaters", Ex.getMessage()); } } }
public int addPlayer(Player newPlayer) { // check whether this lobby is still able to accept new players if (this.isFull()) { // if not, return some error value Log.info("Lobby(" + this.id + ") cannot accept a new player: is already full!"); return -17; } // check whether the specified name is already registered in this lobby for (Player player : this.players) { if (newPlayer.getName().equals(player.getName())) { Log.info( "Lobby(" + this.id + ") cannot accept new player " + newPlayer + ": Name already exists in this lobby: " + player); return -2; } } // otherwise add player to lobby this.players.add(newPlayer); Log.info("Lobby(" + this.id + "): Added " + newPlayer); // now check whether lobby is full if (this.players.size() == this.slots) { // if yes, lobby is ready to start this.status = LobbyStatus.READY; Log.info("Lobby(" + this.id + ") is ready to start!"); // so announce it ServerBroadcaster.sendMsgGameStart(this.id); } return newPlayer.getId(); }
// attempts to move the first player from this lobby (the one which is at // the first position of the players-queue) to otherLobby public boolean moveFirstPlayerTo(Lobby otherLobby) { if (otherLobby.isFull()) { Log.warning( "Lobby(" + this.id + "): Tried to move a player to a lobby which is full." + " Aborting."); return false; } Player player = this.players.remove(0); Log.info("Lobby(" + this.id + "): movePlayer: Player " + player + "removed."); if (this.status == LobbyStatus.READY) { // lobby was ready (however, the gameStart()-message is // still on it's way somewhere), so it is WAITING now Log.info("Lobby(" + this.id + "): is now waiting again (was ready)"); this.status = LobbyStatus.WAITING; return true; } return otherLobby.addPlayer(player) >= 0; }
public void changePlayersNameByInterfaceCheck(Player p1) { if (this.status != LobbyStatus.WAITING && this.status != LobbyStatus.READY) { // name changes are only allowed as long as the game is not started // yet return; } for (Player p2 : this.players) { if (p1.getClientInterface() == p2.getClientInterface()) { Log.info("Lobby(" + this.id + "): Change name of " + p2 + " to " + p1.getName()); p2.setName(p1.getName()); } } }
/** Exit the Application. Note: This may be called from the various tab pages. */ public void exitForm(java.awt.event.WindowEvent evt) { // GEN-FIRST:event_exitForm try { // close the server and image server connections gently // TBD: really should be in a client task Log.print("AdminFrame.exitForm"); try { client.Global.theServerConnection.shutdown(); closeSession(evt); } catch (Exception e) { } try { synchronized (ImageThread.class) { if (Global.theImageConnection != null) { Global.theImageConnection.shutdown(); } } } catch (Exception e) { } System.exit(0); } catch (Throwable th) { Log.quit(th); } System.exit(0); } // GEN-LAST:event_exitForm
/** * Add a measurement set to this Sats store * * @param id * @param m * @return * @throws IOException */ public boolean add(int id, Measurement m) throws IOException { if (m instanceof RtMeasurement) { try { save(m, rtFileName); } catch (IOException e) { // NEED TO SET A FLAG HERE THAT IS THEN SEEN BY THE GUI WHEN IT POLLS FOR RESULTS e.printStackTrace(Log.getWriter()); } rtRecords.add(m); updatedRt = true; return true; } else if (m instanceof PassMeasurement) { try { save(m, passFileName); } catch (IOException e) { // NEED TO SET A FLAG HERE THAT IS THEN SEEN BY THE GUI WHEN IT POLLS FOR RESULTS e.printStackTrace(Log.getWriter()); } passRecords.add(m); updatedPass = true; return true; } return false; }
private void formWindowOpened( java.awt.event.WindowEvent evt) { // GEN-FIRST:event_formWindowOpened // Add your handling code here: try { // Close the login frame, if any. (This is done the first time the window is made visible.) if (loginFrame != null) { loginFrame.dispose(); loginFrame = null; } // hide any invalid pages if (!Global.theServerConnection.getPermissionAdmin() && !Global.theServerConnection.getPermissionTeamLeader()) { tabbedPane.remove(sessionPanel); } if (!Global.theServerConnection.getPermissionAdminProject()) { tabbedPane.remove(projectPanel); } if (!Global.theServerConnection.getPermissionAdminUsers()) { tabbedPane.remove(userAdminPanel); tabbedPane.remove(teamAdminPanel); } if (!Global.theServerConnection.getPermissionAdminImport()) { tabbedPane.remove(importPanel); tabbedPane.remove(populatePanel); } if (!Global.theServerConnection.getPermissionAdminExport()) { tabbedPane.remove(exportPanel); } if (!Global.theServerConnection.getPermissionAdminProfit()) { tabbedPane.remove(receivablesPanel); } if (!Global.theServerConnection.getPermissionAdminBatch()) { tabbedPane.remove(batchingPanel); } if (!Global.theServerConnection.getPermissionAdmin()) { tabbedPane.remove(tablePanel); tabbedPane.remove(reportPanel); tabbedPane.remove(sessionPanel); } // Open the first page, after window is open AbstractPage newPage = (AbstractPage) tabbedPane.getSelectedComponent(); openNewPage(newPage); } catch (Throwable t) { Log.quit(t); } } // GEN-LAST:event_formWindowOpened
/** * Create the payload store this this fox id * * @param id */ public SatMeasurementStore(int id) { foxId = id; initArrays(); try { rtFileName = "Fox" + id + RT_LOG; passFileName = "Fox" + id + PASS_LOG; load(rtFileName); load(passFileName); } catch (FileNotFoundException e) { JOptionPane.showMessageDialog( MainWindow.frame, e.toString(), "ERROR Loading Stored Payload data", JOptionPane.ERROR_MESSAGE); e.printStackTrace(Log.getWriter()); } }
public void closeSession(java.awt.event.WindowEvent evt) { try { // close the server and image server connections gently // TBD: really should be in a client task try { // client.Global.theServerConnection.shutdown(); final ClientTask task; task = new TaskGoodbye(); task.enqueue(this); } catch (Exception e) { } // try { // client.Global.theImageConnection.shutdown(); // } catch (Exception e) { // } System.exit(0); } catch (Throwable th) { Log.quit(th); } }
public void run(ServerTask task, Element action) { try { // Log.print("Handler_delimiter_data"); Element givenValueList = action; // Note. "child" may be ignored white space, if not validating parser Node firstChild = givenValueList.getFirstChild(); while (firstChild != null && firstChild.getNodeType() != Node.ELEMENT_NODE) { firstChild = firstChild.getNextSibling(); } if (firstChild != null) { DelimiterData data = new DelimiterData(); // fill in the int and String fields of DelimiterData MessageReader.decode(givenValueList, data, /* trim? */ false); if (data != null) { // update or insert the export row contained in data // Log.print("(Handler_delimiter_data.run) project is " + data.delimiter_set_name); saveDelimiterData(task, data); } } } catch (Throwable t) { Log.quit(t); } }
/** * Add a dependency, where this table has a field pointing to a target table. A change to this * table causes a change to the target table. Must be explicitly called from Tables. */ public void addDependency(ManagedTable targetTable, String columnName) { String targetName = targetTable.tableName; targetTables.add(targetTable); targetIdColumn.add(columnName); Log.print(tableName + " added dependency: " + targetName); }
private void saveDelimiterData(ServerTask task, DelimiterData data) throws java.io.IOException { try { Log.print("(Handler_delimiter_data.save) '" + data.value_separator + "'"); Connection con = task.getConnection(); Statement st = task.getStatement(); PreparedStatement pst = null; if (data.force.equals("")) { // delete pst = con.prepareStatement("delete from export" + " where export_name = ?"); pst.setString(1, data.delimiter_set_name); pst.executeUpdate(); } else { // see if the export_name exists pst = con.prepareStatement("select export_name" + " from export" + " where export_name=?"); pst.setString(1, data.delimiter_set_name); ResultSet rs = pst.executeQuery(); if (rs.next()) { // Log.print("(Handler_export_data.saveExportData) update " + data.delimiter_set_name); // update rs.close(); pst = con.prepareStatement( "update export set" + " force_export = ?," + " uppercase = ?," + " uppercase_names = ?," + " field_delimiter = ?," + " text_qualifier = ?," + " value_separator = ?," + " date_format = ?," + " missing_date = ?," + " missing_year = ?," + " missing_month = ?," + " missing_day = ?," + " missing_date_character = ?," + " name_mask1 = ?," + " name_mask2 = ?," + " name_mask3 = ?," + " name_mask4 = ?," + " brs_format = ?" + " where export_name = ?"); pst.setString(1, data.force); pst.setString(2, data.uppercase); pst.setString(3, data.uppercase_names); pst.setString(4, data.field_delimiter); pst.setString(5, data.text_qualifier); pst.setString(6, data.value_separator); pst.setString(7, data.date_format); pst.setString(8, data.missing_date); pst.setString(9, data.missing_year); pst.setString(10, data.missing_month); pst.setString(11, data.missing_day); pst.setString(12, data.missing_date_character); pst.setString(13, data.name_mask1); pst.setString(14, data.name_mask2); pst.setString(15, data.name_mask3); pst.setString(16, data.name_mask4); pst.setString(17, data.brs_format); pst.setString(18, data.delimiter_set_name); pst.executeUpdate(); pst.close(); } else { // insert // Log.print("(Handler_export_data.saveExportData) insert " + data.delimiter_set_name); rs.close(); pst = con.prepareStatement( "insert into export set" + " force_export = ?," + " uppercase = ?," + " uppercase_names = ?," + " field_delimiter = ?," + " text_qualifier = ?," + " value_separator = ?," + " date_format = ?," + " missing_date = ?," + " missing_year = ?," + " missing_month = ?," + " missing_day = ?," + " missing_date_character = ?," + " export_name = ?," + " name_mask1 = ?," + " name_mask2 = ?," + " name_mask3 = ?," + " name_mask4 = ?," + " brs_format = ?"); pst.setString(1, data.force); pst.setString(2, data.uppercase); pst.setString(3, data.uppercase_names); pst.setString(4, data.field_delimiter); pst.setString(5, data.text_qualifier); pst.setString(6, data.value_separator); pst.setString(7, data.date_format); pst.setString(8, data.missing_date); pst.setString(9, data.missing_year); pst.setString(10, data.missing_month); pst.setString(11, data.missing_day); pst.setString(12, data.missing_date_character); pst.setString(13, data.delimiter_set_name); pst.setString(14, data.name_mask1); pst.setString(15, data.name_mask2); pst.setString(16, data.name_mask3); pst.setString(17, data.name_mask4); pst.setString(18, data.brs_format); pst.executeUpdate(); pst.close(); } } pst.close(); } catch (Throwable t) { Log.quit(t); } MessageWriter writer = task.getMessageWriter(); writer.startElement(T_OK); writer.endElement(); }
/** * Choose given percentage of children in QA status from all teams from the volume open for QA by * the current user. Selecton is done on a team-by-team basis, so each team has at least the given * percentage. A batch is assumed to belong to the team indicated by the last coder to open it. * Selection is also made for a "null" team, for users who have no team assigned. * * @param task current ServerTask to handle the connection from the client to the coding server * @param percent the percentage of children to sample * @return the number of children chosen */ public static int chooseQAChildren(ServerTask task, int percent) throws SQLException, IOException { Statement st = task.getStatement(); ResultSet rs = st.executeQuery( "select teams_id, count(*)" + " from child C" + " inner join batch B using (batch_id)" + " left join batchuser BU using (batch_id)" + " left join users U on U.users_id = BU.coder_id" + " left join childcoded CC" + " on C.child_id=CC.child_id and CC.round=0" // and CC.users_id=0" + " where B.volume_id=" + task.getLockVolumeId() + " and B.status='QA'" + " and CC.child_id is null" + " group by U.teams_id"); ArrayList teams = new ArrayList(); ArrayList counts = new ArrayList(); while (rs.next()) { teams.add(new Integer(rs.getInt(1))); counts.add(new Integer(rs.getInt(2))); } rs.close(); int count = 0; for (int i = 0; i < teams.size(); i++) { int availableCount = ((Integer) counts.get(i)).intValue(); int teamsId = ((Integer) teams.get(i)).intValue(); int selectCount = (availableCount * percent + 99) / 100; count += st.executeUpdate( "insert into childcoded (child_id, status)" + " select C.child_id, 'QA'" + " from child C" + " inner join batch B using (batch_id)" + " left join batchuser BU using (batch_id)" + " left join users U on U.users_id = BU.coder_id" + " left join childcoded CC" + " on C.child_id=CC.child_id and CC.round=0" // and CC.users_id=0" + " where B.volume_id=" + task.getLockVolumeId() + " and B.status='QA'" + " and CC.child_id is null" + " and (teams_id=" + teamsId + " or teams_id is null and " + teamsId + "=0)" + " order by rand()" + " limit " + selectCount); System.out.println("... team=" + teamsId + " selectCount=" + selectCount + " count=" + count); } Log.print("chooseQAChildren: volume=" + task.getLockVolumeId() + " count=" + count); return count; }
private static int chooseQAChildrenForTeam(ServerTask task, int percent, int teamsId) throws SQLException, IOException { Statement st = task.getStatement(); ResultSet rs = st.executeQuery( "select count(*)" + " from child C" + " inner join batch B using (batch_id)" + " left join batchuser BU using (batch_id)" + " left join users U on U.users_id = BU.coder_id" + " left join childcoded CC" + " on C.child_id=CC.child_id and CC.round=0" + " where B.volume_id=" + task.getLockVolumeId() + " and B.status='QA'" + " and U.teams_id=" + teamsId + " and CC.child_id is null" + " group by U.teams_id"); int availableCount = (rs.next() ? rs.getInt(1) : 0); rs.close(); int count = 0; if (availableCount > 0) { int selectCount = (availableCount * percent + 99) / 100; // Note: this SQL is the same as in chooseQAChildren count = st.executeUpdate( "insert into childcoded (child_id, status)" + " select C.child_id, 'QA'" + " from child C" + " inner join batch B using (batch_id)" + " left join batchuser BU using (batch_id)" + " left join users U on U.users_id = BU.coder_id" + " left join childcoded CC" + " on C.child_id=CC.child_id and CC.round=0" + " where B.volume_id=" + task.getLockVolumeId() + " and B.status='QA'" + " and CC.child_id is null" + " and (teams_id=" + teamsId + " or teams_id is null and " + teamsId + "=0)" + " order by rand()" + " limit " + selectCount); } Log.print( "chooseQAChildrenForTeam: volume=" + task.getLockVolumeId() + " count=" + count + " teamsId=" + teamsId); return count; }
public void run(ServerTask task, Element action) throws SQLException, IOException { int volumeId = task.getLockVolumeId(); assert volumeId != 0; assert task.getLockBatchId() == 0; int percent = Integer.parseInt(action.getAttribute(A_PERCENT)); String usersIdString = action.getAttribute(A_USERS_ID); String teamsIdString = action.getAttribute(A_TEAMS_ID); boolean newSample = "YES".equals(action.getAttribute(A_NEW_SAMPLE)); Log.print( "in Handler_sample_qa.run vol=" + volumeId + " pct=" + percent + " user: "******" team: " + teamsIdString + " new_sample: " + newSample); Statement st = null; int count; if (newSample) { // save batches around choose code st = task.getStatement(); st.executeUpdate( "update batch" + " set status =''" + " where volume_id=" + volumeId + " and status = 'QA'"); } if (usersIdString.length() > 0) { assert teamsIdString.length() == 0; if (newSample) { // move QCComplete batches to QA (managed) task.executeUpdate( "update batch B" + " inner join batchuser BU using (batch_id)" + " set B.status ='QA'" + " where B.volume_id=" + volumeId + " and B.status = 'QCComplete'" + " and BU.coder_id=" + usersIdString); } count = chooseQAChildrenForCoder(task, percent, Integer.parseInt(usersIdString)); } else if (teamsIdString.length() > 0) { if (newSample) { // move QCComplete batches to QA (managed) task.executeUpdate( "update batch B" + " inner join batchuser BU using (batch_id)" + " inner join users U on BU.coder_id=U.users_id" + " set B.status ='QA'" + " where B.volume_id=" + volumeId + " and B.status = 'QCComplete'" + " and U.teams_id=" + teamsIdString); } count = chooseQAChildrenForTeam(task, percent, Integer.parseInt(teamsIdString)); } else { if (newSample) { // move QCComplete batches to QA (managed) task.executeUpdate( "update batch" + " set status ='QA'" + " where volume_id=" + volumeId + " and status = 'QCComplete'"); } count = chooseQAChildren(task, percent); } if (newSample) { // restore old QA batches st.executeUpdate( "update batch" + " set status ='QA'" + " where volume_id=" + volumeId + " and status = ''"); } // send back info MessageWriter writer = task.getMessageWriter(); writer.startElement(T_UPDATE_COUNT); writer.writeAttribute(A_COUNT, count); writer.endElement(); }
/** * Load a file from disk * * @param log * @throws FileNotFoundException */ public void load(String log) throws FileNotFoundException { String line; if (!Config.logFileDirectory.equalsIgnoreCase("")) { log = Config.logFileDirectory + File.separator + log; Log.println("Loading: " + log); } File aFile = new File(log); if (!aFile.exists()) { try { aFile.createNewFile(); } catch (IOException e) { JOptionPane.showMessageDialog( MainWindow.frame, e.toString(), "ERROR creating file " + log, JOptionPane.ERROR_MESSAGE); e.printStackTrace(Log.getWriter()); } } BufferedReader dis = new BufferedReader(new FileReader(log)); try { while ((line = dis.readLine()) != null) { if (line != null) { StringTokenizer st = new StringTokenizer(line, ","); String date = st.nextToken(); int id = Integer.valueOf(st.nextToken()).intValue(); int reset = Integer.valueOf(st.nextToken()).intValue(); long uptime = Long.valueOf(st.nextToken()).longValue(); int type = Integer.valueOf(st.nextToken()).intValue(); // We should never get this situation, but good to check.. if (Config.satManager.getSpacecraft(id) == null) { Log.errorDialog( "FATAL", "Attempting to Load payloads from the Payload store for satellite with Fox Id: " + id + "\n when no sattellite with that FoxId is configured. Add this spacecraft to the satellite directory and restart FoxTelem." + "\nProgram will now exit"); System.exit(1); } if (type == RT_MEASUREMENT_TYPE) { RtMeasurement rt = new RtMeasurement(id, date, reset, uptime, type, st); rtRecords.add(rt); updatedRt = true; } if (type == PASS_MEASUREMENT_TYPE) { PassMeasurement rt = new PassMeasurement(id, date, reset, uptime, type, st); passRecords.add(rt); updatedPass = true; } } } } catch (IOException e) { e.printStackTrace(Log.getWriter()); } catch (NumberFormatException n) { n.printStackTrace(Log.getWriter()); } finally { try { dis.close(); } catch (IOException e) { e.printStackTrace(Log.getWriter()); } } }
public void start() { if (this.status != LobbyStatus.READY) { // if lobby is not ready (still waiting for players, or already // started) we don't need to do anything Log.info("Lobby(" + this.id + "): Cannot start game, lobby\'s state is: " + this.status); return; } List<ClientInterface> clients = createListClientInterfaces(); List<String> names = createListNames(); for (int i = 0; i < clients.size(); i++) { ClientInterface client = clients.get(i); // in the following the server tries to call the clients startGame() // method. In case the client is currently not connected to the // network, a remoteException will be raised. Since we can assume // that this happens only when a client has no current network // connection (note: task setting of the project says that the // client doesn't crash and that we don't have to handle client // crashes), we can be sure that the client gets its connection // back. Until then we try to contact him until we're successful // eventually int tries = 0; while (true) { try { client.startGame(i, clients, names); Log.info( "Lobby(" + this.id + "): Sent player " + this.players.get(i) + " the signal to start the game."); // contacting the client was successful -> break from loop break; } catch (RemoteException e) { Log.warning( "Lobby(" + this.id + "): Couldn\'t inform player " + this.players.get(i) + " to start the game: A RemoteException occured.\n" + "This already happened " + tries + " time(s)." + "Retrying in a few seconds.\n-----"); e.printStackTrace(); tries++; // could not reach client -> wait 5 seconds try { Thread.sleep(5000); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } } } this.status = LobbyStatus.STARTED; }