Switch to Maven file structure

This commit is contained in:
P0nk
2021-03-30 21:07:35 +02:00
parent 4acc5675d6
commit 813643036b
817 changed files with 16 additions and 0 deletions

View File

@@ -0,0 +1,215 @@
/*
This file is part of the HeavenMS MapleStory Server
Copyleft (L) 2016 - 2019 RonanLana
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.services;
import config.YamlConfig;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ScheduledFuture;
import net.server.Server;
import net.server.audit.LockCollector;
import net.server.audit.locks.MonitoredLockType;
import net.server.audit.locks.MonitoredReentrantLock;
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
import server.TimerManager;
import tools.Pair;
/**
*
* @author Ronan
*/
public abstract class BaseScheduler {
private int idleProcs = 0;
private List<SchedulerListener> listeners = new LinkedList<>();
private final List<MonitoredReentrantLock> externalLocks = new LinkedList<>();
private Map<Object, Pair<Runnable, Long>> registeredEntries = new HashMap<>();
private ScheduledFuture<?> schedulerTask = null;
private MonitoredReentrantLock schedulerLock;
private Runnable monitorTask = new Runnable() {
@Override
public void run() {
runBaseSchedule();
}
};
protected BaseScheduler(MonitoredLockType lockType) {
schedulerLock = MonitoredReentrantLockFactory.createLock(lockType, true);
}
// NOTE: practice EXTREME caution when adding external locks to the scheduler system, if you don't know what you're doing DON'T USE THIS.
protected BaseScheduler(MonitoredLockType lockType, List<MonitoredReentrantLock> extLocks) {
schedulerLock = MonitoredReentrantLockFactory.createLock(lockType, true);
for(MonitoredReentrantLock lock : extLocks) {
externalLocks.add(lock);
}
}
protected void addListener(SchedulerListener listener) {
listeners.add(listener);
}
private void lockScheduler() {
if(!externalLocks.isEmpty()) {
for(MonitoredReentrantLock l : externalLocks) {
l.lock();
}
}
schedulerLock.lock();
}
private void unlockScheduler() {
if(!externalLocks.isEmpty()) {
for(MonitoredReentrantLock l : externalLocks) {
l.unlock();
}
}
schedulerLock.unlock();
}
private void runBaseSchedule() {
List<Object> toRemove;
Map<Object, Pair<Runnable, Long>> registeredEntriesCopy;
lockScheduler();
try {
if(registeredEntries.isEmpty()) {
idleProcs++;
if(idleProcs >= YamlConfig.config.server.MOB_STATUS_MONITOR_LIFE) {
if(schedulerTask != null) {
schedulerTask.cancel(false);
schedulerTask = null;
}
}
return;
}
idleProcs = 0;
registeredEntriesCopy = new HashMap<>(registeredEntries);
} finally {
unlockScheduler();
}
long timeNow = Server.getInstance().getCurrentTime();
toRemove = new LinkedList<>();
for(Entry<Object, Pair<Runnable, Long>> rmd : registeredEntriesCopy.entrySet()) {
Pair<Runnable, Long> r = rmd.getValue();
if(r.getRight() < timeNow) {
r.getLeft().run(); // runs the scheduled action
toRemove.add(rmd.getKey());
}
}
if(!toRemove.isEmpty()) {
lockScheduler();
try {
for(Object o : toRemove) {
registeredEntries.remove(o);
}
} finally {
unlockScheduler();
}
}
dispatchRemovedEntries(toRemove, true);
}
protected void registerEntry(Object key, Runnable removalAction, long duration) {
lockScheduler();
try {
idleProcs = 0;
if(schedulerTask == null) {
schedulerTask = TimerManager.getInstance().register(monitorTask, YamlConfig.config.server.MOB_STATUS_MONITOR_PROC, YamlConfig.config.server.MOB_STATUS_MONITOR_PROC);
}
registeredEntries.put(key, new Pair<>(removalAction, Server.getInstance().getCurrentTime() + duration));
} finally {
unlockScheduler();
}
}
protected void interruptEntry(Object key) {
Runnable toRun = null;
lockScheduler();
try {
Pair<Runnable, Long> rm = registeredEntries.remove(key);
if(rm != null) {
toRun = rm.getLeft();
}
} finally {
unlockScheduler();
}
if(toRun != null) {
toRun.run();
}
dispatchRemovedEntries(Collections.singletonList(key), false);
}
private void dispatchRemovedEntries(List<Object> toRemove, boolean fromUpdate) {
for (SchedulerListener listener : listeners.toArray(new SchedulerListener[listeners.size()])) {
listener.removedScheduledEntries(toRemove, fromUpdate);
}
}
public void dispose() {
lockScheduler();
try {
if(schedulerTask != null) {
schedulerTask.cancel(false);
schedulerTask = null;
}
listeners.clear();
registeredEntries.clear();
} finally {
unlockScheduler();
externalLocks.clear();
}
disposeLocks();
}
private void disposeLocks() {
LockCollector.getInstance().registerDisposeAction(new Runnable() {
@Override
public void run() {
emptyLocks();
}
});
}
private void emptyLocks() {
schedulerLock = schedulerLock.dispose();
}
}

