2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.context;
24 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
25 import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
26 import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
29 * The Interface ContextAlbum is implemented by all classes that manage context in Apex. Context
30 * albums may store context in memory, on disk, in a repository or in a mechanism such as a
33 * <p>A context album uses plugins to handle its context schemas, its distribution, its locking, and
36 * <p>The schema that defines the items in a context album is interpreted by a plugin that implements
37 * the {@link SchemaHelper} interface. The schema helper uses the schema definition to provide new
38 * instances for a context album. By default, context albums use Java schemas.
40 * <p>Context albums may be shared across an arbitrary number of JVMs using a distribution mechanism.
41 * Apex context distributed context albums using plugins that implement the {@link Distributor}
42 * interface. By default, context albums use JVM local distribution, that is context albums are only
43 * available in a single JVM
45 * <p>Items in a context album may be locked across all distributed instances of an album. Apex locks
46 * instances on context albums using the distributed locking mechanism in a plugin that implements
47 * the {@link LockManager} interface. By default, context albums use Java locking local to a single
48 * JVM on each context album instance.
50 * <p>Context albums may be persisted to disk, database, or any other repository. Apex persists context
51 * albums using the persistence mechanism in a plugin that implements the {@link Persistor}
52 * interface. By default, context albums use a dummy persistor plugin that does not persist context
55 * @author Liam Fallon (liam.fallon@ericsson.com)
57 public interface ContextAlbum extends Map<String, Object> {
59 * Gets the key of the context album instance.
63 AxArtifactKey getKey();
66 * Gets the name of the context album instance.
73 * Get the current context album with values.
75 * @return the current context runtime values
77 AxContextAlbum getAlbumDefinition();
80 * Get the schema helper for the technology that is handling the schema for this album.
82 * @return the schema helper
84 SchemaHelper getSchemaHelper();
87 * Place a read lock on a key in this album across the entire cluster.
89 * @param key The key to lock
90 * @throws ContextException on locking errors
92 void lockForReading(String key) throws ContextException;
95 * Place a write lock on a key in this album across the entire cluster.
97 * @param key The key to lock
98 * @throws ContextException on locking errors
100 void lockForWriting(String key) throws ContextException;
103 * Release the the read lock on a key in this album across the entire cluster.
105 * @param key The key to unlock
106 * @throws ContextException on locking errors
108 void unlockForReading(String key) throws ContextException;
111 * Release the the write lock on a key in this album across the entire cluster.
113 * @param key The key to unlock
114 * @throws ContextException on locking errors
116 void unlockForWriting(String key) throws ContextException;
119 * Get the stack of artifact keys currently using this context item.
121 * @return the keys of the artifacts using the context album at the moment
123 AxConcept[] getUserArtifactStack();
126 * Set the stack of artifact keys currently using this context item.
128 * @param userArtifactStack the keys of the artifacts using the context album at the moment
130 void setUserArtifactStack(AxConcept[] userArtifactStack);
133 * Flush the context album to the distribution and persistence mechanism.
135 * @throws ContextException On context flush errors
137 void flush() throws ContextException;