View Javadoc

1   package org.apache.helix.tools;
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 org.apache.helix.HelixManager;
23  
24  public class TestCommand
25  {
26    public enum CommandType
27    {
28      MODIFY,
29      VERIFY,
30      START,
31      STOP
32    }
33  
34    public static class NodeOpArg
35    {
36      public HelixManager _manager;
37      public Thread _thread;
38  
39      public NodeOpArg(HelixManager manager, Thread thread)
40      {
41        _manager = manager;
42        _thread = thread;
43      }
44    }
45  
46    public TestTrigger _trigger;
47    public CommandType _commandType;
48    public ZnodeOpArg _znodeOpArg;
49    public NodeOpArg _nodeOpArg;
50  
51    public long _startTimestamp;
52    public long _finishTimestamp;
53  
54    /**
55     *
56     * @param type
57     * @param arg
58     */
59    public TestCommand(CommandType type, ZnodeOpArg arg)
60    {
61      this(type, new TestTrigger(), arg);
62    }
63  
64    /**
65     *
66     * @param type
67     * @param trigger
68     * @param arg
69     */
70    public TestCommand(CommandType type, TestTrigger trigger, ZnodeOpArg arg)
71    {
72      _commandType = type;
73      _trigger = trigger;
74      _znodeOpArg = arg;
75    }
76  
77    /**
78     *
79     * @param type
80     * @param trigger
81     * @param arg
82     */
83    public TestCommand(CommandType type, TestTrigger trigger, NodeOpArg arg)
84    {
85      _commandType = type;
86      _trigger = trigger;
87      _nodeOpArg = arg;
88    }
89  
90    @Override
91    public String toString()
92    {
93      String ret = super.toString().substring(super.toString().lastIndexOf(".") + 1) + " ";
94      if (_finishTimestamp > 0)
95      {
96        ret += "FINISH@" + _finishTimestamp + "-START@" + _startTimestamp
97                 + "=" + (_finishTimestamp - _startTimestamp) + "ms ";
98      }
99      if (_commandType == CommandType.MODIFY || _commandType == CommandType.VERIFY)
100     {
101       ret += _commandType.toString() + "|" + _trigger.toString() + "|" + _znodeOpArg.toString();
102     }
103     else if (_commandType == CommandType.START || _commandType == CommandType.STOP)
104     {
105       ret += _commandType.toString() + "|" + _trigger.toString() + "|" + _nodeOpArg.toString();
106     }
107 
108     return ret;
109   }
110 }