View File

@@ -0,0 +1,37 @@
/*
This file is part of the HeavenMS MapleStory Server, commands OdinMS-based
Copyleft (L) 2016 - 2019 RonanLana
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.services;
import config.YamlConfig;
/**
*
* @author Ronan
*/
public abstract class BaseService {
protected static int getChannelSchedulerIndex(int mapid) {
int section = 1000000000 / YamlConfig.config.server.CHANNEL_LOCKS;
return mapid / section;
}
public abstract void dispose();
}

View File

@@ -0,0 +1,30 @@
/*
This file is part of the HeavenMS MapleStory Server
Copyleft (L) 2016 - 2019 RonanLana
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.services;
import java.util.List;
/**
*
* @author Ronan
*/
public interface SchedulerListener {
public void removedScheduledEntries(List<Object> entries, boolean update);
}

View File

@@ -0,0 +1,50 @@
/*
This file is part of the HeavenMS MapleStory Server, commands OdinMS-based
Copyleft (L) 2016 - 2019 RonanLana
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.services;
/**
*
* @author Ronan
*/
public class Service <T extends BaseService> {
private Class<T> cls;
private BaseService service;
public Service(Class<T> s) {
try {
cls = s;
service = (BaseService) cls.getConstructor().newInstance();
} catch (Exception e) {
e.printStackTrace();
}
}
public T getService() {
return cls.cast(service);
}
public void dispose() {
service.dispose();
service = null;
}
}

View File

@@ -0,0 +1,30 @@
/*
This file is part of the HeavenMS MapleStory Server, commands OdinMS-based
Copyleft (L) 2016 - 2019 RonanLana
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.services;
/**
*
* @author Ronan
*/
public interface ServiceType <T extends Enum<?>> {
public abstract Service createService();
public int ordinal();
public T[] enumValues();
}

View File

@@ -0,0 +1,50 @@
/*
This file is part of the HeavenMS MapleStory Server, commands OdinMS-based
Copyleft (L) 2016 - 2019 RonanLana
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.services;
/**
*
* @author Ronan
*/
public class ServicesManager {
private Service[] services;
public ServicesManager(ServiceType serviceBundle) {
Enum[] serviceTypes = serviceBundle.enumValues();
services = new Service[serviceTypes.length];
for (Enum type : serviceTypes) {
services[type.ordinal()] = ((ServiceType) type).createService();
}
}
public Service getAccess(ServiceType s) {
return services[s.ordinal()];
}
public void shutdown() {
for (int i = 0; i < services.length; i++) {
services[i].dispose();
}
services = null;
}
}

View File

