Package com.ponysdk.core.command

Source Code of com.ponysdk.core.command.PushListenerCollection

package com.ponysdk.core.command;

import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArrayList;

import com.ponysdk.core.event.HandlerRegistration;

public class PushListenerCollection<T> implements Iterable<PusherListener<T>> {

    private final Collection<PusherListener<T>> listeners = new CopyOnWriteArrayList<PusherListener<T>>();

    public HandlerRegistration register(final PusherListener<T> listener) {
        listeners.add(listener);
        return new HandlerRegistration() {

            @Override
            public void removeHandler() {
                listeners.remove(listener);
            }
        };
    }

    @Override
    public Iterator<PusherListener<T>> iterator() {
        return listeners.iterator();
    }

}
TOP

Related Classes of com.ponysdk.core.command.PushListenerCollection

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.