public static CompositeActivityValues createCompositeValues( ActivityPersistenceFactory activityPersistenceFactory, Collection<SenseiSchema.FieldDefinition> fieldNames, List<TimeAggregateInfo> aggregatedActivities, Comparator<String> versionComparator) { CompositeActivityValues ret = new CompositeActivityValues(); CompositeActivityStorage persistentColumnManager = activityPersistenceFactory.getCompositeStorage(); ret.metadata = activityPersistenceFactory.getMetadata(); ret.activityConfig = activityPersistenceFactory.getActivityConfig(); ret.updateBatch = new UpdateBatch<Update>(ret.activityConfig); ret.pendingDeletes = new UpdateBatch<Update>(ret.activityConfig); ret.recentlyAddedUids = new RecentlyAddedUids(ret.activityConfig.getUndeletableBufferSize()); int count = 0; if (ret.metadata != null) { ret.metadata.init(); ret.lastVersion = ret.metadata.version; count = ret.metadata.count; } if (persistentColumnManager != null) { persistentColumnManager.decorateCompositeActivityValues(ret, ret.metadata); // metadata might be trimmed count = ret.metadata.count; } logger.info( "Init compositeActivityValues. Documents = " + ret.uidToArrayIndex.size() + ", Deletes = " + ret.deletedIndexes.size()); ret.versionComparator = versionComparator; ret.valuesMap = new HashMap<String, ActivityValues>(fieldNames.size()); for (TimeAggregateInfo aggregatedActivity : aggregatedActivities) { ret.valuesMap.put( aggregatedActivity.fieldName, TimeAggregatedActivityValues.createTimeAggregatedValues( aggregatedActivity.fieldName, aggregatedActivity.times, count, activityPersistenceFactory)); } for (SenseiSchema.FieldDefinition field : fieldNames) { if (field.isActivity && !ret.valuesMap.containsKey(field.name)) { ActivityPrimitiveValues values = ActivityPrimitiveValues.createActivityPrimitiveValues( activityPersistenceFactory, field, count); ret.valuesMap.put(field.name, values); } } return ret; }
public void close() { closed = true; executor.shutdown(); try { executor.awaitTermination(2, TimeUnit.SECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } if (activityStorage != null) { activityStorage.close(); } for (ActivityValues activityIntValues : valuesMap.values()) { activityIntValues.close(); } }
protected CompositeActivityStorage getCompositeStorage() { CompositeActivityStorage ret = new CompositeActivityStorage(indexDirPath); ret.init(); return ret; }