]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics/src/org/simantics/internal/TimedSessionCache.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics / src / org / simantics / internal / TimedSessionCache.java
index 7b764e7a76546f8cd420e26de909aeb0489afdeb..c59ee7c030db1d365636653a2b1aac0eeb5d5201 100644 (file)
@@ -1,83 +1,83 @@
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.internal;\r
-\r
-import java.util.Hashtable;\r
-\r
-import org.osgi.framework.BundleContext;\r
-import org.osgi.framework.ServiceRegistration;\r
-import org.simantics.db.Disposable;\r
-import org.simantics.db.management.ISessionContext;\r
-import org.simantics.utils.datastructures.cache.SoftTimedCache;\r
-import org.simantics.utils.datastructures.disposable.IDisposable;\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class TimedSessionCache extends SoftTimedCache</*ServerAddress*/Object, ISessionContext> {\r
-\r
-    private static ServiceRegistration<?> service       = null;\r
-    private static BundleContext          bundleContext = null;\r
-    private static boolean                disposed      = false;\r
-\r
-    TimedSessionCache() {\r
-        super("Database Session Cache Timer");\r
-    }\r
-\r
-    /**\r
-     * Invoked by the bundle activator to initialize the cache service.\r
-     * \r
-     * @param context the bundle context to register the service with\r
-     */\r
-    @SuppressWarnings({ "unchecked", "rawtypes" })\r
-    public synchronized static void initialize(BundleContext context) {\r
-        bundleContext = context;\r
-        service = context.registerService(TimedSessionCache.class.getName(), new TimedSessionCache(), new Hashtable());\r
-        disposed = false;\r
-    }\r
-\r
-    /**\r
-     * Invoked by the bundle activator to close the cache service.\r
-     */\r
-    public synchronized static void close() {\r
-        if (service != null) {\r
-            TimedSessionCache cache = getCache();\r
-            cache.clear();\r
-            \r
-            service.unregister();\r
-            service = null;\r
-            disposed = true;\r
-        }\r
-        bundleContext = null;\r
-    }\r
-\r
-    public static synchronized TimedSessionCache getCache() {\r
-        if (disposed)\r
-            throw new IllegalStateException("cache service is disposed");\r
-        if (service == null)\r
-            throw new IllegalStateException("cache service not initialized");\r
-        return (TimedSessionCache) bundleContext.getService(service.getReference());\r
-    }\r
-\r
-    @Override\r
-    protected void disposeValue(ISessionContext v) {\r
-        super.disposeValue(v);\r
-        // Implementing Disposable allows immediate disposal of the value\r
-        // object instead of leaving the disposal up to garbage\r
-        // collection and finalization.\r
-        if (v instanceof IDisposable) {\r
-            ((IDisposable) v).safeDispose();\r
-        } else if (v instanceof Disposable) {\r
-            ((Disposable) v).dispose();\r
-        }\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.internal;
+
+import java.util.Hashtable;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.simantics.db.Disposable;
+import org.simantics.db.management.ISessionContext;
+import org.simantics.utils.datastructures.cache.SoftTimedCache;
+import org.simantics.utils.datastructures.disposable.IDisposable;
+/**
+ * @author Tuukka Lehtonen
+ */
+public class TimedSessionCache extends SoftTimedCache</*ServerAddress*/Object, ISessionContext> {
+
+    private static ServiceRegistration<?> service       = null;
+    private static BundleContext          bundleContext = null;
+    private static boolean                disposed      = false;
+
+    TimedSessionCache() {
+        super("Database Session Cache Timer");
+    }
+
+    /**
+     * Invoked by the bundle activator to initialize the cache service.
+     * 
+     * @param context the bundle context to register the service with
+     */
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    public synchronized static void initialize(BundleContext context) {
+        bundleContext = context;
+        service = context.registerService(TimedSessionCache.class.getName(), new TimedSessionCache(), new Hashtable());
+        disposed = false;
+    }
+
+    /**
+     * Invoked by the bundle activator to close the cache service.
+     */
+    public synchronized static void close() {
+        if (service != null) {
+            TimedSessionCache cache = getCache();
+            cache.clear();
+            
+            service.unregister();
+            service = null;
+            disposed = true;
+        }
+        bundleContext = null;
+    }
+
+    public static synchronized TimedSessionCache getCache() {
+        if (disposed)
+            throw new IllegalStateException("cache service is disposed");
+        if (service == null)
+            throw new IllegalStateException("cache service not initialized");
+        return (TimedSessionCache) bundleContext.getService(service.getReference());
+    }
+
+    @Override
+    protected void disposeValue(ISessionContext v) {
+        super.disposeValue(v);
+        // Implementing Disposable allows immediate disposal of the value
+        // object instead of leaving the disposal up to garbage
+        // collection and finalization.
+        if (v instanceof IDisposable) {
+            ((IDisposable) v).safeDispose();
+        } else if (v instanceof Disposable) {
+            ((Disposable) v).dispose();
+        }
+    }
+
+}