jkevan commented on code in PR #424: URL: https://github.com/apache/unomi/pull/424#discussion_r876839109
########## services/src/main/java/org/apache/unomi/services/impl/scope/ScopeServiceImpl.java: ########## @@ -0,0 +1,107 @@ +/* + * 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. + */ +package org.apache.unomi.services.impl.scope; + +import org.apache.unomi.api.Item; +import org.apache.unomi.api.Metadata; +import org.apache.unomi.api.PartialList; +import org.apache.unomi.api.Scope; +import org.apache.unomi.api.services.SchedulerService; +import org.apache.unomi.api.services.ScopeService; +import org.apache.unomi.persistence.spi.PersistenceService; + +import java.util.LinkedList; +import java.util.List; +import java.util.TimerTask; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +public class ScopeServiceImpl implements ScopeService { + + private PersistenceService persistenceService; + + private SchedulerService schedulerService; + + private Integer scopesRefreshInterval = 1000; + + private ConcurrentMap<String, Scope> scopes = new ConcurrentHashMap<>(); + + private ScheduledFuture<?> scheduledFuture; + + public void setPersistenceService(PersistenceService persistenceService) { + this.persistenceService = persistenceService; + } + + public void setSchedulerService(SchedulerService schedulerService) { + this.schedulerService = schedulerService; + } + + public void setScopesRefreshInterval(Integer scopesRefreshInterval) { + this.scopesRefreshInterval = scopesRefreshInterval; + } + + public void postConstruct() { + initializeTimers(); + } + + public void preDestroy() { + scheduledFuture.cancel(true); + } + + @Override + public PartialList<Metadata> getScopesMetadatas(int offset, int size, String sortBy) { + PartialList<Scope> items = persistenceService.getAllItems(Scope.class, offset, size, sortBy); + List<Metadata> details = new LinkedList<>(); + for (Scope definition : items.getList()) { + details.add(definition.getMetadata()); + } + return new PartialList<>(details, items.getOffset(), items.getPageSize(), items.getTotalSize(), items.getTotalSizeRelation()); + } Review Comment: Since we are loading the scopes in RAM, I'm not sure it's interesting to keep this query. We should return the list of in RAM Scopes, witch make the parameters like: int offset, int size, String sortBy obsolete. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
