blob: 4d0b7134e8dfbd0dd922fa00442d6e756463268a [file] [log] [blame]
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package com.alibaba.jstorm.batch;
import java.io.Serializable;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
public class BatchId implements Serializable {
private static final long serialVersionUID = 5720810158625748049L;
protected final long id;
protected BatchId(long id) {
this.id = id;
}
public long getId() {
return id;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (id ^ (id >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BatchId other = (BatchId) obj;
if (id != other.id)
return false;
return true;
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}
private static AtomicLong staticId = new AtomicLong(0);
public static void updateId(long id) {
staticId.set(id);
}
public static BatchId mkInstance() {
long id = staticId.incrementAndGet();
return new BatchId(id);
}
public static BatchId incBatchId(BatchId old) {
long other = old.getId();
return new BatchId(other + 1);
}
}