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.monitoring;
23 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
24 import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
25 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
26 import org.slf4j.ext.XLogger;
27 import org.slf4j.ext.XLoggerFactory;
30 * This class is used to monitor context creates, deletes, gets, sets, locks and unlocks on context items in Apex
33 * @author Liam Fallon (liam.fallon@ericsson.com)
35 public class ContextMonitor {
36 // Logger for this class
37 private static final XLogger LOGGER = XLoggerFactory.getXLogger(ContextMonitor.class);
40 * Monitor an initiation on a context item.
42 * @param albumKey The item album
43 * @param schemaKey The item schema
44 * @param name The name of the item
45 * @param value The value of the item
47 public void monitorInit(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
49 LOGGER.trace(monitor("INIT", null, albumKey, schemaKey, name, value));
53 * Monitor an initiation on a context item.
55 * @param albumKey The item album
56 * @param schemaKey The item schema
57 * @param name The name of the item
58 * @param value The value of the item
59 * @param userArtifactStack the keys of the artifacts using the context map at the moment
61 public void monitorInit(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
62 final Object value, final AxConcept[] userArtifactStack) {
63 LOGGER.trace(monitor("INIT", userArtifactStack, albumKey, schemaKey, name, value));
67 * Monitor a deletion on a context item.
69 * @param albumKey The item album
70 * @param schemaKey The item schema
71 * @param name The name of the item
72 * @param value The value of the item
73 * @param userArtifactStack the keys of the artifacts using the context map at the moment
75 public void monitorDelete(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
76 final Object value, final AxConcept[] userArtifactStack) {
77 LOGGER.trace(monitor("DEL", userArtifactStack, albumKey, schemaKey, name, value));
81 * Monitor get on a context item.
83 * @param albumKey The item album
84 * @param schemaKey The item schema
85 * @param name The name of the item
86 * @param value The value of the item
87 * @param userArtifactStack the keys of the artifacts using the context map at the moment
89 public void monitorGet(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
90 final Object value, final AxConcept[] userArtifactStack) {
91 LOGGER.trace(monitor("GET", userArtifactStack, albumKey, schemaKey, name, value));
95 * Monitor set on a context item.
97 * @param albumKey The item album
98 * @param schemaKey The item schema
99 * @param name The name of the item
100 * @param value The value of the item
101 * @param userArtifactStack the keys of the artifacts using the context map at the moment
103 public void monitorSet(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
104 final Object value, final AxConcept[] userArtifactStack) {
105 LOGGER.trace(monitor("SET", userArtifactStack, albumKey, schemaKey, name, value));
109 * Monitor a read lock on a key.
111 * @param albumKey The item album
112 * @param schemaKey The item schema
113 * @param name The name of the item
114 * @param userArtifactStack the keys of the artifacts using the context map at the moment
116 public void monitorReadLock(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
117 final AxConcept[] userArtifactStack) {
118 LOGGER.trace(monitor("READLOCK", userArtifactStack, albumKey, schemaKey, name, null));
122 * Monitor a write lock on a key.
124 * @param albumKey The item album
125 * @param schemaKey The item schema
126 * @param name The name of the item
127 * @param userArtifactStack the keys of the artifacts using the context map at the moment
129 public void monitorWriteLock(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
130 final AxConcept[] userArtifactStack) {
131 LOGGER.trace(monitor("WRITELOCK", userArtifactStack, albumKey, schemaKey, name, null));
135 * Monitor a read unlock on a key.
137 * @param albumKey The item album
138 * @param schemaKey The item schema
139 * @param name The name of the item
140 * @param userArtifactStack the keys of the artifacts using the context map at the moment
142 public void monitorReadUnlock(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
143 final AxConcept[] userArtifactStack) {
144 LOGGER.trace(monitor("READUNLOCK", userArtifactStack, albumKey, schemaKey, name, null));
148 * Monitor a write unlock on a key.
150 * @param albumKey The item album
151 * @param schemaKey The item schema
152 * @param name The name of the item
153 * @param userArtifactStack the keys of the artifacts using the context map at the moment
155 public void monitorWriteUnlock(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
156 final AxConcept[] userArtifactStack) {
157 LOGGER.trace(monitor("WRITEUNLOCK", userArtifactStack, albumKey, schemaKey, name, null));
161 * Monitor the user artifact stack.
163 * @param preamble the preamble
164 * @param userArtifactStack The user stack to print
165 * @param albumKey the album key
166 * @param schemaKey the schema key
167 * @param name the name
168 * @param value the value
171 private String monitor(final String preamble, final AxConcept[] userArtifactStack, final AxArtifactKey albumKey,
172 final AxArtifactKey schemaKey, final String name, final Object value) {
173 final StringBuilder builder = new StringBuilder();
175 builder.append(preamble);
176 builder.append(",[");
178 if (userArtifactStack != null) {
179 boolean first = true;
180 for (final AxConcept stackKey : userArtifactStack) {
186 if (stackKey instanceof AxArtifactKey) {
187 builder.append(((AxArtifactKey) stackKey).getID());
188 } else if (stackKey instanceof AxReferenceKey) {
189 builder.append(((AxReferenceKey) stackKey).getID());
191 builder.append(stackKey.toString());
195 builder.append("],");
197 builder.append(albumKey.getID());
199 builder.append(schemaKey.getID());
201 builder.append(name);
205 builder.append(value.toString());
208 return builder.toString();