@@ -0,0 +1,67 @@
/*
This file is part of the HeavenMS MapleStory Server
Copyleft (L) 2016 - 2019 RonanLana
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.services.task.channel;
import net.server.services.BaseService;
import config.YamlConfig;
import net.server.audit.locks.MonitoredLockType;
import net.server.services.BaseScheduler;
/**
*
* @author Ronan
*/
public class EventService extends BaseService {
private EventScheduler eventSchedulers[] = new EventScheduler[YamlConfig.config.server.CHANNEL_LOCKS];
public EventService() {
for(int i = 0; i < YamlConfig.config.server.CHANNEL_LOCKS; i++) {
eventSchedulers[i] = new EventScheduler();
}
}
@Override
public void dispose() {
for(int i = 0; i < YamlConfig.config.server.CHANNEL_LOCKS; i++) {
if(eventSchedulers[i] != null) {
eventSchedulers[i].dispose();
eventSchedulers[i] = null;
}
}
}
public void registerEventAction(int mapid, Runnable runAction, long delay) {
eventSchedulers[getChannelSchedulerIndex(mapid)].registerDelayedAction(runAction, delay);
}
private class EventScheduler extends BaseScheduler {
public EventScheduler() {
super(MonitoredLockType.CHANNEL_EVENTS);
}
public void registerDelayedAction(Runnable runAction, long delay) {
registerEntry(runAction, runAction, delay);
}
}
}

View File

@@ -0,0 +1,130 @@
/*
This file is part of the HeavenMS MapleStory Server
Copyleft (L) 2016 - 2019 RonanLana
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.services.task.channel;
import net.server.services.BaseService;
import client.MapleCharacter;
import config.YamlConfig;
import java.util.Collections;
import net.server.audit.LockCollector;
import net.server.audit.locks.MonitoredLockType;
import net.server.audit.locks.MonitoredReentrantLock;
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
import net.server.services.BaseScheduler;
import server.maps.MapleMap;
import tools.MaplePacketCreator;
/**
*
* @author Ronan
*/
public class FaceExpressionService extends BaseService {
private FaceExpressionScheduler faceExpressionSchedulers[] = new FaceExpressionScheduler[YamlConfig.config.server.CHANNEL_LOCKS];
private MonitoredReentrantLock faceLock[] = new MonitoredReentrantLock[YamlConfig.config.server.CHANNEL_LOCKS];
public FaceExpressionService() {
for(int i = 0; i < YamlConfig.config.server.CHANNEL_LOCKS; i++) {
faceLock[i] = MonitoredReentrantLockFactory.createLock(MonitoredLockType.CHANNEL_FACEEXPRS, true);
faceExpressionSchedulers[i] = new FaceExpressionScheduler(faceLock[i]);
}
}
private void emptyLocks() {
for(int i = 0; i < YamlConfig.config.server.CHANNEL_LOCKS; i++) {
faceLock[i] = faceLock[i].dispose();
}
}
private void disposeLocks() {
LockCollector.getInstance().registerDisposeAction(new Runnable() {
@Override
public void run() {
emptyLocks();
}
});
}
@Override
public void dispose() {
for(int i = 0; i < YamlConfig.config.server.CHANNEL_LOCKS; i++) {
if(faceExpressionSchedulers[i] != null) {
faceExpressionSchedulers[i].dispose();
faceExpressionSchedulers[i] = null;
}
}
disposeLocks();
}
public void registerFaceExpression(final MapleMap map, final MapleCharacter chr, int emote) {
int lockid = getChannelSchedulerIndex(map.getId());
Runnable cancelAction = new Runnable() {
@Override
public void run() {
if(chr.isLoggedinWorld()) {
map.broadcastMessage(chr, MaplePacketCreator.facialExpression(chr, 0), false);
}
}
};
faceLock[lockid].lock();
try {
if(!chr.isLoggedinWorld()) {
return;
}
faceExpressionSchedulers[lockid].registerFaceExpression(chr.getId(), cancelAction);
} finally {
faceLock[lockid].unlock();
}
map.broadcastMessage(chr, MaplePacketCreator.facialExpression(chr, emote), false);
}
public void unregisterFaceExpression(int mapid, MapleCharacter chr) {
int lockid = getChannelSchedulerIndex(mapid);
faceLock[lockid].lock();
try {
faceExpressionSchedulers[lockid].unregisterFaceExpression(chr.getId());
} finally {
faceLock[lockid].unlock();
}
}
private class FaceExpressionScheduler extends BaseScheduler {
public FaceExpressionScheduler(final MonitoredReentrantLock channelFaceLock) {
super(MonitoredLockType.CHANNEL_FACESCHDL, Collections.singletonList(channelFaceLock));
}
public void registerFaceExpression(Integer characterId, Runnable runAction) {
registerEntry(characterId, runAction, 5000);
}
public void unregisterFaceExpression(Integer characterId) {
interruptEntry(characterId);
}
}
}

