Skip to content

ContainerLifeCycleMap #13647

@gregw

Description

@gregw

Jetty version(s)
Implement a ContainerLifeCycleMap that tracks values as beans.

Enhancement Description

package org.eclipse.jetty.util.component;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class ContainerLifeCycleMap<K, V extends LifeCycle> extends ContainerLifeCycle implements Map<K, V>, Container
{
    private final Map<K, V> _map = new HashMap<>();

    @Override
    public Set<Entry<K, V>> entrySet()
    {
        return _map.entrySet();
    }

    @Override
    public int size()
    {
        return _map.size();
    }

    @Override
    public boolean isEmpty()
    {
        return _map.isEmpty();
    }

    @Override
    public boolean containsKey(Object key)
    {
        return _map.containsKey(key);
    }

    @Override
    public boolean containsValue(Object value)
    {
        return _map.containsValue(value);
    }

    @Override
    public V get(Object key)
    {
        return _map.get(key);
    }

    @Override
    public V put(K key, V value)
    {
        V old = _map.put(key, value);
        updateBean(old, value);
        return old;
    }

    @Override
    public V remove(Object key)
    {
        return _map.remove(key);
    }

    @Override
    public void putAll(Map<? extends K, ? extends V> m)
    {
        for (Entry<? extends K, ? extends V> entry : m.entrySet())
        {
            V old = put(entry.getKey(), entry.getValue());
            updateBean(old, entry.getValue());
        }
    }

    @Override
    public void clear()
    {
        for (V v : _map.values())
            removeBean(v);
        _map.clear();
    }

    @Override
    public Set<K> keySet()
    {
        // TODO we need to wrap the set to track modifications to it, so we can update beans
        return _map.keySet();
    }

    @Override
    public Collection<V> values()
    {
        // TODO we need to wrap the collection to track modifications to it, so we can update beans
        return _map.values();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    🏗 In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions