Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re"opening" https://github.com/apache/activemq/pull/835 to see test results #1137

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
*/
package org.apache.activemq.transport.discovery.masterslave;

import java.net.URI;
import org.apache.activemq.transport.discovery.simple.SimpleDiscoveryAgent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;

/**
* A static DiscoveryAgent that supports connecting to a Master / Slave tuple
* of brokers.
*
* @deprecated This class is superseded by StaticFailoverDiscoveryAgent and will be removed in a future release
*/
@Deprecated(forRemoval = true)
public class MasterSlaveDiscoveryAgent extends SimpleDiscoveryAgent {

private final static Logger LOG = LoggerFactory.getLogger(MasterSlaveDiscoveryAgent.class);
Expand Down Expand Up @@ -58,6 +62,8 @@ public void setServices(URI services[]) {
}

protected void configureServices() {
LOG.warn("masterSlave is deprecated and will be removed in a future release. Use staticfailover instead.");

if ((msServices == null) || (msServices.length < 2)) {
LOG.error("masterSlave requires at least 2 URIs");
msServices = new String[]{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.net.URI;
import java.util.Map;

@Deprecated(forRemoval = true)
public class MasterSlaveDiscoveryAgentFactory extends DiscoveryAgentFactory {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.transport.discovery.staticfailover;

import java.net.URI;
import org.apache.activemq.transport.discovery.simple.SimpleDiscoveryAgent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A static DiscoveryAgent that supports connecting to an HA tuple of brokers.
*/
public class StaticFailoverDiscoveryAgent extends SimpleDiscoveryAgent {

private final static Logger LOG = LoggerFactory.getLogger(StaticFailoverDiscoveryAgent.class);

private String[] msServices = new String[]{};

@Override
public String[] getServices() {
return msServices;
}

@Override
public void setServices(String services) {
this.msServices = services.split(",");
configureServices();
}

@Override
public void setServices(String services[]) {
this.msServices = services;
configureServices();
}

@Override
public void setServices(URI services[]) {
this.msServices = new String[services.length];
for (int i = 0; i < services.length; i++) {
this.msServices[i] = services[i].toString();
}
configureServices();
}

protected void configureServices() {
if ((msServices == null) || (msServices.length < 2)) {
LOG.error("ha requires at least 2 URIs");
msServices = new String[]{};
throw new IllegalArgumentException("Expecting at least 2 arguments");
}

StringBuffer buf = new StringBuffer();

buf.append("failover:(");

for (int i = 0; i < (msServices.length - 1); i++) {
buf.append(msServices[i]);
buf.append(',');
}
buf.append(msServices[msServices.length - 1]);

buf.append(")?randomize=false&maxReconnectAttempts=0");

super.setServices(new String[]{buf.toString()});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.transport.discovery.staticfailover;

import org.apache.activemq.transport.discovery.DiscoveryAgent;
import org.apache.activemq.transport.discovery.DiscoveryAgentFactory;
import org.apache.activemq.util.IOExceptionSupport;
import org.apache.activemq.util.IntrospectionSupport;
import org.apache.activemq.util.URISupport;
import org.apache.activemq.util.URISupport.CompositeData;

import java.io.IOException;
import java.net.URI;
import java.util.Map;

public class StaticFailoverDiscoveryAgentFactory extends DiscoveryAgentFactory {

@Override
protected DiscoveryAgent doCreateDiscoveryAgent(URI uri) throws IOException {
try {

CompositeData data = URISupport.parseComposite(uri);
Map options = data.getParameters();

StaticFailoverDiscoveryAgent rc = new StaticFailoverDiscoveryAgent();
IntrospectionSupport.setProperties(rc, options);
rc.setServices(data.getComponents());

return rc;

} catch (Throwable e) {
throw IOExceptionSupport.create("Could not create discovery agent: " + uri, e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
</head>
<body>

Static discovery implementation for an HA tuple

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
class=org.apache.activemq.transport.discovery.staticfailover.StaticFailoverDiscoveryAgentFactory
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class DuplexStartNpeTest {
public void reproduceNpe() throws Exception {
BrokerService broker0 = createBroker();

NetworkConnector networkConnector = broker0.addNetworkConnector("masterslave:(" + urlString + "," + urlString + ")");
NetworkConnector networkConnector = broker0.addNetworkConnector("staticfailover:(" + urlString + "," + urlString + ")");
networkConnector.setDuplex(true);
networkConnector.setStaticBridge(true);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.network;

public class MasterSlaveDiscoveryAgentTest extends NetworkConnectionsTest {
@Override
protected NetworkConnector addNetworkConnector() throws Exception {
return localBroker.addNetworkConnector("masterslave:(" + REMOTE_BROKER_TRANSPORT_URI + "," + REMOTE_BROKER_TRANSPORT_URI + ")");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,28 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jakarta.jms.*;
import jakarta.jms.Connection;
import jakarta.jms.Message;
import jakarta.jms.MessageConsumer;
import jakarta.jms.MessageProducer;
import jakarta.jms.Session;

public class NetworkConnectionsTest extends TestCase {
private static final Logger LOG = LoggerFactory.getLogger(NetworkConnectionsTest.class);

private static final String LOCAL_BROKER_TRANSPORT_URI = "tcp://localhost:61616";
private static final String REMOTE_BROKER_TRANSPORT_URI = "tcp://localhost:61617";
protected static final String REMOTE_BROKER_TRANSPORT_URI = "tcp://localhost:61617";
private static final String DESTINATION_NAME = "TEST.RECONNECT";

private BrokerService localBroker;
protected BrokerService localBroker;
private BrokerService remoteBroker;

@Test
public void testIsStarted() throws Exception {
LOG.info("testIsStarted is starting...");

LOG.info("Adding network connector...");
NetworkConnector nc = localBroker.addNetworkConnector("static:(" + REMOTE_BROKER_TRANSPORT_URI + ")");
NetworkConnector nc = addNetworkConnector();
nc.setName("NC1");

LOG.info("Starting network connector...");
Expand Down Expand Up @@ -80,7 +84,7 @@ public void testNetworkConnectionRestart() throws Exception {
LOG.info("testNetworkConnectionRestart is starting...");

LOG.info("Adding network connector...");
NetworkConnector nc = localBroker.addNetworkConnector("static:(" + REMOTE_BROKER_TRANSPORT_URI + ")");
NetworkConnector nc = addNetworkConnector();
nc.setName("NC1");
nc.start();
assertTrue(nc.isStarted());
Expand Down Expand Up @@ -132,7 +136,7 @@ public void testNetworkConnectionReAddURI() throws Exception {
LOG.info("testNetworkConnectionReAddURI is starting...");

LOG.info("Adding network connector 'NC1'...");
NetworkConnector nc = localBroker.addNetworkConnector("static:(" + REMOTE_BROKER_TRANSPORT_URI + ")");
NetworkConnector nc = addNetworkConnector();
nc.setName("NC1");
nc.start();
assertTrue(nc.isStarted());
Expand Down Expand Up @@ -242,4 +246,8 @@ protected void tearDown() throws Exception {
remoteBroker = null;
}
}

protected NetworkConnector addNetworkConnector() throws Exception {
return localBroker.addNetworkConnector("static:(" + REMOTE_BROKER_TRANSPORT_URI + ")");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.network;

public class StaticFailoverDiscoveryAgentTest extends NetworkConnectionsTest {
@Override
protected NetworkConnector addNetworkConnector() throws Exception {
return localBroker.addNetworkConnector("staticfailover:(" + REMOTE_BROKER_TRANSPORT_URI + "," + REMOTE_BROKER_TRANSPORT_URI + ")");
}
}