private void buildPerceptions() { playersToRemove.clear(); /** We reset the cache at Perceptions */ MessageS2CPerception.clearPrecomputedPerception(); for (PlayerEntry entry : playerContainer) { try { // Before creating the perception we check the player is still there. if (entry.isTimeout()) { logger.info("Request (TIMEOUT) disconnection of Player " + entry.getAddress()); playersToRemove.add(entry); continue; } if (entry.state == ClientState.GAME_BEGIN) { Perception perception = getPlayerPerception(entry); sendPlayerPerception(entry, perception, entry.object); } } catch (Exception e) { logger.error( "Removing player(" + entry.clientid + ") because it caused a Exception while contacting it", e); playersToRemove.add(entry); } } for (PlayerEntry entry : playersToRemove) { logger.warn("RP Disconnecting entry: " + entry); netMan.disconnectClient(entry.channel); } }
/** * This method creates the real connection to database. * * @param connInfo connection information like url, username and password * @return a connection to the database * @throws DatabaseConnectionException if the connection cannot be established. */ protected Connection createConnection(Properties connInfo) throws DatabaseConnectionException { try { // instantiate the Driver class try { if (connInfo.get("jdbc_class") != null) { Class.forName((String) connInfo.get("jdbc_class")).newInstance(); } } catch (Exception e) { throw new DatabaseConnectionException( "Cannot load driver class " + connInfo.get("jdbc_class"), e); } Properties connectionInfo = new Properties(); if (connInfo.get("jdbc_user") != null) { connectionInfo.put("user", connInfo.get("jdbc_user")); } if (connInfo.get("jdbc_pwd") != null) { connectionInfo.put("password", connInfo.get("jdbc_pwd")); } connectionInfo.put("charSet", "UTF-8"); Connection conn = DriverManager.getConnection((String) connInfo.get("jdbc_url"), connectionInfo); // enable transaction support conn.setAutoCommit(false); conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); DatabaseMetaData meta = conn.getMetaData(); logger.info( "Connected to " + connInfo.get("jdbc_url") + ": " + meta.getDatabaseProductName() + " " + meta.getDatabaseProductVersion() + " with driver " + meta.getDriverName() + " " + meta.getDriverVersion()); return conn; } catch (SQLException e) { throw new DatabaseConnectionException( "Unable to create a connection to: " + connInfo.get("jdbc_url"), e); } }