Package: CacheingRemoteRepository

CacheingRemoteRepository

nameinstructionbranchcomplexitylinemethod
CacheingRemoteRepository(RemoteRepositoryConfiguration, EventLogger, RepositoryCacheFactory)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
createCacheingQuery(RepositoryCache, Query)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createQuery(Query)
M: 2 C: 9
82%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 2
100%
M: 0 C: 1
100%
createQuery(String, String)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
createQuery(String, String, Map)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getRepositoryCache()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
start()
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
stop()
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2008, 2010 VMware Inc.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * VMware Inc. - initial contribution
10: *******************************************************************************/
11:
12: package org.eclipse.virgo.repository.internal.cacheing;
13:
14: import java.util.Map;
15: import java.util.Set;
16:
17: import org.eclipse.virgo.medic.eventlog.EventLogger;
18: import org.eclipse.virgo.repository.Query;
19: import org.eclipse.virgo.repository.configuration.RemoteRepositoryConfiguration;
20: import org.eclipse.virgo.repository.internal.cacheing.cache.RepositoryCache;
21: import org.eclipse.virgo.repository.internal.cacheing.cache.RepositoryCacheFactory;
22: import org.eclipse.virgo.repository.internal.remote.RemoteRepository;
23:
24: /**
25: * {@link CacheingRemoteRepository} extends {@link RemoteRepository} by cacheing retrieved artifacts in a local disk
26: * cache.
27: * <p />
28: *
29: * <strong>Concurrent Semantics</strong><br />
30: *
31: * Thread safe.
32: *
33: */
34: public final class CacheingRemoteRepository extends RemoteRepository {
35:
36: private final Object monitor = new Object();
37:
38: private final RepositoryCacheFactory repositoryCacheFactory;
39:
40: private RepositoryCache cache;
41:
42: public CacheingRemoteRepository(RemoteRepositoryConfiguration configuration, EventLogger eventLogger,
43: RepositoryCacheFactory repositoryCacheFactory) {
44: super(configuration, eventLogger);
45: this.repositoryCacheFactory = repositoryCacheFactory;
46: }
47:
48: /**
49: * {@inheritDoc}
50: */
51: @Override
52: protected void start() {
53: super.start();
54: synchronized (this.monitor) {
55: this.cache = this.repositoryCacheFactory.createRepositoryCache(this);
56: }
57: }
58:
59: /**
60: * {@inheritDoc}
61: */
62: @Override
63: public void stop() {
64: synchronized (this.monitor) {
65: this.cache = null;
66: }
67: super.stop();
68: }
69:
70: /**
71: * {@inheritDoc}
72: */
73: @Override
74: public Query createQuery(String key, String value) {
75: Query uncachedQuery = super.createQuery(key, value);
76: return createQuery(uncachedQuery);
77: }
78:
79: /**
80: * {@inheritDoc}
81: */
82: @Override
83: public Query createQuery(String key, String value, Map<String, Set<String>> properties) {
84: Query uncachedQuery = super.createQuery(key, value, properties);
85: return createQuery(uncachedQuery);
86: }
87:
88: private Query createQuery(Query uncachedQuery) {
89: RepositoryCache repositoryCache = getRepositoryCache();
90:• return repositoryCache == null ? uncachedQuery : createCacheingQuery(repositoryCache, uncachedQuery);
91: }
92:
93: private RepositoryCache getRepositoryCache() {
94: synchronized (this.monitor) {
95: return this.cache;
96: }
97: }
98:
99: // This method takes a RepositoryCache parameter rather than using the instance variable to avoid racing with stop().
100: private static Query createCacheingQuery(RepositoryCache activeCache, Query uncachedQuery) {
101: return new CacheingQuery(uncachedQuery, activeCache);
102: }
103:
104: }