Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
remove circular refs
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn Feldman committed Apr 8, 2015
1 parent 7b229d4 commit 5cc3bf6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
@@ -0,0 +1,43 @@
/*
*
* * Licensed to the Apache Software Foundation (ASF) under one or more
* * contributor license agreements. 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. For additional information regarding
* * copyright in this work, please see the NOTICE file in the top level
* * directory of this distribution.
*
*/
package org.apache.usergrid.corepersistence;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.apache.usergrid.persistence.EntityManager;

/**
* returns instances of cache.
*/
@Singleton
public class ApplicationIdCacheFactory {
private final ApplicationIdCacheFig fig;
private final ManagerCache cache;

@Inject
public ApplicationIdCacheFactory(ApplicationIdCacheFig fig,ManagerCache cache){

this.fig = fig;
this.cache = cache;
}
public ApplicationIdCache getInstance(EntityManager managementEntityManager){
return new ApplicationIdCacheImpl(managementEntityManager,cache,fig);
}
}
Expand Up @@ -51,25 +51,22 @@
* Implements the org app cache for faster runtime lookups. These values are immutable, so this LRU cache can stay
* full for the duration of the execution
*/
@Singleton
public class ApplicationIdCacheImpl implements ApplicationIdCache {
private static final Logger logger = LoggerFactory.getLogger(ApplicationIdCacheImpl.class);


/**
* Cache the pointer to our root entity manager for reference
*/
private final EntityManager rootEm;
private final CpEntityManagerFactory emf;

private final LoadingCache<String, Optional<UUID>> appCache;
private final EntityManager managementEnityManager;
private final ManagerCache managerCache;



@Inject
public ApplicationIdCacheImpl(final EntityManagerFactory emf, ApplicationIdCacheFig fig) {
this.emf = (CpEntityManagerFactory)emf;
this.rootEm = emf.getEntityManager(emf.getManagementAppId());
public ApplicationIdCacheImpl(final EntityManager managementEnityManager, ManagerCache managerCache, ApplicationIdCacheFig fig) {
this.managementEnityManager = managementEnityManager;
this.managerCache = managerCache;
appCache = CacheBuilder.newBuilder()
.maximumSize(fig.getCacheSize())
.expireAfterWrite(fig.getCacheTimeout(), TimeUnit.MILLISECONDS)
Expand Down Expand Up @@ -101,12 +98,12 @@ private Optional<UUID> fetchApplicationId( final String applicationName ) {

UUID value = null;

EntityCollectionManager ecm = emf.getManagerCache().getEntityCollectionManager(
EntityCollectionManager ecm = managerCache.getEntityCollectionManager(
new ApplicationScopeImpl(
new SimpleId( CpNamingUtils.MANAGEMENT_APPLICATION_ID, Schema.TYPE_APPLICATION ) ) );

try {
if ( rootEm.getApplication() == null ) {
if ( managementEnityManager.getApplication() == null ) {
return Optional.empty();
}
} catch ( Exception e ) {
Expand Down
Expand Up @@ -110,6 +110,7 @@ public void configureMigrationProvider() {
// install(new QueueModule());

bind(ManagerCache.class).to( CpManagerCache.class );
bind(ApplicationIdCacheFactory.class);

Multibinder<EntityDeleted> entityBinder =
Multibinder.newSetBinder(binder(), EntityDeleted.class);
Expand Down Expand Up @@ -143,7 +144,6 @@ public void configureMigrationProvider() {
bind(AllApplicationsObservable.class).to(AllApplicationsObservableImpl.class);

install(new GuicyFigModule(ApplicationIdCacheFig.class));
bind(ApplicationIdCache.class).to(ApplicationIdCacheImpl.class);

}

Expand Down
Expand Up @@ -118,7 +118,7 @@ public CpEntityManagerFactory(
this.entityIndexFactory = injector.getInstance(EntityIndexFactory.class);
this.managerCache = injector.getInstance( ManagerCache.class );
this.metricsFactory = injector.getInstance( MetricsFactory.class );
this.applicationIdCache = injector.getInstance(ApplicationIdCache.class);
this.applicationIdCache = injector.getInstance(ApplicationIdCacheFactory.class).getInstance(getManagementEntityManager());
}


Expand Down

0 comments on commit 5cc3bf6

Please sign in to comment.