2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.aai.sparky.synchronizer;
24 import java.util.Calendar;
25 import java.util.Date;
26 import java.util.concurrent.Semaphore;
28 import org.onap.aai.sparky.sync.IndexCleaner;
29 import org.onap.aai.sparky.sync.IndexSynchronizer;
30 import org.onap.aai.sparky.sync.IndexValidator;
31 import org.onap.aai.sparky.sync.SyncController;
32 import org.onap.aai.sparky.sync.SyncControllerImpl.SyncActions;
33 import org.onap.aai.sparky.sync.enumeration.OperationState;
34 import org.onap.aai.sparky.sync.enumeration.SynchronizerState;
36 public class TestSyncController implements SyncController {
38 private String controllerName;
39 private boolean periodic;
40 private SynchronizerState internalState;
41 private Semaphore gate;
43 public TestSyncController(String name) {
44 this.controllerName = name;
45 this.internalState = SynchronizerState.IDLE;
46 this.gate = new Semaphore(1);
51 public String getControllerName() {
52 return this.controllerName;
56 public OperationState performAction(SyncActions requestedAction) {
58 if (gate.tryAcquire()) {
60 internalState = SynchronizerState.PERFORMING_SYNCHRONIZATION;
62 // System.out.println("performaAction = " + requestedAction);
64 System.out.println("Sync started with thread = " + Thread.currentThread().getName()
65 + " at date = " + new Date(Calendar.getInstance().getTimeInMillis()));
69 } catch (InterruptedException e) {
70 // TODO Auto-generated catch block
71 Thread.currentThread().interrupt();
74 System.out.println("Sync done with thread = " + Thread.currentThread().getName()
75 + " at date = " + new Date(Calendar.getInstance().getTimeInMillis()));
76 internalState = SynchronizerState.IDLE;
78 System.out.println("Next Sync at = " + Thread.currentThread().getName()
79 + " at date = " + new Date(Calendar.getInstance().getTimeInMillis() + 30000L));
84 return OperationState.OK;
86 return OperationState.IGNORED_SYNC_NOT_IDLE;
91 public void registerEntitySynchronizer(IndexSynchronizer entitySynchronizer) {
92 // TODO Auto-generated method stub
97 public void registerIndexValidator(IndexValidator indexValidator) {
98 // TODO Auto-generated method stub
103 public void registerIndexCleaner(IndexCleaner indexCleaner) {
104 // TODO Auto-generated method stub
109 public void shutdown() {
110 // TODO Auto-generated method stub
111 // System.out.println("shutdown");
115 public SynchronizerState getState() {
116 // System.out.println("getState()");
117 return SynchronizerState.IDLE;
121 public long getDelayInMs() {
122 // TODO Auto-generated method stub
127 public void setDelayInMs(long delayInMs) {
128 // TODO Auto-generated method stub
133 public long getSyncFrequencyInMs() {
134 // TODO Auto-generated method stub
139 public void setSyncFrequencyInMs(long syncFrequencyInMs) {
140 // TODO Auto-generated method stub
145 public Date getSyncStartTime() {
146 // System.out.println("getSyncStateTime()");
147 // TODO Auto-generated method stub
152 public void setSyncStartTime(Date syncStartTime) {
153 // TODO Auto-generated method stub
158 public Date getLastExecutionDate() {
159 // TODO Auto-generated method stub
164 public void setLastExecutionDate(Date lastExecutionDate) {
165 // TODO Auto-generated method stub
171 public Calendar getCreationTime() {
172 // TODO Auto-generated method stub
177 public String getNextSyncTime() {
178 // TODO Auto-generated method stub
184 public boolean isPeriodicSyncEnabled() {
185 // TODO Auto-generated method stub
191 public boolean isRunOnceSyncEnabled() {
192 // TODO Auto-generated method stub