Repository: kafka Updated Branches: refs/heads/trunk d7b5eadb9 -> 19f266d40
MINOR: Move `Os` class to utils package and rename it to OperatingSystem The `common` package is public and this class is internal. Author: Ismael Juma <[email protected]> Reviewers: Jason Gustafson <[email protected]> Closes #2759 from ijuma/move-os-to-utils Project: http://git-wip-us.apache.org/repos/asf/kafka/repo Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/19f266d4 Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/19f266d4 Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/19f266d4 Branch: refs/heads/trunk Commit: 19f266d4075a8c56d56f6b8c7e95773378b95211 Parents: d7b5ead Author: Ismael Juma <[email protected]> Authored: Sat Apr 22 13:57:27 2017 -0700 Committer: Jason Gustafson <[email protected]> Committed: Sat Apr 22 13:57:27 2017 -0700 ---------------------------------------------------------------------- .../main/java/org/apache/kafka/common/Os.java | 30 ----------------- .../kafka/common/utils/OperatingSystem.java | 34 ++++++++++++++++++++ .../apache/kafka/common/utils/ShellTest.java | 5 ++- .../main/scala/kafka/log/AbstractIndex.scala | 14 ++++---- 4 files changed, 42 insertions(+), 41 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kafka/blob/19f266d4/clients/src/main/java/org/apache/kafka/common/Os.java ---------------------------------------------------------------------- diff --git a/clients/src/main/java/org/apache/kafka/common/Os.java b/clients/src/main/java/org/apache/kafka/common/Os.java deleted file mode 100644 index ba41516..0000000 --- a/clients/src/main/java/org/apache/kafka/common/Os.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 org.apache.kafka.common; - -import java.util.Locale; - -public final class Os { - public static final String NAME; - - public static final boolean IS_WINDOWS; - - static { - NAME = System.getProperty("os.name").toLowerCase(Locale.ROOT); - IS_WINDOWS = NAME.startsWith("windows"); - } -} http://git-wip-us.apache.org/repos/asf/kafka/blob/19f266d4/clients/src/main/java/org/apache/kafka/common/utils/OperatingSystem.java ---------------------------------------------------------------------- diff --git a/clients/src/main/java/org/apache/kafka/common/utils/OperatingSystem.java b/clients/src/main/java/org/apache/kafka/common/utils/OperatingSystem.java new file mode 100644 index 0000000..9d80295 --- /dev/null +++ b/clients/src/main/java/org/apache/kafka/common/utils/OperatingSystem.java @@ -0,0 +1,34 @@ +/* + * 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 org.apache.kafka.common.utils; + +import java.util.Locale; + +public final class OperatingSystem { + + private OperatingSystem() { + } + + public static final String NAME; + + public static final boolean IS_WINDOWS; + + static { + NAME = System.getProperty("os.name").toLowerCase(Locale.ROOT); + IS_WINDOWS = NAME.startsWith("windows"); + } +} http://git-wip-us.apache.org/repos/asf/kafka/blob/19f266d4/clients/src/test/java/org/apache/kafka/common/utils/ShellTest.java ---------------------------------------------------------------------- diff --git a/clients/src/test/java/org/apache/kafka/common/utils/ShellTest.java b/clients/src/test/java/org/apache/kafka/common/utils/ShellTest.java index 72d0590..923783e 100644 --- a/clients/src/test/java/org/apache/kafka/common/utils/ShellTest.java +++ b/clients/src/test/java/org/apache/kafka/common/utils/ShellTest.java @@ -16,7 +16,6 @@ */ package org.apache.kafka.common.utils; -import org.apache.kafka.common.Os; import org.junit.Rule; import org.junit.Test; import org.junit.rules.Timeout; @@ -30,14 +29,14 @@ public class ShellTest { @Test public void testEchoHello() throws Exception { - assumeTrue(!Os.IS_WINDOWS); + assumeTrue(!OperatingSystem.IS_WINDOWS); String output = Shell.execCommand("echo", "hello"); assertEquals("hello\n", output); } @Test public void testHeadDevZero() throws Exception { - assumeTrue(!Os.IS_WINDOWS); + assumeTrue(!OperatingSystem.IS_WINDOWS); final int length = 100000; String output = Shell.execCommand("head", "-c", Integer.toString(length), "/dev/zero"); assertEquals(length, output.length()); http://git-wip-us.apache.org/repos/asf/kafka/blob/19f266d4/core/src/main/scala/kafka/log/AbstractIndex.scala ---------------------------------------------------------------------- diff --git a/core/src/main/scala/kafka/log/AbstractIndex.scala b/core/src/main/scala/kafka/log/AbstractIndex.scala index 53b2f74..bddd1b3 100644 --- a/core/src/main/scala/kafka/log/AbstractIndex.scala +++ b/core/src/main/scala/kafka/log/AbstractIndex.scala @@ -25,8 +25,7 @@ import java.util.concurrent.locks.{Lock, ReentrantLock} import kafka.log.IndexSearchType.IndexSearchEntity import kafka.utils.CoreUtils.inLock import kafka.utils.{CoreUtils, Logging} -import org.apache.kafka.common.Os -import org.apache.kafka.common.utils.Utils +import org.apache.kafka.common.utils.{OperatingSystem, Utils} import sun.nio.ch.DirectBuffer import scala.math.ceil @@ -105,7 +104,7 @@ abstract class AbstractIndex[K, V](@volatile var file: File, val baseOffset: Lon val position = mmap.position /* Windows won't let us modify the file length while the file is mmapped :-( */ - if(Os.IS_WINDOWS) + if (OperatingSystem.IS_WINDOWS) forceUnmap(mmap); try { raf.setLength(roundedNewSize) @@ -217,12 +216,11 @@ abstract class AbstractIndex[K, V](@volatile var file: File, val baseOffset: Lon * and this requires synchronizing reads. */ protected def maybeLock[T](lock: Lock)(fun: => T): T = { - if(Os.IS_WINDOWS) + if (OperatingSystem.IS_WINDOWS) lock.lock() - try { - fun - } finally { - if(Os.IS_WINDOWS) + try fun + finally { + if (OperatingSystem.IS_WINDOWS) lock.unlock() } }
