Made duplicate ID handling more efficient

Shouldn't create a new objectId each server run, by using a duplicateId
database that takes other things (such as planetcrc, templatecrc,
building, container, cell, coordinates)

Currently best solution I can see that doesn't consume a brand new lot
of 20,000 objectids each bootup.
This commit is contained in:
Treeku
2014-03-24 19:20:06 +00:00
parent e363b438ef
commit 94ae856f6f
4 changed files with 60 additions and 10 deletions
View File
+6
View File
@@ -182,6 +182,7 @@ public class NGECore {
private ObjectDatabase mailODB;
private ObjectDatabase guildODB;
private ObjectDatabase objectIdODB;
private ObjectDatabase duplicateIdODB;
private BusConfiguration eventBusConfig = BusConfiguration.Default(1, new ThreadPoolExecutor(1, 4, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>()));
@@ -231,6 +232,7 @@ public class NGECore {
mailODB = new ObjectDatabase("mails", true, false, true);
guildODB = new ObjectDatabase("guild", true, false, true);
objectIdODB = new ObjectDatabase("oids", true, false, false);
duplicateIdODB = new ObjectDatabase("doids", true, false, true);
// Services
loginService = new LoginService(this);
@@ -518,6 +520,10 @@ public class NGECore {
return objectIdODB;
}
public ObjectDatabase getDuplicateIdODB() {
return duplicateIdODB;
}
public int getActiveClients() {
int connections = 0;
for (Map.Entry<IoSession, Client> c : clients.entrySet()) {
+26
View File
@@ -0,0 +1,26 @@
package services.object;
import com.sleepycat.persist.model.Entity;
import com.sleepycat.persist.model.PrimaryKey;
@Entity
public class DuplicateId {
@PrimaryKey
private String key;
private long objectId;
public DuplicateId(String key, long objectId) {
this.key = key;
this.objectId = objectId;
}
public DuplicateId() {
}
public long getObjectId() {
return objectId;
}
}
+28 -10
View File
@@ -53,6 +53,7 @@ import org.apache.mina.core.session.IoSession;
import org.python.core.Py;
import org.python.core.PyObject;
import com.sleepycat.je.Transaction;
import com.sleepycat.persist.EntityCursor;
import com.sleepycat.persist.model.Entity;
import com.sleepycat.persist.model.PrimaryKey;
@@ -832,23 +833,38 @@ public class ObjectService implements INetworkDispatch {
SWGObject object = getObject(objectId);
// Same coordinates is a true duplicate
if ((px + x1) == object.getPosition().x &&
if ((px + ((containerId == 0) ? 0 : x1)) == object.getPosition().x &&
py == object.getPosition().y &&
(pz + z1) == object.getPosition().z) {
(pz + ((containerId == 0) ? 0 : z1)) == object.getPosition().z) {
//System.out.println("Duplicate buildout object: " + template);
continue;
}
}
if (objectId != 0 && getObject(objectId) != null) {
duplicate.put(objectId, generateObjectID());
objectId = duplicate.get(objectId);
}
if (duplicate.containsKey(containerId)) {
containerId = duplicate.get(containerId);
}
if (objectId != 0 && getObject(objectId) != null) {
SWGObject container = getObject(containerId);
int x = ((int) (px + ((container == null) ? x1 : container.getPosition().x)));
int z = ((int) (pz + ((container == null) ? z1 : container.getPosition().z)));
String key = "" + CRC.StringtoCRC(planet.getName()) + CRC.StringtoCRC(template) + type + containerId + cellIndex + x + py + z;
long newObjectId = 0;
if (core.getDuplicateIdODB().contains(key, String.class, DuplicateId.class)) {
newObjectId = core.getDuplicateIdODB().get(key, String.class, DuplicateId.class).getObjectId();
} else {
newObjectId = generateObjectID();
Transaction txn = core.getDuplicateIdODB().getEnvironment().beginTransaction(null, null);
core.getDuplicateIdODB().put(new DuplicateId(key, newObjectId), String.class, DuplicateId.class, txn);
txn.commitSync();
}
duplicate.put(objectId, newObjectId);
objectId = newObjectId;
}
List<Long> containers = new ArrayList<Long>();
SWGObject object;
if(objectId != 0 && containerId == 0) {
@@ -856,9 +872,11 @@ public class ObjectService implements INetworkDispatch {
containers.add(objectId);
object = createObject(template, objectId, planet, new Point3D(px + x1, py, pz + z1), new Quaternion(qw, qx, qy, qz), null, true);
object.setAttachment("childObjects", null);
((BuildingObject) object).createTransaction(core.getBuildingODB().getEnvironment());
core.getBuildingODB().put((BuildingObject) object, Long.class, BuildingObject.class, ((BuildingObject) object).getTransaction());
((BuildingObject) object).getTransaction().commitSync();
if (!duplicate.containsValue(objectId)) {
((BuildingObject) object).createTransaction(core.getBuildingODB().getEnvironment());
core.getBuildingODB().put((BuildingObject) object, Long.class, BuildingObject.class, ((BuildingObject) object).getTransaction());
((BuildingObject) object).getTransaction().commitSync();
}
} else {
object = createObject(template, objectId, planet, new Point3D(px + x1, py, pz + z1), new Quaternion(qw, qx, qy, qz));
}