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