X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.management%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fmanagement%2FSessionContext.java;h=79df14026cc6a9c646ec1871b6433ebc8ab11e1f;hb=refs%2Fheads%2Fprivate%2Fantin_tyomaa;hp=ef5f270531021b890888c3016ae2f08e8ed096f9;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.management/src/org/simantics/db/management/SessionContext.java b/bundles/org.simantics.db.management/src/org/simantics/db/management/SessionContext.java index ef5f27053..79df14026 100644 --- a/bundles/org.simantics.db.management/src/org/simantics/db/management/SessionContext.java +++ b/bundles/org.simantics.db.management/src/org/simantics/db/management/SessionContext.java @@ -11,30 +11,19 @@ *******************************************************************************/ package org.simantics.db.management; -import java.io.IOException; import java.lang.reflect.Method; import java.util.Arrays; import java.util.UUID; import java.util.concurrent.TimeoutException; -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.request.Read; import org.simantics.db.service.LifecycleSupport; import org.simantics.db.service.VirtualGraphSupport; -import org.simantics.db.services.GlobalServiceInitializer; import org.simantics.layer0.Layer0; import org.simantics.utils.datastructures.disposable.DisposeState; import org.simantics.utils.datastructures.disposable.IDisposable; @@ -43,10 +32,6 @@ import org.simantics.utils.datastructures.hints.HintContext; 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. @@ -62,110 +47,30 @@ public class SessionContext extends HintContext implements ISessionContext, Disp private Session session; - private UserAuthenticationAgent authenticator; - - private boolean servicesRegistered = false; - - private IStatus servicesRegisteredStatus = null; - public static SessionContext create(Session session, boolean initialize) throws DatabaseException { 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)); s.registerService(VirtualGraph.class, s.getService(VirtualGraphSupport.class).getMemoryPersistent(UUID.randomUUID().toString())); // Builtins needs to be initialized for the new session before // anything useful can be done with it. - s.syncRequest(new ReadRequest() { + s.syncRequest(new Read() { @Override - public void run(ReadGraph g) { + public Object perform(ReadGraph g) { // Registers Builtins with the ServiceLocator of the Graph's session. Layer0.getInstance(g); + return null; } }); - } - - public void registerServices() { - if (servicesRegistered) - return; - - // Register any services available for the SessionLocator of the new - // Session. - servicesRegisteredStatus = new GlobalServiceInitializer().initialize(session); - if (!servicesRegisteredStatus.isOK()) { - Activator.getDefault().getLog().log(servicesRegisteredStatus); - } - - servicesRegistered = true; + } // @Override