use of org.olat.core.util.coordinate.SyncerExecutor in project OpenOLAT by OpenOLAT.
the class BinderUserInformationsDAO method updateBinderUserInformations.
/**
* Update (or create if not exists) the course informations for a user. To creation
* of the user infos is made with doInSync.
*
* @param binder The binder
* @param identity The identity
*/
public void updateBinderUserInformations(final Binder binder, final Identity identity) {
int updatedRows = lowLevelUpdate(binder, identity);
// to make it quick
dbInstance.commit();
if (updatedRows == 0) {
OLATResourceable lockRes = OresHelper.createOLATResourceableInstance("BinderLaunchDate::Identity", identity.getKey());
CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(lockRes, new SyncerExecutor() {
@Override
public void execute() {
try {
int retryUpdatedRows = lowLevelUpdate(binder, identity);
if (retryUpdatedRows == 0) {
createAndPersistUserInfos(binder, identity);
}
} catch (Exception e) {
log.error("Cannot update binder informations for: " + identity + " from " + identity, e);
}
}
});
}
}
use of org.olat.core.util.coordinate.SyncerExecutor in project OpenOLAT by OpenOLAT.
the class ProjectBrokerManagerImpl method setProjectState.
@Override
public void setProjectState(final Project project, final String state) {
final Long projectBrokerId = project.getProjectBroker().getKey();
OLATResourceable projectBrokerOres = OresHelper.createOLATResourceableInstance(this.getClass(), projectBrokerId);
CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(projectBrokerOres, new SyncerExecutor() {
@Override
public void execute() {
// For cluster-safe : reload project object here another node might have changed this in the meantime
Project reloadedProject = (Project) dbInstance.loadObject(project, true);
reloadedProject.setState(state);
updateProjectAndInvalidateCache(reloadedProject);
}
});
}
use of org.olat.core.util.coordinate.SyncerExecutor in project OpenOLAT by OpenOLAT.
the class BGAreaManagerImpl method deleteBGArea.
/**
* @see org.olat.group.area.BGAreaManager#deleteBGArea(org.olat.group.area.BGArea)
*/
@Override
public void deleteBGArea(final BGArea area) {
final OLATResource resource = area.getResource();
CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(resource, new SyncerExecutor() {
@Override
public void execute() {
BGArea reloadArea = loadArea(area.getKey());
if (reloadArea != null) {
// 1) delete all area - group relations
deleteBGtoAreaRelations(reloadArea);
// 2) delete area - assessment mode relations
deleteAssessmentModeToAreaRelations(reloadArea);
// 3) delete area itself
dbInstance.deleteObject(reloadArea);
logAudit("Deleted Business Group Area", reloadArea.toString());
} else {
logAudit("Business Group Area was already deleted", area.toString());
}
}
});
}
use of org.olat.core.util.coordinate.SyncerExecutor in project OpenOLAT by OpenOLAT.
the class CoordinatorTest method testDoInSyncWithSyncerExecutor.
/**
* Test with 2 threads T1 & T2.
* T1 T2
* doInSync T1-1 sleep 5sec
* sleep 10sec ...
* ... ...
* ... doInSync T2-1
* ... sleep 10sec
* ... ...
* doInSync T1-2 ...
* finished ...
* doInSync T2-2
* finished
*/
@Test
public void testDoInSyncWithSyncerExecutor() {
final List<Exception> exceptionHolder = Collections.synchronizedList(new ArrayList<Exception>(1));
final List<Boolean> statusList = Collections.synchronizedList(new ArrayList<Boolean>(1));
final CountDownLatch finishCount = new CountDownLatch(2);
final OLATResourceable ores = OresHelper.createOLATResourceableInstance("testDoInSync", new Long("123"));
// thread 1
new Thread(new Runnable() {
public void run() {
try {
// do something in sync
CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ores, new SyncerExecutor() {
public void execute() {
log.info("Thread-1: execute doInSync 1");
}
});
// end syncerCallback
// sleep
sleep(1000);
// do again do something in sync
CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ores, new SyncerExecutor() {
public void execute() {
log.info("Thread-1: execute doInSync 2");
}
});
// end syncerCallback
log.info("Thread-1: finished");
statusList.add(Boolean.TRUE);
} catch (Exception e) {
exceptionHolder.add(e);
} finally {
try {
DBFactory.getInstance().closeSession();
} catch (Exception e) {
// ignore
}
finishCount.countDown();
}
}
}).start();
// thread 2
new Thread(new Runnable() {
public void run() {
try {
// sleep
sleep(500);
// do something in sync
CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ores, new SyncerExecutor() {
public void execute() {
log.info("Thread-2: execute doInSync 1");
}
});
// end syncerCallback
// sleep
sleep(1000);
// do again do something in sync
CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ores, new SyncerExecutor() {
public void execute() {
log.info("Thread-2: execute doInSync 2");
}
});
// end syncerCallback
log.info("Thread-2: finished");
statusList.add(Boolean.TRUE);
} catch (Exception e) {
exceptionHolder.add(e);
} finally {
try {
DBFactory.getInstance().closeSession();
} catch (Exception e) {
// ignore
}
finishCount.countDown();
}
}
}).start();
// sleep until t1 and t2 should have terminated/excepted
try {
finishCount.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Assert.fail("Threads did not finish in 10sec");
}
// if not -> they are in deadlock and the db did not detect it
for (Exception exception : exceptionHolder) {
log.error("exception: ", exception);
}
Assert.assertEquals("It throws an exception in test", 0, exceptionHolder.size());
}
use of org.olat.core.util.coordinate.SyncerExecutor in project OpenOLAT by OpenOLAT.
the class ProfileFormController method formOK.
@Override
protected void formOK(final UserRequest ureq) {
User user = identityToModify.getUser();
// update each user field
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
FormItem formItem = formItems.get(userPropertyHandler.getName());
if (formItem.isEnabled()) {
userPropertyHandler.updateUserFromFormItem(user, formItem);
}
}
if (portraitDeleted) {
File img = dps.getLargestPortrait(identityToModify.getName());
if (img != null) {
dps.deletePortrait(identityToModify);
notifyPortraitChanged();
}
}
File uploadedImage = portraitUpload.getUploadFile();
String uploadedFilename = portraitUpload.getUploadFileName();
if (uploadedImage != null) {
dps.setPortrait(uploadedImage, uploadedFilename, identityToModify.getName());
notifyPortraitChanged();
}
if (logoDeleted) {
File img = dps.getLargestLogo(identityToModify.getName());
if (img != null) {
dps.deleteLogo(identityToModify);
notifyPortraitChanged();
}
}
if (logoUpload != null) {
File uploadedLogo = logoUpload.getUploadFile();
String uploadedLogoname = logoUpload.getUploadFileName();
if (uploadedLogo != null) {
dps.setLogo(uploadedLogo, uploadedLogoname, identityToModify.getName());
notifyPortraitChanged();
}
}
// Store the "about me" text.
HomePageConfig conf = hpcm.loadConfigFor(identityToModify.getName());
conf.setTextAboutMe(textAboutMe.getValue());
hpcm.saveConfigTo(identityToModify.getName(), conf);
// fire the appropriate event
fireEvent(ureq, Event.DONE_EVENT);
// update the user profile data
CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(OresHelper.createOLATResourceableInstance(Identity.class, identityToModify.getKey()), new SyncerExecutor() {
@Override
public void execute() {
UserManager um = UserManager.getInstance();
identityToModify = (Identity) DBFactory.getInstance().loadObject(identityToModify);
currentEmail = identityToModify.getUser().getProperty("email", null);
identityToModify = updateIdentityFromFormData(identityToModify);
changedEmail = identityToModify.getUser().getProperty("email", null);
emailChanged = false;
if ((currentEmail == null && StringHelper.containsNonWhitespace(changedEmail)) || (currentEmail != null && !currentEmail.equals(changedEmail))) {
if (isAllowedToChangeEmailWithoutVerification(ureq) || !StringHelper.containsNonWhitespace(changedEmail)) {
String key = identityToModify.getUser().getProperty("emchangeKey", null);
TemporaryKey tempKey = rm.loadTemporaryKeyByRegistrationKey(key);
if (tempKey != null) {
rm.deleteTemporaryKey(tempKey);
}
securityManager.deleteInvalidAuthenticationsByEmail(currentEmail);
} else {
emailChanged = true;
// change email address to old address until it is verified
identityToModify.getUser().setProperty("email", currentEmail);
}
}
if (!um.updateUserFromIdentity(identityToModify)) {
getWindowControl().setInfo(translate("profile.unsuccessful"));
// reload user data from db
identityToModify = BaseSecurityManager.getInstance().loadIdentityByKey(identityToModify.getKey());
}
OLATResourceable modRes = OresHelper.createOLATResourceableInstance(Identity.class, identityToModify.getKey());
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new MultiUserEvent("changed"), modRes);
if (!emailChanged) {
fireEvent(ureq, Event.FAILED_EVENT);
}
}
});
if (emailChanged) {
removeAsListenerAndDispose(dialogCtr);
String dialogText = "";
if (identityToModify.equals(ureq.getIdentity())) {
dialogText = translate("email.change.dialog.text");
} else {
dialogText = translate("email.change.dialog.text.usermanager");
}
dialogCtr = DialogBoxUIFactory.createYesNoDialog(ureq, getWindowControl(), translate("email.change.dialog.title"), dialogText);
listenTo(dialogCtr);
dialogCtr.activate();
}
}
Aggregations