-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Made Partition into its own class & refactored stuff to make that work * Made CounterUnit its own class & refactored JobCounter to work with it.
- Loading branch information
1 parent
d36afdc
commit e9bb7e0
Showing
16 changed files
with
127 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright DataStax, Inc. | ||
* | ||
* Licensed 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.datastax.cdm.job; | ||
|
||
import java.io.Serializable; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
public class CounterUnit implements Serializable { | ||
|
||
private static final long serialVersionUID = 2194336948011681878L; | ||
private final AtomicLong globalCounter = new AtomicLong(0); | ||
private final transient ThreadLocal<Long> threadLocalCounter = ThreadLocal.withInitial(() -> 0L); | ||
|
||
public void incrementThreadCounter(long incrementBy) { | ||
threadLocalCounter.set(threadLocalCounter.get() + incrementBy); | ||
} | ||
|
||
public long getThreadCounter() { | ||
return threadLocalCounter.get(); | ||
} | ||
|
||
public void resetThreadCounter() { | ||
threadLocalCounter.set(0L); | ||
} | ||
|
||
public void setGlobalCounter(long value) { | ||
globalCounter.set(value); | ||
} | ||
|
||
public void addThreadToGlobalCounter() { | ||
globalCounter.addAndGet(threadLocalCounter.get()); | ||
} | ||
|
||
public long getGlobalCounter() { | ||
return globalCounter.get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright DataStax, Inc. | ||
* | ||
* Licensed 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.datastax.cdm.job; | ||
|
||
import java.io.Serializable; | ||
import java.math.BigInteger; | ||
|
||
public class Partition implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
|
||
private final BigInteger min; | ||
private final BigInteger max; | ||
|
||
public Partition(BigInteger min, BigInteger max) { | ||
this.min = min; | ||
this.max = max; | ||
} | ||
|
||
public BigInteger getMin() { | ||
return min; | ||
} | ||
|
||
public BigInteger getMax() { | ||
return max; | ||
} | ||
|
||
public String toString() { | ||
return "Processing partition for token range " + min + " to " + max; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.