View File

@@ -0,0 +1,127 @@
/*
This file is part of the HeavenMS MapleStory Server
Copyleft (L) 2016 - 2019 RonanLana
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.services.task.channel;
import net.server.services.BaseService;
import config.YamlConfig;
import net.server.audit.locks.MonitoredLockType;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.server.audit.LockCollector;
import net.server.audit.locks.MonitoredReentrantLock;
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
import net.server.services.BaseScheduler;
import net.server.services.SchedulerListener;
/**
*
* @author Ronan
*/
public class MobAnimationService extends BaseService {
private MobAnimationScheduler mobAnimationSchedulers[] = new MobAnimationScheduler[YamlConfig.config.server.CHANNEL_LOCKS];
public MobAnimationService() {
for(int i = 0; i < YamlConfig.config.server.CHANNEL_LOCKS; i++) {
mobAnimationSchedulers[i] = new MobAnimationScheduler();
}
}
@Override
public void dispose() {
for(int i = 0; i < YamlConfig.config.server.CHANNEL_LOCKS; i++) {
if(mobAnimationSchedulers[i] != null) {
mobAnimationSchedulers[i].dispose();
mobAnimationSchedulers[i] = null;
}
}
}
public boolean registerMobOnAnimationEffect(int mapid, int mobHash, long delay) {
return mobAnimationSchedulers[getChannelSchedulerIndex(mapid)].registerAnimationMode(mobHash, delay);
}
private static Runnable r = new Runnable() {
@Override
public void run() {} // do nothing
};
private class MobAnimationScheduler extends BaseScheduler {
Set<Integer> onAnimationMobs = new HashSet<>(1000);
private MonitoredReentrantLock animationLock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.CHANNEL_MOBANIMAT, true);
public MobAnimationScheduler() {
super(MonitoredLockType.CHANNEL_MOBACTION);
super.addListener(new SchedulerListener() {
@Override
public void removedScheduledEntries(List<Object> toRemove, boolean update) {
animationLock.lock();
try {
for(Object hashObj : toRemove) {
Integer mobHash = (Integer) hashObj;
onAnimationMobs.remove(mobHash);
}
} finally {
animationLock.unlock();
}
}
});
}
public boolean registerAnimationMode(Integer mobHash, long animationTime) {
animationLock.lock();
try {
if(onAnimationMobs.contains(mobHash)) {
return false;
}
registerEntry(mobHash, r, animationTime);
onAnimationMobs.add(mobHash);
return true;
} finally {
animationLock.unlock();
}
}
@Override
public void dispose() {
disposeLocks();
super.dispose();
}
private void disposeLocks() {
LockCollector.getInstance().registerDisposeAction(new Runnable() {
@Override
public void run() {
emptyLocks();
}
});
}
private void emptyLocks() {
animationLock = animationLock.dispose();
}
}
}

View File

