public JMSContainer(JMSConfiguration config, JMSQueueListener listener) { super(); // configuration this.config = config; // the listener used to handle incoming events setMessageListener(listener); }
@Override public void start() throws JmsException { if (!verified) { verify(jmsFactory, "failed to get a JMSFactory"); verified = true; } if (!isRunning()) { // configure the container configure(); // start it super.start(); // initialize the container initialize(); } }
/** Returns the total number of JMS events consumed by this GeoServer instance. */ public int getConsumedEventsCount() { return (int) jmsQueueListener.getConsumedEvents(); }
@PostConstruct private void init() { // change the default autostartup status to false setAutoStartup(false); // force no concurrent consumers setConcurrentConsumers(1); // set to topic setPubSubDomain(true); // set subscription durability setSubscriptionDurable(Boolean.parseBoolean(config.getConfiguration(TopicConfiguration.DURABLE_KEY).toString())); // set subscription ID setDurableSubscriptionName(config.getConfiguration(JMSConfiguration.INSTANCE_NAME_KEY).toString()); // times to test (connection) max = Integer.parseInt(config.getConfiguration(ConnectionConfiguration.CONNECTION_RETRY_KEY).toString()); // millisecs to wait between tests (connection) maxWait = Long.parseLong(config.getConfiguration(ConnectionConfiguration.CONNECTION_MAXWAIT_KEY).toString()); // check configuration for connection and try to start if needed // configure (needed by initializeBean) configure(); }
if (!isRunning()) { LOGGER.info("Connecting..."); start(); if (isRunning()) { for (int repReg = 1; repReg <= max; ++repReg) { LOGGER.info("Registration..."); if (isRegisteredWithDestination()) { LOGGER.info("Now GeoServer is registered with the destination"); return true; LOGGER.log( Level.SEVERE, "Registration aborted due to a connection problem"); stop(); LOGGER.info("Disconnected"); } else { stop(); LOGGER.info("Disconnected"); return false;
public void connectClient(final boolean connect) throws IOException { if (connect) { if (!container.isRunning()) { if (container.connect()) { if (container.isRunning()) { if (container.disconnect()) { config.putConfiguration( ConnectionConfiguration.CONNECTION_KEY,
/** * try to disconnect * * @return true if success */ public boolean disconnect() { if (isRunning()) { LOGGER.info("Disconnecting..."); stop(); for (int rep = 1; rep <= max; ++rep) { LOGGER.info("Unregistering..."); if (!isRunning()) { LOGGER.info("Succesfully un-registered from the destination topic"); LOGGER.warning("You will (probably) loose next incoming events from other instances!!! (depending on how you have configured the broker)"); return true; } LOGGER.info("Waiting for connection shutdown...(" + rep + "/" + max + ")"); try { Thread.sleep(maxWait); } catch (InterruptedException e) { LOGGER.log(Level.SEVERE,e.getLocalizedMessage(), e); } } } else { LOGGER.severe("Connection is already stopped"); } return false; }
private void configure() { final Properties conf = config.getConfigurations(); // set destination setDestination(jmsFactory.getClientDestination(conf)); // use a CachingConnectionFactory setConnectionFactory(jmsFactory.getConnectionFactory(conf)); }
@Override public void onApplicationEvent(ContextRefreshedEvent event) { if (event.getApplicationContext() == applicationContext) { final String startString = config .getConfiguration(ConnectionConfiguration.CONNECTION_KEY); if (startString != null && startString.equals(ConnectionConfigurationStatus.enabled.toString())) { if (!connect()) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.severe("Unable to connect to the broker, force connection status to disabled"); } // change configuration status config.putConfiguration(ConnectionConfiguration.CONNECTION_KEY, ConnectionConfigurationStatus.disabled.toString()); // store changes to the configuration try { config.storeConfig(); } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } } } } } }
@Override protected void handleListenerSetupFailure(Throwable ex, boolean alreadyRecovered) { super.handleListenerSetupFailure(ex, alreadyRecovered); if (jmsContainerHandleExceptionListener != null) { for (JMSContainerHandlerExceptionListener handler : jmsContainerHandleExceptionListener) { handler.handleListenerSetupFailure(ex, alreadyRecovered); } } }
/** Resets the total number of JMS events consumed by this GeoServer instance. */ public void resetConsumedEventsCount() { jmsQueueListener.resetconsumedevents(); }
@PostConstruct private void init() { // change the default autostartup status to false setAutoStartup(false); // force no concurrent consumers setConcurrentConsumers(1); // set to topic setPubSubDomain(true); // set subscription durability setSubscriptionDurable( Boolean.parseBoolean( config.getConfiguration(TopicConfiguration.DURABLE_KEY).toString())); // set subscription ID setDurableSubscriptionName( config.getConfiguration(JMSConfiguration.INSTANCE_NAME_KEY).toString()); // times to test (connection) max = Integer.parseInt( config.getConfiguration(ConnectionConfiguration.CONNECTION_RETRY_KEY) .toString()); // millisecs to wait between tests (connection) maxWait = Long.parseLong( config.getConfiguration(ConnectionConfiguration.CONNECTION_MAXWAIT_KEY) .toString()); // check configuration for connection and try to start if needed // configure (needed by initializeBean) configure(); }
@Override public void start() throws JmsException { if (!verified) { verify(jmsFactory, "failed to get a JMSFactory"); verified = true; } if (!isRunning()) { // configure the container configure(); // start it super.start(); // initialize the container initialize(); } }
if (!isRunning()) { LOGGER.info("Connecting..."); start(); if (isRunning()) { for (int repReg = 1; repReg <= max; ++repReg) { LOGGER.info("Registration..."); if (isRegisteredWithDestination()) { LOGGER.info("Now GeoServer is registered with the destination"); return true; } else if (repReg == max) { LOGGER.log(Level.SEVERE,"Registration aborted due to a connection problem"); stop(); LOGGER.info("Disconnected"); } else { stop(); LOGGER.info("Disconnected"); return false;
/** * try to disconnect * * @return true if success */ public boolean disconnect() { if (isRunning()) { LOGGER.info("Disconnecting..."); stop(); for (int rep = 1; rep <= max; ++rep) { LOGGER.info("Unregistering..."); if (!isRunning()) { LOGGER.info("Succesfully un-registered from the destination topic"); LOGGER.warning( "You will (probably) loose next incoming events from other instances!!! (depending on how you have configured the broker)"); return true; } LOGGER.info("Waiting for connection shutdown...(" + rep + "/" + max + ")"); try { Thread.sleep(maxWait); } catch (InterruptedException e) { LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); } } } else { LOGGER.severe("Connection is already stopped"); } return false; }
private void configure() { final Properties conf = config.getConfigurations(); // set destination setDestination(jmsFactory.getClientDestination(conf)); // use a CachingConnectionFactory setConnectionFactory(jmsFactory.getConnectionFactory(conf)); }
@Override public void onApplicationEvent(ContextRefreshedEvent event) { if (event.getApplicationContext() == applicationContext) { final String startString = config.getConfiguration(ConnectionConfiguration.CONNECTION_KEY); if (startString != null && startString.equals(ConnectionConfigurationStatus.enabled.toString())) { if (!connect()) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.severe( "Unable to connect to the broker, force connection status to disabled"); } // change configuration status config.putConfiguration( ConnectionConfiguration.CONNECTION_KEY, ConnectionConfigurationStatus.disabled.toString()); // store changes to the configuration try { config.storeConfig(); } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } } } } } }
public JMSContainer(JMSConfiguration config, JMSApplicationListener listener) { super(); // configuration this.config = config; // the listener used to handle incoming events setMessageListener(listener); }
@Override protected void handleListenerSetupFailure(Throwable ex, boolean alreadyRecovered) { super.handleListenerSetupFailure(ex, alreadyRecovered); if (jmsContainerHandleExceptionListener != null) { for (JMSContainerHandlerExceptionListener handler : jmsContainerHandleExceptionListener) { handler.handleListenerSetupFailure(ex, alreadyRecovered); } } }
/** Will wait until the expected number of events was consumed or the timeout is reached. */ public void waitEvents(int number, int timeoutMs) { int loops = timeoutMs / 25; for (int i = 0; i <= loops && jmsQueueListener.getConsumedEvents() < number; i++) { try { // wait for 25 milliseconds Thread.sleep(25); } catch (InterruptedException exception) { // well we got interrupted Thread.currentThread().interrupt(); } } }