implemented sparky graph extensibility
[aai/sparky-be.git] / sparkybe-onap-service / src / main / java / org / onap / aai / sparky / viewandinspect / context / BaseGizmoVisualizationContextBuilder.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright Â© 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright Â© 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.aai.sparky.viewandinspect.context;
22
23 import java.security.SecureRandom;
24 import java.util.concurrent.ExecutorService;
25
26 import org.onap.aai.cl.api.Logger;
27 import org.onap.aai.cl.eelf.LoggerFactory;
28 import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
29 import org.onap.aai.sparky.dal.GizmoAdapter;
30 import org.onap.aai.sparky.util.NodeUtils;
31 import org.onap.aai.sparky.viewandinspect.VisualizationContext;
32 import org.onap.aai.sparky.viewandinspect.VisualizationContextBuilder;
33 import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs;
34
35 public class BaseGizmoVisualizationContextBuilder implements VisualizationContextBuilder {
36
37   private static final Logger LOG =
38       LoggerFactory.getInstance().getLogger(BaseGizmoVisualizationContextBuilder.class);
39
40   private SecureRandom secureRandom = new SecureRandom();
41   private GizmoAdapter gizmoAdapter;
42   private final ExecutorService executorService;
43   private VisualizationConfigs visualizationConfig;
44   private OxmEntityLookup oxmEntityLookup;
45
46
47   public BaseGizmoVisualizationContextBuilder(GizmoAdapter gizmoAdapter, int numWorkers,
48       VisualizationConfigs visualizationConfig, OxmEntityLookup oxmEntityLookup) {
49     this.gizmoAdapter = gizmoAdapter;
50     this.executorService = NodeUtils.createNamedExecutor("SLNC-WORKER", numWorkers, LOG);
51     this.visualizationConfig = visualizationConfig;
52     this.oxmEntityLookup = oxmEntityLookup;
53   }
54
55   @Override
56   public VisualizationContext getVisualizationContext() throws Exception {
57
58     return new BaseGizmoVisualizationContext(secureRandom.nextLong(), this.gizmoAdapter,
59         executorService, visualizationConfig, oxmEntityLookup);
60
61   }
62
63   @Override
64   public void shutdown() {
65     if (executorService != null) {
66       executorService.shutdown();
67     }
68
69   }
70
71 }