class ClusterJMSService implements ClusterService {

    @Override
    public void connect() {
        try {
            final String jmsUserName = clusterParameters.getJmsUserName();
            final String jmsPassword = clusterParameters.getJmsPassword();
            final ConnectionFactory factory;
            switch (clusterParameters.getConnectionMode()) {
                case REMOTE:
                    final String jmsURL = clusterParameters.getProviderUrl();
                    factory = createRemoteConnectionFactory(jmsURL,
                                                            jmsUserName,
                                                            jmsPassword);
                    break;
                case JNDI:
                    final InitialContext context = new InitialContext(clusterParameters.getInitialContextFactory());
                    factory = createJNDIConnectionFactory(context);
                    break;
                default:
                    throw new RuntimeException("Error setting the cluster mode (should be defined as REMOTE or JNDI");
            }
            if (thereIsNoCredentials(jmsUserName, jmsPassword)) {
                connection = factory.createConnection();
            } else {
                connection = factory.createConnection(jmsUserName, jmsPassword);
            }
            connection.setExceptionListener(new JMSExceptionListener());
            connection.start();
        } catch (Exception e) {
            LOGGER.error("Error connecting on JMS " + e.getMessage());
            throw new RuntimeException(e);
        }
    }

    public  ClusterJMSService();

}