View Javadoc

1   package org.apache.helix.manager;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  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,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.List;
23  
24  import org.apache.helix.ConfigChangeListener;
25  import org.apache.helix.ControllerChangeListener;
26  import org.apache.helix.CurrentStateChangeListener;
27  import org.apache.helix.ExternalViewChangeListener;
28  import org.apache.helix.IdealStateChangeListener;
29  import org.apache.helix.LiveInstanceChangeListener;
30  import org.apache.helix.MessageListener;
31  import org.apache.helix.NotificationContext;
32  import org.apache.helix.model.CurrentState;
33  import org.apache.helix.model.ExternalView;
34  import org.apache.helix.model.IdealState;
35  import org.apache.helix.model.InstanceConfig;
36  import org.apache.helix.model.LiveInstance;
37  import org.apache.helix.model.Message;
38  
39  
40  public class MockListener implements IdealStateChangeListener, LiveInstanceChangeListener,
41      ConfigChangeListener, CurrentStateChangeListener, ExternalViewChangeListener,
42      ControllerChangeListener, MessageListener
43  
44  {
45    public boolean isIdealStateChangeListenerInvoked = false;
46    public boolean isLiveInstanceChangeListenerInvoked = false;
47    public boolean isCurrentStateChangeListenerInvoked = false;
48    public boolean isMessageListenerInvoked = false;
49    public boolean isConfigChangeListenerInvoked = false;
50    public boolean isExternalViewChangeListenerInvoked = false;
51    public boolean isControllerChangeListenerInvoked = false;
52  
53    public void reset()
54    {
55      isIdealStateChangeListenerInvoked = false;
56      isLiveInstanceChangeListenerInvoked = false;
57      isCurrentStateChangeListenerInvoked = false;
58      isMessageListenerInvoked = false;
59      isConfigChangeListenerInvoked = false;
60      isExternalViewChangeListenerInvoked = false;
61      isControllerChangeListenerInvoked = false;
62    }
63  
64    @Override
65    public void onIdealStateChange(List<IdealState> idealState, NotificationContext changeContext)
66    {
67      isIdealStateChangeListenerInvoked = true;
68    }
69  
70    @Override
71    public void onLiveInstanceChange(List<LiveInstance> liveInstances, NotificationContext changeContext)
72    {
73      isLiveInstanceChangeListenerInvoked = true;
74    }
75  
76    @Override
77    public void onConfigChange(List<InstanceConfig> configs, NotificationContext changeContext)
78    {
79      isConfigChangeListenerInvoked = true;
80    }
81  
82    @Override
83    public void onStateChange(String instanceName,
84                              List<CurrentState> statesInfo,
85                              NotificationContext changeContext)
86    {
87      isCurrentStateChangeListenerInvoked = true;
88    }
89  
90    @Override
91    public void onExternalViewChange(List<ExternalView> externalViewList,
92                                     NotificationContext changeContext)
93    {
94      isExternalViewChangeListenerInvoked = true;
95    }
96  
97    @Override
98    public void onControllerChange(NotificationContext changeContext)
99    {
100     isControllerChangeListenerInvoked = true;
101   }
102 
103   @Override
104   public void onMessage(String instanceName,
105                         List<Message> messages,
106                         NotificationContext changeContext)
107   {
108     isMessageListenerInvoked = true;
109   }
110 }