Skip to content

Commit 345d595

Browse files
author
Shawn Hartsock
committed
licenses
1 parent e0f1357 commit 345d595

9 files changed

+169
-3
lines changed

src/main/java/com/pssd/cache/CacheFactory.java

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/* License added by: GRADLE-LICENSE-PLUGIN
2+
*
3+
* Copyright (C) 2012 Shawn Hartsock <[email protected]>
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
package com.pssd.cache;
219

320
import com.pssd.cache.errors.ConfigurationFoundButNotAccessableException;
@@ -13,15 +30,19 @@
1330
import java.util.LinkedList;
1431

1532
/**
16-
* The basic idea here is to build caches based on objects.
33+
* The basic idea here is to build caches based on objects. You would assemble a POJO that was appropriate for use
34+
* as a key in a hash. This would be an object that held all the salient variables for the method. Then you back off
35+
* your particular method into an anonymous inner class implementing the CacheableFunction interface.
36+
* <p/>
37+
* In the testing directory, the class SimpleCacheUser shows one of the simplest ways to use this Caching API.
1738
* <p/>
1839
* @author Shawn Hartsock
1940
*/
2041
public class CacheFactory {
2142
/**
2243
* The singleton owner of caches in this system.
2344
*/
24-
final static CacheManager cacheManager = new CacheManager();
45+
final static CacheManager cacheManager = new CacheManager(); //TODO: allow configuration from XML in classpath
2546

2647
/**
2748
* builds a CacheConfiguration object based on properties
@@ -190,3 +211,4 @@ private static Object put(final Ehcache cache, final Object parameter, final Cac
190211
return result;
191212
}
192213
}
214+

src/main/java/com/pssd/cache/CacheableFunction.java

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/* License added by: GRADLE-LICENSE-PLUGIN
2+
*
3+
* Copyright (C) 2012 Shawn Hartsock <[email protected]>
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
package com.pssd.cache;
219

320
/**
@@ -21,3 +38,4 @@
2138
public interface CacheableFunction<P,T> {
2239
T cached(P parameter);
2340
}
41+

src/main/java/com/pssd/cache/Configuration.java

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/* License added by: GRADLE-LICENSE-PLUGIN
2+
*
3+
* Copyright (C) 2012 Shawn Hartsock <[email protected]>
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
package com.pssd.cache;
219

320
import net.sf.ehcache.config.CacheConfiguration;
@@ -150,3 +167,4 @@ public int hashCode() {
150167
return result;
151168
}
152169
}
170+

src/main/java/com/pssd/cache/LambdaCache.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/* License added by: GRADLE-LICENSE-PLUGIN
2+
*
3+
* Copyright (C) 2012 Shawn Hartsock <[email protected]>
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
package com.pssd.cache;
219

320
/**
@@ -9,4 +26,5 @@
926
*/
1027
public interface LambdaCache<P,T> {
1128
T invoke(CacheableFunction<P,T> cacheableFunction, P parameter);
12-
}
29+
}
30+
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1+
/* License added by: GRADLE-LICENSE-PLUGIN
2+
*
3+
* Copyright (C) 2012 Shawn Hartsock <[email protected]>
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
package com.pssd.cache.errors;
219

320
public class ConfigurationFoundButNotAccessableException extends IllegalStateException {
421
public ConfigurationFoundButNotAccessableException(Class owner, String name) {
522
super("found static field " + name + " on " + owner.getCanonicalName() + " but could not access");
623
}
724
}
25+

src/main/java/com/pssd/cache/errors/NoConfigurationFoundException.java

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/* License added by: GRADLE-LICENSE-PLUGIN
2+
*
3+
* Copyright (C) 2012 Shawn Hartsock <[email protected]>
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
package com.pssd.cache.errors;
219

320
public class NoConfigurationFoundException extends IllegalStateException {
@@ -9,3 +26,4 @@ public NoConfigurationFoundException(final Class owner,final String name) {
926
super("could not find static field " + name + " on " + owner.getCanonicalName());
1027
}
1128
}
29+

src/test/java/com/pssd/cache/CacheFactoryConfigurationMethodTests.java

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/* License added by: GRADLE-LICENSE-PLUGIN
2+
*
3+
* Copyright (C) 2012 Shawn Hartsock <[email protected]>
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
package com.pssd.cache;
219

320
import net.sf.ehcache.config.CacheConfiguration;
@@ -56,3 +73,4 @@ private void assertCorrectFifoCacheConfiguration(Configuration configuration) {
5673
}
5774

5875
}
76+

src/test/java/com/pssd/cache/CacheFactoryTests.java

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/* License added by: GRADLE-LICENSE-PLUGIN
2+
*
3+
* Copyright (C) 2012 Shawn Hartsock <[email protected]>
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
package com.pssd.cache;
219

320
import net.sf.ehcache.config.CacheConfiguration;
@@ -26,3 +43,4 @@ public void testSimpleCacheUserNamedCacheCorrectResult() {
2643

2744
}
2845
}
46+

src/test/java/com/pssd/cache/SimpleCacheUser.java

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/* License added by: GRADLE-LICENSE-PLUGIN
2+
*
3+
* Copyright (C) 2012 Shawn Hartsock <[email protected]>
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
package com.pssd.cache;
219

320
public class SimpleCacheUser {
@@ -22,3 +39,4 @@ public Integer cached(String number) {
2239
});
2340
}
2441
}
42+

0 commit comments

Comments
 (0)