mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-08 08:23:11 +00:00
Added more debug messages
This commit is contained in:
@@ -5,9 +5,15 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.l2jserver.util.PrimeFinder;
|
||||
|
||||
public class BitSetIDAllocator implements IDAllocator {
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(BitSetIDAllocator.class);
|
||||
|
||||
/**
|
||||
* Lock to guarantee synchronization
|
||||
*/
|
||||
@@ -32,12 +38,15 @@ public class BitSetIDAllocator implements IDAllocator {
|
||||
freeIdCount = new AtomicInteger(ALLOCABLE_IDS);
|
||||
|
||||
nextId = new AtomicInteger(ids.nextClearBit(0));
|
||||
log.info("BitSet IDAllocator initialized. Next available ID is {}",
|
||||
nextId.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void allocate(int id) {
|
||||
if (ids.get(id - FIRST_ID))
|
||||
throw new IDAllocatorException("ID not allocated");
|
||||
log.debug("Allocating ID {}", id);
|
||||
lock.lock();
|
||||
try {
|
||||
if (id < FIRST_ID)
|
||||
@@ -57,6 +66,9 @@ public class BitSetIDAllocator implements IDAllocator {
|
||||
ids.set(newID);
|
||||
freeIdCount.decrementAndGet();
|
||||
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Allocated a new ID {}", newID + FIRST_ID);
|
||||
|
||||
int nextFree = ids.nextClearBit(newID);
|
||||
|
||||
if (nextFree < 0) {
|
||||
@@ -66,12 +78,12 @@ public class BitSetIDAllocator implements IDAllocator {
|
||||
if (ids.size() < ALLOCABLE_IDS) {
|
||||
increaseBitSetCapacity();
|
||||
} else {
|
||||
log.error("ID exhaustion");
|
||||
throw new IDAllocatorException("ID exhaustion");
|
||||
}
|
||||
}
|
||||
|
||||
nextId.set(nextFree);
|
||||
|
||||
return newID + FIRST_ID;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
@@ -86,6 +98,7 @@ public class BitSetIDAllocator implements IDAllocator {
|
||||
if (!ids.get(id - FIRST_ID))
|
||||
throw new IDAllocatorException("ID not allocated");
|
||||
|
||||
log.debug("Releasing allocated ID {}", id);
|
||||
lock.lock();
|
||||
try {
|
||||
ids.clear(id - FIRST_ID);
|
||||
@@ -96,6 +109,7 @@ public class BitSetIDAllocator implements IDAllocator {
|
||||
}
|
||||
|
||||
private void increaseBitSetCapacity() {
|
||||
log.debug("Increasing BitSet capacity from {}", ids.size());
|
||||
BitSet newBitSet = new BitSet(
|
||||
PrimeFinder.nextPrime((getAllocatedIDs() * 11) / 10));
|
||||
newBitSet.or(ids);
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.l2jserver.model.world.player;
|
||||
|
||||
import com.l2jserver.model.world.actor.ActorEvent;
|
||||
import com.l2jserver.model.world.actor.ActorListener;
|
||||
import com.l2jserver.model.world.event.WorldEvent;
|
||||
import com.l2jserver.model.world.event.WorldListener;
|
||||
|
||||
public abstract class PlayerListener implements ActorListener {
|
||||
@Override
|
||||
@@ -12,11 +14,7 @@ public abstract class PlayerListener implements ActorListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Once the event call is dispatched, the listener <b>WILL NOT</b> be
|
||||
* removed. You must manually remove it from the <tt>event</tt> object.
|
||||
*
|
||||
* @param e
|
||||
* the event
|
||||
* @see WorldListener#dispatch(WorldEvent)
|
||||
*/
|
||||
protected abstract boolean dispatch(PlayerEvent e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user