You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2016/11/13 21:07:31 UTC
svn commit: r1769546 - in
/sling/whiteboard/olli/caching/org.apache.sling.commons.caching: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/sling/ src/main/java/org/apache/sling/commons/
src/main/ja...
Author: olli
Date: Sun Nov 13 21:07:31 2016
New Revision: 1769546
URL: http://svn.apache.org/viewvc?rev=1769546&view=rev
Log:
SLING-6281 Provide Commons Caching (JSR 107/JCache)
Added:
sling/whiteboard/olli/caching/org.apache.sling.commons.caching/
sling/whiteboard/olli/caching/org.apache.sling.commons.caching/pom.xml
sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/
sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/
sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/
sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/
sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/
sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/
sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/
sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/
sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/CacheManagerService.java
sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/base/
sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/base/AbstractCacheManagerService.java
sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/base/package-info.java
sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/package-info.java
Added: sling/whiteboard/olli/caching/org.apache.sling.commons.caching/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/olli/caching/org.apache.sling.commons.caching/pom.xml?rev=1769546&view=auto
==============================================================================
--- sling/whiteboard/olli/caching/org.apache.sling.commons.caching/pom.xml (added)
+++ sling/whiteboard/olli/caching/org.apache.sling.commons.caching/pom.xml Sun Nov 13 21:07:31 2016
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>29</version>
+ <relativePath/>
+ </parent>
+
+ <artifactId>org.apache.sling.commons.caching</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <name>Apache Sling Commons Caching</name>
+ <description>Apache Sling Commons Caching</description>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <!-- javax -->
+ <dependency>
+ <groupId>javax.cache</groupId>
+ <artifactId>cache-api</artifactId>
+ <version>1.0.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <!-- OSGi -->
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.annotation</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <!-- jsr305 -->
+ <dependency>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>jsr305</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Added: sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/CacheManagerService.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/CacheManagerService.java?rev=1769546&view=auto
==============================================================================
--- sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/CacheManagerService.java (added)
+++ sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/CacheManagerService.java Sun Nov 13 21:07:31 2016
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.commons.caching;
+
+import java.net.URI;
+
+import javax.annotation.Nonnull;
+import javax.cache.Cache;
+import javax.cache.configuration.Configuration;
+
+import org.osgi.annotation.versioning.ProviderType;
+
+@ProviderType
+public interface CacheManagerService {
+
+ /**
+ * @see javax.cache.CacheManager#getURI()
+ */
+ URI getURI();
+
+ /**
+ * @see javax.cache.CacheManager#createCache(String, Configuration)
+ */
+ <K, V, C extends Configuration<K, V>> Cache<K, V> createCache(@Nonnull String cacheName, @Nonnull C configuration) throws IllegalArgumentException;
+
+ /**
+ * @see javax.cache.CacheManager#getCache(String, Class, Class)
+ */
+ <K, V> Cache<K, V> getCache(@Nonnull String cacheName, @Nonnull Class<K> keyType, @Nonnull Class<V> valueType);
+
+ /**
+ * @see javax.cache.CacheManager#getCache(String)
+ */
+ <K, V> Cache<K, V> getCache(@Nonnull String cacheName);
+
+ /**
+ * @see javax.cache.CacheManager#getCacheNames()
+ */
+ Iterable<String> getCacheNames();
+
+ /**
+ * @see javax.cache.CacheManager#destroyCache(String)
+ */
+ void destroyCache(@Nonnull String cacheName);
+
+ /**
+ * @see javax.cache.CacheManager#enableManagement(String, boolean)
+ */
+ void enableManagement(@Nonnull String cacheName, boolean enabled);
+
+ /**
+ * @see javax.cache.CacheManager#enableStatistics(String, boolean)
+ */
+ void enableStatistics(@Nonnull String cacheName, boolean enabled);
+
+ /**
+ * @see javax.cache.CacheManager#isClosed()
+ */
+ boolean isClosed();
+
+ /**
+ * @see javax.cache.CacheManager#unwrap(Class)
+ */
+ <T> T unwrap(@Nonnull Class<T> clazz);
+
+}
Added: sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/base/AbstractCacheManagerService.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/base/AbstractCacheManagerService.java?rev=1769546&view=auto
==============================================================================
--- sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/base/AbstractCacheManagerService.java (added)
+++ sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/base/AbstractCacheManagerService.java Sun Nov 13 21:07:31 2016
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.commons.caching.base;
+
+import java.net.URI;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+import javax.annotation.Nonnull;
+import javax.cache.Cache;
+import javax.cache.CacheManager;
+import javax.cache.configuration.Configuration;
+
+import org.apache.sling.commons.caching.CacheManagerService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+public abstract class AbstractCacheManagerService implements CacheManagerService {
+
+ protected Map<String, ServiceRegistration<Cache>> cacheRegistrations = new HashMap<>();
+
+ public AbstractCacheManagerService() {
+ }
+
+ protected abstract BundleContext getBundleContext();
+
+ protected abstract CacheManager getCacheManager();
+
+ @Override
+ public URI getURI() {
+ return getCacheManager().getURI();
+ }
+
+ @Override
+ public <K, V, C extends Configuration<K, V>> Cache<K, V> createCache(@Nonnull final String cacheName, @Nonnull final C configuration) throws IllegalArgumentException {
+ return getCacheManager().createCache(cacheName, configuration);
+ }
+
+ @Override
+ public <K, V> Cache<K, V> getCache(@Nonnull final String cacheName, @Nonnull final Class<K> keyType, @Nonnull final Class<V> valueType) {
+ return getCacheManager().getCache(cacheName, keyType, valueType);
+ }
+
+ @Override
+ public <K, V> Cache<K, V> getCache(@Nonnull final String cacheName) {
+ return getCacheManager().getCache(cacheName);
+ }
+
+ @Override
+ public Iterable<String> getCacheNames() {
+ return getCacheManager().getCacheNames();
+ }
+
+ @Override
+ public void destroyCache(@Nonnull final String cacheName) {
+ getCacheManager().destroyCache(cacheName);
+ }
+
+ @Override
+ public void enableManagement(@Nonnull final String cacheName, final boolean enabled) {
+ getCacheManager().enableManagement(cacheName, enabled);
+ }
+
+ @Override
+ public void enableStatistics(@Nonnull final String cacheName, final boolean enabled) {
+ getCacheManager().enableStatistics(cacheName, enabled);
+ }
+
+ @Override
+ public boolean isClosed() {
+ return getCacheManager().isClosed();
+ }
+
+ @Override
+ public <T> T unwrap(@Nonnull final Class<T> clazz) {
+ return getCacheManager().unwrap(clazz);
+ }
+
+ protected void registerCache(@Nonnull final Cache cache, @Nonnull final Configuration configuration) {
+ final Dictionary<String, Object> properties = new Hashtable<>();
+ properties.put("name", cache.getName());
+ properties.put("keyType", configuration.getKeyType());
+ properties.put("valueType", configuration.getValueType());
+ properties.put("storeByValue", configuration.isStoreByValue());
+ final ServiceRegistration<Cache> cacheRegistration = getBundleContext().registerService(Cache.class, cache, properties);
+ cacheRegistrations.put(cache.getName(), cacheRegistration);
+ }
+
+ protected void unregisterCache(@Nonnull final String cacheName) {
+ final ServiceRegistration<Cache> cacheRegistration = cacheRegistrations.remove(cacheName);
+ if (cacheRegistration != null) {
+ cacheRegistration.unregister();
+ }
+ }
+
+}
Added: sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/base/package-info.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/base/package-info.java?rev=1769546&view=auto
==============================================================================
--- sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/base/package-info.java (added)
+++ sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/base/package-info.java Sun Nov 13 21:07:31 2016
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+@Version("0.0.1")
+package org.apache.sling.commons.caching.base;
+
+import org.osgi.annotation.versioning.Version;
Added: sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/package-info.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/package-info.java?rev=1769546&view=auto
==============================================================================
--- sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/package-info.java (added)
+++ sling/whiteboard/olli/caching/org.apache.sling.commons.caching/src/main/java/org/apache/sling/commons/caching/package-info.java Sun Nov 13 21:07:31 2016
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+@Version("0.0.1")
+package org.apache.sling.commons.caching;
+
+import org.osgi.annotation.versioning.Version;