aboutsummaryrefslogtreecommitdiffstats
path: root/appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/openecomp/appc/lockmanager/impl/sql/Synchronizer.java
diff options
context:
space:
mode:
Diffstat (limited to 'appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/openecomp/appc/lockmanager/impl/sql/Synchronizer.java')
-rw-r--r--appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/openecomp/appc/lockmanager/impl/sql/Synchronizer.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/openecomp/appc/lockmanager/impl/sql/Synchronizer.java b/appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/openecomp/appc/lockmanager/impl/sql/Synchronizer.java
new file mode 100644
index 000000000..8d1f0bbfd
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/openecomp/appc/lockmanager/impl/sql/Synchronizer.java
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.lockmanager.impl.sql;
+
+public class Synchronizer {
+
+ private int participantNo;
+ private int participantCount;
+
+ public Synchronizer(int participantNo) {
+ this.participantNo = participantNo;
+ }
+
+ public int getParticipantCount() {
+ return participantCount;
+ }
+
+ public void postLoadLockRecord(String resource, String owner) {
+ synchronized(this) {
+ waitForAllParticipants(this, participantNo, ++participantCount);
+ }
+ }
+
+ public void preAddLockRecord(String resource, String owner) {
+ }
+
+ public void postAddLockRecord(String resource, String owner) {
+ }
+
+ public void preUpdateLockRecord(String resource, String owner) {
+ }
+
+ public void postUpdateLockRecord(String resource, String owner) {
+ }
+
+ public void releaseWait() {
+ synchronized(this) {
+ this.notifyAll();
+ }
+ }
+
+ protected void waitOn(Object obj, long timeout) {
+ try {
+ obj.wait(timeout);
+ } catch(InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected void waitOn(Object obj) {
+ waitOn(obj, 0);
+ }
+
+ protected void waitForAllParticipants(Object waitObj, int totalParticipantsNo, int currentParticipantsNo) {
+ if(totalParticipantsNo > currentParticipantsNo) {
+ waitOn(waitObj);
+ } else {
+ waitObj.notifyAll();
+ }
+ }
+}