-
Notifications
You must be signed in to change notification settings - Fork 656
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
14 changed files
with
610 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?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.2-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>api</artifactId> | ||
|
||
<packaging>bundle</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>javax.cache</groupId> | ||
<artifactId>cache-api</artifactId> | ||
<version>1.1.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<extensions>true</extensions> | ||
<configuration> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
17 changes: 17 additions & 0 deletions
17
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,17 @@ | ||
package org.apache.karaf.cache.api; | ||
|
||
import javax.cache.configuration.Configuration; | ||
import java.util.List; | ||
|
||
public interface CacheService { | ||
|
||
void createCache(String name, Configuration<?, ?> configuration); | ||
|
||
Object get(String name, Object key); | ||
|
||
void put(String name, Object key, Object value); | ||
|
||
void invalidateCache(String name); | ||
|
||
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,65 @@ | ||
<?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.2-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>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>api</artifactId> | ||
<version>${project.version}</version> | ||
</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> |
39 changes: 39 additions & 0 deletions
39
cache/commands/src/main/java/org/apache/karaf/cache/core/commands/Create.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,39 @@ | ||
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.Argument; | ||
import org.apache.karaf.shell.api.action.Command; | ||
import org.apache.karaf.shell.api.action.lifecycle.Reference; | ||
import org.apache.karaf.shell.api.action.lifecycle.Service; | ||
|
||
import javax.cache.configuration.Configuration; | ||
import javax.cache.configuration.MutableConfiguration; | ||
import javax.cache.expiry.CreatedExpiryPolicy; | ||
import javax.cache.expiry.Duration; | ||
|
||
@Service | ||
@Command(scope = "cache", name = "create", description = "") | ||
public class Create implements Action { | ||
|
||
@Argument(index = 0, required = true) | ||
String cacheName; | ||
@Argument(index = 1, required = true) | ||
String keyType; | ||
@Argument(index = 2, required = true) | ||
String valueType; | ||
@Reference | ||
private CacheService cacheService; | ||
|
||
@Override | ||
public Object execute() throws Exception { | ||
Class keyClass = Class.forName(keyType); | ||
Class valueClass = Class.forName(valueType); | ||
Configuration<?, ?> configuration = new MutableConfiguration<>() | ||
.setTypes(keyClass, valueClass) | ||
.setStoreByValue(false) | ||
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(Duration.ONE_MINUTE)); | ||
cacheService.createCache(cacheName, configuration); | ||
return null; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
cache/commands/src/main/java/org/apache/karaf/cache/core/commands/Get.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,30 @@ | ||
package org.apache.karaf.cache.core.commands; | ||
|
||
import org.apache.karaf.cache.api.CacheService; | ||
import org.apache.karaf.cache.core.commands.completers.CacheNameCompleter; | ||
import org.apache.karaf.shell.api.action.Action; | ||
import org.apache.karaf.shell.api.action.Argument; | ||
import org.apache.karaf.shell.api.action.Command; | ||
import org.apache.karaf.shell.api.action.Completion; | ||
import org.apache.karaf.shell.api.action.lifecycle.Reference; | ||
import org.apache.karaf.shell.api.action.lifecycle.Service; | ||
|
||
@Service | ||
@Command(scope = "cache", name = "get", description = "") | ||
public class Get implements Action { | ||
|
||
@Reference | ||
CacheService cacheService; | ||
|
||
@Argument(index = 0, required = true) | ||
@Completion(CacheNameCompleter.class) | ||
String cacheName; | ||
|
||
@Argument(index = 1, required = true) | ||
Object key; | ||
|
||
@Override | ||
public Object execute() throws Exception { | ||
return cacheService.get(cacheName, key); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
cache/commands/src/main/java/org/apache/karaf/cache/core/commands/Invalidate.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,28 @@ | ||
package org.apache.karaf.cache.core.commands; | ||
|
||
import org.apache.karaf.cache.api.CacheService; | ||
import org.apache.karaf.cache.core.commands.completers.CacheNameCompleter; | ||
import org.apache.karaf.shell.api.action.Action; | ||
import org.apache.karaf.shell.api.action.Argument; | ||
import org.apache.karaf.shell.api.action.Command; | ||
import org.apache.karaf.shell.api.action.Completion; | ||
import org.apache.karaf.shell.api.action.lifecycle.Reference; | ||
import org.apache.karaf.shell.api.action.lifecycle.Service; | ||
|
||
@Service | ||
@Command(scope = "cache", name = "invalidate", description = "") | ||
public class Invalidate implements Action { | ||
|
||
@Reference | ||
CacheService cacheService; | ||
|
||
@Argument(index = 0, required = true) | ||
@Completion(CacheNameCompleter.class) | ||
String cacheName; | ||
|
||
@Override | ||
public Object execute() throws Exception { | ||
cacheService.invalidateCache(cacheName); | ||
return cacheService + " invalidated"; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
cache/commands/src/main/java/org/apache/karaf/cache/core/commands/ListCaches.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,20 @@ | ||
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.Command; | ||
import org.apache.karaf.shell.api.action.lifecycle.Reference; | ||
import org.apache.karaf.shell.api.action.lifecycle.Service; | ||
|
||
@Service | ||
@Command(scope = "cache", name = "list", description = "") | ||
public class ListCaches implements Action { | ||
|
||
@Reference | ||
CacheService cacheService; | ||
|
||
@Override | ||
public Object execute() throws Exception { | ||
return cacheService.listCaches(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
cache/commands/src/main/java/org/apache/karaf/cache/core/commands/Put.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,34 @@ | ||
package org.apache.karaf.cache.core.commands; | ||
|
||
import org.apache.karaf.cache.api.CacheService; | ||
import org.apache.karaf.cache.core.commands.completers.CacheNameCompleter; | ||
import org.apache.karaf.shell.api.action.Action; | ||
import org.apache.karaf.shell.api.action.Argument; | ||
import org.apache.karaf.shell.api.action.Command; | ||
import org.apache.karaf.shell.api.action.Completion; | ||
import org.apache.karaf.shell.api.action.lifecycle.Reference; | ||
import org.apache.karaf.shell.api.action.lifecycle.Service; | ||
|
||
@Service | ||
@Command(scope = "cache", name = "put", description = "") | ||
public class Put implements Action { | ||
|
||
@Reference | ||
private CacheService cacheService; | ||
|
||
@Argument(index = 0, required = true) | ||
@Completion(CacheNameCompleter.class) | ||
String cacheName; | ||
|
||
@Argument(index = 1, required = true) | ||
Object key; | ||
|
||
@Argument(index = 2, required = true) | ||
Object value; | ||
|
||
@Override | ||
public Object execute() throws Exception { | ||
cacheService.put(cacheName, key, value); | ||
return null; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...nds/src/main/java/org/apache/karaf/cache/core/commands/completers/CacheNameCompleter.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,32 @@ | ||
package org.apache.karaf.cache.core.commands.completers; | ||
|
||
import org.apache.karaf.cache.api.CacheService; | ||
import org.apache.karaf.shell.api.action.lifecycle.Reference; | ||
import org.apache.karaf.shell.api.action.lifecycle.Service; | ||
import org.apache.karaf.shell.api.console.CommandLine; | ||
import org.apache.karaf.shell.api.console.Completer; | ||
import org.apache.karaf.shell.api.console.Session; | ||
import org.apache.karaf.shell.support.completers.StringsCompleter; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
public class CacheNameCompleter implements Completer { | ||
|
||
@Reference | ||
CacheService cacheService; | ||
|
||
@Override | ||
public int complete(Session session, CommandLine commandLine, List<String> candidates) { | ||
StringsCompleter delegate = new StringsCompleter(); | ||
try { | ||
for (String cache : cacheService.listCaches()) { | ||
delegate.getStrings().add(cache); | ||
} | ||
} catch (Exception e) { | ||
// nothing to do | ||
} | ||
|
||
return delegate.complete(session, commandLine, candidates); | ||
} | ||
} |
Oops, something went wrong.