use of org.apache.geode.cache.client.internal.QueueManager.QueueConnections in project geode by apache.
the class OpExecutorImpl method executeOnAllQueueServers.
public void executeOnAllQueueServers(Op op) {
if (queueManager == null) {
throw new SubscriptionNotEnabledException();
}
RuntimeException lastException = null;
QueueConnections connections = queueManager.getAllConnectionsNoWait();
Connection primary = connections.getPrimary();
if (primary != null) {
try {
executeWithPossibleReAuthentication(primary, op);
} catch (Exception e) {
try {
handleException(e, primary, 0, false);
} catch (RuntimeException e2) {
lastException = e2;
}
}
}
List backups = connections.getBackups();
for (int i = 0; i < backups.size(); i++) {
Connection conn = (Connection) backups.get(i);
try {
executeWithPossibleReAuthentication(conn, op);
} catch (Exception e) {
try {
handleException(e, conn, 0, false);
} catch (RuntimeException e2) {
lastException = e2;
}
}
}
if (lastException != null) {
throw lastException;
}
}
use of org.apache.geode.cache.client.internal.QueueManager.QueueConnections in project geode by apache.
the class OpExecutorImpl method executeOnServer.
private Object executeOnServer(ServerLocation p_server, Op op, boolean accessed, boolean onlyUseExistingCnx) {
ServerLocation server = p_server;
boolean returnCnx = true;
boolean pingOp = (op instanceof PingOp.PingOpImpl);
Connection conn = null;
if (pingOp) {
// not create a pooled cnx when all we have is queue cnxs.
if (this.queueManager != null) {
// see if our QueueManager has a connection to this guy that we can send
// the ping on.
Endpoint ep = (Endpoint) this.endpointManager.getEndpointMap().get(server);
if (ep != null) {
QueueConnections qcs = this.queueManager.getAllConnectionsNoWait();
conn = qcs.getConnection(ep);
if (conn != null) {
// we found one to do the ping on
returnCnx = false;
}
}
}
}
if (conn == null) {
if (useThreadLocalConnection(op, pingOp)) {
// no need to set threadLocal to null while the op is in progress since
// 43718 does not impact single-hop
conn = getActivatedThreadLocalConnectionForSingleHop(server, onlyUseExistingCnx);
returnCnx = false;
} else {
conn = connectionManager.borrowConnection(server, serverTimeout, onlyUseExistingCnx);
}
}
boolean success = true;
try {
return executeWithPossibleReAuthentication(conn, op);
} catch (Exception e) {
success = false;
// This method will throw an exception if we need to stop
// It also unsets the threadlocal connection and notifies
// the connection manager if there are failures.
handleException(e, conn, 0, true);
// this shouldn't actually be reached, handle exception will throw something
throw new ServerConnectivityException("Received error connecting to server", e);
} finally {
if (this.serverAffinity.get() && this.affinityServerLocation.get() == null) {
if (logger.isDebugEnabled()) {
logger.debug("setting server affinity to {} server:{}", conn.getEndpoint().getMemberId(), conn.getServer());
}
this.affinityServerLocation.set(conn.getServer());
}
if (useThreadLocalConnection(op, pingOp)) {
this.connectionManager.passivate(conn, success);
setThreadLocalConnectionForSingleHop(server, conn);
}
if (returnCnx) {
connectionManager.returnConnection(conn, accessed);
}
}
}
use of org.apache.geode.cache.client.internal.QueueManager.QueueConnections in project geode by apache.
the class OpExecutorImpl method executeOnQueuesAndReturnPrimaryResult.
/*
* (non-Javadoc)
*
* @see
* org.apache.geode.cache.client.internal.ExecutablePool#executeOnAllQueueServers(org.apache.geode
* .cache.client.internal.Op)
*/
public Object executeOnQueuesAndReturnPrimaryResult(Op op) {
if (queueManager == null) {
throw new SubscriptionNotEnabledException();
}
QueueConnections connections = queueManager.getAllConnections();
List backups = connections.getBackups();
if (logger.isTraceEnabled(LogMarker.BRIDGE_SERVER)) {
logger.trace(LogMarker.BRIDGE_SERVER, "sending {} to backups: {}", op, backups);
}
for (int i = backups.size() - 1; i >= 0; i--) {
Connection conn = (Connection) backups.get(i);
try {
executeWithPossibleReAuthentication(conn, op);
} catch (Exception e) {
handleException(e, conn, 0, false);
}
}
Connection primary = connections.getPrimary();
HashSet attemptedPrimaries = new HashSet();
while (true) {
try {
if (logger.isTraceEnabled(LogMarker.BRIDGE_SERVER)) {
logger.trace(LogMarker.BRIDGE_SERVER, "sending {} to primary: {}", op, primary);
}
return executeWithPossibleReAuthentication(primary, op);
} catch (Exception e) {
if (logger.isTraceEnabled(LogMarker.BRIDGE_SERVER)) {
logger.trace(LogMarker.BRIDGE_SERVER, "caught exception sending to primary {}", e.getMessage(), e);
}
boolean finalAttempt = !attemptedPrimaries.add(primary.getServer());
handleException(e, primary, 0, finalAttempt);
primary = queueManager.getAllConnections().getPrimary();
// we shouldn't reach this code, but just in case
if (finalAttempt) {
throw new ServerConnectivityException("Tried the same primary server twice.", e);
}
}
}
}
Aggregations