Skip to main content
summaryrefslogtreecommitdiffstats
blob: a41fd1be25548241a0abefea2c022c09d7a03a62 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*******************************************************************************
 * Copyright (c) 2012 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.messaging.data;

import org.eclipse.osee.framework.messaging.services.ServiceNotification;
import org.eclipse.osee.framework.messaging.services.messages.ServiceHealth;

/**
 * @author Roberto E. Escobar
 */
public class TestServiceNotification implements ServiceNotification {

   private volatile int serviceUpdates;
   private volatile int serviceAway;
   private volatile boolean onServiceGoneReceived;
   private volatile boolean onServiceUpdateReceived;
   private volatile boolean serviceIsGone;

   public TestServiceNotification() {
      super();
      reset();
   }

   public synchronized void setServiceGone(boolean isGone) {
      serviceIsGone = isGone;
   }

   public synchronized void reset() {
      serviceIsGone = false;
      serviceUpdates = 0;
      serviceAway = 0;
      onServiceGoneReceived = false;
      onServiceUpdateReceived = false;
   }

   @Override
   public synchronized void onServiceGone(ServiceHealth serviceHealth) {
      serviceAway++;
      onServiceGoneReceived = true;
      notify();
   }

   @Override
   public synchronized void onServiceUpdate(ServiceHealth serviceHealth) {
      serviceUpdates++;
      onServiceUpdateReceived = true;
      notify();
   }

   @Override
   public boolean isServiceGone(ServiceHealth serviceHealth) {
      return serviceIsGone;
   }

   public int getServiceUpdatesCount() {
      return serviceUpdates;
   }

   public int getServiceAwayCount() {
      return serviceAway;
   }

   public boolean wasOnServiceGoneReceived() {
      return onServiceGoneReceived;
   }

   public boolean wasOnServiceUpdateReceived() {
      return onServiceUpdateReceived;
   }

}

Back to the top