1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.db.service;
\r
14 import org.simantics.db.SessionManager;
\r
15 import org.simantics.db.SessionReference;
\r
16 import org.simantics.db.exception.DatabaseException;
\r
18 public interface LifecycleSupport {
\r
20 public enum LifecycleState {
\r
21 CREATING, ALIVE, CLOSING, CLOSED
\r
24 public interface LifecycleListener {
\r
25 void stateChanged(LifecycleState newState);
\r
29 * Get session reference
\r
30 * @return session reference
\r
32 SessionReference getSessionReference();
\r
35 * @return the SessionManager that created this Session.
\r
37 SessionManager getSessionManager();
\r
40 * @return <code>true</code> if session is closed and thus no longer usable
\r
42 boolean isClosing();
\r
45 void addListener(LifecycleListener listener);
\r
46 void removeListener(LifecycleListener listener);
\r
49 * Close this database session.
\r
50 * This should also dispose any Disposable services registered
\r
51 * into this ServiceLocator.
\r
53 * @param timeout maximum time to wait for prerequisites for close to become true.
\r
54 * If negative waits indefinitely. If zero polls. Time is given in milliseconds.
\r
55 * @param force If true close session after timeout even if transactions are still active.
\r
56 * If false throws TimeoutException if transactions are still active.
\r
57 * @throws DatabaseException
\r
59 void close(long timeout, boolean force)
\r
60 throws DatabaseException;
\r
63 * Same as close(0, false).
\r
66 throws DatabaseException;
\r
70 * @return identifier that can be used to reconnect if the session was
\r
71 * not closed gracefully. SessionManagerSource.NullSessionId if closed
\r
77 throws DatabaseException;
\r