View Javadoc

1   /**
2    * Copyright 2010 The Apache Software Foundation
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, 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   */
20  package org.apache.hadoop.hbase.executor;
21  
22  import java.io.DataInput;
23  import java.io.DataOutput;
24  import java.io.IOException;
25  
26  import org.apache.hadoop.hbase.HMsg;
27  import org.apache.hadoop.hbase.executor.HBaseEventHandler.HBaseEventType;
28  import org.apache.hadoop.io.Writable;
29  
30  public class RegionTransitionEventData implements Writable {
31    private HBaseEventType hbEvent;
32    private String rsName;
33    private long timeStamp;
34    private HMsg hmsg;
35    
36    public RegionTransitionEventData() {
37    }
38  
39    public RegionTransitionEventData(HBaseEventType hbEvent, String rsName) {
40      this(hbEvent, rsName, null);
41    }
42  
43    public RegionTransitionEventData(HBaseEventType hbEvent, String rsName, HMsg hmsg) {
44      this.hbEvent = hbEvent;
45      this.rsName = rsName;
46      this.timeStamp = System.currentTimeMillis();
47      this.hmsg = hmsg;
48    }
49    
50    public HBaseEventType getHbEvent() {
51      return hbEvent;
52    }
53  
54    public String getRsName() {
55      return rsName;
56    }
57  
58    public long getTimeStamp() {
59      return timeStamp;
60    }
61  
62    public HMsg getHmsg() {
63      return hmsg;
64    }
65  
66    @Override
67    public void readFields(DataInput in) throws IOException {
68      // the event type byte
69      hbEvent = HBaseEventType.fromByte(in.readByte());
70      // the hostname of the RS sending the data
71      rsName = in.readUTF();
72      // the timestamp
73      timeStamp = in.readLong();
74      if(in.readBoolean()) {
75        // deserialized the HMsg from ZK
76        hmsg = new HMsg();
77        hmsg.readFields(in);
78      }
79    }
80  
81    @Override
82    public void write(DataOutput out) throws IOException {
83      out.writeByte(hbEvent.getByteValue());
84      out.writeUTF(rsName);
85      out.writeLong(System.currentTimeMillis());
86      out.writeBoolean((hmsg != null));
87      if(hmsg != null) {
88        hmsg.write(out);
89      }
90    }
91  
92  }