// backup node becomes live public synchronized void activate() { if (backup) { backup = false; for (BroadcastGroup broadcastGroup : broadcastGroups.values()) { try { broadcastGroup.start(); broadcastGroup.activate(); } catch (Exception e) { log.warn("unable to start broadcast group " + broadcastGroup.getName(), e); } } for (ClusterConnection clusterConnection : clusterConnections.values()) { try { clusterConnection.activate(); } catch (Exception e) { log.warn("unable to start cluster connection " + clusterConnection.getName(), e); } } for (Bridge bridge : bridges.values()) { try { bridge.start(); } catch (Exception e) { log.warn("unable to start bridge " + bridge.getName(), e); } } } }
// XXX HORNETQ-720 + cluster fixes: needs review @Override public void announceReplicatingBackup(Channel liveChannel) { List<ClusterConnectionConfiguration> configs = this.configuration.getClusterConfigurations(); if (!configs.isEmpty()) { ClusterConnectionConfiguration config = configs.get(0); TransportConfiguration connector = configuration.getConnectorConfigurations().get(config.getConnectorName()); if (connector == null) { log.warn( "No connector with name '" + config.getConnectorName() + "'. backup cannot be announced."); return; } liveChannel.send( new BackupRegistrationMessage( nodeUUID.toString(), connector, configuration.getClusterUser(), configuration.getClusterPassword())); } else { log.warn("no cluster connections defined, unable to announce backup"); } }
@Override protected void tearDown() throws Exception { try { jmsServer2.stop(); server2.stop(); context2.close(); } catch (Throwable e) { log.warn("Can't stop server2", e); } ((HornetQConnectionFactory) cf1).close(); ((HornetQConnectionFactory) cf2).close(); server2 = null; jmsServer2 = null; context2 = null; cf1 = null; try { jmsServer1.stop(); server1.stop(); context1.close(); } catch (Throwable e) { log.warn("Can't stop server2", e); } server1 = null; jmsServer1 = null; context1 = null; super.tearDown(); }
public void flushExecutors() { for (PageSubscription cursor : activeCursors.values()) { cursor.flushExecutors(); } Future future = new Future(); executor.execute(future); while (!future.await(10000)) { log.warn("Waiting cursor provider " + this + " to finish executors " + executor); } }
/** * @param cursorList * @param currentPage * @throws Exception */ private void storePositions(ArrayList<PageSubscription> cursorList, Page currentPage) throws Exception { try { // First step: Move every cursor to the next bookmarked page (that was just created) for (PageSubscription cursor : cursorList) { cursor.confirmPosition(new PagePositionImpl(currentPage.getPageId(), -1)); } while (!storageManager.waitOnOperations(5000)) { log.warn("Couldn't complete operations on IO context " + storageManager.getContext()); } } finally { for (PageSubscription cursor : cursorList) { cursor.enableAutoCleanup(); } } }
// for testing public void clear() { for (Bridge bridge : bridges.values()) { try { bridge.stop(); } catch (Exception e) { log.warn(e.getMessage(), e); } } bridges.clear(); for (ClusterConnection clusterConnection : clusterConnections.values()) { try { clusterConnection.stop(); } catch (Exception e) { e.printStackTrace(); } } clearClusterConnections(); }
public void stop() throws Exception { synchronized (this) { if (!started) { return; } if (clustered) { for (BroadcastGroup group : broadcastGroups.values()) { group.stop(); managementService.unregisterBroadcastGroup(group.getName()); } broadcastGroups.clear(); for (ClusterConnection clusterConnection : clusterConnections.values()) { clusterConnection.stop(); managementService.unregisterCluster(clusterConnection.getName().toString()); } } for (Bridge bridge : bridges.values()) { bridge.stop(); managementService.unregisterBridge(bridge.getName().toString()); } bridges.clear(); } for (ServerLocatorInternal clusterLocator : clusterLocators) { try { clusterLocator.close(); } catch (Exception e) { log.warn( "Error closing serverLocator=" + clusterLocator + ", message=" + e.getMessage(), e); } } clusterLocators.clear(); started = false; clearClusterConnections(); }
private void deployClusterConnection(final ClusterConnectionConfiguration config) throws Exception { if (config.getName() == null) { ClusterManagerImpl.log.warn( "Must specify a unique name for each cluster connection. This one will not be deployed."); return; } if (config.getAddress() == null) { ClusterManagerImpl.log.warn( "Must specify an address for each cluster connection. This one will not be deployed."); return; } TransportConfiguration connector = configuration.getConnectorConfigurations().get(config.getConnectorName()); if (connector == null) { log.warn( "No connector with name '" + config.getConnectorName() + "'. The cluster connection will not be deployed."); return; } if (clusterConnections.containsKey(config.getName())) { log.warn( "Cluster Configuration '" + config.getConnectorName() + "' already exists. The cluster connection will not be deployed.", new Exception("trace")); return; } ClusterConnectionImpl clusterConnection; if (config.getDiscoveryGroupName() != null) { DiscoveryGroupConfiguration dg = configuration.getDiscoveryGroupConfigurations().get(config.getDiscoveryGroupName()); if (dg == null) { ClusterManagerImpl.log.warn( "No discovery group with name '" + config.getDiscoveryGroupName() + "'. The cluster connection will not be deployed."); return; } if (log.isDebugEnabled()) { log.debug( this + " Starting a Discovery Group Cluster Connection, name=" + config.getDiscoveryGroupName() + ", dg=" + dg); } clusterConnection = new ClusterConnectionImpl( this, dg, connector, new SimpleString(config.getName()), new SimpleString(config.getAddress()), config.getMinLargeMessageSize(), config.getClientFailureCheckPeriod(), config.getConnectionTTL(), config.getRetryInterval(), config.getRetryIntervalMultiplier(), config.getMaxRetryInterval(), config.getReconnectAttempts(), config.getCallTimeout(), config.getCallFailoverTimeout(), config.isDuplicateDetection(), config.isForwardWhenNoConsumers(), config.getConfirmationWindowSize(), executorFactory, server, postOffice, managementService, scheduledExecutor, config.getMaxHops(), nodeUUID, backup, server.getConfiguration().getClusterUser(), server.getConfiguration().getClusterPassword(), config.isAllowDirectConnectionsOnly()); } else { TransportConfiguration[] tcConfigs = config.getStaticConnectors() != null ? connectorNameListToArray(config.getStaticConnectors()) : null; if (log.isDebugEnabled()) { log.debug(this + " defining cluster connection towards " + Arrays.toString(tcConfigs)); } clusterConnection = new ClusterConnectionImpl( this, tcConfigs, connector, new SimpleString(config.getName()), new SimpleString(config.getAddress()), config.getMinLargeMessageSize(), config.getClientFailureCheckPeriod(), config.getConnectionTTL(), config.getRetryInterval(), config.getRetryIntervalMultiplier(), config.getMaxRetryInterval(), config.getReconnectAttempts(), config.getCallTimeout(), config.getCallFailoverTimeout(), config.isDuplicateDetection(), config.isForwardWhenNoConsumers(), config.getConfirmationWindowSize(), executorFactory, server, postOffice, managementService, scheduledExecutor, config.getMaxHops(), nodeUUID, backup, server.getConfiguration().getClusterUser(), server.getConfiguration().getClusterPassword(), config.isAllowDirectConnectionsOnly()); } if (defaultClusterConnection == null) { defaultClusterConnection = clusterConnection; } managementService.registerCluster(clusterConnection, config); clusterConnections.put(config.getName(), clusterConnection); if (log.isDebugEnabled()) { log.debug("ClusterConnection.start at " + clusterConnection, new Exception("trace")); } }
public void cleanup() { ArrayList<Page> depagedPages = new ArrayList<Page>(); while (true) { if (pagingStore.lock(100)) { break; } if (!pagingStore.isStarted()) return; } synchronized (this) { try { if (!pagingStore.isStarted()) { return; } if (pagingStore.getNumberOfPages() == 0) { return; } if (log.isDebugEnabled()) { log.debug("Asserting cleanup for address " + this.pagingStore.getAddress()); } ArrayList<PageSubscription> cursorList = new ArrayList<PageSubscription>(); cursorList.addAll(activeCursors.values()); long minPage = checkMinPage(cursorList); if (minPage == pagingStore.getCurrentWritingPage() && pagingStore.getCurrentPage().getNumberOfMessages() > 0) { boolean complete = true; for (PageSubscription cursor : cursorList) { if (!cursor.isComplete(minPage)) { if (log.isDebugEnabled()) { log.debug("Cursor " + cursor + " was considered incomplete at page " + minPage); } complete = false; break; } else { if (log.isDebugEnabled()) { log.debug("Cursor " + cursor + "was considered **complete** at page " + minPage); } } } if (!pagingStore.isStarted()) { return; } if (complete) { if (log.isDebugEnabled()) { log.debug( "Address " + pagingStore.getAddress() + " is leaving page mode as all messages are consumed and acknowledged from the page store"); } pagingStore.forceAnotherPage(); Page currentPage = pagingStore.getCurrentPage(); storePositions(cursorList, currentPage); pagingStore.stopPaging(); // This has to be called after we stopped paging for (PageSubscription cursor : cursorList) { cursor.scheduleCleanupCheck(); } } } for (long i = pagingStore.getFirstPage(); i < minPage; i++) { Page page = pagingStore.depage(); if (page == null) { break; } depagedPages.add(page); } if (pagingStore.getNumberOfPages() == 0 || pagingStore.getNumberOfPages() == 1 && pagingStore.getCurrentPage().getNumberOfMessages() == 0) { pagingStore.stopPaging(); } else { if (log.isTraceEnabled()) { log.trace( "Couldn't cleanup page on address " + this.pagingStore.getAddress() + " as numberOfPages == " + pagingStore.getNumberOfPages() + " and currentPage.numberOfMessages = " + pagingStore.getCurrentPage().getNumberOfMessages()); } } } catch (Exception ex) { log.warn("Couldn't complete cleanup on paging", ex); return; } finally { pagingStore.unlock(); } } try { for (Page depagedPage : depagedPages) { PageCache cache; PagedMessage[] pgdMessages; synchronized (softCache) { cache = softCache.get((long) depagedPage.getPageId()); } if (isTrace) { log.trace("Removing page " + depagedPage.getPageId() + " from page-cache"); } if (cache == null) { // The page is not on cache any more // We need to read the page-file before deleting it // to make sure we remove any large-messages pending storageManager.beforePageRead(); List<PagedMessage> pgdMessagesList = null; try { depagedPage.open(); pgdMessagesList = depagedPage.read(storageManager); } finally { try { depagedPage.close(); } catch (Exception e) { } storageManager.afterPageRead(); } depagedPage.close(); pgdMessages = pgdMessagesList.toArray(new PagedMessage[pgdMessagesList.size()]); } else { pgdMessages = cache.getMessages(); } depagedPage.delete(pgdMessages); synchronized (softCache) { softCache.remove((long) depagedPage.getPageId()); } } } catch (Exception ex) { log.warn("Couldn't complete cleanup on paging", ex); return; } }