diff --git a/akka-actor/src/main/java/org/jboss/netty/akka/logging/AbstractInternalLogger.java b/akka-actor/src/main/java/org/jboss/netty/akka/logging/AbstractInternalLogger.java deleted file mode 100644 index 555ea86f09..0000000000 --- a/akka-actor/src/main/java/org/jboss/netty/akka/logging/AbstractInternalLogger.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat 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.jboss.netty.akka.logging; - -/** - * A skeletal implementation of {@link InternalLogger}. This class implements - * all methods that have a {@link InternalLogLevel} parameter by default to call - * specific logger methods such as {@link #info(String)} or {@link #isInfoEnabled()}. - * - * @author The Netty Project - * @author Trustin Lee - * @version $Rev: 2080 $, $Date: 2010-01-26 18:04:19 +0900 (Tue, 26 Jan 2010) $ - */ -public abstract class AbstractInternalLogger implements InternalLogger { - - /** - * Creates a new instance. - */ - protected AbstractInternalLogger() { - super(); - } - - public boolean isEnabled(InternalLogLevel level) { - switch (level) { - case DEBUG: - return isDebugEnabled(); - case INFO: - return isInfoEnabled(); - case WARN: - return isWarnEnabled(); - case ERROR: - return isErrorEnabled(); - default: - throw new Error(); - } - } - - public void log(InternalLogLevel level, String msg, Throwable cause) { - switch (level) { - case DEBUG: - debug(msg, cause); - break; - case INFO: - info(msg, cause); - break; - case WARN: - warn(msg, cause); - break; - case ERROR: - error(msg, cause); - break; - default: - throw new Error(); - } - } - - public void log(InternalLogLevel level, String msg) { - switch (level) { - case DEBUG: - debug(msg); - break; - case INFO: - info(msg); - break; - case WARN: - warn(msg); - break; - case ERROR: - error(msg); - break; - default: - throw new Error(); - } - } -} diff --git a/akka-actor/src/main/java/org/jboss/netty/akka/logging/InternalLogLevel.java b/akka-actor/src/main/java/org/jboss/netty/akka/logging/InternalLogLevel.java deleted file mode 100644 index c9963d26d6..0000000000 --- a/akka-actor/src/main/java/org/jboss/netty/akka/logging/InternalLogLevel.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat 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.jboss.netty.akka.logging; - -/** - * The log level that {@link InternalLogger} can log at. - * - * @author The Netty Project - * @author Trustin Lee - * @version $Rev: 2080 $, $Date: 2010-01-26 18:04:19 +0900 (Tue, 26 Jan 2010) $ - */ -public enum InternalLogLevel { - /** - * 'DEBUG' log level. - */ - DEBUG, - /** - * 'INFO' log level. - */ - INFO, - /** - * 'WARN' log level. - */ - WARN, - /** - * 'ERROR' log level. - */ - ERROR; -} diff --git a/akka-actor/src/main/java/org/jboss/netty/akka/logging/InternalLogger.java b/akka-actor/src/main/java/org/jboss/netty/akka/logging/InternalLogger.java deleted file mode 100644 index 19d3373e6c..0000000000 --- a/akka-actor/src/main/java/org/jboss/netty/akka/logging/InternalLogger.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat 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.jboss.netty.akka.logging; - -/** - * Internal-use-only logger used by Netty. DO NOT - * access this class outside of Netty. - * - * @author The Netty Project - * @author Trustin Lee - * - * @version $Rev: 2080 $, $Date: 2010-01-26 18:04:19 +0900 (Tue, 26 Jan 2010) $ - */ -public interface InternalLogger { - /** - * Returns {@code true} if a DEBUG level message is logged. - */ - boolean isDebugEnabled(); - - /** - * Returns {@code true} if an INFO level message is logged. - */ - boolean isInfoEnabled(); - - /** - * Returns {@code true} if a WARN level message is logged. - */ - boolean isWarnEnabled(); - - /** - * Returns {@code true} if an ERROR level message is logged. - */ - boolean isErrorEnabled(); - - /** - * Returns {@code true} if the specified log level message is logged. - */ - boolean isEnabled(InternalLogLevel level); - - /** - * Logs a DEBUG level message. - */ - void debug(String msg); - - /** - * Logs a DEBUG level message. - */ - void debug(String msg, Throwable cause); - - /** - * Logs an INFO level message. - */ - void info(String msg); - - /** - * Logs an INFO level message. - */ - void info(String msg, Throwable cause); - - /** - * Logs a WARN level message. - */ - void warn(String msg); - - /** - * Logs a WARN level message. - */ - void warn(String msg, Throwable cause); - - /** - * Logs an ERROR level message. - */ - void error(String msg); - - /** - * Logs an ERROR level message. - */ - void error(String msg, Throwable cause); - - /** - * Logs a message. - */ - void log(InternalLogLevel level, String msg); - - /** - * Logs a message. - */ - void log(InternalLogLevel level, String msg, Throwable cause); -} diff --git a/akka-actor/src/main/java/org/jboss/netty/akka/logging/InternalLoggerFactory.java b/akka-actor/src/main/java/org/jboss/netty/akka/logging/InternalLoggerFactory.java deleted file mode 100644 index bda537b35b..0000000000 --- a/akka-actor/src/main/java/org/jboss/netty/akka/logging/InternalLoggerFactory.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat 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.jboss.netty.akka.logging; - -import org.jboss.netty.akka.util.internal.StackTraceSimplifier; - -/** - * Creates an {@link InternalLogger} or changes the default factory - * implementation. This factory allows you to choose what logging framework - * Netty should use. The default factory is {@link JdkLoggerFactory}. - * You can change it to your preferred logging framework before other Netty - * classes are loaded: - *
- * {@link org.jboss.netty.akka.logging.InternalLoggerFactory}.setDefaultFactory(new {@link Log4JLoggerFactory}());
- * 
- * Please note that the new default factory is effective only for the classes - * which were loaded after the default factory is changed. Therefore, - * {@link #setDefaultFactory(org.jboss.netty.akka.logging.InternalLoggerFactory)} should be called as early - * as possible and shouldn't be called more than once. - * - * @author The Netty Project - * @author Trustin Lee - * - * @version $Rev: 2122 $, $Date: 2010-02-02 11:00:04 +0900 (Tue, 02 Feb 2010) $ - * - * @apiviz.landmark - * @apiviz.has org.jboss.netty.logging.InternalLogger oneway - - creates - */ -public abstract class InternalLoggerFactory { - private static volatile InternalLoggerFactory defaultFactory = new JdkLoggerFactory(); - - static { - // Load the dependent classes in advance to avoid the case where - // the VM fails to load the required classes because of too many open - // files. - StackTraceSimplifier.simplify(new Exception()); - } - - /** - * Returns the default factory. The initial default factory is - * {@link JdkLoggerFactory}. - */ - public static InternalLoggerFactory getDefaultFactory() { - return defaultFactory; - } - - /** - * Changes the default factory. - */ - public static void setDefaultFactory(InternalLoggerFactory defaultFactory) { - if (defaultFactory == null) { - throw new NullPointerException("defaultFactory"); - } - InternalLoggerFactory.defaultFactory = defaultFactory; - } - - /** - * Creates a new logger instance with the name of the specified class. - */ - public static InternalLogger getInstance(Class clazz) { - return getInstance(clazz.getName()); - } - - /** - * Creates a new logger instance with the specified name. - */ - public static InternalLogger getInstance(String name) { - final InternalLogger logger = getDefaultFactory().newInstance(name); - return new InternalLogger() { - - public void debug(String msg) { - logger.debug(msg); - } - - public void debug(String msg, Throwable cause) { - StackTraceSimplifier.simplify(cause); - logger.debug(msg, cause); - } - - public void error(String msg) { - logger.error(msg); - } - - public void error(String msg, Throwable cause) { - StackTraceSimplifier.simplify(cause); - logger.error(msg, cause); - } - - public void info(String msg) { - logger.info(msg); - } - - public void info(String msg, Throwable cause) { - StackTraceSimplifier.simplify(cause); - logger.info(msg, cause); - } - - public boolean isDebugEnabled() { - return logger.isDebugEnabled(); - } - - public boolean isErrorEnabled() { - return logger.isErrorEnabled(); - } - - public boolean isInfoEnabled() { - return logger.isInfoEnabled(); - } - - public boolean isWarnEnabled() { - return logger.isWarnEnabled(); - } - - public void warn(String msg) { - logger.warn(msg); - } - - public void warn(String msg, Throwable cause) { - StackTraceSimplifier.simplify(cause); - logger.warn(msg, cause); - } - - public boolean isEnabled(InternalLogLevel level) { - return logger.isEnabled(level); - } - - public void log(InternalLogLevel level, String msg) { - logger.log(level, msg); - } - - public void log(InternalLogLevel level, String msg, Throwable cause) { - StackTraceSimplifier.simplify(cause); - logger.log(level, msg, cause); - } - }; - } - - /** - * Creates a new logger instance with the specified name. - */ - public abstract InternalLogger newInstance(String name); -} diff --git a/akka-actor/src/main/java/org/jboss/netty/akka/logging/JdkLogger.java b/akka-actor/src/main/java/org/jboss/netty/akka/logging/JdkLogger.java deleted file mode 100644 index 56d68e74a0..0000000000 --- a/akka-actor/src/main/java/org/jboss/netty/akka/logging/JdkLogger.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat 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.jboss.netty.akka.logging; - -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * java.util.logging - * logger. - * - * @author The Netty Project - * @author Trustin Lee - * - * @version $Rev: 2080 $, $Date: 2010-01-26 18:04:19 +0900 (Tue, 26 Jan 2010) $ - * - */ -class JdkLogger extends AbstractInternalLogger { - - private final Logger logger; - private final String loggerName; - - JdkLogger(Logger logger, String loggerName) { - this.logger = logger; - this.loggerName = loggerName; - } - - public void debug(String msg) { - logger.logp(Level.FINE, loggerName, null, msg); - } - - public void debug(String msg, Throwable cause) { - logger.logp(Level.FINE, loggerName, null, msg, cause); - } - - public void error(String msg) { - logger.logp(Level.SEVERE, loggerName, null, msg); - } - - public void error(String msg, Throwable cause) { - logger.logp(Level.SEVERE, loggerName, null, msg, cause); - } - - public void info(String msg) { - logger.logp(Level.INFO, loggerName, null, msg); - } - - public void info(String msg, Throwable cause) { - logger.logp(Level.INFO, loggerName, null, msg, cause); - } - - public boolean isDebugEnabled() { - return logger.isLoggable(Level.FINE); - } - - public boolean isErrorEnabled() { - return logger.isLoggable(Level.SEVERE); - } - - public boolean isInfoEnabled() { - return logger.isLoggable(Level.INFO); - } - - public boolean isWarnEnabled() { - return logger.isLoggable(Level.WARNING); - } - - public void warn(String msg) { - logger.logp(Level.WARNING, loggerName, null, msg); - } - - public void warn(String msg, Throwable cause) { - logger.logp(Level.WARNING, loggerName, null, msg, cause); - } - - @Override - public String toString() { - return loggerName; - } -} diff --git a/akka-actor/src/main/java/org/jboss/netty/akka/logging/JdkLoggerFactory.java b/akka-actor/src/main/java/org/jboss/netty/akka/logging/JdkLoggerFactory.java deleted file mode 100644 index d4be45bf9d..0000000000 --- a/akka-actor/src/main/java/org/jboss/netty/akka/logging/JdkLoggerFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat 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.jboss.netty.akka.logging; - - -/** - * Logger factory which creates a - * java.util.logging - * logger. - * - * @author The Netty Project - * @author Trustin Lee - * - * @version $Rev: 2080 $, $Date: 2010-01-26 18:04:19 +0900 (Tue, 26 Jan 2010) $ - * - */ -public class JdkLoggerFactory extends InternalLoggerFactory { - - @Override - public InternalLogger newInstance(String name) { - final java.util.logging.Logger logger = - java.util.logging.Logger.getLogger(name); - return new JdkLogger(logger, name); - } -} diff --git a/akka-actor/src/main/java/org/jboss/netty/akka/util/DebugUtil.java b/akka-actor/src/main/java/org/jboss/netty/akka/util/DebugUtil.java deleted file mode 100644 index 6038c8decd..0000000000 --- a/akka-actor/src/main/java/org/jboss/netty/akka/util/DebugUtil.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat 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.jboss.netty.akka.util; - -import org.jboss.netty.akka.util.internal.SystemPropertyUtil; - -/** - * Determines if Netty is running in a debug mode or not. Please note that - * this is not a Java debug mode. You can enable Netty debug mode by - * specifying the {@code "org.jboss.netty.debug"} system property (e.g. - * {@code java -Dorg.jboss.netty.debug ...}) - *

- * If debug mode is disabled (default), the stack trace of the exceptions are - * compressed to help debugging a user application. - *

- * If debug mode is enabled, the stack trace of the exceptions raised in - * {@link ChannelPipeline} or {@link ChannelSink} are retained as it is to help - * debugging Netty. - * - * @author The Netty Project - * @author Trustin Lee - * - * @version $Rev: 2080 $, $Date: 2010-01-26 18:04:19 +0900 (Tue, 26 Jan 2010) $ - */ -public class DebugUtil { - - /** - * Returns {@code true} if and only if Netty debug mode is enabled. - */ - public static boolean isDebugEnabled() { - String value; - try { - value = SystemPropertyUtil.get("org.jboss.netty.debug"); - } catch (Exception e) { - value = null; - } - - if (value == null) { - return false; - } - - value = value.trim().toUpperCase(); - return !value.startsWith("N") && - !value.startsWith("F") && - !value.equals("0"); - } - - private DebugUtil() { - // Unused - } -} diff --git a/akka-actor/src/main/java/org/jboss/netty/akka/util/HashedWheelTimer.java b/akka-actor/src/main/java/org/jboss/netty/akka/util/HashedWheelTimer.java index bc6e6d9829..328d2dc39f 100644 --- a/akka-actor/src/main/java/org/jboss/netty/akka/util/HashedWheelTimer.java +++ b/akka-actor/src/main/java/org/jboss/netty/akka/util/HashedWheelTimer.java @@ -15,12 +15,11 @@ */ package org.jboss.netty.akka.util; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.Executors; +import akka.event.LoggingAdapter; +import org.jboss.netty.akka.util.internal.ConcurrentIdentityHashMap; +import org.jboss.netty.akka.util.internal.ReusableIterator; + +import java.util.*; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -28,12 +27,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; -import org.jboss.netty.akka.logging.InternalLogger; -import org.jboss.netty.akka.logging.InternalLoggerFactory; -import org.jboss.netty.akka.util.internal.ConcurrentIdentityHashMap; -import org.jboss.netty.akka.util.internal.ReusableIterator; -import org.jboss.netty.akka.util.internal.SharedResourceMisuseDetector; - /** * A {@link Timer} optimized for approximated I/O timeout scheduling. * @@ -82,14 +75,8 @@ import org.jboss.netty.akka.util.internal.SharedResourceMisuseDetector; * @version $Rev: 2297 $, $Date: 2010-06-07 10:50:02 +0900 (Mon, 07 Jun 2010) $ */ public class HashedWheelTimer implements Timer { - - static final InternalLogger logger = - InternalLoggerFactory.getInstance(HashedWheelTimer.class); private static final AtomicInteger id = new AtomicInteger(); - private static final SharedResourceMisuseDetector misuseDetector = - new SharedResourceMisuseDetector(HashedWheelTimer.class); - private final Worker worker = new Worker(); final Thread workerThread; final AtomicBoolean shutdown = new AtomicBoolean(); @@ -101,65 +88,7 @@ public class HashedWheelTimer implements Timer { final int mask; final ReadWriteLock lock = new ReentrantReadWriteLock(); volatile int wheelCursor; - - /** - * Creates a new timer with the default thread factory - * ({@link java.util.concurrent.Executors#defaultThreadFactory()}), default tick duration, and - * default number of ticks per wheel. - */ - public HashedWheelTimer() { - this(Executors.defaultThreadFactory()); - } - - /** - * Creates a new timer with the default thread factory - * ({@link java.util.concurrent.Executors#defaultThreadFactory()}) and default number of ticks - * per wheel. - * - * @param tickDuration the duration between tick - * @param unit the time unit of the {@code tickDuration} - */ - public HashedWheelTimer(long tickDuration, TimeUnit unit) { - this(Executors.defaultThreadFactory(), tickDuration, unit); - } - - /** - * Creates a new timer with the default thread factory - * ({@link java.util.concurrent.Executors#defaultThreadFactory()}). - * - * @param tickDuration the duration between tick - * @param unit the time unit of the {@code tickDuration} - * @param ticksPerWheel the size of the wheel - */ - public HashedWheelTimer(long tickDuration, TimeUnit unit, int ticksPerWheel) { - this(Executors.defaultThreadFactory(), tickDuration, unit, ticksPerWheel); - } - - /** - * Creates a new timer with the default tick duration and default number of - * ticks per wheel. - * - * @param threadFactory a {@link java.util.concurrent.ThreadFactory} that creates a - * background {@link Thread} which is dedicated to - * {@link TimerTask} execution. - */ - public HashedWheelTimer(ThreadFactory threadFactory) { - this(threadFactory, 100, TimeUnit.MILLISECONDS); - } - - /** - * Creates a new timer with the default number of ticks per wheel. - * - * @param threadFactory a {@link java.util.concurrent.ThreadFactory} that creates a - * background {@link Thread} which is dedicated to - * {@link TimerTask} execution. - * @param tickDuration the duration between tick - * @param unit the time unit of the {@code tickDuration} - */ - public HashedWheelTimer( - ThreadFactory threadFactory, long tickDuration, TimeUnit unit) { - this(threadFactory, tickDuration, unit, 512); - } + private LoggingAdapter logger; /** * Creates a new timer. @@ -172,6 +101,7 @@ public class HashedWheelTimer implements Timer { * @param ticksPerWheel the size of the wheel */ public HashedWheelTimer( + LoggingAdapter logger, ThreadFactory threadFactory, long tickDuration, TimeUnit unit, int ticksPerWheel) { @@ -190,6 +120,8 @@ public class HashedWheelTimer implements Timer { "ticksPerWheel must be greater than 0: " + ticksPerWheel); } + this.logger = logger; + // Normalize ticksPerWheel to power of two and initialize the wheel. wheel = createWheel(ticksPerWheel); iterators = createIterators(wheel); @@ -207,12 +139,7 @@ public class HashedWheelTimer implements Timer { } roundDuration = tickDuration * wheel.length; - - workerThread = threadFactory.newThread(new ThreadRenamingRunnable( - worker, "Hashed wheel timer #" + id.incrementAndGet())); - - // Misuse check - misuseDetector.increase(); + workerThread = threadFactory.newThread(worker); } @SuppressWarnings("unchecked") @@ -295,8 +222,6 @@ public class HashedWheelTimer implements Timer { Thread.currentThread().interrupt(); } - misuseDetector.decrease(); - Set unprocessedTimeouts = new HashSet(); for (Set bucket: wheel) { unprocessedTimeouts.addAll(bucket); @@ -323,7 +248,6 @@ public class HashedWheelTimer implements Timer { delay = unit.toMillis(delay); HashedWheelTimeout timeout = new HashedWheelTimeout(task, currentTime + delay); scheduleTimeout(timeout, delay); - // TODO : remove return timeout; } @@ -519,7 +443,7 @@ public class HashedWheelTimer implements Timer { try { task.run(this); } catch (Throwable t) { - logger.warn( + logger.warning( "An exception was thrown by " + TimerTask.class.getSimpleName() + ".", t); } diff --git a/akka-actor/src/main/java/org/jboss/netty/akka/util/ThreadNameDeterminer.java b/akka-actor/src/main/java/org/jboss/netty/akka/util/ThreadNameDeterminer.java deleted file mode 100644 index 304e54d548..0000000000 --- a/akka-actor/src/main/java/org/jboss/netty/akka/util/ThreadNameDeterminer.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat 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.jboss.netty.akka.util; - -/** - * Overrides the thread name proposed by {@link ThreadRenamingRunnable}. - * - * @author The Netty Project - * @author Trustin Lee - * @version $Rev: 2080 $, $Date: 2010-01-26 18:04:19 +0900 (Tue, 26 Jan 2010) $ - */ -public interface ThreadNameDeterminer { - - /** - * {@link org.jboss.netty.akka.util.ThreadNameDeterminer} that accepts the proposed thread name - * as is. - */ - ThreadNameDeterminer PROPOSED = new ThreadNameDeterminer() { - public String determineThreadName(String currentThreadName, - String proposedThreadName) throws Exception { - return proposedThreadName; - } - }; - - /** - * {@link org.jboss.netty.akka.util.ThreadNameDeterminer} that rejects the proposed thread name and - * retains the current one. - */ - ThreadNameDeterminer CURRENT = new ThreadNameDeterminer() { - public String determineThreadName(String currentThreadName, - String proposedThreadName) throws Exception { - return null; - } - }; - - /** - * Overrides the thread name proposed by {@link ThreadRenamingRunnable}. - * - * @param currentThreadName the current thread name - * @param proposedThreadName the proposed new thread name - * @return the actual new thread name. - * If {@code null} is returned, the proposed thread name is - * discarded (i.e. no rename). - */ - String determineThreadName(String currentThreadName, String proposedThreadName) throws Exception; -} diff --git a/akka-actor/src/main/java/org/jboss/netty/akka/util/ThreadRenamingRunnable.java b/akka-actor/src/main/java/org/jboss/netty/akka/util/ThreadRenamingRunnable.java deleted file mode 100644 index bb8a1a5cc9..0000000000 --- a/akka-actor/src/main/java/org/jboss/netty/akka/util/ThreadRenamingRunnable.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat 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.jboss.netty.akka.util; - -import org.jboss.netty.akka.logging.InternalLogger; -import org.jboss.netty.akka.logging.InternalLoggerFactory; - - -/** - * A {@link Runnable} that changes the current thread name and reverts it back - * when its execution ends. To change the default thread names set by Netty, - * use {@link #setThreadNameDeterminer(ThreadNameDeterminer)}. - * - * @author The Netty Project - * @author Trustin Lee - * - * @version $Rev: 2080 $, $Date: 2010-01-26 18:04:19 +0900 (Tue, 26 Jan 2010) $ - * - * @apiviz.landmark - * @apiviz.has org.jboss.netty.util.ThreadNameDeterminer oneway - - - * - */ -public class ThreadRenamingRunnable implements Runnable { - - private static final InternalLogger logger = - InternalLoggerFactory.getInstance(ThreadRenamingRunnable.class); - - private static volatile ThreadNameDeterminer threadNameDeterminer = - ThreadNameDeterminer.PROPOSED; - - /** - * Returns the {@link ThreadNameDeterminer} which overrides the proposed - * new thread name. - */ - public static ThreadNameDeterminer getThreadNameDeterminer() { - return threadNameDeterminer; - } - - /** - * Sets the {@link ThreadNameDeterminer} which overrides the proposed new - * thread name. Please note that the specified {@link ThreadNameDeterminer} - * affects only new {@link org.jboss.netty.akka.util.ThreadRenamingRunnable}s; the existing instances - * are not affected at all. Therefore, you should make sure to call this - * method at the earliest possible point (i.e. before any Netty worker - * thread starts) for consistent thread naming. Otherwise, you might see - * the default thread names and the new names appear at the same time in - * the full thread dump. - */ - public static void setThreadNameDeterminer(ThreadNameDeterminer threadNameDeterminer) { - if (threadNameDeterminer == null) { - throw new NullPointerException("threadNameDeterminer"); - } - ThreadRenamingRunnable.threadNameDeterminer = threadNameDeterminer; - } - - private final Runnable runnable; - private final String proposedThreadName; - - /** - * Creates a new instance which wraps the specified {@code runnable} - * and changes the thread name to the specified thread name when the - * specified {@code runnable} is running. - */ - public ThreadRenamingRunnable(Runnable runnable, String proposedThreadName) { - if (runnable == null) { - throw new NullPointerException("runnable"); - } - if (proposedThreadName == null) { - throw new NullPointerException("proposedThreadName"); - } - this.runnable = runnable; - this.proposedThreadName = proposedThreadName; - } - - public void run() { - final Thread currentThread = Thread.currentThread(); - final String oldThreadName = currentThread.getName(); - final String newThreadName = getNewThreadName(oldThreadName); - - // Change the thread name before starting the actual runnable. - boolean renamed = false; - if (!oldThreadName.equals(newThreadName)) { - try { - currentThread.setName(newThreadName); - renamed = true; - } catch (SecurityException e) { - logger.debug( - "Failed to rename a thread " + - "due to security restriction.", e); - } - } - - // Run the actual runnable and revert the name back when it ends. - try { - runnable.run(); - } finally { - if (renamed) { - // Revert the name back if the current thread was renamed. - // We do not check the exception here because we know it works. - currentThread.setName(oldThreadName); - } - } - } - - private String getNewThreadName(String currentThreadName) { - String newThreadName = null; - - try { - newThreadName = - getThreadNameDeterminer().determineThreadName( - currentThreadName, proposedThreadName); - } catch (Throwable t) { - logger.warn("Failed to determine the thread name", t); - } - - return newThreadName == null? currentThreadName : newThreadName; - } -} diff --git a/akka-actor/src/main/java/org/jboss/netty/akka/util/internal/SharedResourceMisuseDetector.java b/akka-actor/src/main/java/org/jboss/netty/akka/util/internal/SharedResourceMisuseDetector.java deleted file mode 100644 index a93db3f7ac..0000000000 --- a/akka-actor/src/main/java/org/jboss/netty/akka/util/internal/SharedResourceMisuseDetector.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat 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.jboss.netty.akka.util.internal; - -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicLong; - -import org.jboss.netty.akka.logging.InternalLogger; -import org.jboss.netty.akka.logging.InternalLoggerFactory; - -/** - * Warn when user creates too many instances to avoid {@link OutOfMemoryError}. - * - * @author The Netty Project - * @author Trustin Lee - * @version $Rev: 2234 $, $Date: 2010-04-06 18:23:25 +0900 (Tue, 06 Apr 2010) $ - */ -public class SharedResourceMisuseDetector { - - private static final int MAX_ACTIVE_INSTANCES = 256; - private static final InternalLogger logger = - InternalLoggerFactory.getInstance(SharedResourceMisuseDetector.class); - - private final Class type; - private final AtomicLong activeInstances = new AtomicLong(); - private final AtomicBoolean logged = new AtomicBoolean(); - - public SharedResourceMisuseDetector(Class type) { - if (type == null) { - throw new NullPointerException("type"); - } - this.type = type; - } - - public void increase() { - if (activeInstances.incrementAndGet() > MAX_ACTIVE_INSTANCES) { - if (logged.compareAndSet(false, true)) { - logger.warn( - "You are creating too many " + type.getSimpleName() + - " instances. " + type.getSimpleName() + - " is a shared resource that must be reused across the" + - " application, so that only a few instances are created."); - } - } - } - - public void decrease() { - activeInstances.decrementAndGet(); - } -} diff --git a/akka-actor/src/main/java/org/jboss/netty/akka/util/internal/StackTraceSimplifier.java b/akka-actor/src/main/java/org/jboss/netty/akka/util/internal/StackTraceSimplifier.java deleted file mode 100644 index 3a0842b409..0000000000 --- a/akka-actor/src/main/java/org/jboss/netty/akka/util/internal/StackTraceSimplifier.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat 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.jboss.netty.akka.util.internal; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Pattern; - -import org.jboss.netty.akka.util.DebugUtil; - -/** - * Simplifies an exception stack trace by removing unnecessary - * {@link StackTraceElement}s. Please note that the stack trace simplification - * is disabled if {@linkplain DebugUtil debug mode} is turned on. - * - * @author The Netty Project - * @author Trustin Lee - * - * @version $Rev: 2080 $, $Date: 2010-01-26 18:04:19 +0900 (Tue, 26 Jan 2010) $ - * - */ -public class StackTraceSimplifier { - - private static final boolean SIMPLIFY_STACK_TRACE = !DebugUtil.isDebugEnabled(); - private static final Pattern EXCLUDED_STACK_TRACE = - Pattern.compile( - "^org\\.jboss\\.netty\\." + - "(util\\.(ThreadRenamingRunnable|internal\\.DeadLockProofWorker)" + - "|channel\\.(SimpleChannel(Upstream|Downstream)?Handler|(Default|Static)ChannelPipeline.*))(\\$.*)?$"); - - /** - * Removes unnecessary {@link StackTraceElement}s from the specified - * exception. {@link ThreadRenamingRunnable}, {@link SimpleChannelHandler}, - * {@link DefaultChannelPipeline}, and {@link StaticChannelPipeline} - * will be dropped from the trace. - */ - public static void simplify(Throwable e) { - if (!SIMPLIFY_STACK_TRACE) { - return; - } - - if (e.getCause() != null) { - simplify(e.getCause()); - } - - StackTraceElement[] trace = e.getStackTrace(); - if (trace == null || trace.length == 0) { - return; - } - - // Perhaps Netty bug. Let us not strip things out. - if (EXCLUDED_STACK_TRACE.matcher(trace[0].getClassName()).matches()) { - return; - } - - List simpleTrace = - new ArrayList(trace.length); - - simpleTrace.add(trace[0]); - - // Remove unnecessary stack trace elements. - for (int i = 1; i < trace.length; i ++) { - if (EXCLUDED_STACK_TRACE.matcher(trace[i].getClassName()).matches()) { - continue; - } - simpleTrace.add(trace[i]); - } - - e.setStackTrace( - simpleTrace.toArray(new StackTraceElement[simpleTrace.size()])); - } -} diff --git a/akka-actor/src/main/scala/akka/AkkaApplication.scala b/akka-actor/src/main/scala/akka/AkkaApplication.scala index 31b328ad49..e358d058d9 100644 --- a/akka-actor/src/main/scala/akka/AkkaApplication.scala +++ b/akka-actor/src/main/scala/akka/AkkaApplication.scala @@ -5,7 +5,6 @@ package akka import akka.config._ import akka.actor._ -import akka.dispatch._ import akka.event._ import akka.util.duration._ import java.net.InetAddress @@ -13,11 +12,10 @@ import com.eaio.uuid.UUID import akka.dispatch.{ Dispatchers, Future } import akka.util.Duration import akka.util.ReflectiveAccess -import akka.routing.Routing -import akka.remote.RemoteSupport import akka.serialization.Serialization import java.net.InetSocketAddress import org.jboss.netty.akka.util.HashedWheelTimer +import java.util.concurrent.{ TimeUnit, Executors } object AkkaApplication { @@ -179,7 +177,7 @@ class AkkaApplication(val name: String, val config: Configuration) extends Actor implicit val dispatcher = dispatcherFactory.defaultGlobalDispatcher // Start the scheduler before the provider (to prevent null pointers from happening in e.g. Gossiper) - val scheduler = new DefaultScheduler(new HashedWheelTimer) + val scheduler = new DefaultScheduler(new HashedWheelTimer(log, Executors.defaultThreadFactory, 100, TimeUnit.MILLISECONDS, 512)) // TODO think about memory consistency effects when doing funky stuff inside constructor val reflective = new ReflectiveAccess(this) diff --git a/akka-actor/src/main/scala/akka/actor/ActorRef.scala b/akka-actor/src/main/scala/akka/actor/ActorRef.scala index 6a3392f910..37874cb3e7 100644 --- a/akka-actor/src/main/scala/akka/actor/ActorRef.scala +++ b/akka-actor/src/main/scala/akka/actor/ActorRef.scala @@ -9,10 +9,9 @@ import akka.util._ import scala.collection.immutable.Stack import java.lang.{ UnsupportedOperationException, IllegalStateException } import akka.AkkaApplication -import akka.event.ActorEventBus import akka.serialization.Serialization -import akka.actor.DeadLetterActorRef.SerializedDeadLetterActorRef import java.net.InetSocketAddress +import java.util.concurrent.TimeUnit /** * ActorRef is an immutable and serializable handle to an Actor. @@ -413,3 +412,57 @@ abstract class AskActorRef(protected val app: AkkaApplication)(timeout: Timeout @throws(classOf[java.io.ObjectStreamException]) private def writeReplace(): AnyRef = app.provider.serialize(this) } + +import org.jboss.netty.akka.util.{ HashedWheelTimer, TimerTask } +class DefaultScheduler(hashedWheelTimer: HashedWheelTimer) extends Scheduler { + + def schedule(receiver: ActorRef, message: Any, initialDelay: Long, delay: Long, timeUnit: TimeUnit): Cancellable = + new DefaultCancellable(hashedWheelTimer.newTimeout(createContinuousTask(receiver, message, delay, timeUnit), initialDelay, timeUnit)) + + def scheduleOnce(runnable: Runnable, delay: Long, timeUnit: TimeUnit): Cancellable = + new DefaultCancellable(hashedWheelTimer.newTimeout(createSingleTask(runnable), delay, timeUnit)) + + def scheduleOnce(receiver: ActorRef, message: Any, delay: Long, timeUnit: TimeUnit): Cancellable = + new DefaultCancellable(hashedWheelTimer.newTimeout(createSingleTask(receiver, message), delay, timeUnit)) + + def schedule(f: () ⇒ Unit, initialDelay: Long, delay: Long, timeUnit: TimeUnit): Cancellable = + new DefaultCancellable(hashedWheelTimer.newTimeout(createContinuousTask(f, delay, timeUnit), initialDelay, timeUnit)) + + def scheduleOnce(f: () ⇒ Unit, delay: Long, timeUnit: TimeUnit): Cancellable = + new DefaultCancellable(hashedWheelTimer.newTimeout(createSingleTask(f), delay, timeUnit)) + + private def createSingleTask(runnable: Runnable): TimerTask = + new TimerTask() { def run(timeout: org.jboss.netty.akka.util.Timeout) { runnable.run() } } + + private def createSingleTask(receiver: ActorRef, message: Any): TimerTask = + new TimerTask { def run(timeout: org.jboss.netty.akka.util.Timeout) { receiver ! message } } + + private def createContinuousTask(receiver: ActorRef, message: Any, delay: Long, timeUnit: TimeUnit): TimerTask = { + new TimerTask { + def run(timeout: org.jboss.netty.akka.util.Timeout) { + receiver ! message + timeout.getTimer.newTimeout(this, delay, timeUnit) + } + } + } + + private def createSingleTask(f: () ⇒ Unit): TimerTask = + new TimerTask { def run(timeout: org.jboss.netty.akka.util.Timeout) { f() } } + + private def createContinuousTask(f: () ⇒ Unit, delay: Long, timeUnit: TimeUnit): TimerTask = { + new TimerTask { + def run(timeout: org.jboss.netty.akka.util.Timeout) { + f() + timeout.getTimer.newTimeout(this, delay, timeUnit) + } + } + } + + private[akka] def stop() = hashedWheelTimer.stop() +} + +class DefaultCancellable(timeout: org.jboss.netty.akka.util.Timeout) extends Cancellable { + def cancel() { timeout.cancel() } + + def isCancelled: Boolean = { timeout.isCancelled } +} \ No newline at end of file diff --git a/akka-actor/src/main/scala/akka/actor/Scheduler.scala b/akka-actor/src/main/scala/akka/actor/Scheduler.scala index 4a1fe5cb66..d12dcb6329 100644 --- a/akka-actor/src/main/scala/akka/actor/Scheduler.scala +++ b/akka-actor/src/main/scala/akka/actor/Scheduler.scala @@ -17,9 +17,7 @@ package akka.actor import java.util.concurrent._ import akka.util.Duration -import org.jboss.netty.akka.util.{ HashedWheelTimer, TimerTask } import akka.AkkaException -import org.jboss.netty.akka.util.{ Timeout ⇒ TimeOut } case class SchedulerException(msg: String, e: Throwable) extends AkkaException(msg, e) { def this(msg: String) = this(msg, null) @@ -49,60 +47,8 @@ abstract class Scheduler extends JScheduler { scheduleOnce(f, delay.length, delay.unit) } -class DefaultScheduler(hashedWheelTimer: HashedWheelTimer) extends Scheduler { - def schedule(receiver: ActorRef, message: Any, initialDelay: Long, delay: Long, timeUnit: TimeUnit): Cancellable = - new DefaultCancellable(hashedWheelTimer.newTimeout(createContinuousTask(receiver, message, delay, timeUnit), initialDelay, timeUnit)) - - def scheduleOnce(runnable: Runnable, delay: Long, timeUnit: TimeUnit): Cancellable = - new DefaultCancellable(hashedWheelTimer.newTimeout(createSingleTask(runnable), delay, timeUnit)) - - def scheduleOnce(receiver: ActorRef, message: Any, delay: Long, timeUnit: TimeUnit): Cancellable = - new DefaultCancellable(hashedWheelTimer.newTimeout(createSingleTask(receiver, message), delay, timeUnit)) - - def schedule(f: () ⇒ Unit, initialDelay: Long, delay: Long, timeUnit: TimeUnit): Cancellable = - new DefaultCancellable(hashedWheelTimer.newTimeout(createContinuousTask(f, delay, timeUnit), initialDelay, timeUnit)) - - def scheduleOnce(f: () ⇒ Unit, delay: Long, timeUnit: TimeUnit): Cancellable = - new DefaultCancellable(hashedWheelTimer.newTimeout(createSingleTask(f), delay, timeUnit)) - - private def createSingleTask(runnable: Runnable): TimerTask = - new TimerTask() { def run(timeout: org.jboss.netty.akka.util.Timeout) { runnable.run() } } - - private def createSingleTask(receiver: ActorRef, message: Any): TimerTask = - new TimerTask { def run(timeout: org.jboss.netty.akka.util.Timeout) { receiver ! message } } - - private def createContinuousTask(receiver: ActorRef, message: Any, delay: Long, timeUnit: TimeUnit): TimerTask = { - new TimerTask { - def run(timeout: org.jboss.netty.akka.util.Timeout) { - receiver ! message - timeout.getTimer.newTimeout(this, delay, timeUnit) - } - } - } - - private def createSingleTask(f: () ⇒ Unit): TimerTask = - new TimerTask { def run(timeout: org.jboss.netty.akka.util.Timeout) { f() } } - - private def createContinuousTask(f: () ⇒ Unit, delay: Long, timeUnit: TimeUnit): TimerTask = { - new TimerTask { - def run(timeout: org.jboss.netty.akka.util.Timeout) { - f() - timeout.getTimer.newTimeout(this, delay, timeUnit) - } - } - } - - private[akka] def stop() = hashedWheelTimer.stop() -} - trait Cancellable { def cancel(): Unit def isCancelled: Boolean -} - -class DefaultCancellable(timeout: TimeOut) extends Cancellable { - def cancel() { timeout.cancel() } - - def isCancelled: Boolean = { timeout.isCancelled } } \ No newline at end of file diff --git a/akka-remote/src/main/scala/akka/remote/Gossiper.scala b/akka-remote/src/main/scala/akka/remote/Gossiper.scala index fba6bfd04b..13b73c592f 100644 --- a/akka-remote/src/main/scala/akka/remote/Gossiper.scala +++ b/akka-remote/src/main/scala/akka/remote/Gossiper.scala @@ -4,7 +4,6 @@ package akka.remote -import akka.AkkaApplication import akka.actor._ import akka.actor.Status._ import akka.event.Logging @@ -14,7 +13,6 @@ import akka.remote.RemoteProtocol.RemoteSystemDaemonMessageType._ import java.net.InetSocketAddress import java.util.concurrent.atomic.AtomicReference -import java.util.concurrent.TimeUnit import java.security.SecureRandom import System.{ currentTimeMillis ⇒ newTimestamp } @@ -109,7 +107,6 @@ class Gossiper(remote: Remote) { private val failureDetector = remote.failureDetector private val connectionManager = new RemoteConnectionManager(app, remote, Map.empty[InetSocketAddress, ActorRef]) private val seeds = Set(address) // FIXME read in list of seeds from config - private val scheduler = app.scheduler private val address = app.defaultAddress private val nodeFingerprint = address.## @@ -126,8 +123,8 @@ class Gossiper(remote: Remote) { { // start periodic gossip and cluster scrutinization - default is run them every second with 1/2 second in between - scheduler schedule (() ⇒ initateGossip(), initalDelayForGossip.toSeconds, gossipFrequency.toSeconds, timeUnit) - scheduler schedule (() ⇒ scrutinize(), initalDelayForGossip.toSeconds, gossipFrequency.toSeconds, timeUnit) + app.scheduler schedule (() ⇒ initateGossip(), initalDelayForGossip.toSeconds, gossipFrequency.toSeconds, timeUnit) + app.scheduler schedule (() ⇒ scrutinize(), initalDelayForGossip.toSeconds, gossipFrequency.toSeconds, timeUnit) } /**