*******************************************************************************/
package org.simantics.db.management;
-import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.UUID;
import org.eclipse.core.runtime.IStatus;
import org.simantics.db.Disposable;
import org.simantics.db.ReadGraph;
-import org.simantics.db.ServerReference;
import org.simantics.db.Session;
-import org.simantics.db.SessionManager;
-import org.simantics.db.SessionReference;
import org.simantics.db.VirtualGraph;
-import org.simantics.db.authentication.UserAuthenticationAgent;
import org.simantics.db.common.processor.MergingDelayedWriteProcessor;
import org.simantics.db.common.processor.MergingGraphRequestProcessor;
import org.simantics.db.common.request.ReadRequest;
import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.exception.InternalException;
import org.simantics.db.management.internal.Activator;
import org.simantics.db.service.LifecycleSupport;
import org.simantics.db.service.VirtualGraphSupport;
import org.simantics.utils.threads.IThreadWorkQueue;
import org.simantics.utils.threads.SyncListenerList;
-import fi.vtt.simantics.procore.ProCoreServerReference;
-import fi.vtt.simantics.procore.ProCoreSessionReference;
-import fi.vtt.simantics.procore.SessionManagerSource;
-
/**
* Holds all information that is needed to create and manage a single database
* session in the Simantics workbench UI.
private Session session;
- private UserAuthenticationAgent authenticator;
-
private boolean servicesRegistered = false;
private IStatus servicesRegisteredStatus = null;
return new SessionContext(session, initialize);
}
-// public static SessionContext openSession(IServerAddress info, UserAuthenticationAgent auth) throws IOException, DatabaseException {
-// return new SessionContext(info, auth, false);
-// }
-//
-// public static SessionContext openAndInitializeSession(IServerAddress info, UserAuthenticationAgent auth) throws IOException, DatabaseException {
-// return new SessionContext(info, auth, true);
-// }
-
- private static SessionReference createSessionReference(/*IServerAddress address,*/ long sessionId) throws InternalException {
- ProCoreServerReference server = new ProCoreServerReference();
- ProCoreSessionReference ref = new ProCoreSessionReference(server, sessionId);
- return ref;
- }
-
-// private SessionContext(IServerAddress addr, UserAuthenticationAgent auth, boolean initialize) throws IOException, DatabaseException {
-// if (addr == null)
-// throw new IllegalArgumentException("null address");
-//// this.address = addr;
-// this.authenticator = auth;
-//
-// SessionManager sessionManager = SessionManagerProvider.getInstance().getSessionManager();
-//
-// if (initialize) {
-// initializeSession(sessionManager);
-// if (SESSION_DEBUG) {
-// System.err.println("Initialized session: " + addr);
-// System.err.flush();
-// }
-// } else {
-// SessionReference ref = createSessionReference(SessionManagerSource.NullSessionId);
-// this.session = sessionManager.createSession(ref, auth);
-// if (SESSION_DEBUG) {
-// System.err.println("Opened session: " + addr);
-// System.err.flush();
-// }
-// }
-//
-// }
-
private SessionContext(Session session, boolean initialize) throws DatabaseException {
if (initialize)
initializeSession(session);
- ServerReference ref = session.getService( LifecycleSupport.class ).getSessionReference().getServerReference();
-// this.address = ref.serverAddress();
this.session = session;
}
- private void initializeSession(SessionManager sessionManager) throws DatabaseException, IOException {
- Session s = null;
- boolean success = false;
- try {
- SessionReference ref = createSessionReference(SessionManagerSource.NullSessionId);
- s = sessionManager.createSession(ref, authenticator);
- initializeSession(s);
- this.session = s;
- success = true;
- } finally {
- if (!success) {
- if (s != null) {
- LifecycleSupport support = s.getService(LifecycleSupport.class);
- support.close();
- }
- }
- }
- }
-
private void initializeSession(Session s) throws DatabaseException {
s.registerService(MergingGraphRequestProcessor.class, new MergingGraphRequestProcessor("SessionService", s, 20));
s.registerService(MergingDelayedWriteProcessor.class, new MergingDelayedWriteProcessor(s, 20));