From 1896c902073388fd3f4e779e308e191d7a070101 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 13 Feb 2009 07:51:46 +0000 Subject: [PATCH] * Removed ChannelGroupFactory that causes memory leak * Added the default constructor for DefaultChannelGroup --- .../channel/group/ChannelGroupFactory.java | 65 ------------------- .../channel/group/DefaultChannelGroup.java | 7 ++ 2 files changed, 7 insertions(+), 65 deletions(-) delete mode 100644 src/main/java/org/jboss/netty/channel/group/ChannelGroupFactory.java diff --git a/src/main/java/org/jboss/netty/channel/group/ChannelGroupFactory.java b/src/main/java/org/jboss/netty/channel/group/ChannelGroupFactory.java deleted file mode 100644 index 24bbd60b4a..0000000000 --- a/src/main/java/org/jboss/netty/channel/group/ChannelGroupFactory.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * - * Copyright 2008, Red Hat Middleware LLC, and individual contributors - * by the @author tags. See the COPYRIGHT.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.jboss.netty.channel.group; - -import java.util.concurrent.ConcurrentMap; - -import org.jboss.netty.util.ConcurrentHashMap; - - -/** - * @author The Netty Project (netty-dev@lists.jboss.org) - * @author Trustin Lee (tlee@redhat.com) - * @version $Rev$, $Date$ - * - * @apiviz.landmark - * @apiviz.has org.jboss.netty.channel.group.ChannelGroup oneway - - creates - */ -public class ChannelGroupFactory { - - // FIXME: Memory leak - use ConcurrentWeakValueHashMap - private static final ConcurrentMap groups = - new ConcurrentHashMap(); - - public static ChannelGroup getGroup(Class groupType) { - return getGroup(groupType.getName()); - } - - public static ChannelGroup getGroup(String groupName) { - ChannelGroup g = groups.get(groupName); - if (g != null) { - return g; - } - - g = new DefaultChannelGroup(groupName); - ChannelGroup oldGroup = groups.putIfAbsent(groupName, g); - if (oldGroup != null) { - g = oldGroup; - } - return g; - } - - private ChannelGroupFactory() { - super(); - } -} diff --git a/src/main/java/org/jboss/netty/channel/group/DefaultChannelGroup.java b/src/main/java/org/jboss/netty/channel/group/DefaultChannelGroup.java index 0603423ef3..4226e24589 100644 --- a/src/main/java/org/jboss/netty/channel/group/DefaultChannelGroup.java +++ b/src/main/java/org/jboss/netty/channel/group/DefaultChannelGroup.java @@ -31,6 +31,7 @@ import java.util.Iterator; import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicInteger; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelFuture; @@ -46,6 +47,8 @@ import org.jboss.netty.util.ConcurrentHashMap; */ public class DefaultChannelGroup extends AbstractSet implements ChannelGroup { + private static final AtomicInteger nextId = new AtomicInteger(); + private final String name; private final ConcurrentMap serverChannels = new ConcurrentHashMap(); private final ConcurrentMap nonServerChannels = new ConcurrentHashMap(); @@ -55,6 +58,10 @@ public class DefaultChannelGroup extends AbstractSet implements Channel } }; + public DefaultChannelGroup() { + this("group-0x" + Integer.toHexString(nextId.incrementAndGet())); + } + public DefaultChannelGroup(String name) { if (name == null) { throw new NullPointerException("name");