com.eventsourcing.index.CQIndexEngine Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eventsourcing-core Show documentation
Show all versions of eventsourcing-core Show documentation
Event capture and querying framework for Java
/**
* Copyright (c) 2016, All Contributors (see CONTRIBUTORS file)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.eventsourcing.index;
import com.eventsourcing.*;
import com.googlecode.cqengine.ConcurrentIndexedCollection;
import com.googlecode.cqengine.IndexedCollection;
import com.googlecode.cqengine.persistence.Persistence;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public abstract class CQIndexEngine extends AbstractIndexEngine {
protected Repository repository;
protected Journal journal;
protected Map indexedCollections = new ConcurrentHashMap<>();
@Override @SuppressWarnings("unchecked")
public IndexedCollection> getIndexedCollection(Class klass) {
IndexedCollection existingCollection = indexedCollections.get(klass.getName());
if (existingCollection == null) {
JournalPersistence tJournalPersistence = null;
if (Event.class.isAssignableFrom(klass))
tJournalPersistence = (JournalPersistence) new EventJournalPersistence<>(journal,
(Class) klass);
if (Command.class.isAssignableFrom(klass))
tJournalPersistence = (JournalPersistence) new CommandJournalPersistence<>(journal,
(Class) klass);
if (tJournalPersistence == null) {
throw new IllegalArgumentException();
}
IndexedCollection> indexedCollection = createIndexedCollection(tJournalPersistence);
indexedCollections.put(klass.getName(), indexedCollection);
return indexedCollection;
} else {
return existingCollection;
}
}
protected IndexedCollection>
createIndexedCollection(Persistence, ? extends Comparable> persistence) {
return new ConcurrentIndexedCollection<>(persistence);
}
@Override
protected void doStart() {
notifyStarted();
}
@Override
protected void doStop() {
notifyStopped();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy