use of com.gamingmesh.jobs.dao.JobsDAO in project Jobs by GamingMesh.
the class PlayerManager method saveAll.
/**
* Save all the information of all of the players in the game
*/
public void saveAll() {
JobsDAO dao = Jobs.getJobsDAO();
/*
* Saving is a three step process to minimize synchronization locks when called asynchronously.
*
* 1) Safely copy list for saving.
* 2) Perform save on all players on copied list.
* 3) Garbage collect the real list to remove any offline players with saved data
*/
ArrayList<JobsPlayer> list = null;
synchronized (players) {
list = new ArrayList<JobsPlayer>(players.values());
}
for (JobsPlayer jPlayer : list) {
jPlayer.save(dao);
}
synchronized (players) {
Iterator<JobsPlayer> iter = players.values().iterator();
while (iter.hasNext()) {
JobsPlayer jPlayer = iter.next();
synchronized (jPlayer.saveLock) {
if (!jPlayer.isOnline() && jPlayer.isSaved()) {
iter.remove();
}
}
}
}
}
use of com.gamingmesh.jobs.dao.JobsDAO in project Jobs by GamingMesh.
the class PlayerManager method transferJob.
/**
* Transfers player job
* @param jPlayer
* @param oldjob - the old job
* @param newjob - the new job
*/
public void transferJob(JobsPlayer jPlayer, Job oldjob, Job newjob) {
synchronized (jPlayer.saveLock) {
if (!jPlayer.transferJob(oldjob, newjob))
return;
JobsDAO dao = Jobs.getJobsDAO();
dao.quitJob(jPlayer, oldjob);
dao.joinJob(jPlayer, newjob);
jPlayer.save(dao);
}
}
Aggregations