1 /*
2
3 Copyright 2005-2007 Tamas Cservenak (t.cservenak@gmail.com)
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 */
18 package org.abstracthorizon.proximity.logic;
19
20 import org.abstracthorizon.proximity.Item;
21 import org.abstracthorizon.proximity.ProximityRequest;
22 import org.abstracthorizon.proximity.Repository;
23
24 // TODO: Auto-generated Javadoc
25 /**
26 * Repository logic that drives repository's behaviour.
27 * <p>
28 * Asked on every request got by Repository, it have a few simple questions to answer and postprocess items after local
29 * and remote retrieval.
30 *
31 * @author cstamas
32 */
33 public interface RepositoryLogic
34 {
35
36 /**
37 * Return true if repository should check for local cached version of the path.
38 *
39 * @param repository the repository
40 * @param request the request
41 *
42 * @return true, if should check for local copy
43 */
44 boolean shouldCheckForLocalCopy( Repository repository, ProximityRequest request );
45
46 /**
47 * Postprocess item if needed after local copy found.
48 *
49 * @param item the item
50 * @param repository the repository
51 * @param request the request
52 *
53 * @return the item
54 */
55 Item afterLocalCopyFound( Repository repository, ProximityRequest request, Item item );
56
57 /**
58 * Return true if repository should initiate remote lookup.
59 *
60 * @param repository the repository
61 * @param request the request
62 * @param localItem the local item
63 *
64 * @return true is there is need to check remote copy
65 */
66 boolean shouldCheckForRemoteCopy( Repository repository, ProximityRequest request, Item localItem );
67
68 /**
69 * Postprocess item if needed after remote retrieval.
70 *
71 * @param localItem - the artifact found locally
72 * @param repository - the artifact found remotely
73 * @param request the request
74 * @param remoteItem the remote item
75 *
76 * @return the item
77 */
78 Item afterRemoteCopyFound( Repository repository, ProximityRequest request, Item localItem, Item remoteItem );
79
80 /**
81 * Return true if reposotiry should store the remote retrieved item in a local writable store.
82 *
83 * @param localItem the local item
84 * @param remoteItem the remote item
85 * @param repository the repository
86 * @param request the request
87 *
88 * @return true, if should store locally after remote retrieval
89 */
90 boolean shouldStoreLocallyAfterRemoteRetrieval( Repository repository, ProximityRequest request, Item localItem,
91 Item remoteItem );
92
93 /**
94 * Choose tha artifact to serve.
95 *
96 * @param repository the repository
97 * @param request the request
98 * @param localItem the local item
99 * @param remoteItem the remote item
100 *
101 * @return the item
102 */
103 public Item afterRetrieval( Repository repository, ProximityRequest request, Item localItem, Item remoteItem );
104
105 }