正在查看: SpeedCash v6.5.1482 应用的 AMQConnection.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: SpeedCash v6.5.1482 应用的 AMQConnection.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.rabbitmq.client.impl;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.AlreadyClosedException;
import com.rabbitmq.client.BlockedListener;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Command;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ExceptionHandler;
import com.rabbitmq.client.MetricsCollector;
import com.rabbitmq.client.MissedHeartbeatException;
import com.rabbitmq.client.NoOpMetricsCollector;
import com.rabbitmq.client.SaslConfig;
import com.rabbitmq.client.ShutdownSignalException;
import com.rabbitmq.client.impl.AMQChannel;
import com.rabbitmq.client.impl.recovery.RecoveryCanBeginListener;
import com.rabbitmq.utility.BlockingCell;
import com.rabbitmq.utility.Utility;
import com.unnamed.b.atv.model.TreeNode;
import defpackage.bv5;
import defpackage.mt1;
import java.io.EOFException;
import java.io.IOException;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AMQConnection extends ShutdownNotifierComponent implements Connection, NetworkConnection {
public static final double CHANNEL_SHUTDOWN_TIMEOUT_MULTIPLIER = 1.05d;
public static final Logger M = LoggerFactory.getLogger(AMQConnection.class);
public static final Version N = new Version(0, 9);
public static long O = 10000;
public final int A;
public final int B;
public final int C;
public final CredentialsProvider D;
public final Collection<BlockedListener> E;
public final int F;
public final boolean G;
public volatile int H;
public volatile int I;
public volatile int J;
public volatile ChannelManager K;
public volatile Map<String, Object> L;
protected ConsumerWorkService _workService;
public final ExecutorService d;
public final ScheduledExecutorService e;
public final ExecutorService f;
public Thread g;
public ThreadFactory h;
public String i;
public final List<RecoveryCanBeginListener> j;
public final ErrorOnWriteListener k;
public final int l;
public final AtomicBoolean m;
protected final MetricsCollector metricsCollector;
public final AMQChannel n;
public final FrameHandler o;
public volatile boolean p;
public final ExceptionHandler q;
public final BlockingCell<Object> r;
public volatile boolean s;
public volatile boolean t;
public mt1 u;
public final String v;
public final Map<String, Object> w;
public final SaslConfig x;
public final int y;
public final int z;
public class a extends AMQChannel {
public a(AMQConnection aMQConnection, int i) {
super(aMQConnection, i);
}
@Override
public boolean processAsync(Command command) throws IOException {
return getConnection().processControlCommand(command);
}
}
public class b implements ErrorOnWriteListener {
public b() {
}
@Override
public void handle(Connection connection, IOException iOException) throws IOException {
throw iOException;
}
}
public class c extends AMQChannel.BlockingRpcContinuation<AMQCommand> {
public final ShutdownSignalException a;
public c(ShutdownSignalException shutdownSignalException) {
this.a = shutdownSignalException;
}
@Override
public AMQCommand transformReply(AMQCommand aMQCommand) {
AMQConnection.this.l(this.a);
return aMQCommand;
}
}
public class d implements Runnable {
public d() {
}
@Override
public void run() {
boolean z;
while (AMQConnection.this.p) {
try {
AMQConnection.this.v(AMQConnection.this.o.readFrame());
} catch (Throwable th) {
try {
if (th instanceof InterruptedException) {
z = false;
} else {
AMQConnection.this.n(th);
z = true;
}
if (!z) {
return;
}
} finally {
AMQConnection.this.doFinalShutdown();
}
}
}
}
public d(AMQConnection aMQConnection, a aVar) {
this();
}
}
public class e implements Runnable {
public final ShutdownSignalException a;
public e(ShutdownSignalException shutdownSignalException) {
this.a = shutdownSignalException;
}
@Override
public void run() {
try {
try {
AMQConnection.this.r.get(AMQConnection.O);
} catch (InterruptedException unused) {
Thread.currentThread().interrupt();
} catch (TimeoutException unused2) {
}
} finally {
AMQConnection.this.p = false;
AMQConnection.this.n.notifyOutstandingRpc(this.a);
}
}
}
public AMQConnection(ConnectionParams connectionParams, FrameHandler frameHandler) {
this(connectionParams, frameHandler, new NoOpMetricsCollector());
}
public static Map<String, Object> defaultClientProperties() {
HashMap hashMap = new HashMap();
hashMap.put("product", LongStringHelper.asLongString("RabbitMQ"));
hashMap.put("version", LongStringHelper.asLongString(ClientVersion.VERSION));
hashMap.put("platform", LongStringHelper.asLongString("Java"));
hashMap.put("copyright", LongStringHelper.asLongString("Copyright (c) 2007-2018 Pivotal Software, Inc."));
hashMap.put("information", LongStringHelper.asLongString("Licensed under the MPL. See http://www.rabbitmq.com/"));
HashMap hashMap2 = new HashMap();
Boolean bool = Boolean.TRUE;
hashMap2.put("publisher_confirms", bool);
hashMap2.put("exchange_exchange_bindings", bool);
hashMap2.put("basic.nack", bool);
hashMap2.put("consumer_cancel_notify", bool);
hashMap2.put("connection.blocked", bool);
hashMap2.put("authentication_failure_close", bool);
hashMap.put("capabilities", hashMap2);
return hashMap;
}
public static void j() {
AMQCommand.checkPreconditions();
}
public static int s(int i, int i2) {
return (i == 0 || i2 == 0) ? Math.max(i, i2) : Math.min(i, i2);
}
@Override
public void abort() {
abort(-1);
}
@Override
public void addBlockedListener(BlockedListener blockedListener) {
this.E.add(blockedListener);
}
public void addRecoveryCanBeginListener(RecoveryCanBeginListener recoveryCanBeginListener) {
this.j.add(recoveryCanBeginListener);
}
@Override
public void clearBlockedListeners() {
this.E.clear();
}
@Override
public void close() throws IOException {
close(-1);
}
public void configureChannelManager(ChannelManager channelManager) {
channelManager.setShutdownExecutor(this.f);
channelManager.setChannelShutdownTimeout((int) (this.y * 1.05d * 1000.0d));
}
@Override
public Channel createChannel(int i) throws IOException {
ensureIsOpen();
ChannelManager channelManager = this.K;
if (channelManager == null) {
return null;
}
ChannelN createChannel = channelManager.createChannel(this, i);
this.metricsCollector.newChannel(createChannel);
return createChannel;
}
public final void disconnectChannel(ChannelN channelN) {
ChannelManager channelManager = this.K;
if (channelManager != null) {
channelManager.releaseChannelNumber(channelN);
}
}
public void doFinalShutdown() {
if (this.m.compareAndSet(false, true)) {
this.o.close();
this.r.set(null);
k();
notifyListeners();
u();
}
}
public final void ensureIsOpen() throws AlreadyClosedException {
if (!isOpen()) {
throw new AlreadyClosedException(getCloseReason());
}
}
public void flush() throws IOException {
try {
this.o.flush();
} catch (IOException e2) {
this.k.handle(this, e2);
}
}
@Override
public InetAddress getAddress() {
return this.o.getAddress();
}
@Override
public int getChannelMax() {
ChannelManager channelManager = this.K;
if (channelManager == null) {
return 0;
}
return channelManager.getChannelMax();
}
public int getChannelRpcTimeout() {
return this.F;
}
@Override
public Map<String, Object> getClientProperties() {
return new HashMap(this.w);
}
@Override
public String getClientProvidedName() {
return (String) this.w.get("connection_name");
}
@Override
public ExceptionHandler getExceptionHandler() {
return this.q;
}
public FrameHandler getFrameHandler() {
return this.o;
}
@Override
public int getFrameMax() {
return this.H;
}
@Override
public int getHeartbeat() {
return this.J;
}
@Override
public String getId() {
return this.i;
}
@Override
public InetAddress getLocalAddress() {
return this.o.getLocalAddress();
}
@Override
public int getLocalPort() {
return this.o.getLocalPort();
}
@Override
public int getPort() {
return this.o.getPort();
}
@Override
public Map<String, Object> getServerProperties() {
return this.L;
}
public ThreadFactory getThreadFactory() {
return this.h;
}
public void handleConnectionClose(Command command) {
ShutdownSignalException shutdown = shutdown(command.getMethod(), false, null, this.t);
try {
this.n.quiescingTransmit(new AMQP.Connection.CloseOk.Builder().build());
} catch (IOException unused) {
}
this.s = true;
e eVar = new e(shutdown);
ExecutorService executorService = this.f;
if (executorService != null) {
executorService.execute(eVar);
return;
}
Environment.newThread(this.h, eVar, "RabbitMQ connection shutdown monitor " + m() + TreeNode.NODES_ID_SEPARATOR + getPort()).start();
}
public void handleHeartbeatFailure() {
MissedHeartbeatException missedHeartbeatException = new MissedHeartbeatException("Heartbeat missing with heartbeat = " + this.J + " seconds");
try {
this.q.handleUnexpectedConnectionDriverException(this, missedHeartbeatException);
shutdown(null, false, missedHeartbeatException, true);
} finally {
doFinalShutdown();
}
}
public void handleIoError(Throwable th) {
try {
n(th);
} finally {
doFinalShutdown();
}
}
public boolean handleReadFrame(Frame frame) {
if (!this.p) {
return false;
}
try {
v(frame);
return true;
} catch (WorkPoolFullException e2) {
throw e2;
} catch (Throwable th) {
try {
n(th);
return false;
} finally {
doFinalShutdown();
}
}
}
public boolean hasBrokerInitiatedShutdown() {
return this.s;
}
public ChannelManager instantiateChannelManager(int i, ThreadFactory threadFactory) {
ChannelManager channelManager = new ChannelManager(this._workService, i, threadFactory, this.metricsCollector);
configureChannelManager(channelManager);
return channelManager;
}
public boolean isRunning() {
return this.p;
}
public final void k() {
if (r() && t() && this.g.isAlive()) {
this.g.interrupt();
}
}
public final void l(ShutdownSignalException shutdownSignalException) {
ChannelManager channelManager = this.K;
if (channelManager != null) {
channelManager.handleSignal(shutdownSignalException);
}
}
public final String m() {
if (getAddress() == null) {
return null;
}
return getAddress().getHostAddress();
}
public final void n(Throwable th) {
if (!(th instanceof EOFException)) {
this.q.handleUnexpectedConnectionDriverException(this, th);
shutdown(null, false, th, true);
} else {
if (this.s) {
return;
}
shutdown(null, false, th, true);
}
}
public int negotiateChannelMax(int i, int i2) {
return s(i, i2);
}
public final void o() throws SocketTimeoutException {
if (this.t) {
throw new SocketTimeoutException("Timeout during Connection negotiation");
}
if (this.J == 0) {
return;
}
int i = this.I + 1;
this.I = i;
if (i <= 8) {
return;
}
throw new MissedHeartbeatException("Heartbeat missing with heartbeat = " + this.J + " seconds");
}
public final void p() {
this._workService = new ConsumerWorkService(this.d, this.h, this.l, this.C);
}
public boolean processControlCommand(Command command) throws IOException {
com.rabbitmq.client.Method method = command.getMethod();
if (!isOpen()) {
if (method instanceof AMQP.Connection.Close) {
try {
this.n.quiescingTransmit(new AMQP.Connection.CloseOk.Builder().build());
} catch (IOException unused) {
}
return true;
}
if (!(method instanceof AMQP.Connection.CloseOk)) {
return true;
}
this.p = false;
return !this.n.isOutstandingRpc();
}
if (method instanceof AMQP.Connection.Close) {
handleConnectionClose(command);
return true;
}
if (method instanceof AMQP.Connection.Blocked) {
AMQP.Connection.Blocked blocked = (AMQP.Connection.Blocked) method;
try {
Iterator<BlockedListener> it = this.E.iterator();
while (it.hasNext()) {
it.next().handleBlocked(blocked.getReason());
}
} catch (Throwable th) {
getExceptionHandler().handleBlockedListenerException(this, th);
}
return true;
}
if (!(method instanceof AMQP.Connection.Unblocked)) {
return false;
}
try {
Iterator<BlockedListener> it2 = this.E.iterator();
while (it2.hasNext()) {
it2.next().handleUnblocked();
}
} catch (Throwable th2) {
getExceptionHandler().handleBlockedListenerException(this, th2);
}
return true;
}
public final void q() {
this.u = new mt1(this.o, this.e, this.h);
}
public final boolean r() {
return this.g != null;
}
@Override
public boolean removeBlockedListener(BlockedListener blockedListener) {
return this.E.remove(blockedListener);
}
public void removeRecoveryCanBeginListener(RecoveryCanBeginListener recoveryCanBeginListener) {
this.j.remove(recoveryCanBeginListener);
}
public void setHeartbeat(int i) {
try {
this.u.d(i);
this.J = i;
this.o.setTimeout((i * 1000) / 4);
} catch (SocketException unused) {
}
}
@Override
public void setId(String str) {
this.i = str;
}
public void setThreadFactory(ThreadFactory threadFactory) {
this.h = threadFactory;
}
public ShutdownSignalException shutdown(com.rabbitmq.client.Method method, boolean z, Throwable th, boolean z2) {
ShutdownSignalException w = w(method, z, th, z2);
l(w);
return w;
}
public void start() throws java.io.IOException, java.util.concurrent.TimeoutException {
throw new UnsupportedOperationException("Method not decompiled: com.rabbitmq.client.impl.AMQConnection.start():void");
}
public void startMainLoop() {
Thread newThread = Environment.newThread(this.h, new d(this, null), "AMQP Connection " + m() + TreeNode.NODES_ID_SEPARATOR + getPort());
this.g = newThread;
newThread.start();
}
public final boolean t() {
return Thread.currentThread() != this.g;
}
public String toString() {
String str;
if ("/".equals(this.v)) {
str = this.v;
} else {
str = "/" + this.v;
}
return "amqp://" + this.D.getUsername() + "@" + m() + TreeNode.NODES_ID_SEPARATOR + getPort() + str;
}
public final void u() {
ShutdownSignalException closeReason = getCloseReason();
Iterator it = Utility.copy(this.j).iterator();
while (it.hasNext()) {
((RecoveryCanBeginListener) it.next()).recoveryCanBegin(closeReason);
}
}
public final void v(Frame frame) throws IOException {
ChannelManager channelManager;
if (frame == null) {
o();
return;
}
this.I = 0;
if (frame.type == 8) {
return;
}
if (frame.channel == 0) {
this.n.handleFrame(frame);
} else {
if (!isOpen() || (channelManager = this.K) == null) {
return;
}
try {
channelManager.getChannel(frame.channel).handleFrame(frame);
} catch (bv5 unused) {
M.info("Received a frame on an unknown channel, ignoring it");
}
}
}
public final ShutdownSignalException w(com.rabbitmq.client.Method method, boolean z, Throwable th, boolean z2) {
ShutdownSignalException shutdownSignalException = new ShutdownSignalException(true, z, method, this);
shutdownSignalException.initCause(th);
if (!setShutdownCauseIfOpen(shutdownSignalException) && z) {
throw new AlreadyClosedException(getCloseReason(), th);
}
this.u.e();
this.n.processShutdownSignal(shutdownSignalException, !z, z2);
return shutdownSignalException;
}
public boolean willCheckRpcResponseType() {
return this.G;
}
public boolean willShutDownConsumerExecutor() {
return this._workService.usesPrivateExecutor();
}
public void writeFrame(Frame frame) throws IOException {
this.o.writeFrame(frame);
this.u.f();
}
public AMQConnection(ConnectionParams connectionParams, FrameHandler frameHandler, MetricsCollector metricsCollector) {
this.h = Executors.defaultThreadFactory();
this.j = Collections.synchronizedList(new ArrayList());
this.m = new AtomicBoolean(false);
this._workService = null;
this.p = false;
this.r = new BlockingCell<>();
this.E = new CopyOnWriteArrayList();
this.H = 0;
this.I = 0;
this.J = 0;
j();
this.D = connectionParams.getCredentialsProvider();
this.o = frameHandler;
this.v = connectionParams.getVirtualHost();
this.q = connectionParams.getExceptionHandler();
this.w = new HashMap(connectionParams.getClientProperties());
this.A = connectionParams.getRequestedFrameMax();
this.z = connectionParams.getRequestedChannelMax();
this.y = connectionParams.getRequestedHeartbeat();
this.B = connectionParams.getHandshakeTimeout();
this.C = connectionParams.getShutdownTimeout();
this.x = connectionParams.getSaslConfig();
this.d = connectionParams.getConsumerWorkServiceExecutor();
this.e = connectionParams.getHeartbeatExecutor();
this.f = connectionParams.getShutdownExecutor();
this.h = connectionParams.getThreadFactory();
if (connectionParams.getChannelRpcTimeout() < 0) {
throw new IllegalArgumentException("Continuation timeout on RPC calls cannot be less than 0");
}
this.F = connectionParams.getChannelRpcTimeout();
this.G = connectionParams.channelShouldCheckRpcResponseType();
this.n = new a(this, 0);
this.K = null;
this.s = false;
this.t = true;
this.metricsCollector = metricsCollector;
this.k = connectionParams.getErrorOnWriteListener() != null ? connectionParams.getErrorOnWriteListener() : new b();
this.l = connectionParams.getWorkPoolTimeout();
}
@Override
public void abort(int i, String str) {
abort(i, str, -1);
}
@Override
public void close(int i) throws IOException {
close(200, "OK", i);
}
@Override
public void abort(int i) {
abort(200, "OK", i);
}
@Override
public void close(int i, String str) throws IOException {
close(i, str, -1);
}
@Override
public void abort(int i, String str, int i2) {
try {
close(i, str, true, null, i2, true);
} catch (IOException unused) {
}
}
@Override
public void close(int i, String str, int i2) throws IOException {
close(i, str, true, null, i2, false);
}
public void close(int i, String str, boolean z, Throwable th) throws IOException {
close(i, str, z, th, -1, false);
}
@Override
public Channel createChannel() throws IOException {
ensureIsOpen();
ChannelManager channelManager = this.K;
if (channelManager == null) {
return null;
}
ChannelN createChannel = channelManager.createChannel(this);
this.metricsCollector.newChannel(createChannel);
return createChannel;
}
public void close(int i, String str, boolean z, Throwable th, int i2, boolean z2) throws IOException {
boolean z3 = Thread.currentThread() != this.g;
try {
try {
try {
AMQP.Connection.Close build = new AMQP.Connection.Close.Builder().replyCode(i).replyText(str).build();
ShutdownSignalException w = w(build, z, th, true);
if (z3) {
c cVar = new c(w);
this.n.quiescingRpc(build, cVar);
cVar.getReply(i2);
} else {
this.n.quiescingTransmit(build);
}
if (!z3) {
return;
}
} catch (IOException e2) {
if (!z2) {
throw e2;
}
if (!z3) {
return;
}
}
} catch (ShutdownSignalException e3) {
if (!z2) {
throw e3;
}
if (!z3) {
return;
}
} catch (TimeoutException unused) {
if (!z2) {
ShutdownSignalException shutdownSignalException = new ShutdownSignalException(true, true, null, this);
shutdownSignalException.initCause(th);
throw shutdownSignalException;
}
if (!z3) {
return;
}
}
this.o.close();
} catch (Throwable th2) {
if (z3) {
this.o.close();
}
throw th2;
}
}
}