use of io.jans.orm.couchbase.model.SimpleSessionState in project jans by JanssenProject.
the class CouchbaseConcurentSessionUpdateSample method main.
public static void main(String[] args) throws InterruptedException {
// Prepare sample connection details
CouchbaseEntryManagerSample couchbaseEntryManagerSample = new CouchbaseEntryManagerSample();
final CouchbaseEntryManager couchbaseEntryManager = couchbaseEntryManagerSample.createCouchbaseEntryManager();
try {
// Create Couchbase entry manager
String sessionId = "xyzcyzxy-a41a-45ad-8a83-61485dbad561";
final String sessionDn = "uniqueIdentifier=" + sessionId + ",ou=session,o=jans";
final String userDn = "inum=@!E8F2.853B.1E7B.ACE2!0001!39A4.C163!0000!A8F2.DE1E.D7FB,ou=people,o=jans";
final SimpleSessionState simpleSessionState = new SimpleSessionState();
simpleSessionState.setDn(sessionDn);
simpleSessionState.setId(sessionId);
simpleSessionState.setLastUsedAt(new Date());
couchbaseEntryManager.persist(simpleSessionState);
System.out.println("Persisted");
int threadCount = 500;
ExecutorService executorService = Executors.newFixedThreadPool(threadCount, daemonThreadFactory());
for (int i = 0; i < threadCount; i++) {
final int count = i;
executorService.execute(new Runnable() {
@Override
public void run() {
final SimpleSessionState simpleSessionStateFromCouchbase = couchbaseEntryManager.find(SimpleSessionState.class, sessionDn);
String beforeUserDn = simpleSessionStateFromCouchbase.getUserDn();
String randomUserDn = count % 2 == 0 ? userDn : "";
try {
simpleSessionStateFromCouchbase.setUserDn(randomUserDn);
simpleSessionStateFromCouchbase.setLastUsedAt(new Date());
couchbaseEntryManager.merge(simpleSessionStateFromCouchbase);
System.out.println("Merged thread: " + count + ", userDn: " + randomUserDn + ", before userDn: " + beforeUserDn);
} catch (Throwable e) {
System.out.println("ERROR !!!, thread: " + count + ", userDn: " + randomUserDn + ", before userDn: " + beforeUserDn + ", error:" + e.getMessage());
// e.printStackTrace();
}
}
});
}
Thread.sleep(5000L);
} finally {
couchbaseEntryManager.destroy();
}
}
use of io.jans.orm.couchbase.model.SimpleSessionState in project jans by JanssenProject.
the class CouchbaseUpateMissingEntrySample method main.
public static void main(String[] args) {
// Prepare sample connection details
CouchbaseEntryManagerSample sqlSampleEntryManager = new CouchbaseEntryManagerSample();
// Create SQL entry manager
CouchbaseEntryManager sqlEntryManager = sqlSampleEntryManager.createCouchbaseEntryManager();
String sessionId = UUID.randomUUID().toString();
final String sessionDn = "uniqueIdentifier=" + sessionId + ",ou=session,o=jans";
final SimpleSessionState simpleSessionState = new SimpleSessionState();
simpleSessionState.setDn(sessionDn);
simpleSessionState.setId(sessionId);
simpleSessionState.setLastUsedAt(new Date());
try {
sqlEntryManager.merge(simpleSessionState);
System.out.println("Updated");
} catch (EntryPersistenceException ex) {
LOG.info("Failed to update, root case exception: {}", ex.getCause().getClass(), ex);
}
}
Aggregations