Here are the examples of the java api class org.apache.activemq.artemis.spi.core.remoting.Connection taken from open source projects.
1. InVMConnector#close()
Project: activemq-artemis
File: InVMConnector.java
File: InVMConnector.java
@Override public synchronized void close() { if (!started) { return; } for (Connection connection : connections.values()) { listener.connectionDestroyed(connection.getID()); } started = false; }
2. ClientSessionFactoryImpl#establishNewConnection()
Project: activemq-artemis
File: ClientSessionFactoryImpl.java
File: ClientSessionFactoryImpl.java
protected RemotingConnection establishNewConnection() { Connection transportConnection = createTransportConnection(); if (transportConnection == null) { if (ClientSessionFactoryImpl.logger.isTraceEnabled()) { logger.trace("Neither backup or live were active, will just give up now"); } return null; } RemotingConnection newConnection = clientProtocolManager.connect(transportConnection, callTimeout, callFailoverTimeout, incomingInterceptors, outgoingInterceptors, new SessionFactoryTopologyHandler()); newConnection.addFailureListener(new DelegatingFailureListener(newConnection.getID())); schedulePing(); if (logger.isTraceEnabled()) { logger.trace("returning " + newConnection); } return newConnection; }
3. ClientSessionFactoryImpl#openTransportConnection()
Project: activemq-artemis
File: ClientSessionFactoryImpl.java
File: ClientSessionFactoryImpl.java
protected Connection openTransportConnection(final Connector connector) { connector.start(); Connection transportConnection = connector.createConnection(); if (transportConnection == null) { if (logger.isDebugEnabled()) { logger.debug("Connector towards " + connector + " failed"); } try { connector.close(); } catch (Throwable t) { } } return transportConnection; }
4. ServerSessionPacketHandler#transferConnection()
Project: activemq-artemis
File: ServerSessionPacketHandler.java
File: ServerSessionPacketHandler.java
public int transferConnection(final CoreRemotingConnection newConnection, final int lastReceivedCommandID) { // We need to disable delivery on all the consumers while the transfer is occurring- otherwise packets might get // delivered // after the channel has transferred but *before* packets have been replayed - this will give the client the wrong // sequence of packets. // It is not sufficient to just stop the session, since right after stopping the session, another session start // might be executed // before we have transferred the connection, leaving it in a started state session.setTransferring(true); List<CloseListener> closeListeners = remotingConnection.removeCloseListeners(); List<FailureListener> failureListeners = remotingConnection.removeFailureListeners(); // Note. We do not destroy the replicating connection here. In the case the live server has really crashed // then the connection will get cleaned up anyway when the server ping timeout kicks in. // In the case the live server is really still up, i.e. a split brain situation (or in tests), then closing // the replicating connection will cause the outstanding responses to be be replayed on the live server, // if these reach the client who then subsequently fails over, on reconnection to backup, it will have // received responses that the backup did not know about. channel.transferConnection(newConnection); newConnection.syncIDGeneratorSequence(remotingConnection.getIDGeneratorSequence()); Connection oldTransportConnection = remotingConnection.getTransportConnection(); remotingConnection = newConnection; remotingConnection.setCloseListeners(closeListeners); remotingConnection.setFailureListeners(failureListeners); int serverLastReceivedCommandID = channel.getLastConfirmedCommandID(); channel.replayCommands(lastReceivedCommandID); channel.setTransferring(false); session.setTransferring(false); // We do this because the old connection could be out of credits on netty // this will force anything to resume after the reattach through the ReadyListener callbacks oldTransportConnection.fireReady(true); return serverLastReceivedCommandID; }
5. ActiveMQSessionContext#sendPacketWithoutLock()
Project: activemq-artemis
File: ActiveMQSessionContext.java
File: ActiveMQSessionContext.java
private void sendPacketWithoutLock(final Channel parameterChannel, final Packet packet) { packet.setChannelID(parameterChannel.getID()); Connection conn = parameterChannel.getConnection().getTransportConnection(); ActiveMQBuffer buffer = packet.encode(this.getCoreConnection()); conn.write(buffer, false, false); }
6. NettyAcceptor#stop()
Project: activemq-artemis
File: NettyAcceptor.java
File: NettyAcceptor.java
@Override public synchronized void stop() { if (channelClazz == null) { return; } if (protocolHandler != null) { protocolHandler.close(); } if (batchFlusherFuture != null) { batchFlusherFuture.cancel(false); flusher.cancel(); flusher = null; batchFlusherFuture = null; } // serverChannelGroup has been unbound in pause() if (serverChannelGroup != null) { serverChannelGroup.close().awaitUninterruptibly(); } if (channelGroup != null) { ChannelGroupFuture future = channelGroup.close().awaitUninterruptibly(); if (!future.isSuccess()) { ActiveMQServerLogger.LOGGER.nettyChannelGroupError(); Iterator<Channel> iterator = future.group().iterator(); while (iterator.hasNext()) { Channel channel = iterator.next(); if (channel.isActive()) { ActiveMQServerLogger.LOGGER.nettyChannelStillOpen(channel, channel.remoteAddress()); } } } } // Shutdown the EventLoopGroup if no new task was added for 100ms or if // 3000ms elapsed. eventLoopGroup.shutdownGracefully(100, 3000, TimeUnit.MILLISECONDS); eventLoopGroup = null; channelClazz = null; for (Connection connection : connections.values()) { listener.connectionDestroyed(connection.getID()); } connections.clear(); if (notificationService != null) { TypedProperties props = new TypedProperties(); props.putSimpleStringProperty(new SimpleString("factory"), new SimpleString(NettyAcceptorFactory.class.getName())); props.putSimpleStringProperty(new SimpleString("host"), new SimpleString(host)); props.putIntProperty(new SimpleString("port"), port); Notification notification = new Notification(null, CoreNotificationType.ACCEPTOR_STOPPED, props); try { notificationService.sendNotification(notification); } catch (Exception e) { logger.warn("failed to send notification", e.getMessage(), e); } } paused = false; }
7. InVMConnector#disconnect()
Project: activemq-artemis
File: InVMConnector.java
File: InVMConnector.java
public void disconnect(final String connectionID) { if (!started) { return; } Connection conn = connections.get(connectionID); if (conn != null) { conn.close(); } }
8. InVMAcceptor#disconnect()
Project: activemq-artemis
File: InVMAcceptor.java
File: InVMAcceptor.java
public void disconnect(final String connectionID) { if (!started) { return; } Connection conn = connections.get(connectionID); if (conn != null) { conn.close(); } }
9. InVMAcceptor#stop()
Project: activemq-artemis
File: InVMAcceptor.java
File: InVMAcceptor.java
@Override public synchronized void stop() { if (!started) { return; } if (!paused) { InVMRegistry.instance.unregisterAcceptor(id); } for (Connection connection : connections.values()) { listener.connectionDestroyed(connection.getID()); } connections.clear(); if (notificationService != null) { TypedProperties props = new TypedProperties(); props.putSimpleStringProperty(new SimpleString("factory"), new SimpleString(InVMAcceptorFactory.class.getName())); props.putIntProperty(new SimpleString("id"), id); Notification notification = new Notification(null, CoreNotificationType.ACCEPTOR_STOPPED, props); try { notificationService.sendNotification(notification); } catch (Exception e) { logger.warn("failed to send notification", e.getMessage(), e); } } started = false; paused = false; }
10. NettyConnector#close()
Project: activemq-artemis
File: NettyConnector.java
File: NettyConnector.java
@Override public synchronized void close() { if (channelClazz == null) { return; } if (batchFlusherFuture != null) { batchFlusherFuture.cancel(false); flusher.cancel(); flusher = null; batchFlusherFuture = null; } bootstrap = null; channelGroup.close().awaitUninterruptibly(); // Shutdown the EventLoopGroup if no new task was added for 100ms or if // 3000ms elapsed. group.shutdownGracefully(100, 3000, TimeUnit.MILLISECONDS); channelClazz = null; for (Connection connection : connections.values()) { listener.connectionDestroyed(connection.getID()); } connections.clear(); }
11. ClientSessionFactoryImpl#createTransportConnection()
Project: activemq-artemis
File: ClientSessionFactoryImpl.java
File: ClientSessionFactoryImpl.java
/** * It will connect to either live or backup accordingly to the current configurations * it will also switch to backup case it can't connect to live and there's a backup configured * * @return */ protected Connection createTransportConnection() { Connection transportConnection = null; try { if (logger.isDebugEnabled()) { logger.debug("Trying to connect with connector = " + connectorFactory + ", parameters = " + connectorConfig.getParams() + " connector = " + connector); } Connector liveConnector = createConnector(connectorFactory, connectorConfig); if ((transportConnection = openTransportConnection(liveConnector)) != null) { // if we can't connect the connect method will return null, hence we have to try the backup connector = liveConnector; } else if (backupConfig != null) { if (logger.isDebugEnabled()) { logger.debug("Trying backup config = " + backupConfig); } ConnectorFactory backupConnectorFactory = instantiateConnectorFactory(backupConfig.getFactoryClassName()); Connector backupConnector = createConnector(backupConnectorFactory, backupConfig); transportConnection = openTransportConnection(backupConnector); if (transportConnection != null) { if (logger.isDebugEnabled()) { logger.debug("Connected to the backup at " + backupConfig); } // Switching backup as live connector = backupConnector; connectorConfig = backupConfig; backupConfig = null; connectorFactory = backupConnectorFactory; } else { if (logger.isDebugEnabled()) { logger.debug("Backup is not active."); } } } } catch (Exception cause) { ActiveMQClientLogger.LOGGER.createConnectorException(cause); if (transportConnection != null) { try { transportConnection.close(); } catch (Throwable t) { } } if (connector != null) { try { connector.close(); } catch (Throwable t) { } } transportConnection = null; connector = null; } return transportConnection; }