diff --git a/pom.xml b/pom.xml index ca7ecbc62..f3818b657 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,7 @@ jar runtime - + org.slf4j slf4j-log4j12 @@ -72,14 +72,14 @@ com.h2database h2 - 1.3.154 + 1.3.155 jar runtime commons-dbcp commons-dbcp - 20030825.184428 + 1.4 jar runtime @@ -122,23 +122,23 @@ runtime - org.apache.commons + commons-io commons-io - 1.3.2 + 2.0.1 jar runtime commons-pool commons-pool - 20030825.183949 + 1.5.6 jar runtime commons-collections commons-collections - 20040616 + 3.2.1 jar runtime diff --git a/src/main/java/com/l2jserver/service/database/JDBCDatabaseConfiguration.java b/src/main/java/com/l2jserver/service/database/JDBCDatabaseConfiguration.java index b22ce5ed9..9e3f321eb 100644 --- a/src/main/java/com/l2jserver/service/database/JDBCDatabaseConfiguration.java +++ b/src/main/java/com/l2jserver/service/database/JDBCDatabaseConfiguration.java @@ -73,4 +73,43 @@ public interface JDBCDatabaseConfiguration extends DatabaseConfiguration { */ @ConfigurationPropertySetter(name = "jdbc.password") void setPassword(String password); + + /** + * @return the maximum number of active connections + */ + @ConfigurationPropertyGetter(name = "jdbc.active.max", defaultValue = "20") + int getMaxActiveConnections(); + + /** + * @param password + * the maximum number of active connections + */ + @ConfigurationPropertySetter(name = "jdbc.active.max") + void setMaxActiveConnections(int password); + + /** + * @return the maximum number of idle connections + */ + @ConfigurationPropertyGetter(name = "jdbc.idle.max", defaultValue = "20") + int getMaxIdleConnections(); + + /** + * @param password + * the maximum number of idle connections + */ + @ConfigurationPropertySetter(name = "jdbc.idle.max") + void setMaxIdleConnections(int password); + + /** + * @return the minimum number of idle connections + */ + @ConfigurationPropertyGetter(name = "jdbc.idle.min", defaultValue = "5") + int getMinIdleConnections(); + + /** + * @param password + * the minimum number of idle connections + */ + @ConfigurationPropertySetter(name = "jdbc.idle.min") + void setMinIdleConnections(int password); } diff --git a/src/main/java/com/l2jserver/service/database/JDBCDatabaseService.java b/src/main/java/com/l2jserver/service/database/JDBCDatabaseService.java index 8fcc392a0..3c2a236df 100644 --- a/src/main/java/com/l2jserver/service/database/JDBCDatabaseService.java +++ b/src/main/java/com/l2jserver/service/database/JDBCDatabaseService.java @@ -33,7 +33,6 @@ import org.apache.commons.dbcp.DriverManagerConnectionFactory; import org.apache.commons.dbcp.PoolableConnectionFactory; import org.apache.commons.dbcp.PoolingDataSource; import org.apache.commons.io.FileUtils; -import org.apache.commons.pool.ObjectPool; import org.apache.commons.pool.impl.GenericObjectPool; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -83,7 +82,7 @@ public class JDBCDatabaseService extends AbstractService implements /** * The database connection pool */ - private ObjectPool connectionPool; + private GenericObjectPool connectionPool; /** * The dayabase connection factory */ @@ -113,10 +112,18 @@ public class JDBCDatabaseService extends AbstractService implements @Override protected void doStart() throws ServiceStartException { connectionPool = new GenericObjectPool(null); + connectionPool.setMaxActive(config.getMaxActiveConnections()); + connectionPool.setMinIdle(config.getMinIdleConnections()); + connectionPool.setMaxIdle(config.getMaxIdleConnections()); + + // test if connections are active while idle + connectionPool.setTestWhileIdle(true); + connectionFactory = new DriverManagerConnectionFactory( config.getJdbcUrl(), config.getUsername(), config.getPassword()); poolableConnectionFactory = new PoolableConnectionFactory( - connectionFactory, connectionPool, null, null, false, true); + connectionFactory, connectionPool, null, "SELECT 1", false, + true); dataSource = new PoolingDataSource(connectionPool); // cache must be large enough for all world objects, to avoid @@ -127,7 +134,6 @@ public class JDBCDatabaseService extends AbstractService implements @Override public void install() { - @SuppressWarnings("unchecked") Collection files = FileUtils.listFiles(new File("dist/sql/h2"), new String[] { "sql" }, false); try { diff --git a/src/main/java/com/l2jserver/service/game/map/pathing/AStarPathingService.java b/src/main/java/com/l2jserver/service/game/map/pathing/AStarPathingService.java index 75c3c79ae..42f68264c 100644 --- a/src/main/java/com/l2jserver/service/game/map/pathing/AStarPathingService.java +++ b/src/main/java/com/l2jserver/service/game/map/pathing/AStarPathingService.java @@ -34,8 +34,157 @@ public class AStarPathingService extends AbstractService implements PathingService { @Override public Path findPath(PositionableObject object, Point3D point) { - // TODO Auto-generated method stub return null; } + // public class Position { + // private double x; + // + // private double y; + // } + // + // public class Node { + // + // protected String id; + // } + // + // public class Edge { + // + // protected String from; + // + // protected String to; + // + // } + // + // public class Adjacency { + // protected N node; + // protected Set neighbors; + // } + // + // public class Graph { + // + // protected List nodeList; + // + // protected List edgeList; + // + // // Index for fast access + // private Map> adjacency; + // + // // directed graph or not + // protected boolean diGraph; + // } + // + // public class NavNode extends Node { + // protected Position position; + // protected List extraData; + // } + // + // public class NavEdge extends Edge { + // protected double cost; + // } + // + // public class NavGraph extends Graph { + // + // public void addConnection(String firstId, String secondId) { + // NavNode node1 = this.getNode(firstId); + // NavNode node2 = this.getNode(secondId); + // if (node1 != null && node2 != null) { + // double cost = this.calcManhattanDistance(node1, node2); + // NavEdge edge1 = new NavEdge(firstId, secondId, cost); + // NavEdge edge2 = new NavEdge(secondId, firstId, cost); + // this.addEdge(edge1); + // this.addEdge(edge2); + // } + // } + // + // public void removeConnection(String firstId, String secondId) { + // NavEdge edge1 = new NavEdge(firstId, secondId); + // NavEdge edge2 = new NavEdge(secondId, firstId); + // this.removeEdge(edge1); + // this.removeEdge(edge2); + // } + // + // public double calcManhattanDistance(NavNode a, NavNode b) { + // return abs(a.getPosition().getX() - b.getPosition().getX()) + // + abs(a.getPosition().getY() - b.getPosition().getY()); + // } + // } + // + // public class NavGraphLoader { + // + // public NavGraphData load(String filePath) { + // try { + // String json = this.readFileAsString(filePath); + // JSONReader reader = new JSONReader(); + // Map map = (Map) reader.read(json); + // NavGraphData data = new NavGraphData(); + // data.fromJSON(map); + // + // return data; + // } catch (IOException e) { + // throw new RuntimeException("Cannot read file " + filePath); + // } + // } + // + // String readFileAsString(String filePath) throws java.io.IOException { + // BufferedReader reader = new BufferedReader(new InputStreamReader( + // this.getClass().getResourceAsStream(filePath))); + // StringBuffer sb = new StringBuffer(4096); + // + // String line = reader.readLine(); + // while (line != null) { + // sb.append(line); + // line = reader.readLine(); + // } + // + // reader.close(); + // + // return sb.toString(); + // } + // } + // + // public class NavNodeData { + // private int min; + // private int max; + // private NavNode node; + // + // public NavNodeData() { + // } + // + // public NavNodeData(int min, int max, NavNode node) { + // this.min = min; + // this.max = max; + // this.node = node; + // } + // + // public int getMin() { + // return min; + // } + // + // public void setMin(int min) { + // this.min = min; + // } + // + // public int getMax() { + // return max; + // } + // + // public void setMax(int max) { + // this.max = max; + // } + // + // public NavNode getNode() { + // return node; + // } + // + // public void setNode(NavNode node) { + // this.node = node; + // } + // } + // + // public class MatrixPosition { + // + // private int row; + // private int column; + // } } diff --git a/src/main/java/com/l2jserver/service/game/scripting/impl/ScriptContextImpl.java b/src/main/java/com/l2jserver/service/game/scripting/impl/ScriptContextImpl.java index 74fa2b238..fe31afdfd 100644 --- a/src/main/java/com/l2jserver/service/game/scripting/impl/ScriptContextImpl.java +++ b/src/main/java/com/l2jserver/service/game/scripting/impl/ScriptContextImpl.java @@ -134,7 +134,6 @@ public class ScriptContextImpl implements ScriptContext { ScriptCompiler scriptCompiler = instantiateCompiler(); - @SuppressWarnings("unchecked") Collection files = FileUtils.listFiles(root, scriptCompiler.getSupportedFileTypes(), true);