This project has retired. For details please refer to its
Attic page.
RepositoryInfoCache xref
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */1920package org.apache.chemistry.opencmis.client.bindings.impl;
2122import java.io.Serializable;
2324import org.apache.chemistry.opencmis.client.bindings.cache.Cache;
25import org.apache.chemistry.opencmis.client.bindings.cache.impl.CacheImpl;
26import org.apache.chemistry.opencmis.client.bindings.cache.impl.MapCacheLevelImpl;
27import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
28import org.apache.chemistry.opencmis.commons.SessionParameter;
29import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
3031/**32 * A cache for repository info objects.33 */34publicclassRepositoryInfoCache implements Serializable {
3536privatestaticfinallong serialVersionUID = 1L;
3738privatestaticfinalint CACHE_SIZE_REPOSITORIES = 10;
3940privatefinalCache cache;
4142/**43 * Constructor.44 * 45 * @param session46 * the session object47 */48publicRepositoryInfoCache(BindingSession session) {
49int repCount = session.get(SessionParameter.CACHE_SIZE_REPOSITORIES, CACHE_SIZE_REPOSITORIES);
50if (repCount < 1) {
51 repCount = CACHE_SIZE_REPOSITORIES;
52 }
5354 cache = newCacheImpl("Repository Info Cache");
55 cache.initialize(new String[] { MapCacheLevelImpl.class.getName() + " " + MapCacheLevelImpl.CAPACITY + "="56 + repCount });
57 }
5859/**60 * Adds a repository info object to the cache.61 * 62 * @param repositoryInfo63 * the repository info object64 */65publicvoid put(RepositoryInfo repositoryInfo) {
66if ((repositoryInfo == null) || (repositoryInfo.getId() == null)) {
67return;
68 }
6970 cache.put(repositoryInfo, repositoryInfo.getId());
71 }
7273/**74 * Retrieves a repository info object from the cache.75 * 76 * @param repositoryId77 * the repository id78 * @return the repository info object or <code>null</code> if the object is79 * not in the cache80 */81public RepositoryInfo get(String repositoryId) {
82return (RepositoryInfo) cache.get(repositoryId);
83 }
8485/**86 * Removes a repository info object from the cache.87 * 88 * @param repositoryId89 * the repository id90 */91publicvoid remove(String repositoryId) {
92 cache.remove(repositoryId);
93 }
9495 @Override
96public String toString() {
97return cache.toString();
98 }
99 }