Skip to content

Commit

Permalink
Ensure backward compatibility
Browse files Browse the repository at this point in the history
.. by resurrecting the removed methods and system properties.
  • Loading branch information
trustin committed Dec 4, 2013
1 parent 65b522a commit e881724
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 2 deletions.
2 changes: 1 addition & 1 deletion buffer/src/main/java/io/netty/buffer/WrappedByteBuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.nio.channels.ScatteringByteChannel;
import java.nio.charset.Charset;

public class WrappedByteBuf extends ByteBuf {
class WrappedByteBuf extends ByteBuf {

protected final ByteBuf buf;

Expand Down
24 changes: 23 additions & 1 deletion common/src/main/java/io/netty/util/ResourceLeakDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ public enum Level {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(ResourceLeakDetector.class);

static {
String levelStr = SystemPropertyUtil.get(PROP_LEVEL, DEFAULT_LEVEL.name()).trim().toUpperCase();
final boolean disabled = SystemPropertyUtil.getBoolean("io.netty.noResourceLeakDetection", false);
logger.debug("-Dio.netty.noResourceLeakDetection: {}", disabled);
logger.warn(
"-Dio.netty.noResourceLeakDetection is deprecated. Use '-D{}={}' instead.",
PROP_LEVEL, DEFAULT_LEVEL.name().toLowerCase());

Level defaultLevel = disabled? Level.DISABLED : DEFAULT_LEVEL;
String levelStr = SystemPropertyUtil.get(PROP_LEVEL, defaultLevel.name()).trim().toUpperCase();
Level level = DEFAULT_LEVEL;
for (Level l: EnumSet.allOf(Level.class)) {
if (levelStr.equals(l.name()) || levelStr.equals(String.valueOf(l.ordinal()))) {
Expand All @@ -82,6 +89,21 @@ public enum Level {

private static final int DEFAULT_SAMPLING_INTERVAL = 113;

/**
* @deprecated Use {@link #setLevel(ResourceLeakDetector.Level)} instead.
*/
@Deprecated
public static void setEnabled(boolean enabled) {
setLevel(enabled? Level.SIMPLE : Level.DISABLED);
}

/**
* Returns {@code true} if resource leak detection is enabled.
*/
public static boolean isEnabled() {
return getLevel().ordinal() > Level.DISABLED.ordinal();
}

/**
* Sets the resource leak detection level.
*/
Expand Down
71 changes: 71 additions & 0 deletions common/src/main/java/io/netty/util/ResourceLeakException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2013 The Netty Project
*
* The Netty Project 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 io.netty.util;

import java.util.Arrays;

/**
* @deprecated This class will be removed in the future version.
*/
@Deprecated
public class ResourceLeakException extends RuntimeException {

private static final long serialVersionUID = 7186453858343358280L;

private final StackTraceElement[] cachedStackTrace;

public ResourceLeakException() {
cachedStackTrace = getStackTrace();
}

public ResourceLeakException(String message) {
super(message);
cachedStackTrace = getStackTrace();
}

public ResourceLeakException(String message, Throwable cause) {
super(message, cause);
cachedStackTrace = getStackTrace();
}

public ResourceLeakException(Throwable cause) {
super(cause);
cachedStackTrace = getStackTrace();
}

@Override
public int hashCode() {
StackTraceElement[] trace = cachedStackTrace;
int hashCode = 0;
for (StackTraceElement e: trace) {
hashCode = hashCode * 31 + e.hashCode();
}
return hashCode;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof ResourceLeakException)) {
return false;
}
if (o == this) {
return true;
}

return Arrays.equals(cachedStackTrace, ((ResourceLeakException) o).cachedStackTrace);
}
}

0 comments on commit e881724

Please sign in to comment.