@@ -0,0 +1,67 @@
/*
This file is part of the HeavenMS MapleStory Server
Copyleft (L) 2016 - 2019 RonanLana
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.services.task.channel;
import net.server.services.BaseService;
import config.YamlConfig;
import net.server.audit.locks.MonitoredLockType;
import net.server.services.BaseScheduler;
/**
*
* @author Ronan
*/
public class MobClearSkillService extends BaseService {
private MobClearSkillScheduler mobClearSkillSchedulers[] = new MobClearSkillScheduler[YamlConfig.config.server.CHANNEL_LOCKS];
public MobClearSkillService() {
for(int i = 0; i < YamlConfig.config.server.CHANNEL_LOCKS; i++) {
mobClearSkillSchedulers[i] = new MobClearSkillScheduler();
}
}
@Override
public void dispose() {
for(int i = 0; i < YamlConfig.config.server.CHANNEL_LOCKS; i++) {
if(mobClearSkillSchedulers[i] != null) {
mobClearSkillSchedulers[i].dispose();
mobClearSkillSchedulers[i] = null;
}
}
}
public void registerMobClearSkillAction(int mapid, Runnable runAction, long delay) {
mobClearSkillSchedulers[getChannelSchedulerIndex(mapid)].registerClearSkillAction(runAction, delay);
}
private class MobClearSkillScheduler extends BaseScheduler {
public MobClearSkillScheduler() {
super(MonitoredLockType.CHANNEL_MOBSKILL);
}
public void registerClearSkillAction(Runnable runAction, long delay) {
registerEntry(runAction, runAction, delay);
}
}
}

View File

@@ -0,0 +1,67 @@
/*
This file is part of the HeavenMS MapleStory Server
Copyleft (L) 2016 - 2019 RonanLana
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.services.task.channel;
import net.server.services.BaseService;
import config.YamlConfig;
import net.server.audit.locks.MonitoredLockType;
import net.server.services.BaseScheduler;
/**
*
* @author Ronan
*/
public class MobMistService extends BaseService {
private MobMistScheduler mobMistSchedulers[] = new MobMistScheduler[YamlConfig.config.server.CHANNEL_LOCKS];
public MobMistService() {
for(int i = 0; i < YamlConfig.config.server.CHANNEL_LOCKS; i++) {
mobMistSchedulers[i] = new MobMistScheduler();
}
}
@Override
public void dispose() {
for(int i = 0; i < YamlConfig.config.server.CHANNEL_LOCKS; i++) {
if(mobMistSchedulers[i] != null) {
mobMistSchedulers[i].dispose();
mobMistSchedulers[i] = null;
}
}
}
public void registerMobMistCancelAction(int mapid, Runnable runAction, long delay) {
mobMistSchedulers[getChannelSchedulerIndex(mapid)].registerMistCancelAction(runAction, delay);
}
private class MobMistScheduler extends BaseScheduler {
public MobMistScheduler() {
super(MonitoredLockType.CHANNEL_MOBMIST);
}
public void registerMistCancelAction(Runnable runAction, long delay) {
registerEntry(runAction, runAction, delay);
}
}
}

View File

