Class ClientSessionFactoryImpl
- java.lang.Object
-
- org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl
-
- All Implemented Interfaces:
AutoCloseable,ClientSessionFactory,ClientSessionFactoryInternal,BaseConnectionLifeCycleListener<ClientProtocolManager>,ClientConnectionLifeCycleListener
public class ClientSessionFactoryImpl extends Object implements ClientSessionFactoryInternal, ClientConnectionLifeCycleListener
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classClientSessionFactoryImpl.CloseRunnable
-
Field Summary
Fields Modifier and Type Field Description static Set<ClientSessionFactoryImpl.CloseRunnable>CLOSE_RUNNABLESExceptioncreateTrace
-
Constructor Summary
Constructors Constructor Description ClientSessionFactoryImpl(ServerLocatorInternal serverLocator, TransportConfiguration connectorConfig, ServerLocatorConfig locatorConfig, int reconnectAttempts, Executor threadPool, ScheduledExecutorService scheduledThreadPool, List<Interceptor> incomingInterceptors, List<Interceptor> outgoingInterceptors)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ClientSessionFactoryImpladdFailoverListener(FailoverEventListener listener)Adds a FailoverEventListener to the session which is notified if a failover event occurs on the session.voidaddFailureListener(SessionFailureListener listener)voidcauseExit()voidcleanup()Opposed to close, will call cleanup only on every created session and children objects.voidclose()Closes this factory and any session created by it.voidconnect(int initialConnectAttempts)voidconnect(int initialConnectAttempts, boolean failoverOnInitialConnection)Deprecated.voidconnectionCreated(ActiveMQComponent component, Connection connection, ClientProtocolManager protocol)This method is used both by client connector creation and server connection creation through acceptors.voidconnectionDestroyed(Object connectionID)Called when a connection is destroyed.voidconnectionException(Object connectionID, ActiveMQException me)Called when an error occurs on the connection.voidconnectionReadyForWrites(Object connectionID, boolean ready)protected ConnectorcreateConnector(ConnectorFactory connectorFactory, TransportConfiguration configuration)ClientSessioncreateSession()Creates a non-transacted session.ClientSessioncreateSession(boolean autoCommitSends, boolean autoCommitAcks)Creates a session.ClientSessioncreateSession(boolean xa, boolean autoCommitSends, boolean autoCommitAcks)Creates a session.ClientSessioncreateSession(boolean xa, boolean autoCommitSends, boolean autoCommitAcks, boolean preAcknowledge)Creates a session.ClientSessioncreateSession(boolean autoCommitSends, boolean autoCommitAcks, int ackBatchSize)Creates a session.ClientSessioncreateSession(String username, String password, boolean xa, boolean autoCommitSends, boolean autoCommitAcks, boolean preAcknowledge, int ackBatchSize)Creates an authenticated session.ClientSessioncreateSession(String username, String password, boolean xa, boolean autoCommitSends, boolean autoCommitAcks, boolean preAcknowledge, int ackBatchSize, String clientID)Creates an authenticated session.protected SessionContextcreateSessionChannel(String name, String username, String password, boolean xa, boolean autoCommitSends, boolean autoCommitAcks, boolean preAcknowledge, String clientID)ClientSessioncreateTransactedSession()Creates a transacted session.protected ConnectioncreateTransportConnection()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 configuredClientSessioncreateXASession()Creates a session with XA transaction semantics.protected RemotingConnectionestablishNewConnection()ObjectgetBackupConnector()ConfirmationWindowWarninggetConfirmationWindowWarning()RemotingConnectiongetConnection()Returns the code connection used by this session factory.ObjectgetConnector()TransportConfigurationgetConnectorConfiguration()Return the configuration usedStringgetLiveNodeId()intgetReconnectAttempts()ServerLocatorgetServerLocator()protected ConnectorFactoryinstantiateConnectorFactory(String connectorFactoryClassName)booleanisClosed()LocklockFailover()intnumConnections()intnumSessions()protected ConnectionopenTransportConnection(Connector connector)booleanremoveFailoverListener(FailoverEventListener listener)Removes a FailoverEventListener to the session.booleanremoveFailureListener(SessionFailureListener listener)voidremoveSession(ClientSessionInternal session, boolean failingOver)protected voidschedulePing()voidsetBackupConnector(TransportConfiguration live, TransportConfiguration backUp)voidsetReconnectAttempts(int attempts)voidstopPingingAfterOne()booleanwaitForRetry(long interval)booleanwaitForTopology(long timeout, TimeUnit unit)
-
-
-
Field Detail
-
createTrace
public final Exception createTrace
-
CLOSE_RUNNABLES
public static final Set<ClientSessionFactoryImpl.CloseRunnable> CLOSE_RUNNABLES
-
-
Constructor Detail
-
ClientSessionFactoryImpl
public ClientSessionFactoryImpl(ServerLocatorInternal serverLocator, TransportConfiguration connectorConfig, ServerLocatorConfig locatorConfig, int reconnectAttempts, Executor threadPool, ScheduledExecutorService scheduledThreadPool, List<Interceptor> incomingInterceptors, List<Interceptor> outgoingInterceptors)
-
-
Method Detail
-
lockFailover
public Lock lockFailover()
- Specified by:
lockFailoverin interfaceClientSessionFactoryInternal
-
connect
public void connect(int initialConnectAttempts) throws ActiveMQException- Specified by:
connectin interfaceClientSessionFactoryInternal- Throws:
ActiveMQException
-
connect
@Deprecated public void connect(int initialConnectAttempts, boolean failoverOnInitialConnection) throws ActiveMQException
Deprecated.- Specified by:
connectin interfaceClientSessionFactoryInternal- Throws:
ActiveMQException
-
getConnectorConfiguration
public TransportConfiguration getConnectorConfiguration()
Description copied from interface:ClientSessionFactoryReturn the configuration used- Specified by:
getConnectorConfigurationin interfaceClientSessionFactory- Returns:
-
setBackupConnector
public void setBackupConnector(TransportConfiguration live, TransportConfiguration backUp)
- Specified by:
setBackupConnectorin interfaceClientSessionFactoryInternal
-
getBackupConnector
public Object getBackupConnector()
- Specified by:
getBackupConnectorin interfaceClientSessionFactoryInternal
-
createSession
public ClientSession createSession(String username, String password, boolean xa, boolean autoCommitSends, boolean autoCommitAcks, boolean preAcknowledge, int ackBatchSize, String clientID) throws ActiveMQException
Description copied from interface:ClientSessionFactoryCreates an authenticated session.It is possible to pre-acknowledge messages on the server so that the client can avoid additional network trip to the server to acknowledge messages. While this increase performance, this does not guarantee delivery (as messages can be lost after being pre-acknowledged on the server). Use with caution if your application design permits it.
- Specified by:
createSessionin interfaceClientSessionFactory- Parameters:
username- the user namepassword- the user passwordxa- whether the session support XA transaction semantic or notautoCommitSends-trueto automatically commit message sends,falseto commit manuallyautoCommitAcks-trueto automatically commit message acknowledgement,falseto commit manuallypreAcknowledge-trueto pre-acknowledge messages on the server,falseto let the client acknowledge the messagesclientID- the session clientID- Returns:
- a ClientSession
- Throws:
ActiveMQException- if an exception occurs while creating the session
-
createSession
public ClientSession createSession(String username, String password, boolean xa, boolean autoCommitSends, boolean autoCommitAcks, boolean preAcknowledge, int ackBatchSize) throws ActiveMQException
Description copied from interface:ClientSessionFactoryCreates an authenticated session.It is possible to pre-acknowledge messages on the server so that the client can avoid additional network trip to the server to acknowledge messages. While this increase performance, this does not guarantee delivery (as messages can be lost after being pre-acknowledged on the server). Use with caution if your application design permits it.
- Specified by:
createSessionin interfaceClientSessionFactory- Parameters:
username- the user namepassword- the user passwordxa- whether the session support XA transaction semantic or notautoCommitSends-trueto automatically commit message sends,falseto commit manuallyautoCommitAcks-trueto automatically commit message acknowledgement,falseto commit manuallypreAcknowledge-trueto pre-acknowledge messages on the server,falseto let the client acknowledge the messages- Returns:
- a ClientSession
- Throws:
ActiveMQException- if an exception occurs while creating the session
-
createSession
public ClientSession createSession(boolean autoCommitSends, boolean autoCommitAcks, int ackBatchSize) throws ActiveMQException
Description copied from interface:ClientSessionFactoryCreates a session.- Specified by:
createSessionin interfaceClientSessionFactory- Parameters:
autoCommitSends-trueto automatically commit message sends,falseto commit manuallyautoCommitAcks-trueto automatically commit message acknowledgement,falseto commit manuallyackBatchSize- the batch size of the acknowledgements- Returns:
- a ClientSession
- Throws:
ActiveMQException- if an exception occurs while creating the session
-
createXASession
public ClientSession createXASession() throws ActiveMQException
Description copied from interface:ClientSessionFactoryCreates a session with XA transaction semantics.- Specified by:
createXASessionin interfaceClientSessionFactory- Returns:
- a ClientSession with XA transaction semantics
- Throws:
ActiveMQException- if an exception occurs while creating the session
-
createTransactedSession
public ClientSession createTransactedSession() throws ActiveMQException
Description copied from interface:ClientSessionFactoryCreates a transacted session.It is up to the client to commit when sending and acknowledging messages.
- Specified by:
createTransactedSessionin interfaceClientSessionFactory- Returns:
- a transacted ClientSession
- Throws:
ActiveMQException- if an exception occurs while creating the session- See Also:
ClientSession.commit()
-
createSession
public ClientSession createSession() throws ActiveMQException
Description copied from interface:ClientSessionFactoryCreates a non-transacted session. Message sends and acknowledgements are automatically committed by the session. This does not mean that messages are automatically acknowledged, only that when messages are acknowledged, the session will automatically commit the transaction containing the acknowledgements.- Specified by:
createSessionin interfaceClientSessionFactory- Returns:
- a non-transacted ClientSession
- Throws:
ActiveMQException- if an exception occurs while creating the session
-
createSession
public ClientSession createSession(boolean autoCommitSends, boolean autoCommitAcks) throws ActiveMQException
Description copied from interface:ClientSessionFactoryCreates a session.- Specified by:
createSessionin interfaceClientSessionFactory- Parameters:
autoCommitSends-trueto automatically commit message sends,falseto commit manuallyautoCommitAcks-trueto automatically commit message acknowledgement,falseto commit manually- Returns:
- a ClientSession
- Throws:
ActiveMQException- if an exception occurs while creating the session
-
createSession
public ClientSession createSession(boolean xa, boolean autoCommitSends, boolean autoCommitAcks) throws ActiveMQException
Description copied from interface:ClientSessionFactoryCreates a session.- Specified by:
createSessionin interfaceClientSessionFactory- Parameters:
xa- whether the session support XA transaction semantic or notautoCommitSends-trueto automatically commit message sends,falseto commit manuallyautoCommitAcks-trueto automatically commit message acknowledgement,falseto commit manually- Returns:
- a ClientSession
- Throws:
ActiveMQException- if an exception occurs while creating the session
-
createSession
public ClientSession createSession(boolean xa, boolean autoCommitSends, boolean autoCommitAcks, boolean preAcknowledge) throws ActiveMQException
Description copied from interface:ClientSessionFactoryCreates a session.It is possible to pre-acknowledge messages on the server so that the client can avoid additional network trip to the server to acknowledge messages. While this increase performance, this does not guarantee delivery (as messages can be lost after being pre-acknowledged on the server). Use with caution if your application design permits it.
- Specified by:
createSessionin interfaceClientSessionFactory- Parameters:
xa- whether the session support XA transaction semantic or notautoCommitSends-trueto automatically commit message sends,falseto commit manuallyautoCommitAcks-trueto automatically commit message acknowledgement,falseto commit manuallypreAcknowledge-trueto pre-acknowledge messages on the server,falseto let the client acknowledge the messages- Returns:
- a ClientSession
- Throws:
ActiveMQException- if an exception occurs while creating the session
-
connectionCreated
public void connectionCreated(ActiveMQComponent component, Connection connection, ClientProtocolManager protocol)
Description copied from interface:BaseConnectionLifeCycleListenerThis method is used both by client connector creation and server connection creation through acceptors. On the client side thecomponentparameter is normally passed asnull.Leaving this method here and adding a different one at
ServerConnectionLifeCycleListeneris a compromise for a reasonable split between the activemq-server and activemq-client packages while avoiding to pull too much into activemq-core. The pivotal point keeping us from removing the method isConnectorFactoryand the usage of it.- Specified by:
connectionCreatedin interfaceBaseConnectionLifeCycleListener<ClientProtocolManager>- Parameters:
component- This will probably be anAcceptorand only used on the server side.connection- the connection that has been createdprotocol- the messaging protocol type this connection uses
-
connectionDestroyed
public void connectionDestroyed(Object connectionID)
Description copied from interface:BaseConnectionLifeCycleListenerCalled when a connection is destroyed.- Specified by:
connectionDestroyedin interfaceBaseConnectionLifeCycleListener<ClientProtocolManager>- Parameters:
connectionID- the connection being destroyed.
-
connectionException
public void connectionException(Object connectionID, ActiveMQException me)
Description copied from interface:BaseConnectionLifeCycleListenerCalled when an error occurs on the connection.- Specified by:
connectionExceptionin interfaceBaseConnectionLifeCycleListener<ClientProtocolManager>- Parameters:
connectionID- the id of the connection.me- the exception.
-
removeSession
public void removeSession(ClientSessionInternal session, boolean failingOver)
- Specified by:
removeSessionin interfaceClientSessionFactoryInternal
-
connectionReadyForWrites
public void connectionReadyForWrites(Object connectionID, boolean ready)
- Specified by:
connectionReadyForWritesin interfaceBaseConnectionLifeCycleListener<ClientProtocolManager>
-
numConnections
public int numConnections()
- Specified by:
numConnectionsin interfaceClientSessionFactoryInternal
-
numSessions
public int numSessions()
- Specified by:
numSessionsin interfaceClientSessionFactoryInternal
-
addFailureListener
public void addFailureListener(SessionFailureListener listener)
- Specified by:
addFailureListenerin interfaceClientSessionFactoryInternal
-
removeFailureListener
public boolean removeFailureListener(SessionFailureListener listener)
- Specified by:
removeFailureListenerin interfaceClientSessionFactoryInternal
-
addFailoverListener
public ClientSessionFactoryImpl addFailoverListener(FailoverEventListener listener)
Description copied from interface:ClientSessionFactoryAdds a FailoverEventListener to the session which is notified if a failover event occurs on the session.- Specified by:
addFailoverListenerin interfaceClientSessionFactory- Parameters:
listener- the listener to add- Returns:
- this ClientSessionFactory
-
removeFailoverListener
public boolean removeFailoverListener(FailoverEventListener listener)
Description copied from interface:ClientSessionFactoryRemoves a FailoverEventListener to the session.- Specified by:
removeFailoverListenerin interfaceClientSessionFactory- Parameters:
listener- the listener to remove- Returns:
trueif the listener was removed,falseelse
-
causeExit
public void causeExit()
- Specified by:
causeExitin interfaceClientSessionFactoryInternal
-
close
public void close()
Description copied from interface:ClientSessionFactoryCloses this factory and any session created by it.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceClientSessionFactory
-
cleanup
public void cleanup()
Description copied from interface:ClientSessionFactoryOpposed to close, will call cleanup only on every created session and children objects.- Specified by:
cleanupin interfaceClientSessionFactory
-
waitForTopology
public boolean waitForTopology(long timeout, TimeUnit unit)- Specified by:
waitForTopologyin interfaceClientSessionFactoryInternal
-
isClosed
public boolean isClosed()
- Specified by:
isClosedin interfaceClientSessionFactory- Returns:
trueif the factory is closed,falseotherwise.
-
getServerLocator
public ServerLocator getServerLocator()
- Specified by:
getServerLocatorin interfaceClientSessionFactory- Returns:
- the server locator associated with this session factory
-
stopPingingAfterOne
public void stopPingingAfterOne()
-
waitForRetry
public boolean waitForRetry(long interval)
- Specified by:
waitForRetryin interfaceClientSessionFactoryInternal
-
getConnection
public RemotingConnection getConnection()
Description copied from interface:ClientSessionFactoryReturns the code connection used by this session factory.- Specified by:
getConnectionin interfaceClientSessionFactory- Returns:
- the core connection
-
schedulePing
protected void schedulePing()
-
instantiateConnectorFactory
protected ConnectorFactory instantiateConnectorFactory(String connectorFactoryClassName)
-
setReconnectAttempts
public void setReconnectAttempts(int attempts)
- Specified by:
setReconnectAttemptsin interfaceClientSessionFactoryInternal
-
getReconnectAttempts
public int getReconnectAttempts()
-
getConnector
public Object getConnector()
- Specified by:
getConnectorin interfaceClientSessionFactoryInternal
-
getConfirmationWindowWarning
public ConfirmationWindowWarning getConfirmationWindowWarning()
- Specified by:
getConfirmationWindowWarningin interfaceClientSessionFactoryInternal
-
openTransportConnection
protected Connection openTransportConnection(Connector connector)
-
createConnector
protected Connector createConnector(ConnectorFactory connectorFactory, TransportConfiguration configuration)
-
createTransportConnection
protected Connection createTransportConnection()
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- Returns:
-
establishNewConnection
protected RemotingConnection establishNewConnection()
-
createSessionChannel
protected SessionContext createSessionChannel(String name, String username, String password, boolean xa, boolean autoCommitSends, boolean autoCommitAcks, boolean preAcknowledge, String clientID) throws ActiveMQException
- Throws:
ActiveMQException
-
getLiveNodeId
public String getLiveNodeId()
- Specified by:
getLiveNodeIdin interfaceClientSessionFactoryInternal
-
-