public synchronized void freeze(final CoreRemotingConnection connectionToKeepOpen) { if (!started) return; failureCheckAndFlushThread.close(false); for (Acceptor acceptor : acceptors) { try { acceptor.pause(); } catch (Exception e) { HornetQServerLogger.LOGGER.errorStoppingAcceptor(); } } HashMap<Object, ConnectionEntry> connectionEntries = new HashMap<Object, ConnectionEntry>(connections); // Now we ensure that no connections will process any more packets after this method is // complete then send a disconnect packet for (Entry<Object, ConnectionEntry> entry : connectionEntries.entrySet()) { RemotingConnection conn = entry.getValue().connection; if (conn.equals(connectionToKeepOpen)) continue; if (HornetQServerLogger.LOGGER.isTraceEnabled()) { HornetQServerLogger.LOGGER.trace("Sending connection.disconnection packet to " + conn); } if (!conn.isClient()) { conn.disconnect(false); connections.remove(entry.getKey()); } } }
public void createQueue( final SimpleString address, final SimpleString name, final SimpleString filterString, final boolean temporary, final boolean durable) throws Exception { if (durable) { // make sure the user has privileges to create this queue securityStore.check(address, CheckType.CREATE_DURABLE_QUEUE, this); } else { securityStore.check(address, CheckType.CREATE_NON_DURABLE_QUEUE, this); } Queue queue = server.createQueue(address, name, filterString, durable, temporary); if (temporary) { // Temporary queue in core simply means the queue will be deleted if // the remoting connection // dies. It does not mean it will get deleted automatically when the // session is closed. // It is up to the user to delete the queue when finished with it TempQueueCleanerUpper cleaner = new TempQueueCleanerUpper(postOffice, name, queue); remotingConnection.addCloseListener(cleaner); remotingConnection.addFailureListener(cleaner); tempQueueCleannerUppers.put(name, cleaner); } }
public void stop(final boolean criticalError) throws Exception { if (!started) { return; } failureCheckAndFlushThread.close(criticalError); // We need to stop them accepting first so no new connections are accepted after we send the // disconnect message for (Acceptor acceptor : acceptors) { if (HornetQServerLogger.LOGGER.isDebugEnabled()) { HornetQServerLogger.LOGGER.debug("Pausing acceptor " + acceptor); } acceptor.pause(); } if (HornetQServerLogger.LOGGER.isDebugEnabled()) { HornetQServerLogger.LOGGER.debug("Sending disconnect on live connections"); } HashSet<ConnectionEntry> connectionEntries = new HashSet<ConnectionEntry>(connections.values()); // Now we ensure that no connections will process any more packets after this method is complete // then send a disconnect packet for (ConnectionEntry entry : connectionEntries) { RemotingConnection conn = entry.connection; if (HornetQServerLogger.LOGGER.isTraceEnabled()) { HornetQServerLogger.LOGGER.trace("Sending connection.disconnection packet to " + conn); } conn.disconnect(criticalError); } for (Acceptor acceptor : acceptors) { acceptor.stop(); } acceptors.clear(); connections.clear(); if (managementService != null) { managementService.unregisterAcceptors(); } threadPool.shutdown(); if (!criticalError) { boolean ok = threadPool.awaitTermination(10000, TimeUnit.MILLISECONDS); if (!ok) { HornetQServerLogger.LOGGER.timeoutRemotingThreadPool(); } } started = false; }
public Map<String, String> getNodes() { synchronized (recordsGuard) { Map<String, String> nodes = new HashMap<String, String>(); for (Entry<String, MessageFlowRecord> entry : records.entrySet()) { RemotingConnection fwdConnection = entry.getValue().getBridge().getForwardingConnection(); if (fwdConnection != null) { nodes.put(entry.getKey(), fwdConnection.getRemoteAddress()); } } return nodes; } }
@Test public void testSessionClosedOnRemotingConnectionFailure() throws Exception { ClientSession session = addClientSession(sf.createSession()); session.createQueue("fooaddress", "fooqueue"); ClientProducer prod = session.createProducer("fooaddress"); ClientConsumer cons = session.createConsumer("fooqueue"); session.start(); prod.send(session.createMessage(false)); Assert.assertNotNull(cons.receive()); // Now fail the underlying connection RemotingConnection connection = ((ClientSessionInternal) session).getConnection(); connection.fail(new HornetQNotConnectedException()); Assert.assertTrue(session.isClosed()); Assert.assertTrue(prod.isClosed()); Assert.assertTrue(cons.isClosed()); // Now try and use the producer try { prod.send(session.createMessage(false)); Assert.fail("Should throw exception"); } catch (HornetQObjectClosedException oce) { // ok } catch (HornetQException e) { fail("Invalid Exception type:" + e.getType()); } try { cons.receive(); Assert.fail("Should throw exception"); } catch (HornetQObjectClosedException oce) { // ok } catch (HornetQException e) { fail("Invalid Exception type:" + e.getType()); } session.close(); }
public void createQueue( final SimpleString address, final SimpleString name, final SimpleString filterString, final boolean temporary, final boolean durable) throws Exception { if (durable) { // make sure the user has privileges to create this queue securityStore.check(address, CheckType.CREATE_DURABLE_QUEUE, this); } else { securityStore.check(address, CheckType.CREATE_NON_DURABLE_QUEUE, this); } Queue queue = server.createQueue(address, name, filterString, durable, temporary); if (temporary) { // Temporary queue in core simply means the queue will be deleted if // the remoting connection // dies. It does not mean it will get deleted automatically when the // session is closed. // It is up to the user to delete the queue when finished with it TempQueueCleanerUpper cleaner = new TempQueueCleanerUpper(server, name); remotingConnection.addCloseListener(cleaner); remotingConnection.addFailureListener(cleaner); tempQueueCleannerUppers.put(name, cleaner); } if (HornetQServerLogger.LOGGER.isDebugEnabled()) { HornetQServerLogger.LOGGER.debug( "Queue " + name + " created on address " + name + " with filter=" + filterString + " temporary = " + temporary + " durable=" + durable + " on session user="******", connection=" + this.remotingConnection); } }
private synchronized void doClose(final boolean failed) throws Exception { if (tx != null && tx.getXid() == null) { // We only rollback local txs on close, not XA tx branches try { rollback(failed, false); } catch (Exception e) { HornetQLogger.LOGGER.warn(e.getMessage(), e); } } Set<ServerConsumer> consumersClone = new HashSet<ServerConsumer>(consumers.values()); for (ServerConsumer consumer : consumersClone) { consumer.close(failed); } consumers.clear(); server.removeSession(name); if (currentLargeMessage != null) { try { currentLargeMessage.deleteFile(); } catch (Throwable error) { HornetQLogger.LOGGER.errorDeletingLargeMessageFile(error); } } remotingConnection.removeFailureListener(this); callback.closed(); }
public void deleteQueue(final SimpleString name) throws Exception { Binding binding = postOffice.getBinding(name); if (binding == null || binding.getType() != BindingType.LOCAL_QUEUE) { throw new NonExistentQueueException(); } server.destroyQueue(name, this); TempQueueCleanerUpper cleaner = this.tempQueueCleannerUppers.remove(name); if (cleaner != null) { remotingConnection.removeCloseListener(cleaner); remotingConnection.removeFailureListener(cleaner); } }
// https://jira.jboss.org/jira/browse/JBMESSAGING-1703 // Make sure that failing a connection removes it from the connection manager and can't be // returned in a subsequent // call public void testUsingDeadConnection() throws Exception { for (int i = 0; i < 100; i++) { final Connection conn1 = cf1.createConnection(); Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE); RemotingConnection rc1 = ((ClientSessionInternal) ((HornetQSession) sess1).getCoreSession()).getConnection(); rc1.fail(new HornetQException(HornetQException.NOT_CONNECTED, "blah")); try { conn1.createSession(false, Session.AUTO_ACKNOWLEDGE); fail("should throw exception"); } catch (JMSException e) { // pass } conn1.close(); } }
public synchronized void stop() throws Exception { if (!started) { return; } synchronized (replicationLock) { enabled = false; if (replicatingChannel != null) { replicatingChannel.close(); } clearReplicationTokens(); } RemotingConnection toStop = remotingConnection; if (toStop != null) { toStop.removeFailureListener(failureListener); } remotingConnection = null; started = false; }
public HornetQBuffer encode(final RemotingConnection connection) { HornetQBuffer buffer = connection.createBuffer(PacketImpl.INITIAL_PACKET_SIZE); // The standard header fields buffer.writeInt(0); // The length gets filled in at the end buffer.writeByte(type); buffer.writeLong(channelID); encodeRest(buffer); size = buffer.writerIndex(); // The length doesn't include the actual length byte int len = size - DataConstants.SIZE_INT; buffer.setInt(0, len); return buffer; }
private void doClose(final boolean failed) throws Exception { synchronized (this) { if (closed) return; if (tx != null && tx.getXid() == null) { // We only rollback local txs on close, not XA tx branches try { rollback(failed, false); } catch (Exception e) { HornetQServerLogger.LOGGER.warn(e.getMessage(), e); } } server.removeSession(name); remotingConnection.removeFailureListener(this); callback.closed(); closed = true; } // putting closing of consumers outside the sync block // https://issues.jboss.org/browse/HORNETQ-1141 Set<ServerConsumer> consumersClone = new HashSet<ServerConsumer>(consumers.values()); for (ServerConsumer consumer : consumersClone) { consumer.close(failed); } consumers.clear(); if (currentLargeMessage != null) { try { currentLargeMessage.deleteFile(); } catch (Throwable error) { HornetQServerLogger.LOGGER.errorDeletingLargeMessageFile(error); } } }
@Override public void run() { while (!closed) { try { long now = System.currentTimeMillis(); Set<Object> idsToRemove = new HashSet<Object>(); for (ConnectionEntry entry : connections.values()) { RemotingConnection conn = entry.connection; boolean flush = true; if (entry.ttl != -1) { if (!conn.checkDataReceived()) { if (now >= entry.lastCheck + entry.ttl) { idsToRemove.add(conn.getID()); flush = false; } } else { entry.lastCheck = now; } } if (flush) { conn.flush(); } } for (Object id : idsToRemove) { RemotingConnection conn = removeConnection(id); if (conn != null) { conn.fail(HornetQMessageBundle.BUNDLE.clientExited(conn.getRemoteAddress())); } } if (latch.await(pauseInterval, TimeUnit.MILLISECONDS)) return; } catch (Throwable e) { HornetQServerLogger.LOGGER.errorOnFailureCheck(e); } } }
@Override public void run() { conn.fail(new HornetQException(HornetQException.NOT_CONNECTED, "blah")); }
public Object getConnectionID() { return remotingConnection.getID(); }
public ServerSessionImpl( final String name, final String username, final String password, final int minLargeMessageSize, final boolean autoCommitSends, final boolean autoCommitAcks, final boolean preAcknowledge, final boolean strictUpdateDeliveryCount, final boolean xa, final RemotingConnection remotingConnection, final StorageManager storageManager, final PostOffice postOffice, final ResourceManager resourceManager, final SecurityStore securityStore, final ManagementService managementService, final HornetQServer server, final SimpleString managementAddress, final SimpleString defaultAddress, final SessionCallback callback) throws Exception { this.username = username; this.password = password; this.minLargeMessageSize = minLargeMessageSize; this.autoCommitSends = autoCommitSends; this.autoCommitAcks = autoCommitAcks; this.preAcknowledge = preAcknowledge; this.remotingConnection = remotingConnection; this.storageManager = storageManager; this.postOffice = postOffice; this.resourceManager = resourceManager; this.securityStore = securityStore; timeoutSeconds = resourceManager.getTimeoutSeconds(); this.xa = xa; this.strictUpdateDeliveryCount = strictUpdateDeliveryCount; this.managementService = managementService; this.name = name; this.server = server; this.managementAddress = managementAddress; this.callback = callback; this.defaultAddress = defaultAddress; remotingConnection.addFailureListener(this); if (!xa) { tx = newTransaction(); } }