package org.snmp4j.transport;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;
import org.snmp4j.SNMP4JSettings;
import org.snmp4j.TransportStateReference;
import org.snmp4j.log.LogAdapter;
import org.snmp4j.log.LogFactory;
import org.snmp4j.smi.Address;
import org.snmp4j.smi.TcpAddress;

/* JADX INFO: loaded from: classes.dex */
public abstract class TcpTransportMapping extends AbstractTransportMapping<TcpAddress> implements ConnectionOrientedTransportMapping<TcpAddress> {
    private static final LogAdapter logger = LogFactory.getLogger(TcpTransportMapping.class);
    protected TcpAddress tcpAddress;
    private transient Vector<TransportStateListener> transportStateListeners;

    public TcpTransportMapping(TcpAddress tcpAddress) {
        this.tcpAddress = tcpAddress;
    }

    @Override // org.snmp4j.transport.ConnectionOrientedTransportMapping
    public synchronized void addTransportStateListener(TransportStateListener transportStateListener) {
        if (this.transportStateListeners == null) {
            this.transportStateListeners = new Vector<>(2);
        }
        this.transportStateListeners.add(transportStateListener);
    }

    @Override // org.snmp4j.transport.AbstractTransportMapping, org.snmp4j.TransportMapping
    public abstract void close() throws IOException;

    protected void fireConnectionStateChanged(TransportStateEvent transportStateEvent) {
        ArrayList arrayList;
        if (logger.isDebugEnabled()) {
            logger.debug("Firing transport state event: " + transportStateEvent);
        }
        Vector<TransportStateListener> vector = this.transportStateListeners;
        if (vector != null) {
            try {
                synchronized (vector) {
                    arrayList = new ArrayList(vector);
                }
                Iterator it = arrayList.iterator();
                while (it.hasNext()) {
                    ((TransportStateListener) it.next()).connectionStateChanged(transportStateEvent);
                }
            } catch (RuntimeException e2) {
                logger.error("Exception in fireConnectionStateChanged: " + e2.getMessage(), e2);
                if (SNMP4JSettings.isForwardRuntimeExceptions()) {
                    throw e2;
                }
            }
        }
    }

    public TcpAddress getAddress() {
        return this.tcpAddress;
    }

    public abstract MessageLengthDecoder getMessageLengthDecoder();

    @Override // org.snmp4j.transport.AbstractTransportMapping, org.snmp4j.TransportMapping
    public Class<? extends Address> getSupportedAddressClass() {
        return TcpAddress.class;
    }

    @Override // org.snmp4j.transport.AbstractTransportMapping, org.snmp4j.TransportMapping
    public abstract void listen() throws IOException;

    @Override // org.snmp4j.transport.ConnectionOrientedTransportMapping
    public synchronized void removeTransportStateListener(TransportStateListener transportStateListener) {
        if (this.transportStateListeners != null) {
            this.transportStateListeners.remove(transportStateListener);
        }
    }

    @Override // org.snmp4j.transport.AbstractTransportMapping, org.snmp4j.TransportMapping
    public abstract void sendMessage(TcpAddress tcpAddress, byte[] bArr, TransportStateReference transportStateReference) throws IOException;

    public abstract void setConnectionTimeout(long j2);

    public abstract void setMessageLengthDecoder(MessageLengthDecoder messageLengthDecoder);

    @Override // org.snmp4j.TransportMapping
    public TcpAddress getListenAddress() {
        return this.tcpAddress;
    }
}