@@ -0,0 +1,170 @@
/*
This file is part of the HeavenMS MapleStory Server
Copyleft (L) 2016 - 2019 RonanLana
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.services.task.channel;
import net.server.services.BaseService;
import client.status.MonsterStatusEffect;
import config.YamlConfig;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.server.audit.LockCollector;
import net.server.audit.locks.MonitoredLockType;
import net.server.audit.locks.MonitoredReentrantLock;
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
import net.server.services.BaseScheduler;
import net.server.services.SchedulerListener;
/**
*
* @author Ronan
*/
public class MobStatusService extends BaseService {
private MobStatusScheduler mobStatusSchedulers[] = new MobStatusScheduler[YamlConfig.config.server.CHANNEL_LOCKS];
public MobStatusService() {
for(int i = 0; i < YamlConfig.config.server.CHANNEL_LOCKS; i++) {
mobStatusSchedulers[i] = new MobStatusScheduler();
}
}
@Override
public void dispose() {
for(int i = 0; i < YamlConfig.config.server.CHANNEL_LOCKS; i++) {
if(mobStatusSchedulers[i] != null) {
mobStatusSchedulers[i].dispose();
mobStatusSchedulers[i] = null;
}
}
}
public void registerMobStatus(int mapid, MonsterStatusEffect mse, Runnable cancelAction, long duration) {
registerMobStatus(mapid, mse, cancelAction, duration, null, -1);
}
public void registerMobStatus(int mapid, MonsterStatusEffect mse, Runnable cancelAction, long duration, Runnable overtimeAction, int overtimeDelay) {
mobStatusSchedulers[getChannelSchedulerIndex(mapid)].registerMobStatus(mse, cancelAction, duration, overtimeAction, overtimeDelay);
}
public void interruptMobStatus(int mapid, MonsterStatusEffect mse) {
mobStatusSchedulers[getChannelSchedulerIndex(mapid)].interruptMobStatus(mse);
}
private class MobStatusScheduler extends BaseScheduler {
private Map<MonsterStatusEffect, MobStatusOvertimeEntry> registeredMobStatusOvertime = new HashMap<>();
private MonitoredReentrantLock overtimeStatusLock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.CHANNEL_OVTSTATUS, true);
private class MobStatusOvertimeEntry {
private int procCount;
private int procLimit;
private Runnable r;
protected MobStatusOvertimeEntry(int delay, Runnable run) {
procCount = 0;
procLimit = (int)Math.ceil((float) delay / YamlConfig.config.server.MOB_STATUS_MONITOR_PROC);
r = run;
}
protected void update(List<Runnable> toRun) {
procCount++;
if(procCount >= procLimit) {
procCount = 0;
toRun.add(r);
}
}
}
public MobStatusScheduler() {
super(MonitoredLockType.CHANNEL_MOBSTATUS);
super.addListener(new SchedulerListener() {
@Override
public void removedScheduledEntries(List<Object> toRemove, boolean update) {
List<Runnable> toRun = new ArrayList<>();
overtimeStatusLock.lock();
try {
for(Object mseo : toRemove) {
MonsterStatusEffect mse = (MonsterStatusEffect) mseo;
registeredMobStatusOvertime.remove(mse);
}
if(update) {
// it's probably ok to use one thread for both management & overtime actions
List<MobStatusOvertimeEntry> mdoeList = new ArrayList<>(registeredMobStatusOvertime.values());
for(MobStatusOvertimeEntry mdoe : mdoeList) {
mdoe.update(toRun);
}
}
} finally {
overtimeStatusLock.unlock();
}
for(Runnable r : toRun) {
r.run();
}
}
});
}
public void registerMobStatus(MonsterStatusEffect mse, Runnable cancelStatus, long duration, Runnable overtimeStatus, int overtimeDelay) {
if(overtimeStatus != null) {
MobStatusOvertimeEntry mdoe = new MobStatusOvertimeEntry(overtimeDelay, overtimeStatus);
overtimeStatusLock.lock();
try {
registeredMobStatusOvertime.put(mse, mdoe);
} finally {
overtimeStatusLock.unlock();
}
}
registerEntry(mse, cancelStatus, duration);
}
public void interruptMobStatus(MonsterStatusEffect mse) {
interruptEntry(mse);
}
@Override
public void dispose() {
disposeLocks();
super.dispose();
}
private void disposeLocks() {
LockCollector.getInstance().registerDisposeAction(new Runnable() {
@Override
public void run() {
emptyLocks();
}
});
}
private void emptyLocks() {
overtimeStatusLock = overtimeStatusLock.dispose();
}
}
}

View File

@@ -0,0 +1,76 @@
/*
This file is part of the HeavenMS MapleStory Server
Copyleft (L) 2016 - 2019 RonanLana
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.services.task.channel;
import net.server.services.BaseService;
import config.YamlConfig;
import net.server.audit.locks.MonitoredLockType;
import net.server.services.BaseScheduler;
/**
*
* @author Ronan
*/
public class OverallService extends BaseService { // thanks Alex for suggesting a refactor over the several channel schedulers unnecessarily populating the Channel class
private OverallScheduler channelSchedulers[] = new OverallScheduler[YamlConfig.config.server.CHANNEL_LOCKS];
public OverallService() {
for(int i = 0; i < YamlConfig.config.server.CHANNEL_LOCKS; i++) {
channelSchedulers[i] = new OverallScheduler();
}
}
@Override
public void dispose() {
for(int i = 0; i < YamlConfig.config.server.CHANNEL_LOCKS; i++) {
if(channelSchedulers[i] != null) {
channelSchedulers[i].dispose();
channelSchedulers[i] = null;
}
}
}
public void registerOverallAction(int mapid, Runnable runAction, long delay) {
channelSchedulers[getChannelSchedulerIndex(mapid)].registerDelayedAction(runAction, delay);
}
public void forceRunOverallAction(int mapid, Runnable runAction) {
channelSchedulers[getChannelSchedulerIndex(mapid)].forceRunDelayedAction(runAction);
}
public class OverallScheduler extends BaseScheduler {
public OverallScheduler() {
super(MonitoredLockType.CHANNEL_OVERALL);
}
public void registerDelayedAction(Runnable runAction, long delay) {
registerEntry(runAction, runAction, delay);
}
public void forceRunDelayedAction(Runnable runAction) {
interruptEntry(runAction);
}
}
}

