-
Notifications
You must be signed in to change notification settings - Fork 654
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,982 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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"> | ||
<!-- | ||
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. | ||
--> | ||
|
||
<parent> | ||
<artifactId>cache</artifactId> | ||
<groupId>org.apache.karaf.cache</groupId> | ||
<version>4.4.3-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>org.apache.karaf.cache.api</artifactId> | ||
<name>Apache Karaf :: Cache :: API</name> | ||
|
||
<packaging>bundle</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>javax.cache</groupId> | ||
<artifactId>cache-api</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<extensions>true</extensions> | ||
<configuration> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
89 changes: 89 additions & 0 deletions
89
cache/api/src/main/java/org/apache/karaf/cache/api/CacheService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* | ||
* 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.karaf.cache.api; | ||
|
||
import javax.cache.Cache; | ||
import javax.cache.configuration.Configuration; | ||
import java.net.URL; | ||
import java.util.List; | ||
|
||
/** | ||
* A simple caching facade that lets use caching using JSR 107 APIs. | ||
*/ | ||
public interface CacheService { | ||
|
||
/** | ||
* Creates a new cache. | ||
* @param name name of the cache to create | ||
* @param configuration cache configuration, such as its key and value type. | ||
* Specific configurations (such as max size and caching duration) | ||
* will depend on the cache provider. | ||
* @param <K> type of cache keys, e.g. Long or String | ||
* @param <V> type of cache values, e.g. Long or String | ||
*/ | ||
<K, V> void createCache(String name, Configuration<K, V> configuration); | ||
|
||
/** | ||
* Creates a new cache from a configuration file (located in Karaf's etc directory). | ||
* @param configFile config file | ||
* @param classLoader class loader can be passed in case the cache complex custom keys and/or values | ||
*/ | ||
void createCache(URL configFile, ClassLoader classLoader); | ||
|
||
/** | ||
* Get a single cached value by providing cache's name and a key. | ||
* @param name name of the cache to get the value from | ||
* @param key key of the cached item | ||
* @param <K> cache key type | ||
* @param <V> cache value type | ||
* @return | ||
*/ | ||
<K, V> V get(String name, K key); | ||
|
||
/** | ||
* Store a new value in a cache. | ||
* @param name name of the cache to put new value into | ||
* @param key key under which the value will be cached | ||
* @param value value to cache | ||
* @param <K> cache key type | ||
* @param <V> cache value type | ||
*/ | ||
<K, V> void put(String name, K key, V value); | ||
|
||
/** | ||
* Get the cache object directly. | ||
* @param name name of the cache | ||
* @param <K> cache key type | ||
* @param <V> cache value type | ||
* @return | ||
*/ | ||
<K, V> Cache<K, V> getCache(String name); | ||
|
||
/** | ||
* Invalidates a cache. | ||
* @param name name of the cache to invalidate | ||
*/ | ||
void invalidateCache(String name); | ||
|
||
/** | ||
* Lists all available caches by their names. | ||
* @return list of cache names | ||
*/ | ||
List<String> listCaches(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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"> | ||
|
||
<!-- | ||
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. | ||
--> | ||
<parent> | ||
<artifactId>cache</artifactId> | ||
<groupId>org.apache.karaf.cache</groupId> | ||
<version>4.4.3-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<name>Apache Karaf :: Cache :: Commands</name> | ||
|
||
<artifactId>org.apache.karaf.cache.commands</artifactId> | ||
|
||
<packaging>bundle</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.karaf.shell</groupId> | ||
<artifactId>org.apache.karaf.shell.core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.karaf.cache</groupId> | ||
<artifactId>org.apache.karaf.cache.api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.ehcache</groupId> | ||
<artifactId>ehcache</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.karaf.tooling</groupId> | ||
<artifactId>karaf-services-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<instructions> | ||
<Karaf-Commands>*</Karaf-Commands> | ||
</instructions> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
76 changes: 76 additions & 0 deletions
76
cache/commands/src/main/java/org/apache/karaf/cache/core/commands/CacheCommandSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* | ||
* 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.karaf.cache.core.commands; | ||
|
||
import org.apache.karaf.cache.api.CacheService; | ||
import org.apache.karaf.shell.api.action.Action; | ||
import org.apache.karaf.shell.api.action.lifecycle.Reference; | ||
|
||
import javax.cache.Cache; | ||
import javax.cache.configuration.Configuration; | ||
|
||
public abstract class CacheCommandSupport implements Action | ||
{ | ||
|
||
@Reference | ||
private CacheService cacheService; | ||
|
||
@Override | ||
public Object execute() throws Exception | ||
{ | ||
if (cacheService == null) { | ||
throw new IllegalStateException("CacheService not found"); | ||
} | ||
return doExecute(cacheService); | ||
} | ||
|
||
protected abstract Object doExecute(CacheService cacheService) throws Exception; | ||
|
||
@SuppressWarnings("unchecked") | ||
protected Object castKey(String cacheName, Object key) { | ||
Cache cache = cacheService.getCache(cacheName); | ||
if (cache == null) { | ||
throw new IllegalArgumentException("Cache " + cacheName + " not found!"); | ||
} | ||
return cast(key, cacheService.getCache(cacheName).getConfiguration(Configuration.class).getKeyType()); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
protected Object castValue(String cacheName, Object value) { | ||
return cast(value, cacheService.getCache(cacheName).getConfiguration(Configuration.class).getValueType()); | ||
} | ||
|
||
private Object cast(Object argument, Class type) | ||
{ | ||
if (type.equals(Short.class)) { | ||
return Short.parseShort((String) argument); | ||
} | ||
if (type.equals(Integer.class)) { | ||
return Integer.parseInt((String) argument); | ||
} | ||
if (type.equals(Long.class)) { | ||
return Long.parseLong((String) argument); | ||
} | ||
if (type.equals(Boolean.class)) { | ||
return Boolean.parseBoolean((String) argument); | ||
} | ||
|
||
return argument; | ||
} | ||
} |
Oops, something went wrong.