* Removed ChannelGroupFactory that causes memory leak

* Added the default constructor for DefaultChannelGroup
This commit is contained in:
Trustin Lee 2009-02-13 07:51:46 +00:00
parent e8665ea867
commit 1896c90207
2 changed files with 7 additions and 65 deletions

View File

@ -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<String, ChannelGroup> groups =
new ConcurrentHashMap<String, ChannelGroup>();
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();
}
}

View File

@ -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<Channel> implements ChannelGroup {
private static final AtomicInteger nextId = new AtomicInteger();
private final String name;
private final ConcurrentMap<UUID, Channel> serverChannels = new ConcurrentHashMap<UUID, Channel>();
private final ConcurrentMap<UUID, Channel> nonServerChannels = new ConcurrentHashMap<UUID, Channel>();
@ -55,6 +58,10 @@ public class DefaultChannelGroup extends AbstractSet<Channel> implements Channel
}
};
public DefaultChannelGroup() {
this("group-0x" + Integer.toHexString(nextId.incrementAndGet()));
}
public DefaultChannelGroup(String name) {
if (name == null) {
throw new NullPointerException("name");