View File

@@ -0,0 +1,62 @@
/*
This file is part of the HeavenMS MapleStory Server
Copyleft (L) 2016 - 2019 RonanLana
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.services.task.world;
import net.server.audit.locks.MonitoredLockType;
import net.server.services.BaseScheduler;
import net.server.services.BaseService;
/**
*
* @author Ronan
*/
public class CharacterSaveService extends BaseService {
CharacterSaveScheduler chrSaveScheduler = new CharacterSaveScheduler();
@Override
public void dispose() {
if(chrSaveScheduler != null) {
chrSaveScheduler.dispose();
chrSaveScheduler = null;
}
}
public void registerSaveCharacter(int characterId, Runnable runAction) {
chrSaveScheduler.registerSaveCharacter(characterId, runAction);
}
private class CharacterSaveScheduler extends BaseScheduler {
public CharacterSaveScheduler() {
super(MonitoredLockType.WORLD_SAVECHARS);
}
public void registerSaveCharacter(Integer characterId, Runnable runAction) {
registerEntry(characterId, runAction, 0);
}
public void unregisterSaveCharacter(Integer characterId) {
interruptEntry(characterId);
}
}
}

View File

@@ -0,0 +1,63 @@
/*
This file is part of the HeavenMS MapleStory Server, commands OdinMS-based
Copyleft (L) 2016 - 2019 RonanLana
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.services.type;
import net.server.services.ServiceType;
import net.server.services.task.channel.EventService;
import net.server.services.task.channel.FaceExpressionService;
import net.server.services.task.channel.MobAnimationService;
import net.server.services.task.channel.MobClearSkillService;
import net.server.services.task.channel.MobMistService;
import net.server.services.task.channel.MobStatusService;
import net.server.services.task.channel.OverallService;
import net.server.services.BaseService;
import net.server.services.Service;
/**
*
* @author Ronan
*/
public enum ChannelServices implements ServiceType {
MOB_STATUS(MobStatusService.class),
MOB_ANIMATION(MobAnimationService.class),
MOB_CLEAR_SKILL(MobClearSkillService.class),
MOB_MIST(MobMistService.class),
FACE_EXPRESSION(FaceExpressionService.class),
EVENT(EventService.class),
OVERALL(OverallService.class);
private Class<? extends BaseService> s;
private ChannelServices(Class<? extends BaseService> service) {
s = service;
}
@Override
public Service createService() {
return new Service(s);
}
@Override
public ChannelServices[] enumValues() {
return ChannelServices.values();
}
}

View File

@@ -0,0 +1,51 @@
/*
This file is part of the HeavenMS MapleStory Server, commands OdinMS-based
Copyleft (L) 2016 - 2019 RonanLana
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.services.type;
import net.server.services.ServiceType;
import net.server.services.BaseService;
import net.server.services.Service;
import net.server.services.task.world.CharacterSaveService;
/**
*
* @author Ronan
*/
public enum WorldServices implements ServiceType {
SAVE_CHARACTER(CharacterSaveService.class);
private Class<? extends BaseService> s;
private WorldServices(Class<? extends BaseService> service) {
s = service;
}
@Override
public Service createService() {
return new Service(s);
}
@Override
public WorldServices[] enumValues() {
return WorldServices.values();
}
}