Search in sources :

Example 1 with PEPeerListener

use of com.biglybt.core.peer.PEPeerListener in project BiglyBT by BiglySoftware.

the class PeerImpl method addListener.

@Override
public void addListener(final PeerListener2 l) {
    PEPeerListener core_listener = new PEPeerListener() {

        @Override
        public void stateChanged(// seems don't need this here
        final PEPeer peer, int new_state) {
            fireEvent(PeerEvent.ET_STATE_CHANGED, new Integer(new_state));
        }

        @Override
        public void sentBadChunk(// seems don't need this here
        final PEPeer peer, int piece_num, int total_bad_chunks) {
            fireEvent(PeerEvent.ET_BAD_CHUNK, new Integer[] { new Integer(piece_num), new Integer(total_bad_chunks) });
        }

        @Override
        public void addAvailability(final PEPeer peer, BitFlags peerHavePieces) {
            fireEvent(PeerEvent.ET_ADD_AVAILABILITY, peerHavePieces.flags);
        }

        @Override
        public void removeAvailability(final PEPeer peer, BitFlags peerHavePieces) {
            fireEvent(PeerEvent.ET_REMOVE_AVAILABILITY, peerHavePieces.flags);
        }

        protected void fireEvent(final int type, final Object data) {
            try {
                l.eventOccurred(new PeerEvent() {

                    @Override
                    public int getType() {
                        return (type);
                    }

                    @Override
                    public Object getData() {
                        return (data);
                    }
                });
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
        }
    };
    delegate.addListener(core_listener);
    synchronized (this) {
        if (peer_listeners == null) {
            peer_listeners = new HashMap<>();
        }
        peer_listeners.put(l, core_listener);
    }
}
Also used : BitFlags(com.biglybt.core.peermanager.piecepicker.util.BitFlags) PEPeer(com.biglybt.core.peer.PEPeer) PEPeerListener(com.biglybt.core.peer.PEPeerListener)

Aggregations

PEPeer (com.biglybt.core.peer.PEPeer)1 PEPeerListener (com.biglybt.core.peer.PEPeerListener)1 BitFlags (com.biglybt.core.peermanager.piecepicker.util.BitFlags)1