/** * Test hook that returns a list of ServerLocation instances. Each ServerLocation describes a * redundant server. An empty list is returned if we have no redundant servers. */ public List<ServerLocation> getRedundants() { List result = Collections.emptyList(); if (this.queueManager != null) { QueueManager.QueueConnections cons = this.queueManager.getAllConnections(); List<Connection> backupCons = cons.getBackups(); if (backupCons.size() > 0) { result = new ArrayList(backupCons.size()); Iterator<Connection> it = backupCons.iterator(); while (it.hasNext()) { Connection con = it.next(); result.add(con.getServer()); } } } return result; }
private QueueConnectionImpl initializeQueueConnection(Connection connection, boolean isPrimary, ClientUpdater failedUpdater) { QueueConnectionImpl queueConnection = null; FailureTracker failureTracker = denyList.getFailureTracker(connection.getServer()); try { ClientUpdater updater = factory.createServerToClientConnection(connection.getEndpoint(), this, isPrimary, failedUpdater); if (updater != null) { queueConnection = new QueueConnectionImpl(this, connection, updater, failureTracker); } else { logger.warn("unable to create a subscription connection to server {}", connection.getEndpoint()); } } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("error creating subscription connection to server {}", connection.getEndpoint(), e); } } if (queueConnection == null) { failureTracker.addFailure(); connection.destroy(); } return queueConnection; }
private Connection getMockedConnection(ServerLocation serverLocation, Endpoint endpoint) throws Exception { /* * Mock the connection to throw a RuntimeException() when connection.Execute() is called, * so that we attempt to notify listeners in the exception handling logic in * OpExecutorImpl.executeWithPossibleReAuthentication() */ final Connection connection = mock(PooledConnection.class); doReturn(serverLocation).when(connection).getServer(); doReturn(endpoint).when(connection).getEndpoint(); doThrow(new RuntimeException()).when(connection).execute(any()); return connection; }
public ServerLocation getNextOpServerLocation() { ServerLocation retVal = null; Connection conn = (Connection) (threadLocalConnections ? localConnection.get() : null); if (conn == null || conn.isDestroyed()) { conn = connectionManager.borrowConnection(serverTimeout); retVal = conn.getServer(); this.connectionManager.returnConnection(conn); } else { retVal = conn.getServer(); } return retVal; }
public void destroyConnection() { this.connectionLifeCycleLock.writeLock().lock(); try { Connection con = this.connection; if (con != null) { if (!con.isDestroyed()) { con.destroy(); this.sender.getProxy().returnConnection(con); } // Reset the connection so the next time through a new one will be // obtained this.connection = null; this.sender.setServerLocation(null); } } finally { this.connectionLifeCycleLock.writeLock().unlock(); } }
/** * Attempts to send this operation's message out on the given connection * * @param cnx the connection to use when sending * @throws Exception if the send fails */ protected void attemptSend(Connection cnx) throws Exception { setMsgTransactionId(); if (logger.isTraceEnabled(LogMarker.DISTRIBUTION_BRIDGE_SERVER_VERBOSE)) { logger.trace(LogMarker.DISTRIBUTION_BRIDGE_SERVER_VERBOSE, "Sending op={} using {}", getShortClassName(), cnx); } getMessage().setComms(cnx.getSocket(), cnx.getInputStream(), cnx.getOutputStream(), cnx.getCommBuffer(), cnx.getStats()); try { sendMessage(cnx); } finally { getMessage().unsetComms(); } }
public PooledConnection(ConnectionManagerImpl manager, Connection connection) { this.connection = connection; this.endpoint = connection.getEndpoint(); this.birthDate = System.nanoTime(); this.lastAccessed = this.birthDate; }
private Object executeWithPossibleReAuthentication(Connection conn, Op op) throws Exception { try { return conn.execute(op); } catch (ServerConnectivityException sce) { Throwable cause = sce.getCause(); if ((cause instanceof AuthenticationRequiredException && "User authorization attributes not found.".equals(cause.getMessage())) || sce.getMessage().contains("Connection error while authenticating user")) { // (ashetkar) Need a cleaner way of doing above check. // 2nd exception-message above is from AbstractOp.sendMessage() PoolImpl pool = (PoolImpl) PoolManagerImpl.getPMI().find(this.endpointManager.getPoolName()); if (!pool.getMultiuserAuthentication()) { Connection connImpl = this.connectionManager.getConnection(conn); conn.getServer().setUserId((Long) AuthenticateUserOp.executeOn(connImpl, this)); return conn.execute(op); } else { UserAttributes ua = UserAttributes.userAttributes.get(); if (ua != null) { authenticateMultiuser(pool, conn, ua); } return conn.execute(op); } } else { throw sce; } } }
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 (cnx.getServer().getRequiresCredentials()) { userId = cnx.getServer().getUserId(); } else { // multi user mode Object id = UserAttributes.userAttributes.get().getServerToId().get(cnx.getServer()); if (id == null) { hdos.writeLong(cnx.getConnectionID()); hdos.writeLong(userId); getMessage().setSecurePart(((ConnectionImpl) cnx).encryptBytes(hdos.toByteArray()));
try { ServerQueueStatus serverQStatus = null; Socket sock = conn.getSocket(); DataOutputStream dos = new DataOutputStream(sock.getOutputStream()); final InputStream in = sock.getInputStream(); || acceptanceCode == REPLY_EXCEPTION_AUTHENTICATION_FAILED)) { short wanSiteVersion = Version.readOrdinal(dis); conn.setWanSiteVersion(wanSiteVersion); if (communicationMode.isWAN() && Version.GFE_66.compareTo(conn.getWanSiteVersion()) <= 0 && currentClientVersion.compareTo(Version.GFE_66) >= 0) { int remoteDistributedSystemId = in.read(); if (communicationMode.isWAN() && Version.GFE_80.compareTo(conn.getWanSiteVersion()) <= 0 && currentClientVersion.compareTo(Version.GFE_80) >= 0) { int remotePdxSize = dis.readInt();
sender.setServerLocation(con.getServer()); } else { synchronized (this.sender.getLockForConcurrentDispatcher()) { sender.setServerLocation(con.getServer()); this.processor.checkIfPdxNeedsResend(this.connection.getQueueStatus().getPdxSize()); } catch (ConnectionDestroyedException e) { throw new GatewaySenderException(
/** * Send a list of gateway events to a server to execute using connections from the given pool to * communicate with the server. * * @param con the connection to send the message on. * @param pool the pool to use to communicate with the server. * @param events list of gateway events * @param batchId the ID of this batch * @param removeFromQueueOnException true if the events should be processed even after some * exception */ public static void executeOn(Connection con, ExecutablePool pool, List events, int batchId, boolean removeFromQueueOnException, boolean isRetry) { AbstractOp op = null; // System.out.println("Version: "+con.getWanSiteVersion()); // Is this check even needed anymore? It looks like we just create the same exact op impl with // the same parameters... if (Version.GFE_651.compareTo(con.getWanSiteVersion()) >= 0) { op = new GatewaySenderGFEBatchOpImpl(events, batchId, removeFromQueueOnException, con.getDistributedSystemId(), isRetry); } else { // Default should create a batch of server version (ACCEPTOR.VERSION) op = new GatewaySenderGFEBatchOpImpl(events, batchId, removeFromQueueOnException, con.getDistributedSystemId(), isRetry); } pool.executeOn(con, op, true/* timeoutFatal */); }
/** * Process the security information in a response from the server. If the server sends a security * "part" we must process it so all subclasses should allow this method to be invoked. * * @see ServerConnection#updateAndGetSecurityPart() */ protected void processSecureBytes(Connection cnx, Message message) throws Exception { if (cnx.getServer().getRequiresCredentials()) { if (!message.isSecureMode()) { // This can be seen during shutdown if (logger.isTraceEnabled(LogMarker.BRIDGE_SERVER_VERBOSE)) { logger.trace(LogMarker.BRIDGE_SERVER_VERBOSE, "Response message from {} for {} has no secure part.", cnx, this); } return; } byte[] partBytes = message.getSecureBytes(); if (partBytes == null) { if (logger.isDebugEnabled()) { logger.debug("Response message for {} has no bytes in secure part.", this); } return; } byte[] bytes = ((ConnectionImpl) cnx).decryptBytes(partBytes); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes)); cnx.setConnectionID(dis.readLong()); } }
ServerQueueStatus status = connection.getQueueStatus(); if (status.isRedundant() || status.isPrimary()) { oldQueueServers.put(status, connection); primaryQueue = initializeQueueConnection(newPrimary, true, null); if (primaryQueue == null) { newPrimary.destroy(); } else { if (!addToConnectionList(primaryQueue, true)) {
public void internalDestroy() { this.shouldDestroy.set(true); // probably already set but make sure synchronized (this) { this.active = false; notifyAll(); Connection myCon = connection; if (myCon != null) { myCon.destroy(); connection = null; } } }
oldCon = this.connection; this.connection = newCon; this.endpoint = newCon.getEndpoint(); this.birthDate = now; try { oldCon.close(false); } catch (Exception e) {
@Override public Object attempt(Connection cnx) throws Exception { ServerQueueStatus status = cnx.getQueueStatus(); return status.isNonRedundant() ? Boolean.FALSE : Boolean.TRUE; }
@Override public Socket getSocket() { return getConnection().getSocket(); }
@Override public Object execute(Op op) throws Exception { return getConnection().execute(op); }